[geos-devel] Converting shape files to GEOS geometries
strk at refractions.net
strk at refractions.net
Wed Jan 10 09:19:01 EST 2007
On Wed, Jan 10, 2007 at 02:03:13PM +0100, Jean-Claude Repetto wrote:
> Hello list,
>
> This is a newbie question :
>
> I want to create GEOS geometries from data stored in ESRI shapefiles.
> Shapes are composed of several shells and holes. Shells points are
> clockwise, holes are counterclockwise.
>
> I am using the GEOS C API, as recommended in the documentation at
> <http://geos.refractions.net/ro/doxygen_docs/html/>.
>
> For each part of the shapes, I have successfully created a CoordSeq,
> then a LinearRing. But to create polygons (before unioning them), I need
> to know :
> - if a ring is a shell or a hole. In the C++ API, there is a function
> called IsCCW. But how can I do the test with the C API ?
You can't (w/out a feature addition to it).
> - what hole belongs to what shell. Is there a simplest method than
> creating polygons for each hole and testing if they are within every
> shell ? Or is it preferable to make an union of all the shells, then
> remove the intersections with the holes ? (Maybe the second method
> doesn't work if there are shells inside a hole).
Try with calling polygonize and then:
/*
* Iteratively invoke symdifference on outer rings
* as suggested by Carl Anderson:
* postgis-devel/2005-December/001805.html
*/
> Perhaps there is already a program or a library that can do that ?
PostGIS does it:
o See lwgeom/lwgeom_geos_c.c for using the GEOS CAPI
(doesn't need CCW testing)
o See loader/shp2pgsql.c for getting an WKB or WKT
representation you can feed to GEOS.
--strk;
More information about the geos-devel
mailing list