[postgis-commits] svn - r3425 - in trunk: liblwgeom lwgeom
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Tue Dec 16 15:43:02 PST 2008
Author: pramsey
Date: 2008-12-16 15:43:02 -0800 (Tue, 16 Dec 2008)
New Revision: 3425
Modified:
trunk/liblwgeom/lwalgorithm.c
trunk/lwgeom/lwgeom_functions_analytic.c
trunk/lwgeom/lwpostgis.sql.in.c
Log:
Add ST_CrossingDirection(line, line) bindings into SQL.
Modified: trunk/liblwgeom/lwalgorithm.c
===================================================================
--- trunk/liblwgeom/lwalgorithm.c 2008-12-16 22:29:42 UTC (rev 3424)
+++ trunk/liblwgeom/lwalgorithm.c 2008-12-16 23:43:02 UTC (rev 3425)
@@ -210,7 +210,7 @@
** TODO Handle co-linear cases.
*/
- LWDEBUGF(5, "lineCrossingDirection: this_cross=%d, prev_cross=%d, vertex_touch=%d, vertex_touch_type=%d", this_cross, prev_cross, vertex_touch, vertex_touch_type);
+ LWDEBUGF(5, "lineCrossingDirection: this_cross=%d, vertex_touch=%d, vertex_touch_type=%d", this_cross, vertex_touch, vertex_touch_type);
}
Modified: trunk/lwgeom/lwgeom_functions_analytic.c
===================================================================
--- trunk/lwgeom/lwgeom_functions_analytic.c 2008-12-16 22:29:42 UTC (rev 3424)
+++ trunk/lwgeom/lwgeom_functions_analytic.c 2008-12-16 23:43:02 UTC (rev 3425)
@@ -16,6 +16,7 @@
#include "lwgeom_pg.h"
#include "math.h"
#include "lwgeom_rtree.h"
+#include "lwalgorithm.h"
/***********************************************************************
@@ -35,6 +36,7 @@
LWCOLLECTION *simplify2d_collection(const LWCOLLECTION *igeom, double dist);
LWGEOM *simplify2d_lwgeom(const LWGEOM *igeom, double dist);
Datum LWGEOM_simplify2d(PG_FUNCTION_ARGS);
+Datum crossingDirection(PG_FUNCTION_ARGS);
double determineSide(POINT2D *seg1, POINT2D *seg2, POINT2D *point);
int isOnSegment(POINT2D *seg1, POINT2D *seg2, POINT2D *point);
@@ -937,6 +939,60 @@
PG_RETURN_POINTER(out_geom);
}
+
+/*
+** crossingDirection(line1, line2)
+**
+** Determines crossing direction of line2 relative to line1.
+** Only accepts LINESTRING ass parameters!
+*/
+PG_FUNCTION_INFO_V1(crossingDirection);
+Datum crossingDirection(PG_FUNCTION_ARGS)
+{
+ int type1, type2, rv;
+ BOX2DFLOAT4 box1, box2;
+ LWLINE *l1 = NULL;
+ LWLINE *l2 = NULL;
+ PG_LWGEOM *geom1 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+ PG_LWGEOM *geom2 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+
+ errorIfSRIDMismatch(pglwgeom_getSRID(geom1), pglwgeom_getSRID(geom2));
+
+ /*
+ ** If the bounding boxes don't interact, then there can't be any
+ ** crossing, return right away.
+ */
+ if ( getbox2d_p(SERIALIZED_FORM(geom1), &box1) &&
+ getbox2d_p(SERIALIZED_FORM(geom2), &box2) )
+ {
+ if ( ( box2.xmax < box1.xmin ) || ( box2.xmin > box1.xmax ) ||
+ ( box2.ymax < box1.ymin ) || ( box2.ymin > box1.ymax ) )
+ {
+ PG_RETURN_INT32(LINE_NO_CROSS);
+ }
+ }
+
+ type1 = lwgeom_getType((uchar)SERIALIZED_FORM(geom1)[0]);
+ type2 = lwgeom_getType((uchar)SERIALIZED_FORM(geom2)[0]);
+
+ if ( type1 != LINETYPE || type2 != LINETYPE )
+ {
+ elog(ERROR,"This function only accepts LINESTRING as arguments.");
+ PG_RETURN_NULL();
+ }
+
+ l1 = lwline_deserialize(SERIALIZED_FORM(geom1));
+ l2 = lwline_deserialize(SERIALIZED_FORM(geom2));
+
+ rv = lineCrossingDirection(l1, l2);
+
+ PG_FREE_IF_COPY(geom1, 0);
+ PG_FREE_IF_COPY(geom2, 0);
+
+ PG_RETURN_INT32(rv);
+
+}
+
/***********************************************************************
* --strk at keybit.net
***********************************************************************/
Modified: trunk/lwgeom/lwpostgis.sql.in.c
===================================================================
--- trunk/lwgeom/lwpostgis.sql.in.c 2008-12-16 22:29:42 UTC (rev 3424)
+++ trunk/lwgeom/lwpostgis.sql.in.c 2008-12-16 23:43:02 UTC (rev 3425)
@@ -3965,6 +3965,14 @@
AS 'MODULE_PATHNAME','convexhull'
LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict,iscachable);
+-- Only accepts LINESTRING as parameters.
+-- Availability: 1.4.0
+CREATEFUNCTION ST_CrossingDirection(geometry, geometry)
+ RETURNS integer
+ AS 'MODULE_PATHNAME', 'crossingDirection'
+ LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict,iscachable);
+
+
#if POSTGIS_GEOS_VERSION >= 30
-- Requires GEOS >= 3.0.0
-- Availability: 1.3.3
More information about the postgis-commits
mailing list