Thursday, 13 February 2020

PostGIS point distance from polygon not 0 when on edge



I have a pretty simple problem:


SELECT * FROM ST_Distance(ST_GeographyFromText('POLYGON((70 -40,70 -39,71 -39,71 -40,70 -40))'), ST_GeographyFromText('POINT(70.48 -39)'), False)

returns 118.45656881 Shouldn't it be 0? Isn't the point on the edge of the polygon? Why does


SELECT * FROM ST_Distance(ST_GeographyFromText('POLYGON((70 -40,70 -39,71 -39,71 -40,70 -40))'), ST_GeographyFromText('POINT(70.48 -40)'), False)

return 0?


SELECT * FROM ST_Distance(ST_GeographyFromText('POINT(70 -39.5)'), ST_GeographyFromText('POINT(70 -39)'));
SELECT * FROM ST_Distance(ST_GeographyFromText('POINT(70 -39.5)'), ST_GeographyFromText('POINT(70 -40)'));


Why does this return two different (although only slightly) numbers?



Answer



The video explains it very well. If you take the edge in question and segmentize it


 SELECT st_asewkt( st_segmentize(geog,10000)) FROM ST_GeographyFromText('LINESTRING (70 -39,71 -39)') geog

you going to have the following :


enter image description here


the point is the the point you are asking about. The line represents the edge. North is up.


(distance measurement done by hand,no snapping)


As for the 2nd query that returns 0? It does because hte point is actually inside your polygon.



To be more clear the intersection between the two geometries is empty because they simply don't overlap.


select st_asewkt(st_intersection(ST_GeographyFromText('POLYGON((70 -40,70 -39,71 -39,71 -40,70 -40))'), ST_GeographyFromText('POINT(70.48 -39)')))

st_asewkt
--------------
SRID=4326;GEOMETRYCOLLECTION EMPTY

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...