Esri / spatial-framework-for-hadoop

The Spatial Framework for Hadoop allows developers and data scientists to use the Hadoop data processing system for spatial data analysis.
Apache License 2.0
363 stars 160 forks source link

Can't calculate proximity between polygon & point #114

Closed kaxil closed 6 years ago

kaxil commented 7 years ago

I need to check whether a polygon is within 10 km of a point, but I am unable to do it.

I was able to calculate distance between 2 points using ST_GeodesicLengthWGS84 and ST_LineString.

Select ST_GeodesicLengthWGS84(ST_SetSRID(ST_LineString(array(ST_Point(33.30,42.0),ST_Point(3.0,4.0))), 4326))/1000 as
 dist, ts
from table1

But it seems impossible for me to do the same for calculating distance between Polygon and Point .

randallwhitman commented 7 years ago

ST_Distance accepts any geometry type, so is expected to work for polygon and point. If your coordinates are geographic, then the result is in angular measure. If you need linear distance with geographic coordinates, then Spatial-Framework-for-Hadoop does not do that directly. You can use ST_Distance to get the distance in degrees, then utilize ST_GeodesicLengthWgs84 toward getting the linear distance from the angular distance. See also: http://gis.stackexchange.com/questions/185494/proximity-query-in-hive-using-esri-geospatial-library/185500#185500

kaxil commented 7 years ago

@randallwhitman Hi, thanks for the reply. But the function ST_GeodesicLengthWgs84 accepts a binary datatype or a geometrical point right ?

Whereas the ST_Distance will return a double. So I cannot using something like:

Select ST_GeodesicLengthWGS84(ST_Distance(ST_Point(33.30,42.0),ST_Point(3.0,4.0)))/1000 as
dist, long_text_field_1, long_text_field_2, security_tag, short_text_field, ts
from db1;
randallwhitman commented 7 years ago

Indeed, it's not that straightforward. After getting the angular distance, choose/construct a point at that distance, then make the Line. Did you read through to the linked answer and its references?

kaxil commented 7 years ago

@randallwhitman Yes, I did read it but the problem is that I am not allowed to use API's or code in Java, just need to use hive shell and run queries there.

Thanks for the logic, but again I wonder whether creating a point i.e knowing the co-ordinates of a point at some distance is possible ! Is there a function for the same ?

randallwhitman commented 7 years ago

ST_Point with numerical expressions for the arguments.

kaxil commented 7 years ago

@randallwhitman : To be clear

1) Use ST_Distance to calculate the distance between a Polygon and a Point. The Result would be a numeric value, let say 5 (Angular/Coordinate Distance) 2) Use ST_Point to make a point at that location... ??????? How ??

As ST_Point just takes longitude & latitude as arguments, How can I get the coordinates of that new point at a certain angular distance away.

kaxil commented 7 years ago

@randallwhitman

I tried to follow according to my understanding of what you have described, so what I am doing is

ST_GeodesicLengthWGS84(ST_SetSRID(ST_LineString(array(ST_Intersection(table1.geometry, ST_Buffer(table2.point, ST_Distance(table1.geometry, table2.point) + 1)), table2.point)), 4326))/1000

Also the 1 in ST_Distance(table1.geometry, table2.point) + 1 is used as a buffer.

It worked for me.

Do let me know if I am doing something incorrect. Thanks

randallwhitman commented 7 years ago

Or calculate a ratio based on latitude, as per the above-posted link and its reference links.