[geos-devel] GEOSGetCoordinates() and performance (postgis bug fix)

David Blasby dblasby at refractions.net
Fri Oct 24 13:07:24 EDT 2003


> I was trying to remove unnecessary memory copies and I though we could
> call getCoordinatesRO() in PolyFromGeometry. Why call GEOSGetCoordinates
> and then make a copy of the whole list ? The list returned by
> GEOSGetCoordinates is not needed in the first place and moreover it
> might be not in the format suitable for postgis (in the future - who knows?).

Whenever I call the getCoordinates() function, I immediately make a copy 
of the list by converting it from the GEOS coordinates to PostGIS POINT3Ds.

ALL the PostGIS functions look like this:

1. get input PostGIS geometry/geometries
2. convert the PostGIS geometries to GEOS geometries
3. run the GEOS function
4. delete original GEOS geometries
5. convert the resulting GEOS geometry to PostGIS Geometry
6. delete resulting GEOS geometry

* step 4 may take place at the same time as step 6

So, feel free to have all the Postgis GetCoordinates() access read-only 
version.

> Since GEOSGetCoordinates will return a POINT3D array it could detect
> he's faced with a Polygon or Line or whatever and use an ad-hoc function
> to do the job with less copying possible. What do you think ? Will
> Defining functions like GEOSGetCoordinates(Polygon *),
> GEOSGetCoordinates(LineString *), etc  work for this ?


> Do you think it's worth taking this path ? I'm trying to speedup
> unite() aggregate... 

UNIT probably spending a lot of time building Postgis and GEOS geometries.

1. start with 2 input postgis geometrys
2. convert them to GEOS (O(n) where n=# of subcomponents)
3. run union
4. convert back to postgis (O(n) where n=# of subcomponents)
5. start again at step #1

As you can see there possibly O(n^2) constructions (and certainly O(n^2) 
point copies).

If you take an input dataset of disjoint polygons, you'll see this is 
O(n^2) in terms of geometry convertions and copying.

 >>I'd also like to talk about all those strcmp.

You mean in converting from GEOS->PostGIS geometries?  If you add
a GEOS function (or to Postgis_geos_wrapper.cpp) that returns an integer 
instead of a string for geometrytype you'll be able to remove them.

dave




More information about the geos-devel mailing list