]> granicus.if.org Git - postgis/commitdiff
Added geoscentroid function.
authorSandro Santilli <strk@keybit.net>
Wed, 29 Oct 2003 13:59:40 +0000 (13:59 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 29 Oct 2003 13:59:40 +0000 (13:59 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@339 b70326c6-7e19-0410-871a-916f4a2858ee

postgis_geos.c

index 239d3cb53f3a1752866e5eb4aa0b98cdece82e6c..8f1b035cf1ef0e6abe131b7b36b08c2c622c338d 100644 (file)
@@ -10,6 +10,9 @@
  *
  **********************************************************************
  * $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
  *
@@ -169,6 +172,7 @@ extern  char GEOSisSimple(Geometry *g1);
 extern char GEOSisRing(Geometry *g1);
 
 extern Geometry *GEOSpointonSurface(Geometry *g1);
+extern Geometry *GEOSGetCentroid(Geometry *g);
 
 
 Datum relate_full(PG_FUNCTION_ARGS);
@@ -197,6 +201,7 @@ Datum issimple(PG_FUNCTION_ARGS);
 Datum isring(PG_FUNCTION_ARGS);
 Datum geomequals(PG_FUNCTION_ARGS);
 Datum pointonsurface(PG_FUNCTION_ARGS);
+Datum geoscentroid(PG_FUNCTION_ARGS);
 
 
 
@@ -740,6 +745,40 @@ Datum pointonsurface(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);
+}
+
 
 
 //----------------------------------------------
@@ -1813,5 +1852,12 @@ Datum pointonsurface(PG_FUNCTION_ARGS)
        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