Get all vertices of a polygon using OGR and Python

It depends a bit on your file format and geometry, but in principle the continuation could look like this.

  for p in xrange(points):
        lon, lat, z = ring.GetPoint(p)

FYI - for a complete code example based on the original question, and a script you can use right away .. see https://github.com/spatialguru/NME/blob/master/ogr_explode.py


I just ran into the same problem. I ended using the ExportToJson function in ogr and then reading the Json string into a dictionary. Using my data and the notation from the original question, this looks like:

import json
...
ring_dict = json.loads(ring.ExportToJson())
ring_dict

{'coordinates': [[-4.94237, 55.725449],
  [-4.941922, 55.725585],
  [-4.9420024, 55.7252119],
  [-4.9422001, 55.7250997],
  [-4.9423197, 55.7251789],
  [-4.9425472, 55.7253089],
  [-4.94237, 55.725449]],
 'type': 'LineString'}