From: Sandro Santilli Date: Thu, 28 Oct 2004 09:29:38 +0000 (+0000) Subject: Added makeline(point, point). Changed LineFromMultiPoint definition. X-Git-Tag: pgis_1_0_0RC1~232 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d48970b37f2350a8eec9ae4f9ffc9748adea02d;p=postgis Added makeline(point, point). Changed LineFromMultiPoint definition. git-svn-id: http://svn.osgeo.org/postgis/trunk@1060 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/postgis.xml b/doc/postgis.xml index 71595142e..75b6c71b4 100644 --- a/doc/postgis.xml +++ b/doc/postgis.xml @@ -3717,6 +3717,15 @@ FROM geometry_table; + + MakeLine(geometry, geometry) + + + Creates a Linestring from the two given point + geometries. + + + LineFromMultiPoint(multipoint) diff --git a/lwgeom/lwgeom_functions_basic.c b/lwgeom/lwgeom_functions_basic.c index 37de87ea9..b45eb8624 100644 --- a/lwgeom/lwgeom_functions_basic.c +++ b/lwgeom/lwgeom_functions_basic.c @@ -55,6 +55,7 @@ Datum LWGEOM_makepoint(PG_FUNCTION_ARGS); Datum LWGEOM_makepoint3dm(PG_FUNCTION_ARGS); Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS); Datum LWGEOM_makeline(PG_FUNCTION_ARGS); +Datum LWGEOM_line_from_mpoint(PG_FUNCTION_ARGS); Datum LWGEOM_addpoint(PG_FUNCTION_ARGS); @@ -1823,11 +1824,11 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS) } /* - * makeline ( GEOMETRY ) returns a LINE formed by + * LineFromMultiPoint ( GEOMETRY ) returns a LINE formed by * all the points in the in given multipoint. */ -PG_FUNCTION_INFO_V1(LWGEOM_makeline); -Datum LWGEOM_makeline(PG_FUNCTION_ARGS) +PG_FUNCTION_INFO_V1(LWGEOM_line_from_mpoint); +Datum LWGEOM_line_from_mpoint(PG_FUNCTION_ARGS) { PG_LWGEOM *ingeom, *result; LWLINE *lwline; @@ -1974,6 +1975,49 @@ Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS) PG_RETURN_POINTER(result); } +/* + * makeline ( GEOMETRY, GEOMETRY ) returns a LINESTRIN segment + * formed by the given point geometries. + */ +PG_FUNCTION_INFO_V1(LWGEOM_makeline); +Datum LWGEOM_makeline(PG_FUNCTION_ARGS) +{ + PG_LWGEOM *pglwg1, *pglwg2; + PG_LWGEOM *result=NULL; + LWPOINT *lwpoints[2]; + LWLINE *outline; + +#ifdef DEBUG + elog(NOTICE, "LWGEOM_makeline called"); +#endif + + /* Get input datum */ + pglwg1 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + pglwg2 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + + if ( ! TYPE_GETTYPE(pglwg1->type) == POINTTYPE || + ! TYPE_GETTYPE(pglwg2->type) == POINTTYPE ) + { + elog(ERROR, "Input geometries must be points"); + PG_RETURN_NULL(); + } + + if ( lwgeom_getSRID(pglwg1) != lwgeom_getSRID(pglwg2) ) + { + elog(ERROR, "Operation with two geometries with different SRIDs\n"); + PG_RETURN_NULL(); + } + + lwpoints[0] = lwpoint_deserialize(SERIALIZED_FORM(pglwg1)); + lwpoints[1] = lwpoint_deserialize(SERIALIZED_FORM(pglwg2)); + + outline = lwline_from_lwpointarray(lwpoints[0]->SRID, 2, lwpoints); + + result = pglwgeom_serialize((LWGEOM *)outline); + + PG_RETURN_POINTER(result); +} + // makes a polygon of the expanded features bvol - 1st point = LL 3rd=UR // 2d only. (3d might be worth adding). // create new geometry of type polygon, 1 ring, 5 points @@ -2405,7 +2449,7 @@ Datum LWGEOM_addpoint(PG_FUNCTION_ARGS) outline = lwline_addpoint(line, point, where); - result = pglwgeom_serialize(outline); + result = pglwgeom_serialize((LWGEOM *)outline); PG_RETURN_POINTER(result); } diff --git a/lwgeom/lwpostgis.sql.in b/lwgeom/lwpostgis.sql.in index 8fb88f220..ad23cdba7 100644 --- a/lwgeom/lwpostgis.sql.in +++ b/lwgeom/lwpostgis.sql.in @@ -1693,6 +1693,11 @@ CREATEFUNCTION makeline_garray (geometry[]) LANGUAGE 'C'; CREATEFUNCTION LineFromMultiPoint(geometry) + RETURNS geometry + AS '@MODULE_FILENAME@', 'LWGEOM_line_from_mpoint' + LANGUAGE 'C' WITH (iscachable,isstrict); + +CREATEFUNCTION makeline(geometry, geometry) RETURNS geometry AS '@MODULE_FILENAME@', 'LWGEOM_makeline' LANGUAGE 'C' WITH (iscachable,isstrict);