1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Add point <-> polygon distance operator.

Alexander Korotkov, reviewed by Emre Hasegeli.
This commit is contained in:
Heikki Linnakangas
2014-12-15 17:02:49 +02:00
parent ee3bec5e22
commit 4520ba6769
6 changed files with 82 additions and 16 deletions

View File

@ -279,3 +279,14 @@ SELECT '((200,800),(800,800),(800,200),(200,200))' && '(1000,1000,0,0)'::polygo
t
(1 row)
-- distance from a point
SELECT '(0,0)'::point <-> '((0,0),(1,2),(2,1))'::polygon as on_corner,
'(1,1)'::point <-> '((0,0),(2,2),(1,3))'::polygon as on_segment,
'(2,2)'::point <-> '((0,0),(1,4),(3,1))'::polygon as inside,
'(3,3)'::point <-> '((0,2),(2,0),(2,2))'::polygon as near_corner,
'(4,4)'::point <-> '((0,0),(0,3),(4,0))'::polygon as near_segment;
on_corner | on_segment | inside | near_corner | near_segment
-----------+------------+--------+-----------------+--------------
0 | 0 | 0 | 1.4142135623731 | 3.2
(1 row)

View File

@ -172,3 +172,10 @@ SELECT '((0,4),(6,4),(1,2),(6,0),(0,0))'::polygon && '((2,1),(2,3),(3,3),(3,1))'
-- +-------+
SELECT '((1,4),(1,1),(4,1),(4,2),(2,2),(2,4),(1,4))'::polygon && '((3,3),(4,3),(4,4),(3,4),(3,3))'::polygon AS "false";
SELECT '((200,800),(800,800),(800,200),(200,200))' && '(1000,1000,0,0)'::polygon AS "true";
-- distance from a point
SELECT '(0,0)'::point <-> '((0,0),(1,2),(2,1))'::polygon as on_corner,
'(1,1)'::point <-> '((0,0),(2,2),(1,3))'::polygon as on_segment,
'(2,2)'::point <-> '((0,0),(1,4),(3,1))'::polygon as inside,
'(3,3)'::point <-> '((0,2),(2,0),(2,2))'::polygon as near_corner,
'(4,4)'::point <-> '((0,0),(0,3),(4,0))'::polygon as near_segment;