[geos-devel] Examples using GEOS from C?
steve.lime at dnr.state.mn.us
Wed Jun 16 23:54:29 EDT 2004
Thanks Dave (and Norman)! Just the help I needed to get started. Let's
see if we can get buffering working...
>>> dblasby at refractions.net 06/16/04 11:23 AM >>>
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
> 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 *)
if (geom->nobjs == 0)
g1 = POSTGIS2GEOS(geom ); // construct GEOS geometry
result = GEOSisSimple(g1);
if (result == 2)
elog(ERROR,"GEOS issimple() threw an
PG_RETURN_NULL(); //never get here
geos-devel mailing list
geos-devel at geos.refractions.net
More information about the geos-devel