[geos-devel] Status (New Example)

David Blasby dblasby at refractions.net
Fri Apr 4 17:06:22 EST 2003

Yury A. Bychkov wrote:

>I've added a new example that shows how to write a CoordinateList class that
>wraps some other storage method (in this case an array of point_3d) to the CVS.
I've started work on the PostGIS interface to GEOS.  I'm trying to 
decide between the normal
CoordinateList interface (BasicCoordinateList) and a custom CoordinateList:

The "normal list" would be something like: (cf. 
CoordinateListsExample.cpp in examples/)

cl1->add(*(new Coordinate(140,120)));

So, I'd convert my PostGIS point lists into a CoordinateList.  This 
would require
1. about 2* the memory since I'll have my PostGIS POINT3D and GEOS 
Coordinates around.
2. the time required to make the coordinates

The CustomCoordinate (cf. CustomPointCoordinateList.cpp in examples/) 
would allow me
to wrap my PostGIS POINT3D arrays into a CoordinateList.

On first account, this looks more memory efficient and time efficient, 
but upon closer
examination, it looks worse.  Lets look at the getAt(int) function:

Coordinate& CustomPointCoordinateList::getAt(int pos){
    point_3d pt;
    if (pos>=0 && pos<size) {
        return *(new Coordinate(pt.x,pt.y,pt.z));
    } else
        throw "CustomPointCoordinateList exception: can't retrieve 

 From a time perspective, any GEOS function  (like relate() ) that looks 
at each of the points in a
geometry will have to create a new Coordinate() for each PostGIS POINT3D.  
Its even worse if you look at each of the points
in a geometry twice (or more) - you'll construct several Coordanates. 
 This makes the
getAt() function *very* costly.  It also means that coordlist.get(3) 
will return a different object every

For memory usage,  the GEOS function do something like build an index 
(ie. all the Coordinates are stored somewhere),
we are not saving any memory, not to mention we could be leaking memory 
with multiple calls to getAt().

So, it appears that the correct interface to use would be the 
BasicCoordinateList, not a custom one.  


ps. The PostGIS POINT3D is identical to the GEOS geom.h point_3d.

More information about the geos-devel mailing list