[geos-devel] GEOSUnaryUnion performances

Sandro Santilli strk at keybit.net
Fri Oct 26 02:14:18 PDT 2012


Did you profile only the GEOSUnaryUnion call or the whole script ?
Could you break profiling into components ?
Also can you use the latest development version ?

Finally: if any robustness issue is encountered, the union will be
tried again after performing costly snapping operations, so it would
be interesting to see if either GEOS or JTS is getting any of that
(will take adding or enabling debugging lines in the code). 

It'll help to make very sure the two engines do start from the same
geometries. WKB would be the best way to get that.
You can also produce an XML based tester as input, which would then be
used by both JTS testrunner and GEOS XMLTestRunner scripts, for easier
comparison. HEXWKB would be supported there.

--strk;

On Fri, Oct 26, 2012 at 10:00:27AM +0200, Pascal Leroux wrote:
> Hi everyone,
> 
> 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 .
> 
> 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).
> 
> 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).
> 
> Can anyone explain the differences ?
> 
> I use the release 3.3.3 of geos , on Mac OS X (10.6, Snow Leopard).
> 
> Here is the code I used to do tests in C :
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <assert.h>
> #include <geos_c.h>
> #include "shapefil.h"
> 
> GEOSGeometry *SHPObject_to_LineString(SHPObject *object)
> {
>     GEOSCoordSequence *coords = GEOSCoordSeq_create(object->nVertices,2);
>     int i;
> 
>     assert(object->nParts == 1);
>     for (i=0; i<object->nVertices; i++)
>     {
>         GEOSCoordSeq_setX(coords,i,object->padfX[i]);
>         GEOSCoordSeq_setY(coords,i,object->padfY[i]);
>     }
>     return GEOSGeom_createLineString(coords);
> }
> 
> GEOSGeometry *load_shapefile_as_collection(char *pathname)
> {
>     SHPHandle shape;
>     int type, nobjs, i;
>     double minBounds[4], maxBounds[4];
>     GEOSGeometry **geometries;
>     GEOSGeometry *collection;
> 
>     shape = SHPOpen(pathname,"rb");
> 
>     SHPGetInfo(shape,&nobjs,&type,minBounds,maxBounds);
>     assert((type % 10) == SHPT_ARC);
> 
>     assert(geometries = malloc(nobjs*sizeof(GEOSGeometry *)));
> 
>     for (i=0; i<nobjs ;i++)
>     {
>         SHPObject *object = SHPReadObject(shape,i);
>         geometries[i] = SHPObject_to_LineString(object);
>     }
> 
>     SHPClose(shape);
> 
>     collection = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION,
> geometries, nobjs);
>     // collection = GEOSGeom_createCollection(GEOS_MULTILINESTRING,
> geometries, nobjs);
> 
>     return collection;
> }
> 
> 
> int main(int argc,char *argv[])
> {
>     GEOSGeometry *collection;
>     GEOSGeometry *unaryunion;
>     GEOSWKTWriter *writer;
>     FILE *output;
>     int g;
> 
>     initGEOS(printf,printf);
> 
>     collection = load_shapefile_as_collection(argv[1]);
> 
>     unaryunion = GEOSUnaryUnion(collection);
> 
> }


More information about the geos-devel mailing list