From: Sandro Santilli Date: Wed, 29 Oct 2003 13:59:40 +0000 (+0000) Subject: Added geoscentroid function. X-Git-Tag: pgis_0_8_0~43 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8be1b8d0d238f69b8ca534bbf0981442e4d520d4;p=postgis Added geoscentroid function. git-svn-id: http://svn.osgeo.org/postgis/trunk@339 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis_geos.c b/postgis_geos.c index 239d3cb53..8f1b035cf 100644 --- a/postgis_geos.c +++ b/postgis_geos.c @@ -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