[geos-devel] GEOSUnaryUnion performances

Pascal Leroux pa.leroux at gmail.com
Fri Oct 26 06:25:48 PDT 2012


Hi Sandro,

2012/10/26 Sandro Santilli <strk at keybit.net>

> Did you profile only the GEOSUnaryUnion call or the whole script ?
> Could you break profiling into components ?
>

Loading the shapefile is not included in the 50 seconds. In the real code,
there was the C instruction system("date") before and after the
GEOSUnaryUnion call.


> Also can you use the latest development version ?
>
>
I've downloaded and installed the version 3.3.5. It doesn't change anything

[pascal:GraphePlanaire] ./unary_union troncon_de_route.
Ven 26 oct 2012 15:03:16 CEST
Ven 26 oct 2012 15:04:00 CEST



> 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.
>
>
In attached file : the zipped result of (Pyhton instructions)

>>> # linestrings = list of LineString geometries I've used
... wkb = open('linstrings.wkb','w')
>>> for ls in linestrings:
...     print >> wkb, ls.wkb.encode('hex')
...
>>> wkb.closed()



> --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);
> >
> > }
> _______________________________________________
> geos-devel mailing list
> geos-devel at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geos-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geos-devel/attachments/20121026/fa332bbc/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: linestrings.wkb.zip
Type: application/zip
Size: 917377 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/geos-devel/attachments/20121026/fa332bbc/attachment-0001.zip>


More information about the geos-devel mailing list