]> granicus.if.org Git - postgis/commitdiff
Added (bogus) max_distance(geom,geom)
authorSandro Santilli <strk@keybit.net>
Thu, 26 Aug 2004 15:02:59 +0000 (15:02 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 26 Aug 2004 15:02:59 +0000 (15:02 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@753 b70326c6-7e19-0410-871a-916f4a2858ee

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

index d40c46ff3145507acb2a6d34793ecbbbe3d086fc..330eb18a6059c0706cf6bf29b5e635c2d5d6011c 100644 (file)
@@ -23,7 +23,6 @@ FUNC: KEEPING FUNCTION: [nrings(geometry)]
 FUNC: KEEPING FUNCTION: [translate(geometry, double precision, double precision, double precision)]
 FUNC: KEEPING FUNCTION: [envelope(geometry)]
 
-FUNC: KEEPING FUNCTION: [max_distance(geometry, geometry)]
 
 FUNC: KEEPING FUNCTION: [optimistic_overlap(geometry, geometry, double precision)]
 FUNC: KEEPING FUNCTION: [segmentize(geometry, double precision)]
index 71e14a50f1c5e3436d049e570d95c821341122e4..8a32a295e818ab1369a80e5ab64aec697357e92e 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "lwgeom.h"
 
-//#define DEBUG
+#define DEBUG
 
 Datum combine_box2d(PG_FUNCTION_ARGS);
 Datum LWGEOM_mem_size(PG_FUNCTION_ARGS);
@@ -29,6 +29,7 @@ Datum LWGEOM_force_2d(PG_FUNCTION_ARGS);
 Datum LWGEOM_force_3d(PG_FUNCTION_ARGS);
 Datum LWGEOM_force_collection(PG_FUNCTION_ARGS);
 Datum LWGEOM_mindistance2d(PG_FUNCTION_ARGS);
+Datum LWGEOM_maxdistance2d_linestring(PG_FUNCTION_ARGS);
 
 // internal
 char * lwgeom_summary_recursive(char *serialized, int offset);
@@ -747,7 +748,6 @@ lwgeom_mindistance2d_recursive(char *lw1, char *lw2)
        return mindist;
 }
 
-
 /*------------------------------------------------------------------*/
 
 PG_FUNCTION_INFO_V1(combine_box2d);
@@ -1581,7 +1581,6 @@ Datum LWGEOM_force_collection(PG_FUNCTION_ARGS)
 }
 
 // Minimum 2d distance between objects in geom1 and geom2.
-// Returns null if it doesnt exist (future null-safe version).
 PG_FUNCTION_INFO_V1(LWGEOM_mindistance2d);
 Datum LWGEOM_mindistance2d(PG_FUNCTION_ARGS)
 {
@@ -1602,3 +1601,42 @@ Datum LWGEOM_mindistance2d(PG_FUNCTION_ARGS)
        PG_RETURN_FLOAT8(mindist);
 }
 
+// Maximum 2d distance between linestrings.
+// Returns NULL if given geoms are not linestrings.
+// This is very bogus (or I'm missing its meaning)
+PG_FUNCTION_INFO_V1(LWGEOM_maxdistance2d_linestring);
+Datum LWGEOM_maxdistance2d_linestring(PG_FUNCTION_ARGS)
+{
+
+       LWGEOM *geom1;
+       LWGEOM *geom2;
+       LWLINE *line1;
+       LWLINE *line2;
+       double maxdist = 0;
+       int i;
+
+       geom1 = (LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       line1 = lwline_deserialize(SERIALIZED_FORM(geom1));
+       if ( line1 == NULL ) PG_RETURN_NULL(); // not a linestring
+
+       geom2 = (LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+       line2 = lwline_deserialize(SERIALIZED_FORM(geom2));
+       if ( line2 == NULL ) PG_RETURN_NULL(); // not a linestring
+
+       if (lwgeom_getSRID(geom1) != lwgeom_getSRID(geom2))
+       {
+               elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
+               PG_RETURN_NULL();
+       }
+
+       for (i=0; i<line1->points->npoints; i++)
+       {
+               POINT2D *p = (POINT2D *)getPoint(line1->points, i);
+               double dist = distance2d_pt_ptarray(p, line2->points);
+
+               if (dist > maxdist) maxdist = dist;
+       }
+
+       PG_RETURN_FLOAT8(maxdist);
+}
+
index 40ac726ecb591b6d4ffd5c951e9261c1a28dbdfe..0b696d3184b26245f0d3f0727ef45cffcd08a4d5 100644 (file)
@@ -999,6 +999,12 @@ CREATEFUNCTION distance(geometry,geometry)
        AS '@MODULE_FILENAME@', 'LWGEOM_mindistance2d'
        LANGUAGE 'C' WITH (isstrict,iscachable);
 
+-- Maximum distance between linestrings. 2d only. Very bogus.
+CREATEFUNCTION max_distance(geometry,geometry)
+       RETURNS float8
+       AS '@MODULE_FILENAME@', 'LWGEOM_maxdistance2d_linestring'
+       LANGUAGE 'C' WITH (isstrict,iscachable);
+
 
 
 ------------------------------------------------------------------------