[geos-devel] How to create a noded set of linestrings?

Paul Ramsey pramsey at cleverelephant.ca
Wed Apr 2 19:22:46 EDT 2008


Offhand, if you collect them all into one geometrycollection, then run
intersection(collection,empty) you should get something out that does
what you want. You'll have to pick through the results and remove any
empties and points that come out the far side, but the remaining lines
should be ready to pass to your polygonizer...

P

On Wed, Apr 2, 2008 at 3:12 PM, Brent Fraser <bfraser at geoanalytic.com> wrote:
> Hello all,
>
>   I'm really new to using GEOS so please bear with me.
>
>  My basic problem is to create polygons from lines (single
>  segment linestrings).  Using the GEOS example.cpp (and ogr)
>  I've been able to scavange code to read my shapefile of
>  lines, apply the polygonizer to create polygons, then create
>  a shapefile of polygons.  Works great.
>
>  But the lines have a few cases of crossing intersections
>  which I'd like to intersect before polygonization.  How can
>  I get a "noded" set of geometry?  Is it one method in GEOS
>  or something like (btw the code below is NOT logically
>  correct!):
>
>   for (unsigned int i=0; i<input_geoms->size(); i++) {
>   Geometry *g1 = (*input_geoms)[i];
>   for (unsigned int j=i; j<input_geoms->size(); j++) {
>    Geometry *g2 = (*input_geoms)[j];
>    try {
>     if ( g1->crosses(g2) )
>     {
>      Geometry *g3 = g1->Union(g2);
>      geoms->push_back(g3);
>     }else
>     {
>      geoms->push_back(g1);
>     }
>    }
>   }
>   }
>
>  Thanks!
>
>  Brent Fraser
>  GeoAnalytic Inc.
>  Calgary, Alberta
>
>  _______________________________________________
>  geos-devel mailing list
>  geos-devel at lists.osgeo.org
>  http://lists.osgeo.org/mailman/listinfo/geos-devel
>


More information about the geos-devel mailing list