*
**********************************************************************
* $Log$
+ * Revision 1.19 2003/10/29 13:59:40 strk
+ * Added geoscentroid function.
+ *
* Revision 1.18 2003/10/28 15:16:17 strk
* unite_sfunc() from postgis_geos.c renamed to geom_accum() and moved in postgis_fn.c
*
extern char GEOSisRing(Geometry *g1);
extern Geometry *GEOSpointonSurface(Geometry *g1);
+extern Geometry *GEOSGetCentroid(Geometry *g);
Datum relate_full(PG_FUNCTION_ARGS);
Datum isring(PG_FUNCTION_ARGS);
Datum geomequals(PG_FUNCTION_ARGS);
Datum pointonsurface(PG_FUNCTION_ARGS);
+Datum geoscentroid(PG_FUNCTION_ARGS);
PG_RETURN_POINTER(result);
}
+PG_FUNCTION_INFO_V1(geoscentroid);
+Datum geoscentroid(PG_FUNCTION_ARGS)
+{
+ GEOMETRY *geom, *result;
+ Geometry *geosgeom, *geosresult;
+
+ geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+
+ initGEOS(MAXIMUM_ALIGNOF);
+
+ geosgeom = POSTGIS2GEOS(geom);
+
+ geosresult = GEOSGetCentroid(geosgeom);
+ if ( geosresult == NULL )
+ {
+ GEOSdeleteGeometry(geosgeom);
+ elog(ERROR,"GEOS getCentroid() threw an error!");
+ PG_RETURN_NULL();
+ }
+
+ result = GEOS2POSTGIS(geosresult, geom->is3d);
+ if (result == NULL)
+ {
+ GEOSdeleteGeometry(geosgeom);
+ GEOSdeleteGeometry(geosresult);
+ elog(ERROR,"Error in GEOS-PGIS conversion");
+ PG_RETURN_NULL();
+ }
+ GEOSdeleteGeometry(geosgeom);
+ GEOSdeleteGeometry(geosresult);
+
+ PG_RETURN_POINTER(result);
+}
+
//----------------------------------------------
PG_RETURN_NULL(); // never get here
}
+PG_FUNCTION_INFO_V1(pointonsurface);
+Datum geoscentroid(PG_FUNCTION_ARGS)
+{
+ elog(ERROR,"geoscentroid:: operation not implemented - compile PostGIS with GEOS support");
+ PG_RETURN_NULL(); // never get here
+}
+
#endif