[Gdal-dev] help with OGR->python

Dylan Beaudette dylan at iici.no-ip.org
Fri Feb 4 20:37:59 EST 2005


thanks to everyone who replied...

I think that Frank's comments are right on -- if there was some simple way to 
extract features -- points,lines,polygons, into a list of X,Y pairs it would 
be great.


Perhaps it would be a good idea to state my goal:

I have quite a bit of vector data in shapefile format. However, i would like 
to make my maps with GMT -- which expects vector data in the following 
format: (note that ">" is a flag meaning "start new feature")

>Y,X   #start of feature 1
Y,X
Y,X
Y,X
...
>Y,X   #start of feature 2
Y,X
Y,X
Y,X
...

I need to be able to traverse the geometry of polygons in a shapefile and 
output these coordinate lists with a ">" at the start of each feature.

Any ideas would be quite helpful. Or, if anyone has figured out the 
shapefile->GMT problem in the past... 


-- 
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341


On Friday 04 February 2005 01:22 pm, Frank Warmerdam wrote:
> On Fri, 04 Feb 2005 16:14:56 +0100, Julien Demaria <dem at acri-st.fr> wrote:
> > Dylan,
> >
> > The trick is that in the OGR C and Python APIs, a Geometry can contains
> > others Geometries (accessible with Geometry::GetGeometryCount() and
> > Geometry::GetGeometryRef( i )), and that a Polygon has not directly
> > points,
>
> Folks,
>
> Juliens analysis is quite right.  But clearly it would be handy
> to have more direct ways of extracting the lists of points from a
> geometry without having to do so much iteration.  Perhaps we
> need a method that returns the points of a geometry as a list
> of point tuples.  This method could know about "walking" the
> children of a geometry and build up a sort of list of lists to
> match up with the geometries.
>
> So a polygon would have a list of rings,  each ring would be a
> list of points in that ring.  Each point would be an (x,y,z) tuple.
>
> Howard, would you be interested in implementing such a method
> on the Geometry?  Though when I think about it, it might be more
> efficient to implement it in C.
>
> Best regards,



More information about the Gdal-dev mailing list