]> granicus.if.org Git - postgis/commitdiff
Recommitted with changes from 1_34 integrated
authorChris Hodgson <chodgson@refractions.net>
Thu, 5 Jan 2006 00:07:39 +0000 (00:07 +0000)
committerChris Hodgson <chodgson@refractions.net>
Thu, 5 Jan 2006 00:07:39 +0000 (00:07 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@2252 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_functions_basic.c

index 6829ca5791401962675126483726bef70eb3b76f..cfed8ce12db7f0338812130505f76db84a0b7150 100644 (file)
@@ -25,6 +25,7 @@ Datum LWGEOM_area_polygon(PG_FUNCTION_ARGS);
 Datum postgis_uses_stats(PG_FUNCTION_ARGS);
 Datum postgis_autocache_bbox(PG_FUNCTION_ARGS);
 Datum postgis_scripts_released(PG_FUNCTION_ARGS);
+Datum postgis_version(PG_FUNCTION_ARGS);
 Datum postgis_lib_version(PG_FUNCTION_ARGS);
 Datum postgis_lib_build_date(PG_FUNCTION_ARGS);
 Datum LWGEOM_length2d_linestring(PG_FUNCTION_ARGS);
@@ -389,6 +390,17 @@ Datum LWGEOM_summary(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(mytext);
 }
 
+PG_FUNCTION_INFO_V1(postgis_version);
+Datum postgis_version(PG_FUNCTION_ARGS)
+{
+       char *ver = POSTGIS_VERSION;
+       text *result;
+       result = lwalloc(VARHDRSZ  + strlen(ver));
+       VARATT_SIZEP(result) = VARHDRSZ + strlen(ver) ;
+       memcpy(VARDATA(result), ver, strlen(ver));
+       PG_RETURN_POINTER(result);
+}
+
 PG_FUNCTION_INFO_V1(postgis_lib_version);
 Datum postgis_lib_version(PG_FUNCTION_ARGS)
 {
@@ -2727,97 +2739,6 @@ Datum LWGEOM_isempty(PG_FUNCTION_ARGS)
 }
 
 
-#if ! USE_GEOS && ! USE_JTS
-
-LWGEOM *lwgeom_centroid(LWGEOM *in);
-
-LWGEOM *
-lwgeom_centroid(LWGEOM *in)
-{
-       int type = lwgeom_getType(in->type);
-       LWPOLY *poly;
-       LWPOINT *point;
-       LWMPOLY *mpoly;
-       POINTARRAY *ring, *pa;
-       POINT3DZ p, *cent;
-       int i,j,k;
-       uint32 num_points_tot = 0;
-       double tot_x=0, tot_y=0, tot_z=0;
-
-       if (type == POLYGONTYPE)
-       {
-               poly = (LWPOLY*)in;
-               for (j=0; j<poly->nrings; j++)
-               {
-                       ring = poly->rings[j];
-                       for (k=0; k<ring->npoints-1; k++)
-                       {
-                               getPoint3dz_p(ring, k, &p);
-                               tot_x += p.x;
-                               tot_y += p.y;
-                               if ( TYPE_HASZ(ring->dims) ) tot_z += p.z;
-                       }
-                       num_points_tot += ring->npoints-1;
-               }
-       }
-       else if ( type == MULTIPOLYGONTYPE )
-       {
-               mpoly = (LWMPOLY*)in;
-               for (i=0; i<mpoly->ngeoms; i++)
-               {
-                       poly = mpoly->geoms[i];
-                       for (j=0; j<poly->nrings; j++)
-                       {
-                               ring = poly->rings[j];
-                               for (k=0; k<ring->npoints-1; k++)
-                               {
-                                       getPoint3dz_p(ring, k, &p);
-                                       tot_x += p.x;
-                                       tot_y += p.y;
-                                       if ( TYPE_HASZ(ring->dims) ) tot_z += p.z;
-                               }
-                               num_points_tot += ring->npoints-1;
-                       }
-               }
-       }
-       else
-       {
-               return NULL;
-       }
-
-       // Setup point
-       cent = lwalloc(sizeof(POINT3DZ));
-       cent->x = tot_x/num_points_tot;
-       cent->y = tot_y/num_points_tot;
-       cent->z = tot_z/num_points_tot;
-
-       // Construct POINTARRAY (paranoia?)
-       pa = pointArray_construct((uchar *)cent, 1, 0, 1);
-
-       // Construct LWPOINT
-       point = lwpoint_construct(in->SRID, NULL, pa);
-
-       return (LWGEOM *)point;
-}
-
-Datum centroid(PG_FUNCTION_ARGS);
-PG_FUNCTION_INFO_V1(centroid);
-Datum centroid(PG_FUNCTION_ARGS)
-{
-       PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-       LWGEOM *lwgeom = lwgeom_deserialize(SERIALIZED_FORM(geom));
-       LWGEOM *centroid = lwgeom_centroid(lwgeom);
-       PG_LWGEOM *ret;
-
-       lwgeom_release(lwgeom);
-       if ( ! centroid ) PG_RETURN_NULL();
-       ret = pglwgeom_serialize(centroid);
-       lwgeom_release((LWGEOM *)centroid);
-       PG_FREE_IF_COPY(geom, 0);
-       PG_RETURN_POINTER(ret);
-}
-#endif // ! USE_GEOS && ! USE_JTS
-
 // Returns a modified [multi]polygon so that no ring segment is 
 // longer then the given distance (computed using 2d).
 // Every input point is kept.