Hi everyone,<br><br>I want to build a planar graph with a large set of
LineString geometries. When I use OpenJump, it takes 3 or 4 seconds to
determine and create the edges of the graph. I took a look at JTS source
code and this calculation is based on the class UnaryUnionOp .<br>
<br>I have tried to do the same thing in Python (Shapely) with
unary_union (new in release 1.2.16, thanks Sean) and in C (geos C API)
with GEOSUnaryUnion (GEOS_MULTILINESTRING or GEOS_GEOMETRYCOLLECTION
geometry types). <br>
<br>
With the same input data, I have got the same results but it takes about 50 seconds (in C, 1 or 2 seconds more in Python).<br><br>Can anyone explain the differences ?<br><br>
I use the release 3.3.3 of geos , on Mac OS X (10.6, Snow Leopard).<br>
<br>Here is the code I used to do tests in C :<br><br>
#include <stdio.h><br>#include <stdlib.h><br>#include <assert.h><br>#include <geos_c.h><br>#include "shapefil.h"<br><br>GEOSGeometry *SHPObject_to_LineString(SHPObject *object)<br>{<br> GEOSCoordSequence *coords = GEOSCoordSeq_create(object->nVertices,2);<br>
int i;<br><br> assert(object->nParts == 1);<br> for (i=0; i<object->nVertices; i++)<br> {<br> GEOSCoordSeq_setX(coords,i,object->padfX[i]);<br> GEOSCoordSeq_setY(coords,i,object->padfY[i]);<br>
}<br> return GEOSGeom_createLineString(coords);<br>}<br><br>GEOSGeometry *load_shapefile_as_collection(char *pathname)<br>{<br> SHPHandle shape;<br> int type, nobjs, i;<br> double minBounds[4], maxBounds[4];<br>
GEOSGeometry **geometries;<br> GEOSGeometry *collection;<br><br> shape = SHPOpen(pathname,"rb");<br><br> SHPGetInfo(shape,&nobjs,&type,minBounds,maxBounds);<br> assert((type % 10) == SHPT_ARC);<br>
<br> assert(geometries = malloc(nobjs*sizeof(GEOSGeometry *)));<br><br> for (i=0; i<nobjs ;i++)<br> {<br> SHPObject *object = SHPReadObject(shape,i);<br> geometries[i] = SHPObject_to_LineString(object);<br>
}<br><br> SHPClose(shape);<br><br> collection = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, geometries, nobjs);<br> // collection = GEOSGeom_createCollection(GEOS_MULTILINESTRING, geometries, nobjs);<br>
<br> return collection;<br>}<br><br><br>int main(int argc,char *argv[])<br>{<br> GEOSGeometry *collection;<br> GEOSGeometry *unaryunion;<br> GEOSWKTWriter *writer;<br> FILE *output;<br> int g;<br><br> initGEOS(printf,printf);<br>
<br> collection = load_shapefile_as_collection(argv[1]);<br><br> unaryunion = GEOSUnaryUnion(collection);<br> <br>}