]> granicus.if.org Git - postgis/commitdiff
PointN() ported.
authorSandro Santilli <strk@keybit.net>
Tue, 24 Aug 2004 15:50:04 +0000 (15:50 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 24 Aug 2004 15:50:04 +0000 (15:50 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@740 b70326c6-7e19-0410-871a-916f4a2858ee

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

index 661a298f24bf813ce33128f69d99550b0c206ee1..3572c5af8f73796909fe17a437fbadfff2fc53bc 100644 (file)
@@ -28,7 +28,6 @@ FUNC: KEEPING FUNCTION: [envelope(geometry)]
 FUNC: KEEPING FUNCTION: [x(geometry)]
 FUNC: KEEPING FUNCTION: [y(geometry)]
 FUNC: KEEPING FUNCTION: [z(geometry)]
-FUNC: KEEPING FUNCTION: [pointn(geometry, integer)]
 FUNC: KEEPING FUNCTION: [max_distance(geometry, geometry)]
 FUNC: KEEPING FUNCTION: [optimistic_overlap(geometry, geometry, double precision)]
 FUNC: KEEPING FUNCTION: [segmentize(geometry, double precision)]
index 87954e9f47a2b7d5d3fb8eee0f268aba2e123e9d..818957937ec2fd4c43f14670cf5245bb290747e8 100644 (file)
@@ -41,6 +41,8 @@ Datum LWGEOM_exteriorring_polygon(PG_FUNCTION_ARGS);
 Datum LWGEOM_interiorringn_polygon(PG_FUNCTION_ARGS);
 // ---- NumInteriorRings(geometry)
 Datum LWGEOM_numinteriorrings_polygon(PG_FUNCTION_ARGS);
+// ---- PointN(geometry, integer)
+Datum LWGEOM_pointn_linestring(PG_FUNCTION_ARGS);
 
 
 // internal
@@ -387,6 +389,7 @@ Datum LWGEOM_interiorringn_polygon(PG_FUNCTION_ARGS)
                pfree_inspected(inspected);
                PG_RETURN_NULL();
        }
+       pfree_inspected(inspected);
 
        ring = poly->rings[wanted_index+1];
 
@@ -406,3 +409,62 @@ Datum LWGEOM_interiorringn_polygon(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(result);
 }
 
+// PointN(GEOMETRY,INTEGER) -- find the first linestring in GEOMETRY,
+// return the point at index INTEGER (0 is 1st point).  Return NULL if
+// there is no LINESTRING(..) in GEOMETRY or INTEGER is out of bounds.
+PG_FUNCTION_INFO_V1(LWGEOM_pointn_linestring);
+Datum LWGEOM_pointn_linestring(PG_FUNCTION_ARGS)
+{
+       LWGEOM *geom;
+       int32 wanted_index;
+       LWGEOM_INSPECTED *inspected;
+       LWLINE *line = NULL;
+       POINTARRAY *pts;
+       LWPOINT *point;
+       char *serializedpoint;
+       LWGEOM *result;
+       int i;
+
+       wanted_index = PG_GETARG_INT32(1);
+       if ( wanted_index < 0 )
+               PG_RETURN_NULL(); // index out of range
+
+       geom = (LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       inspected = lwgeom_inspect(SERIALIZED_FORM(geom));
+
+       for (i=0; i<inspected->ngeometries; i++)
+       {
+               line = lwgeom_getline_inspected(inspected, i);
+               if ( line ) break;
+       }
+
+       if ( line == NULL ) PG_RETURN_NULL();
+
+       // Ok, now we have a line. Let's see if it has enough points.
+       if ( wanted_index > line->points->npoints-1 )
+       {
+               pfree_inspected(inspected);
+               PG_RETURN_NULL();
+       }
+       pfree_inspected(inspected);
+
+       // Construct a point array
+       pts = pointArray_construct(getPoint(line->points, wanted_index),
+               line->points->ndims, 1);
+
+       // Construct an LWPOINT
+       point = lwpoint_construct(line->points->ndims, lwgeom_getSRID(geom),
+               pts);
+
+       // Serialized the point
+       serializedpoint = lwpoint_serialize(point);
+
+       // And we construct the line (copy again)
+       result = LWGEOM_construct(serializedpoint, lwgeom_getSRID(geom),
+               lwgeom_hasBBOX(geom->type));
+
+       pfree(point);
+       pfree(serializedpoint);
+
+       PG_RETURN_POINTER(result);
+}
index a72e77e765be4a1236ac89d8391271261d9d24c6..2092253f6464e7ccee4e091636734dbeb98274e0 100644 (file)
@@ -11,6 +11,9 @@
 --  
 -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 -- $Log$
+-- Revision 1.13  2004/08/24 15:50:04  strk
+-- PointN() ported.
+--
 -- Revision 1.12  2004/08/24 15:05:34  strk
 -- Added NumInteriorRings() and InteriorRingN()
 --
@@ -885,14 +888,20 @@ CREATEFUNCTION InteriorRingN(geometry,integer)
        AS '@MODULE_FILENAME@','LWGEOM_interiorringn_polygon'
        LANGUAGE 'C' WITH (isstrict);
 
-
-------------------------------------------------------------------------
-
-CREATEFUNCTION geometrytype(geometry)
+CREATEFUNCTION GeometryType(geometry)
        RETURNS text
        AS '@MODULE_FILENAME@', 'LWGEOM_getTYPE'
        LANGUAGE 'C' WITH (isstrict);
 
+CREATEFUNCTION PointN(geometry,integer)
+       RETURNS geometry
+       AS '@MODULE_FILENAME@','LWGEOM_pointn_linestring'
+       LANGUAGE 'C' WITH (isstrict);
+
+
+
+------------------------------------------------------------------------
+
 --
 -- Aggregate functions
 --