[geos-devel] Design of exception-trapping wrapper

David Blasby dblasby at refractions.net
Fri Apr 11 20:40:17 EDT 2003

> No - I think it would be pretty easy.  We could add another class to 
> GEOS.  It wouldnt even have to be compiled unless you're using postgis... 

I forgot to more detail in this.  This would keep the wrapper down to 
its own little class in GEOS:

// GeometryWrapper  -- passes off execution to the appropriate function.
//   any exception are caught.
// for GEOS functions that return a bool, these return 0 (false), 1 
(true), 2 (error)
//  for GEOS functions that return an object, these return the object or 
NULL (error)
class GeometryWrapper
    char   contains(Geometry *g1, Geometry *g2);
   // perhaps put a GeometryFactory in here too

and in the postgis_wrapper.cpp:

GeometryWrapper *wrapper  = new GeometryWrapper();

char GEOScontains(Geometry *g1, Geometry *g2)
    return   wrapper->contains(g1,g2);

postgis_geos.c would look like this:

// overlaps(GEOMETRY g1,GEOMETRY g2)
// returns  if GEOS::g1->overlaps(g2) returns true
// throws an error (elog(ERROR,...)) if GEOS throws an error
Datum overlaps(PG_FUNCTION_ARGS)
   GEOMETRY        *geom1 = (GEOMETRY *)  
   GEOMETRY        *geom2 = (GEOMETRY *)  

   Geometry *g1,*g2;
   bool result;


   g1 =     POSTGIS2GEOS(geom1 );
   g2 =     POSTGIS2GEOS(geom2 );


   result = GEOSrelateOverlaps(g1,g2);
   if (result == 2)
       elog(ERROR,"GEOS overlaps() threw an error!");
       PG_RETURN_NULL(); //never get here


More information about the geos-devel mailing list