DECLARE @polyAgeography
DECLARE @polyBgeography
DECLARE @pointgeography
SET @point= geography::STGeomFromText('POINT(-1.5667444464495464 55.07067670927046)',4326);
SET @polyA= geography::STGeomFromText('POLYGON ((-8 48.83305556, -2 50, -0.25 50, 1.466666667 50.66666667, 1.466666667 51, 2 51.11638889, 2 51.5, 5 55, -5.5 55, -5.5 52.33305556, -8 51, -8 48.83305556))',4326)
SET @ployB= geography::STGeomFromText('POLYGON ((-10 54.5663888888889, -9 54.75, -8.25 55.3330555555556, -7.33305555555556 55.4166666666667, -6.91666666666667 55.3330555555556, -8.16666666666667 54.4166666666667, -5.5 53.9166666666667, -5.5 55, 5 55, 5 57, 0 60, 0 61, -10 61, -10 54.5663888888889))',4326)
SELECT @polyA.STContains(@point) as inRegionA, @polyB.STContains(@point) as inRegionB;
ResultsinRegionA inRegionB
-------------- ----------------
1 0
MS SQL - Geometry - Incorrectly identifies the point as belonging to the RegionB - This matches the ESRI Hadoop library results
DECLARE @polyA2geometry
DECLARE @polyB2geometry
DECLARE @point2geometry
SET @point2= geometry::STGeomFromText('POINT(-1.5667444464495464 55.07067670927046)',4326);
SET @polyA2= geometry::STGeomFromText('POLYGON ((-8 48.83305556, -2 50, -0.25 50, 1.466666667 50.66666667, 1.466666667 51, 2 51.11638889, 2 51.5, 5 55, -5.5 55, -5.5 52.33305556, -8 51, -8 48.83305556))',4326)
SET @polyB2= geometry::STGeomFromText('POLYGON ((-10 54.5663888888889, -9 54.75, -8.25 55.3330555555556, -7.33305555555556 55.4166666666667, -6.91666666666667 55.3330555555556, -8.16666666666667 54.4166666666667, -5.5 53.9166666666667, -5.5 55, 5 55, 5 57, 0 60, 0 61, -10 61, -10 54.5663888888889))',4326)
SELECT @polyA2.STContains(@point2) as inRegionA, @polyB2.STContains(@point2) as inRegionB;
ResultsinRegionA inRegionB
-------------- ----------------
0 1
Geography vs Geometry Plotted Information
Hive/SparkSQL - ESRI Geometry - Correctly identifies the point as belonging to the RegionB because it's using geometry but I want to use Geography types - is there a way?
add jar esri-geometry-api.jar;
add jar spatial-sdk-hadoop.jar;
create function ST_GeomFromText as 'com.esri.hadoop.hive.ST_GeomFromText';
create function ST_Contains as 'com.esri.hadoop.hive.ST_Contains';
SELECT
ST_Contains(
ST_GeomFromText('POLYGON ((-8 48.83305556, -2 50, -0.25 50, 1.466666667 50.66666667, 1.466666667 51, 2 51.11638889, 2 51.5, 5 55, -5.5 55, -5.5 52.33305556, -8 51, -8 48.83305556))', 4326),
ST_GeomFromText('POINT(-1.5667444464495464 55.07067670927046)',4326)
) AS inRegionA,
ST_Contains(
ST_GeomFromText('POLYGON ((-10 54.5663888888889, -9 54.75, -8.25 55.3330555555556, -7.33305555555556 55.4166666666667, -6.91666666666667 55.3330555555556, -8.16666666666667 54.4166666666667, -5.5 53.9166666666667, -5.5 55, 5 55, 5 57, 0 60, 0 61, -10 61, -10 54.5663888888889))', 4326),
ST_GeomFromText('POINT(-1.5667444464495464 55.07067670927046)',4326)
) AS inRegionB;
Results
inRegionA inRegionB
-------------- ----------------
false true