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

Brent Fraser bfraser at geoanalytic.com
Thu Apr 3 17:24:30 EDT 2008


Paul,

  Thanks for the info.  I've switched to the GEOS C api (to
quote the doxygen doc: "If you prefer troubles you can use
the C++ interface.")

Since
    gNodedGeoms = GEOSIntersection( *gGeoms, NULL );

causes a crash, how would I create an empty geometry
collection?


And for comparision, the JTS Developer's Guide gives the
following example:

-------------
A simple trick for noding a group of LineStrings is to union
them together. It turns out that the unioning process will
node the LineStrings for us. For example, the following code
will node a collection of LineStrings:

    Collection lineStrings = . . .
    Geometry nodedLineStrings = (LineString)
lineStrings.get(0);
    for (int i = 1; i < lineStrings.size(); i++) {
        nodedLineStrings =
nodedLineStrings.union((LineString)lineStrings.get(i));
    }
-------------
But I'm not sure what the syntax would be in C (or C++).

Thanks!
Brent Fraser
GeoAnalytic Inc.
Calgary, Alberta

----- Original Message ----- 
From: "Paul Ramsey" <pramsey at cleverelephant.ca>
To: "GEOS Development List" <geos-devel at lists.osgeo.org>
Sent: Wednesday, April 02, 2008 5:22 PM
Subject: Re: [geos-devel] How to create a noded set of
linestrings?


> 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
> >
> _______________________________________________
> 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