[geos-devel] GEOS C API Suggestions

strk at refractions.net strk at refractions.net
Fri Oct 21 04:42:29 EDT 2005


On Sat, Oct 15, 2005 at 11:13:29PM -0400, Frank Warmerdam wrote:
...
>  5) I think it would be nice to provide entry points to directly
>      create and destroy geometries however that is not really critical.
>      However, I found it odd that calls like GEOS_GetNumCoordinate()
>      and GEOSGetNumGeometries() were provided when no calls
>      to get coordinates or geometries were provided.

I've been thinking about this. Geometry destruction is available
alread, so we're talking about fine-grained construction and
inspection.

In order to implement this the least we must do is provide
a CoordinateSequence abstract data type. To allow for internal
storage changes this might expose the following interfaces:

	/*
	 * Create a coordinate sequence specifying number and
	 * dimensions of coordinates
	 */
	GEOSCoordSeq GEOSCoordSeq_create(uint size, uint dims);

	/* Set ordinate values */
	void GEOSCoordSeq_setX(uint idx, double value);
	void GEOSCoordSeq_setY(uint idx, double value);
	void GEOSCoordSeq_setZ(uint idx, double value);
	void GEOSCoordSeq_setOrdinate(uint idx, uint dim, double value);

	/* Get ordinate values */
	double GEOSCoordSeq_getX(uint idx);
	double GEOSCoordSeq_getY(uint idx);
	double GEOSCoordSeq_getZ(uint idx);
	double GEOSCoordSeq_getOrdinate(uint idx, uint dim);

	/* Copy a coordinate sequence */
	GEOSCoordSeq GEOSCoordSeq_clone(GEOSCoordSeq);

	/* Destroy a coordinate sequence */
	void GEOSCoordSeq_destroy(GEOSCoordSeq);

Then, we might construct specific geometry types. 

	GEOSGeom GEOSGeom_createPoint(GEOSCoordSeq cs);
	GEOSGeom GEOSGeom_createLineString(GEOSCoordSeq cs);
	GEOSGeom GEOSGeom_createLinearRing(GEOSCoordSeq cs);

And extract coordinates:

	GEOSCoordSeq GEOSGeom_getCoordSeq(GEOSGeom g);

Finally, to complete constructors:

	GEOSGeom GEOSGeom_createPolygon(GEOSGeom shell,
		GEOSGeom *holes, uint nholes)

The following could replace GEOSMakeCollection, to be more consistent:

	GEOSGeom GEOSGeom_createCollection(int type,
		GEOSGeom *g, uint ngeoms);

About memory management the safer thing would be make extractors
return newly allocated objects and constructors copy input objects.

Comments ?

--strk;



More information about the geos-devel mailing list