<br>Hi Sandro,<br><br><div class="gmail_quote">2012/10/26 Sandro Santilli <span dir="ltr"><<a href="mailto:strk@keybit.net" target="_blank">strk@keybit.net</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Did you profile only the GEOSUnaryUnion call or the whole script ?<br>
Could you break profiling into components ?<br></blockquote><div><br>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.<br>
 </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Also can you use the latest development version ?<br>
<br></blockquote><div><br>I've downloaded and installed the version 3.3.5. It doesn't change anything <br><br><font face="courier new,monospace">[pascal:GraphePlanaire] ./unary_union troncon_de_route.<br>Ven 26 oct 2012 15:03:16 CEST<br>
Ven 26 oct 2012 15:04:00 CEST<br></font><br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Finally: if any robustness issue is encountered, the union will be<br>
tried again after performing costly snapping operations, so it would<br>
be interesting to see if either GEOS or JTS is getting any of that<br>
(will take adding or enabling debugging lines in the code).<br>
<br>
It'll help to make very sure the two engines do start from the same<br>
geometries. WKB would be the best way to get that.<br>
You can also produce an XML based tester as input, which would then be<br>
used by both JTS testrunner and GEOS XMLTestRunner scripts, for easier<br>
comparison. HEXWKB would be supported there.<br>
<br></blockquote><div><br>In attached file : the zipped result of (Pyhton instructions)<br><br><span style="font-family:courier new,monospace">>>> # linestrings = list of LineString geometries I've used<br>... wkb = open('linstrings.wkb','w')<br>
>>> for ls in linestrings:<br>...     print >> wkb, ls.wkb.encode('hex')<br>...<br>>>> wkb.closed()<br></span><br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

--strk;<br>
<div><div class="h5"><br>
On Fri, Oct 26, 2012 at 10:00:27AM +0200, Pascal Leroux wrote:<br>
> Hi everyone,<br>
><br>
> I want to build a planar graph with a large set of LineString geometries.<br>
> When I use OpenJump, it takes 3 or 4 seconds to determine and create the<br>
> edges of the graph. I took a look at JTS source code and this calculation<br>
> is based on the class UnaryUnionOp .<br>
><br>
> I have tried to do the same thing in Python (Shapely) with unary_union (new<br>
> in release 1.2.16, thanks Sean) and in C (geos C API) with GEOSUnaryUnion<br>
> (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<br>
> 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,<br>
> geometries, nobjs);<br>
>     // collection = GEOSGeom_createCollection(GEOS_MULTILINESTRING,<br>
> 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>
> }<br>
</div></div>_______________________________________________<br>
geos-devel mailing list<br>
<a href="mailto:geos-devel@lists.osgeo.org">geos-devel@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/geos-devel" target="_blank">http://lists.osgeo.org/mailman/listinfo/geos-devel</a><br>
</blockquote></div><br>