From: Paul Ramsey <pramsey@cleverelephant.ca>
Date: Thu, 5 Nov 2009 00:58:18 +0000 (+0000)
Subject: Add ST_Intersection() and ST_Intersects() for geography.
X-Git-Tag: 1.5.0b1~288
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f38e1f8e975bfba2332d984c0661723b81f03363;p=postgis

Add ST_Intersection() and ST_Intersects() for geography.


git-svn-id: http://svn.osgeo.org/postgis/trunk@4748 b70326c6-7e19-0410-871a-916f4a2858ee
---

diff --git a/postgis/geography.sql.in.c b/postgis/geography.sql.in.c
index 233532158..1266afd30 100644
--- a/postgis/geography.sql.in.c
+++ b/postgis/geography.sql.in.c
@@ -525,6 +525,12 @@ CREATE OR REPLACE FUNCTION ST_CoveredBy(geography, geography)
 	AS 'SELECT $1 && $2 AND _ST_Covers($2, $1)'
 	LANGUAGE 'SQL' IMMUTABLE STRICT;
 
+-- Availability: 1.5.0
+CREATE OR REPLACE FUNCTION ST_Intersects(geography, geography)
+	RETURNS boolean
+	AS 'SELECT $1 && $2 AND _ST_Distance($1, $2, 0.0, false) < 0.00001'
+	LANGUAGE 'SQL' IMMUTABLE STRICT;
+
 -- Availability: 1.5.0
 CREATE OR REPLACE FUNCTION _ST_BestSRID(geography, geography)
 	RETURNS integer
@@ -543,7 +549,11 @@ CREATE OR REPLACE FUNCTION ST_Buffer(geography, float8)
 	AS 'SELECT geography(ST_Transform(ST_Buffer(ST_Transform(geometry($1), _ST_BestSRID($1)), $2), 4326))'
 	LANGUAGE 'SQL' IMMUTABLE STRICT;
 
-
+-- Availability: 1.5.0
+CREATE OR REPLACE FUNCTION ST_Intersection(geography, geography)
+	RETURNS geography
+	AS 'SELECT geography(ST_Transform(ST_Intersection(ST_Transform(geometry($1), _ST_BestSRID($1, $2)), ST_Transform(geometry($2), _ST_BestSRID($1, $2))), 4326))'
+	LANGUAGE 'SQL' IMMUTABLE STRICT;
 
 -- ---------- ---------- ---------- ---------- ---------- ---------- ----------
 
diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c
index 86a02712a..e6652f678 100644
--- a/postgis/lwgeom_geos.c
+++ b/postgis/lwgeom_geos.c
@@ -2228,7 +2228,7 @@ Datum intersects(PG_FUNCTION_ARGS)
 	type1 = lwgeom_getType((uchar)SERIALIZED_FORM(geom1)[0]);
 	type2 = lwgeom_getType((uchar)SERIALIZED_FORM(geom2)[0]);
 	if ( (type1 == POINTTYPE && (type2 == POLYGONTYPE || type2 == MULTIPOLYGONTYPE)) ||
-	        (type2 == POINTTYPE && (type1 == POLYGONTYPE || type1 == MULTIPOLYGONTYPE)))
+	     (type2 == POINTTYPE && (type1 == POLYGONTYPE || type1 == MULTIPOLYGONTYPE)))
 	{
 		POSTGIS_DEBUG(3, "Point in Polygon test requested...short-circuiting.");