[geos-devel] Examples using GEOS from C?
dblasby at refractions.net
Wed Jun 16 12:23:26 EDT 2004
Steve Lime wrote:
> Hi Folks: I'm starting to tinker with using GEOS with MapServer. I'm
> wondering if folks have any examples of using it from within straight C
> code. I'd also be interested in learning more about the best ways to
> operate on non-GEOS geometries. I've heard folks mention that there
> should be more efficient ways than converting between representations.
PostGIS is a C program, so if you look in there you'll see an example.
Basically, I wrote a very very simple C++ library
(postgis_geos_wrapper.cpp) that interfaced with GEOS. If you tag your
C++ functions with 'extern "C"', you'll be able to call them from a C
You'll have to write your own constructors that take the mapserv
ShapeObjs and convert to GEOS geometries. You can either construct
brand-new real-live GEOS Coordinates, or you can wrap the ShapeObj
coordinates with a CoordinateList class.
extern "C" char GEOSisSimple(Geometry *g1);
char GEOSisSimple(Geometry *g1)
catch (GEOSException *ge)
// give error message as a NOTICE
return 2; // error occured
return 2; //error occured
GEOMETRY *geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
if (geom->nobjs == 0)
g1 = POSTGIS2GEOS(geom ); // construct GEOS geometry
result = GEOSisSimple(g1);
if (result == 2)
elog(ERROR,"GEOS issimple() threw an error!");
PG_RETURN_NULL(); //never get here
More information about the geos-devel