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

Sandro Mani manisandro at gmail.com
Thu Jan 8 04:08:12 PST 2015


On 08.01.2015 12:37, Sandro Santilli wrote:
> On Wed, Jan 07, 2015 at 04:48:24PM +0100, Sandro Mani wrote:
>> So this would mean an API like:
>>
>> /** Create context handle **/
>> extern GEOSContextHandle_t GEOS_DLL initGEOS_r(GEOSMessageHandler
>> notice_function, GEOSMessageHandler error_function);
>> extern GEOSContextHandle_t GEOS_DLL
>> initGEOS_r_fixedPrecision(GEOSMessageHandler notice_function,
>> GEOSMessageHandler error_function, double scale);
> I don't think it's needed to create a context with non-default
> factory, given we have methods to change it later.
>
>> /** Set context handle precision model **/
>> void GEOSContextHandle_t
>> GEOSContext_setPrecisionDouble(GEOSContextHandle_t* handle);
>> void GEOSContextHandle_t
>> GEOSContext_setPrecisionFixed(GEOSContextHandle_t* handle, double
>> scale);
> Yes.
>
>> /** Precision reducer **/
>> extern GEOSGeometryPrecisionReducer* GEOSGeometryPrecisionReducer_create();
>> extern GEOSGeometry*
>> GEOSGeometryPrecisionReducer_reduce(GEOSGeometryPrecisionReducer*
>> reducer, GEOSGeometry* geometry);
>> extern void
>> GEOSGeometryPrecisionReducer_destroy(GEOSGeometryPrecisionReducer*
>> reducer);
> Or, just calling GEOSGeom_clone() after setting context precision
> to fixed ?
This would be very compact, though possibly it makes it quite 
un-inutitive for users to even realize that the reduce functionality is 
implicitly exposed through the C API. Some comments could fix that though.
>
>> The changes needed for reference counting are somewhat invasive IMO.
> True. And I'm not sure it can be done w/out touching the C++ API
> either.
Unless I'm missing something, it should be doable, by keeping the 
reference count in GEOSContextHandleInternal and doing all the couning 
in geos_ts_c.cpp.


So to wrap up, things currently look as follows (which I actually think 
is quite neat!):


/** GEOSContextHandle_t internally keeps a reference count, set to 1 on 
creation
  * - *All* methods producing a GEOSGeom increase the reference count
  * - GEOSGeom_destroy decreses the GeometryFactory reference count, if 
0, it destroys the context
  * - finishGEOS_r decreses the reference count, if 0, it destroys the 
context
  */

/** GEOSGeom_clone() clones the geometry and applies 
PrecisionReducer::reduce
  *  if the PrecisionModel of the current context is different than the 
that of
  *  the passed geometry
  */

/** Set context handle precision model **/
void GEOSContextHandle_t 
GEOSContext_setPrecisionDouble(GEOSContextHandle_t* handle);
void GEOSContextHandle_t 
GEOSContext_setPrecisionFixed(GEOSContextHandle_t* handle, double scale);



More information about the geos-devel mailing list