]> granicus.if.org Git - postgis/commitdiff
Added M(point) function
authorSandro Santilli <strk@keybit.net>
Tue, 16 Aug 2005 21:38:18 +0000 (21:38 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 16 Aug 2005 21:38:18 +0000 (21:38 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1871 b70326c6-7e19-0410-871a-916f4a2858ee

CHANGES
lwgeom/lwgeom_ogc.c
lwgeom/lwpostgis.sql.in

diff --git a/CHANGES b/CHANGES
index c68e336f5e5b3f5b3e04a7431a2ea864c7cabf63..85264b6d053d85218aa6294a0aa50505243975e4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,7 @@ PostGIS 1.1.0CVS
        - initial implementation of postgis_proc_upgrade script
        - NEW line_substring() function
        - NEW line_locate_point() function
+       - New M(point) function
        - JTS support improvements
        - Chunked GeomUnion implementation (much faster)
 
index f68e6243baaa3fa02b1260074a3b4a51a5f0c97a..81b86c1b6205e35d98474f993bf436f6466db08a 100644 (file)
@@ -49,6 +49,8 @@ Datum LWGEOM_x_point(PG_FUNCTION_ARGS);
 Datum LWGEOM_y_point(PG_FUNCTION_ARGS);
 // ---- Z(geometry)
 Datum LWGEOM_z_point(PG_FUNCTION_ARGS);
+// ---- M(geometry)
+Datum LWGEOM_m_point(PG_FUNCTION_ARGS);
 // ---- StartPoint(geometry)
 Datum LWGEOM_startpoint_linestring(PG_FUNCTION_ARGS);
 // ---- EndPoint(geometry)
@@ -661,6 +663,45 @@ Datum LWGEOM_z_point(PG_FUNCTION_ARGS)
        PG_RETURN_FLOAT8(p.z);
 }
 
+// M(GEOMETRY) -- find the first POINT(..) in GEOMETRY, returns its M value.
+// Return NULL if there is no POINT(..) in GEOMETRY.
+// Return 0 if there is no M in this geometry.
+PG_FUNCTION_INFO_V1(LWGEOM_m_point);
+Datum LWGEOM_m_point(PG_FUNCTION_ARGS)
+{
+       PG_LWGEOM *geom;
+       LWGEOM_INSPECTED *inspected;
+       LWPOINT *point = NULL;
+       POINT3DM p;
+       int i;
+
+       geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+
+       // if there's no M return 0
+       if ( ! TYPE_HASM(geom->type) ) PG_RETURN_FLOAT8(0.0);
+
+       inspected = lwgeom_inspect(SERIALIZED_FORM(geom));
+
+       for (i=0; i<inspected->ngeometries; i++)
+       {
+               point = lwgeom_getpoint_inspected(inspected, i);
+               if ( point ) break;
+       }
+       pfree_inspected(inspected);
+
+       if ( point == NULL ) {
+               PG_FREE_IF_COPY(geom, 0);
+               PG_RETURN_NULL();
+       }
+
+       // Ok, now we have a point, let's get M
+       lwpoint_getPoint3dm_p(point, &p);
+
+       PG_FREE_IF_COPY(geom, 0);
+
+       PG_RETURN_FLOAT8(p.m);
+}
+
 // StartPoint(GEOMETRY) -- find the first linestring in GEOMETRY,
 // return the first point.
 // Return NULL if there is no LINESTRING(..) in GEOMETRY 
index 13de5aa89d5c84665b6df8e7472bb44c56147f93..dcb85b48d787245fe079d37d02df6aba182a7e68 100644 (file)
@@ -1030,6 +1030,11 @@ CREATEFUNCTION Z(geometry)
        AS '@MODULE_FILENAME@','LWGEOM_z_point'
        LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict);
 
+CREATEFUNCTION M(geometry)
+       RETURNS float8
+       AS '@MODULE_FILENAME@','LWGEOM_m_point'
+       LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict);
+
 CREATEFUNCTION StartPoint(geometry)
        RETURNS geometry
        AS '@MODULE_FILENAME@', 'LWGEOM_startpoint_linestring'