[geos-devel] Exposing PrecisionModel, GeometryPrecisionReducer in the C API

Sandro Mani manisandro at gmail.com
Wed Jan 7 03:28:17 PST 2015

On 07.01.2015 12:00, Sandro Santilli wrote:
> On Wed, Jan 07, 2015 at 09:54:32AM +0100, Sandro Mani wrote:
>> GeometryFactory does make a copy of the PrecisionModel passed by the
>> user, so it is not necessary to keep the copy around.
> Great
>> By this you mean not exposting the PrecisionModel at all, and
>> instead doing something like this?:
>> /** Geometry Factory **/
>> typedef struct GEOSGeometryFactory_t GEOSGeometryFactory;
>> extern GEOSGeometryFactory* GEOSGeometryFactory_create(int SRID);
>> extern GEOSGeometryFactory*
>> GEOSGeometryFactory_create_doublePrecision(int SRID);
>> extern GEOSGeometryFactory*
>> GEOSGeometryFactory_create_singlePrecision(int SRID);
>> extern GEOSGeometryFactory*
>> GEOSGeometryFactory_create_fixedPrecision(int SRID, double scale);
>> extern void GEOSGeometryFactory_destroy(GEOSGeometryFactory* factory);
>> I'm ok with that, it is actually cleaner.
> Yes. I'm not sure it's worth having support for single-precision,
> and I'd avoid having two different signatures to create a double-precision.
>   extern GEOSGeometryFactory*
>   GEOSGeometryFactory_createDoublePrecision(int SRID);
>   extern GEOSGeometryFactory*
>   GEOSGeometryFactory_createFixedPrecision(int SRID, double scale);
Ah yes indeed GEOSGeometryFactory_create is equivalent to 
> Further thinking about it, I wonder if there's a chance to also hide
> the GeometryFactory object completely. I guess the main reason to expose
> it is to give caller a way to manage it's lifetime, otherwise it could
> be set into the Context before creating any geometry.
I think the main reason for exposing it is to be able to work with 
geometries with different PrecisionModels in the same session. This is 
actually my case: I have a QGIS plugin which take the GEOS Geometries 
from QgsGeometry, which are created with the default (aka double) 
precision, and then I perform operations on those geometries with 
reduced precision. This actually makes me realize that I really should 
be handing back a GEOSGeometry to QgsGeometry with the original 
PrecisionModel, so ideally there would also be a

extern GEOSGeometryPrecisionReducer* 
GEOSGeometryPrecisionReducer_create(double precision);

which does not change the GEOSGeometryFactory of the reduced geometry. 
Or otherwise a function which allows to change the PrecisionModel of a 
Geometry a posteriori.

> Could lifetime
> be taken care of by the C-API with reference counting ? Aren't Geometry
> objects (the sole referers to GeometryFactory objects) solely constructable
> and destroyable via C-API methods ? In that case such methods could
> increase/decrease refcounts and delete no-more-needed ones.
> Refcounting hiding would further simplify the interface because you would
> not need to add new constructors signatures for making actual use of
> the reduced precision.

More information about the geos-devel mailing list