ESRI Hive ST_Contains does not work properly ESRI Hive ST_Contains does not work properly hadoop hadoop

ESRI Hive ST_Contains does not work properly


Only one version of the geometry API should be loaded. Likewise only one of either spatial-sdk-hadoop or the pair of spatial-sdk-json and spatial-sdk-hive .

WKT polygons are closed with an end vertex that repeats the start vertex.

The polygon needs to be specified by vertices in order around the perimeter, not a zigzag order.

The Geometry API is planar and will not support wrapping around the International Date Line.

Probably -170 rather than +170 latitude is intended.

wget https://github.com/Esri/spatial-framework-for-hadoop/releases/download/v1.1/spatial-sdk-hive-1.1.jar \
https://github.com/Esri/spatial-framework-for-hadoop/releases/download/v1.1/spatial-sdk-json-1.1.jar \
https://github.com/Esri/geometry-api-java/releases/download/v1.2.1/esri-geometry-api-1.2.1.jar

hive -S
add jar /pathto/esri-geometry-api-1.2.1.jar
/pathto/spatial-sdk-json-1.1.jar
/pathto/spatial-sdk-hive-1.1.jar ;
create temporary function ST_AsBinary as 'com.esri.hadoop.hive.ST_AsBinary';
-- ...

select ST_Contains(ST_Polygon(1, 1, 1, 4, 4, 4, 4, 1), ST_Point(2, 3));
true
select ST_Contains(ST_Polygon('POLYGON((1 1, 1 4, 4 4, 4 1, 1 1))'), ST_Point(2, 3));
true
select ST_Contains(ST_POLYGON('POLYGON((-170.0 20.0, -170.0 73.0, -50.0 20.0, -50.0 73.0, -170.0 20.0))'), ST_Point(-73.9878531, 40.7484445));
true
select not ST_Contains(ST_POLYGON('POLYGON((-170.0 20.0, -170.0 73.0, -50.0 20.0, -50.0 73.0, -170.0 20.0))'), ST_Point(-73.9878531, 40.7484445));
false


add jar /home/..../esri-geometry-api-1.2.1.jar;add jar /home/..../spatial-sdk-json-1.2.0.jar;add jar /home/..../spatial-sdk-hive-1.2.0.jar;add jar /home/..../spatial-sdk-hadoop.jar;create temporary function ST_AsBinary as 'com.esri.hadoop.hive.ST_AsBinary';CREATE TEMPORARY FUNCTION ST_Polygon AS 'com.esri.hadoop.hive.ST_Polygon';CREATE TEMPORARY FUNCTION ST_Point AS 'com.esri.hadoop.hive.ST_Point';CREATE TEMPORARY FUNCTION ST_Contains AS 'com.esri.hadoop.hive.ST_Contains';CREATE TEMPORARY FUNCTION ST_Geometry AS 'com.esri.hadoop.hive.ST_Geometry';A) load table from geojson data to hive:CREATE TABLE default.lim_xxx_pais(NOM_PLAN string, NMO_PLAN  string, APROXIMADO string, ID1 string, BoundaryShape binary)ROW FORMAT SERDE 'com.esri.hadoop.hive.serde.GeoJsonSerDe'              STORED AS INPUTFORMAT 'com.esri.json.hadoop.EnclosedGeoJsonInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat';B)LOAD DATA INPATH '/user/.../lim_xxx_pais.geojson' OVERWRITE INTO TABLE lim_xxx_pais

;

C)select NOM_PLAN, NMO_PLAN,APROXIMADO,ID1 from default.lim_centrales_pais aawhere ST_Contains(aa.boundaryshape, ST_POINT(-72.08726603,-36.62627804) );