From fcf32c2ccfb0a8135d8e1d4adca41de6793c0302 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 16 Aug 2005 21:38:18 +0000 Subject: [PATCH] Added M(point) function git-svn-id: http://svn.osgeo.org/postgis/trunk@1871 b70326c6-7e19-0410-871a-916f4a2858ee --- CHANGES | 1 + lwgeom/lwgeom_ogc.c | 41 +++++++++++++++++++++++++++++++++++++++++ lwgeom/lwpostgis.sql.in | 5 +++++ 3 files changed, 47 insertions(+) diff --git a/CHANGES b/CHANGES index c68e336f5..85264b6d0 100644 --- 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) diff --git a/lwgeom/lwgeom_ogc.c b/lwgeom/lwgeom_ogc.c index f68e6243b..81b86c1b6 100644 --- a/lwgeom/lwgeom_ogc.c +++ b/lwgeom/lwgeom_ogc.c @@ -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; ingeometries; 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 diff --git a/lwgeom/lwpostgis.sql.in b/lwgeom/lwpostgis.sql.in index 13de5aa89..dcb85b48d 100644 --- a/lwgeom/lwpostgis.sql.in +++ b/lwgeom/lwpostgis.sql.in @@ -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' -- 2.50.0