Revise geometry regression testing to eliminate most cross-platform

variation.  To do this, set extra_float_digits to -3 in the geometry
test, and tweak the CIRCLE_TBL dataset to avoid values that suffer
from severe cancellation error (eg, circles that just touch an axis).
We still need two geometry 'expected' files to account for the
difference between platforms that display minus zero as '-0' and those
that just say '0', but with luck that's all we'll need.
This commit is contained in:
Tom Lane 2002-11-08 20:09:55 +00:00
parent b26dfbb0e3
commit 337f73b1bb
19 changed files with 199 additions and 7128 deletions

View File

@ -2,12 +2,12 @@
-- CIRCLE
--
CREATE TABLE CIRCLE_TBL (f1 circle);
INSERT INTO CIRCLE_TBL VALUES ('<(0,0),3>');
INSERT INTO CIRCLE_TBL VALUES ('<(5,1),3>');
INSERT INTO CIRCLE_TBL VALUES ('<(1,2),100>');
INSERT INTO CIRCLE_TBL VALUES ('1,3,5');
INSERT INTO CIRCLE_TBL VALUES ('((1,2),3)');
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>');
INSERT INTO CIRCLE_TBL VALUES ('<(100,0),100>');
INSERT INTO CIRCLE_TBL VALUES ('<(100,1),115>');
-- bad values
INSERT INTO CIRCLE_TBL VALUES ('<(-100,0),-100>');
ERROR: Bad circle external representation '<(-100,0),-100>'
@ -18,24 +18,24 @@ ERROR: Bad circle external representation '(3,(1,2),3)'
SELECT * FROM CIRCLE_TBL;
f1
----------------
<(0,0),3>
<(5,1),3>
<(1,2),100>
<(1,3),5>
<(1,2),3>
<(100,200),10>
<(100,0),100>
<(100,1),115>
(6 rows)
SELECT '' AS six, center(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (5,1)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
| (100,1)
(6 rows)
SELECT '' AS six, radius(f1) AS radius
@ -47,7 +47,7 @@ SELECT '' AS six, radius(f1) AS radius
| 5
| 3
| 10
| 100
| 115
(6 rows)
SELECT '' AS six, diameter(f1) AS diameter
@ -59,13 +59,13 @@ SELECT '' AS six, diameter(f1) AS diameter
| 10
| 6
| 20
| 200
| 230
(6 rows)
SELECT '' AS two, f1 FROM CIRCLE_TBL WHERE radius(f1) < 5;
two | f1
-----+-----------
| <(0,0),3>
| <(5,1),3>
| <(1,2),3>
(2 rows)
@ -75,7 +75,7 @@ SELECT '' AS four, f1 FROM CIRCLE_TBL WHERE diameter(f1) >= 10;
| <(1,2),100>
| <(1,3),5>
| <(100,200),10>
| <(100,0),100>
| <(100,1),115>
(4 rows)
SELECT '' as five, c1.f1 AS one, c2.f1 AS two, (c1.f1 <-> c2.f1) AS distance
@ -84,10 +84,10 @@ SELECT '' as five, c1.f1 AS one, c2.f1 AS two, (c1.f1 <-> c2.f1) AS distance
ORDER BY distance, one, two;
five | one | two | distance
------+----------------+----------------+------------------
| <(100,200),10> | <(100,0),100> | 90
| <(100,200),10> | <(100,1),115> | 74
| <(100,200),10> | <(1,2),100> | 111.370729772479
| <(1,3),5> | <(100,200),10> | 205.476756144497
| <(5,1),3> | <(100,200),10> | 207.51303816328
| <(1,2),3> | <(100,200),10> | 208.370729772479
| <(0,0),3> | <(100,200),10> | 210.606797749979
(5 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (-0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140472)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186547,72.7106781186547),(-69.7106781186547,-68.7106781186547)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932737)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186547),(29.2893218813453,-70.7106781186547)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,-0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,-0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359017709e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718035418e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077053127e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983794))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887967),(-3.33012701896897,0.500000000081028))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.598076211373729),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048617))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239345139e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983794))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359017709e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718035418e-11),(2.12132034353258,-2.12132034358671),(-4.59307077053127e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181135),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181135),(200,-1.02068239345139e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+------------------
| <(100,0),100> | (5.1,34.5) | 0.97653192697797
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044152
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (-0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140472)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186547,72.7106781186547),(-69.7106781186547,-68.7106781186547)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932737)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186547),(29.2893218813453,-70.7106781186547)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,-0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,-0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359078377e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718156754e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077235131e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983795))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887967),(-3.33012701896897,0.500000000081028))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.598076211373729),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048616))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239385585e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983795))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359078377e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718156754e-11),(2.12132034353258,-2.12132034358671),(-4.59307077235131e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181134),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181134),(200,-1.02068239385585e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+------------------
| <(100,0),100> | (5.1,34.5) | 0.97653192697797
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044152
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (-0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140473)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186548,72.7106781186548),(-69.7106781186548,-68.7106781186548)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932738)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559643)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186548),(29.2893218813452,-70.7106781186548)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,-0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,-0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135332,1.5),(-1.5,2.59807621135332),(-1.83690953073357e-16,3),(1.5,2.59807621135332),(2.59807621135332,1.5),(3,3.67381906146713e-16),(2.59807621135332,-1.5),(1.5,-2.59807621135332),(5.5107285922007e-16,-3),(-1.5,-2.59807621135332),(-2.59807621135332,-1.5))
| ((-99,2),(-85.6025403784439,52),(-49,88.6025403784439),(0.999999999999994,102),(51,88.6025403784439),(87.6025403784439,52),(101,2.00000000000001),(87.6025403784439,-48),(51,-84.6025403784438),(1.00000000000002,-98),(-49,-84.6025403784439),(-85.6025403784438,-48))
| ((-4,3),(-3.33012701892219,5.5),(-1.5,7.33012701892219),(1,8),(3.5,7.33012701892219),(5.33012701892219,5.5),(6,3),(5.33012701892219,0.500000000000001),(3.5,-1.33012701892219),(1,-2),(-1.5,-1.33012701892219),(-3.33012701892219,0.499999999999998))
| ((-2,2),(-1.59807621135332,3.5),(-0.5,4.59807621135332),(1,5),(2.5,4.59807621135332),(3.59807621135332,3.5),(4,2),(3.59807621135332,0.500000000000001),(2.5,-0.598076211353315),(1,-1),(-0.5,-0.598076211353316),(-1.59807621135332,0.499999999999999))
| ((90,200),(91.3397459621556,205),(95,208.660254037844),(100,210),(105,208.660254037844),(108.660254037844,205),(110,200),(108.660254037844,195),(105,191.339745962156),(100,190),(95,191.339745962156),(91.3397459621556,195))
| ((0,0),(13.3974596215561,50),(50,86.6025403784439),(100,100),(150,86.6025403784439),(186.602540378444,50),(200,1.22460635382238e-14),(186.602540378444,-50),(150,-86.6025403784438),(100,-100),(50,-86.6025403784439),(13.3974596215562,-50))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355964,2.12132034355964),(-1.83690953073357e-16,3),(2.12132034355964,2.12132034355964),(3,3.67381906146713e-16),(2.12132034355964,-2.12132034355964),(5.5107285922007e-16,-3),(-2.12132034355964,-2.12132034355964))
| ((-99,2),(-69.7106781186548,72.7106781186548),(0.999999999999994,102),(71.7106781186547,72.7106781186548),(101,2.00000000000001),(71.7106781186548,-68.7106781186547),(1.00000000000002,-98),(-69.7106781186547,-68.7106781186548))
| ((-4,3),(-2.53553390593274,6.53553390593274),(1,8),(4.53553390593274,6.53553390593274),(6,3),(4.53553390593274,-0.535533905932737),(1,-2),(-2.53553390593274,-0.535533905932738))
| ((-2,2),(-1.12132034355964,4.12132034355964),(1,5),(3.12132034355964,4.12132034355964),(4,2),(3.12132034355964,-0.121320343559642),(1,-1),(-1.12132034355964,-0.121320343559643))
| ((90,200),(92.9289321881345,207.071067811865),(100,210),(107.071067811865,207.071067811865),(110,200),(107.071067811865,192.928932188135),(100,190),(92.9289321881345,192.928932188135))
| ((0,0),(29.2893218813452,70.7106781186548),(100,100),(170.710678118655,70.7106781186548),(200,1.22460635382238e-14),(170.710678118655,-70.7106781186547),(100,-100),(29.2893218813453,-70.7106781186548))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+-------------------
| <(100,0),100> | (5.1,34.5) | 0.976531926977964
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044151
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773224
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (-0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140472)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186548,72.7106781186548),(-69.7106781186548,-68.7106781186548)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932738)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559643)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186548),(29.2893218813452,-70.7106781186548)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,-0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,-0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135332,1.5),(-1.5,2.59807621135332),(-1.83690953073357e-16,3),(1.5,2.59807621135332),(2.59807621135332,1.5),(3,3.67381906146713e-16),(2.59807621135332,-1.5),(1.5,-2.59807621135332),(5.5107285922007e-16,-3),(-1.5,-2.59807621135332),(-2.59807621135332,-1.5))
| ((-99,2),(-85.6025403784439,52),(-49,88.6025403784439),(0.999999999999994,102),(51,88.6025403784439),(87.6025403784439,52),(101,2.00000000000001),(87.6025403784439,-48),(51,-84.6025403784438),(1.00000000000002,-98),(-49,-84.6025403784439),(-85.6025403784438,-48))
| ((-4,3),(-3.33012701892219,5.5),(-1.5,7.33012701892219),(1,8),(3.5,7.33012701892219),(5.33012701892219,5.5),(6,3),(5.33012701892219,0.500000000000001),(3.5,-1.33012701892219),(1,-2),(-1.5,-1.33012701892219),(-3.33012701892219,0.499999999999998))
| ((-2,2),(-1.59807621135332,3.5),(-0.5,4.59807621135332),(1,5),(2.5,4.59807621135332),(3.59807621135332,3.5),(4,2),(3.59807621135332,0.500000000000001),(2.5,-0.598076211353315),(1,-1),(-0.5,-0.598076211353316),(-1.59807621135332,0.499999999999999))
| ((90,200),(91.3397459621556,205),(95,208.660254037844),(100,210),(105,208.660254037844),(108.660254037844,205),(110,200),(108.660254037844,195),(105,191.339745962156),(100,190),(95,191.339745962156),(91.3397459621556,195))
| ((0,0),(13.3974596215561,50),(50,86.6025403784439),(100,100),(150,86.6025403784439),(186.602540378444,50),(200,1.22460635382238e-14),(186.602540378444,-50),(150,-86.6025403784438),(100,-100),(50,-86.6025403784439),(13.3974596215562,-50))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355964,2.12132034355964),(-1.83690953073357e-16,3),(2.12132034355964,2.12132034355964),(3,3.67381906146713e-16),(2.12132034355964,-2.12132034355964),(5.5107285922007e-16,-3),(-2.12132034355964,-2.12132034355964))
| ((-99,2),(-69.7106781186548,72.7106781186548),(0.999999999999994,102),(71.7106781186547,72.7106781186548),(101,2.00000000000001),(71.7106781186548,-68.7106781186547),(1.00000000000002,-98),(-69.7106781186547,-68.7106781186548))
| ((-4,3),(-2.53553390593274,6.53553390593274),(1,8),(4.53553390593274,6.53553390593274),(6,3),(4.53553390593274,-0.535533905932737),(1,-2),(-2.53553390593274,-0.535533905932738))
| ((-2,2),(-1.12132034355964,4.12132034355964),(1,5),(3.12132034355964,4.12132034355964),(4,2),(3.12132034355964,-0.121320343559642),(1,-1),(-1.12132034355964,-0.121320343559643))
| ((90,200),(92.9289321881345,207.071067811865),(100,210),(107.071067811865,207.071067811865),(110,200),(107.071067811865,192.928932188135),(100,190),(92.9289321881345,192.928932188135))
| ((0,0),(29.2893218813452,70.7106781186548),(100,100),(170.710678118655,70.7106781186548),(200,1.22460635382238e-14),(170.710678118655,-70.7106781186547),(100,-100),(29.2893218813453,-70.7106781186548))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+-------------------
| <(100,0),100> | (5.1,34.5) | 0.976531926977964
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044151
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773224
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140472)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186547,72.7106781186547),(-69.7106781186547,-68.7106781186547)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932737)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186547),(29.2893218813453,-70.7106781186547)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (0,0),(-20,-20)
| (0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359017709e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718035418e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077053127e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983794))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887967),(-3.33012701896897,0.500000000081028))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.59807621137373),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048617))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239345139e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983794))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359017709e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718035418e-11),(2.12132034353258,-2.12132034358671),(-4.59307077053127e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.7106781191961,72.7106781181135),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181135),(200,-1.02068239345139e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+------------------
| <(100,0),100> | (5.1,34.5) | 0.97653192697797
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044152
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140472)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186547,72.7106781186547),(-69.7106781186547,-68.7106781186547)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932737)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186547),(29.2893218813453,-70.7106781186547)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (0,0),(-20,-20)
| (0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359078377e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718156754e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077235131e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983795))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887967),(-3.33012701896897,0.500000000081028))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.598076211373729),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048616))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239385585e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983795))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359078377e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718156754e-11),(2.12132034353258,-2.12132034358671),(-4.59307077235131e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181134),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181134),(200,-1.02068239385585e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+------------------
| <(100,0),100> | (5.1,34.5) | 0.97653192697797
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044152
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,6 +1,9 @@
--
-- GEOMETRY
--
-- Back off displayed precision a little bit to reduce platform-to-platform
-- variation in results.
SET extra_float_digits TO -3;
--
-- Points
--
@ -28,33 +31,33 @@ SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (5,1)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
| (100,1)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (5,1)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
| (100,1)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
two | center
-----+-------------------------------
| (1.33333333333,1.33333333333)
| (2.33333333333,1.33333333333)
(2 rows)
-- "is horizontal" function
@ -106,8 +109,8 @@ ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
thirty | f1 | s | closest
--------+------------+-------------------------------+----------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
@ -120,18 +123,18 @@ SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (0,0) | [(10,-10),(-3,-4)] | (-2.0487804878,-4.43902439024)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140472)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878,-4.64390243902)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390244,-6.48780487805)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.00284023658959,15.3846148603)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258,15.386461014)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812268,15.3851688427)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221,15.3836744977)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420846,15.3855375282)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993742,15.3827690473)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
@ -147,14 +150,14 @@ SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186547,72.7106781186547),(-69.7106781186547,-68.7106781186547)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932737)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186547),(29.2893218813453,-70.7106781186547)
six | box
-----+----------------------------------------------------------------
| (7.12132034356,3.12132034356),(2.87867965644,-1.12132034356)
| (71.7106781187,72.7106781187),(-69.7106781187,-68.7106781187)
| (4.53553390593,6.53553390593),(-2.53553390593,-0.535533905933)
| (3.12132034356,4.12132034356),(-1.12132034356,-0.12132034356)
| (107.071067812,207.071067812),(92.9289321881,192.928932188)
| (181.317279836,82.3172798365),(18.6827201635,-80.3172798365)
(6 rows)
-- translation
@ -252,8 +255,8 @@ SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
twenty | rotation
--------+----------------------------------------------------------------------
| (0,0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
@ -262,14 +265,14 @@ SELECT '' AS twenty, b.f1 / p.f1 AS rotation
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.0651176557644,0),(0,-0.0483449262493)
| (0.0976764836466,-0.0241724631247),(0.0325588278822,-0.072517389374)
| (0.109762715209,-0.0562379754329),(0.0813970697055,-0.0604311578117)
| (0.0976764836466,-0.072517389374),(0.0976764836466,-0.072517389374)
| (0,0.0828402366864),(-0.201183431953,0)
| (-0.100591715976,0.12426035503),(-0.301775147929,0.0414201183432)
| (-0.251479289941,0.103550295858),(-0.322485207101,0.0739644970414)
| (-0.301775147929,0.12426035503),(-0.301775147929,0.12426035503)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
@ -441,27 +444,27 @@ SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359017709e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718035418e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077053127e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983795))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887967),(-3.33012701896897,0.500000000081028))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.598076211373729),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048616))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239345139e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983795))
six | polygon
-----+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((2,1),(2.40192378865,2.5),(3.5,3.59807621135),(5,4),(6.5,3.59807621135),(7.59807621135,2.5),(8,1),(7.59807621135,-0.5),(6.5,-1.59807621135),(5,-2),(3.5,-1.59807621135),(2.40192378865,-0.5))
| ((-99,2),(-85.6025403784,52),(-49,88.6025403784),(1,102),(51,88.6025403784),(87.6025403784,52),(101,2),(87.6025403784,-48),(51,-84.6025403784),(1,-98),(-49,-84.6025403784),(-85.6025403784,-48))
| ((-4,3),(-3.33012701892,5.5),(-1.5,7.33012701892),(1,8),(3.5,7.33012701892),(5.33012701892,5.5),(6,3),(5.33012701892,0.5),(3.5,-1.33012701892),(1,-2),(-1.5,-1.33012701892),(-3.33012701892,0.5))
| ((-2,2),(-1.59807621135,3.5),(-0.5,4.59807621135),(1,5),(2.5,4.59807621135),(3.59807621135,3.5),(4,2),(3.59807621135,0.5),(2.5,-0.598076211353),(1,-1),(-0.5,-0.598076211353),(-1.59807621135,0.5))
| ((90,200),(91.3397459622,205),(95,208.660254038),(100,210),(105,208.660254038),(108.660254038,205),(110,200),(108.660254038,195),(105,191.339745962),(100,190),(95,191.339745962),(91.3397459622,195))
| ((-15,1),(0.40707856479,58.5),(42.5,100.592921435),(100,116),(157.5,100.592921435),(199.592921435,58.5),(215,1),(199.592921435,-56.5),(157.5,-98.5929214352),(100,-114),(42.5,-98.5929214352),(0.40707856479,-56.5))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359017709e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718035418e-11),(2.12132034353258,-2.12132034358671),(-4.59307077053127e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181135),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181135),(200,-1.02068239345139e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
six | polygon
-----+------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((2,1),(2.87867965644,3.12132034356),(5,4),(7.12132034356,3.12132034356),(8,1),(7.12132034356,-1.12132034356),(5,-2),(2.87867965644,-1.12132034356))
| ((-99,2),(-69.7106781187,72.7106781187),(1,102),(71.7106781187,72.7106781187),(101,2),(71.7106781187,-68.7106781187),(1,-98),(-69.7106781187,-68.7106781187))
| ((-4,3),(-2.53553390593,6.53553390593),(1,8),(4.53553390593,6.53553390593),(6,3),(4.53553390593,-0.535533905933),(1,-2),(-2.53553390593,-0.535533905933))
| ((-2,2),(-1.12132034356,4.12132034356),(1,5),(3.12132034356,4.12132034356),(4,2),(3.12132034356,-0.12132034356),(1,-1),(-1.12132034356,-0.12132034356))
| ((90,200),(92.9289321881,207.071067812),(100,210),(107.071067812,207.071067812),(110,200),(107.071067812,192.928932188),(100,190),(92.9289321881,192.928932188))
| ((-15,1),(18.6827201635,82.3172798365),(100,116),(181.317279836,82.3172798365),(215,1),(181.317279836,-80.3172798365),(100,-114),(18.6827201635,-80.3172798365))
(6 rows)
--
@ -481,10 +484,10 @@ SELECT '' AS six, circle(f1, 50.0)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
four | circle
------+-----------------------
| <(1,1),1.41421356237>
| <(2,2),1.41421356237>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
@ -492,41 +495,38 @@ SELECT '' AS four, circle(f1)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
two | circle
-----+-----------------------------------------------
| <(1.33333333333,1.33333333333),2.04168905064>
| <(2.33333333333,1.33333333333),1.47534300379>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+------------------
| <(100,0),100> | (5.1,34.5) | 0.97653192697797
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044152
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)
twentyfour | circle | point | distance
------------+----------------+------------+---------------
| <(1,2),3> | (-3,4) | 1.472135955
| <(5,1),3> | (0,0) | 2.09901951359
| <(5,1),3> | (-3,4) | 5.54400374532
| <(1,3),5> | (-10,0) | 6.40175425099
| <(1,3),5> | (10,10) | 6.40175425099
| <(5,1),3> | (10,10) | 7.29563014099
| <(1,2),3> | (-10,0) | 8.1803398875
| <(1,2),3> | (10,10) | 9.04159457879
| <(1,3),5> | (-5,-12) | 11.1554944214
| <(5,1),3> | (-10,0) | 12.0332963784
| <(1,2),3> | (-5,-12) | 12.2315462117
| <(5,1),3> | (-5,-12) | 13.4012194669
| <(1,3),5> | (5.1,34.5) | 26.7657047773
| <(1,2),3> | (5.1,34.5) | 29.7575945393
| <(5,1),3> | (5.1,34.5) | 30.5001492534
| <(100,200),10> | (5.1,34.5) | 180.778038568
| <(100,200),10> | (10,10) | 200.237960416
| <(100,200),10> | (-3,4) | 211.415898255
| <(100,200),10> | (0,0) | 213.60679775
| <(100,200),10> | (-10,0) | 218.25424421
| <(100,200),10> | (-5,-12) | 226.577682802
(21 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140473)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186547,72.7106781186547),(-69.7106781186547,-68.7106781186547)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932737)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186547),(29.2893218813453,-70.7106781186547)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,-0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,-0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359017709e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718035418e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077053127e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983795))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887966),(-3.33012701896897,0.500000000081027))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.598076211373729),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048616))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((-0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239345139e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983795))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359017709e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718035418e-11),(2.12132034353258,-2.12132034358671),(-4.59307077053127e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181135),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((-0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181135),(200,-1.02068239345139e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+------------------
| <(100,0),100> | (5.1,34.5) | 0.97653192697797
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044152
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140473)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186547,72.7106781186547),(-69.7106781186547,-68.7106781186547)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932737)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186547),(29.2893218813453,-70.7106781186547)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (0,0),(-20,-20)
| (0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359017709e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718035418e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077053127e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983795))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887966),(-3.33012701896897,0.500000000081027))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.598076211373729),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048616))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239345139e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983795))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359017709e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718035418e-11),(2.12132034353258,-2.12132034358671),(-4.59307077053127e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181135),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181135),(200,-1.02068239345139e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+------------------
| <(100,0),100> | (5.1,34.5) | 0.97653192697797
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044152
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (-0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140472)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186547,72.7106781186547),(-69.7106781186547,-68.7106781186547)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932737)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186547),(29.2893218813453,-70.7106781186547)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,-0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,-0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359017709e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718035418e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077053127e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983795))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887966),(-3.33012701896897,0.500000000081027))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.598076211373729),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048616))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239345139e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983795))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359017709e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718035418e-11),(2.12132034353258,-2.12132034358671),(-4.59307077053127e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181135),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181135),(200,-1.02068239345139e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+------------------
| <(100,0),100> | (5.1,34.5) | 0.97653192697797
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044152
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (-0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140473)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186548,72.7106781186548),(-69.7106781186548,-68.7106781186548)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932738)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186548),(29.2893218813452,-70.7106781186548)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,-0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,-0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359017709e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718035418e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077053127e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983795))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887966),(-3.33012701896897,0.500000000081028))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.59807621137373),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048617))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239345139e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983795))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359017709e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718035418e-11),(2.12132034353258,-2.12132034358671),(-4.59307077053127e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181134),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181134),(200,-1.02068239345139e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+-------------------
| <(100,0),100> | (5.1,34.5) | 0.976531926977965
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044151
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (-0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140472)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186547,72.7106781186547),(-69.7106781186547,-68.7106781186547)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932737)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186547),(29.2893218813453,-70.7106781186547)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,-0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,-0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359017709e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718035418e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077053127e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983795))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887967),(-3.33012701896897,0.500000000081028))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.598076211373729),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048616))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239345139e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983795))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359017709e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718035418e-11),(2.12132034353258,-2.12132034358671),(-4.59307077053127e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181135),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181135),(200,-1.02068239345139e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+------------------
| <(100,0),100> | (5.1,34.5) | 0.97653192697797
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044152
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (-0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140473)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186547,72.7106781186547),(-69.7106781186547,-68.7106781186547)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932737)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559642)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186547),(29.2893218813453,-70.7106781186547)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,-0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,-0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359017709e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718035418e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077053127e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983794))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887966),(-3.33012701896897,0.500000000081028))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.598076211373729),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048617))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239345139e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983794))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359017709e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718035418e-11),(2.12132034353258,-2.12132034358671),(-4.59307077053127e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181135),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181135),(200,-1.02068239345139e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+------------------
| <(100,0),100> | (5.1,34.5) | 0.97653192697797
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044152
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773223
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,532 +0,0 @@
--
-- GEOMETRY
--
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
You will have to retype this query using an explicit cast
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (0,0) | [(0,0),(6,6)] | (-0,0)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140472)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Lines
--
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186548,72.7106781186548),(-69.7106781186548,-68.7106781186548)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932738)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559643)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186548),(29.2893218813452,-70.7106781186548)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (-8,2),(-10,0)
| (-1,6),(-3,4)
| (7.1,36.5),(5.1,34.5)
| (-3,-10),(-5,-12)
| (12,12),(10,10)
| (3,3),(1,1)
| (-7,3),(-9,1)
| (0,7),(-2,5)
| (8.1,37.5),(6.1,35.5)
| (-2,-9),(-4,-11)
| (13,13),(11,11)
| (2.5,3.5),(2.5,2.5)
| (-7.5,3.5),(-7.5,2.5)
| (-0.5,7.5),(-0.5,6.5)
| (7.6,38),(7.6,37)
| (-2.5,-8.5),(-2.5,-9.5)
| (12.5,13.5),(12.5,12.5)
| (3,3),(3,3)
| (-7,3),(-7,3)
| (0,7),(0,7)
| (8.1,37.5),(8.1,37.5)
| (-2,-9),(-2,-9)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (12,2),(10,0)
| (5,-2),(3,-4)
| (-3.1,-32.5),(-5.1,-34.5)
| (7,14),(5,12)
| (-8,-8),(-10,-10)
| (3,3),(1,1)
| (13,3),(11,1)
| (6,-1),(4,-3)
| (-2.1,-31.5),(-4.1,-33.5)
| (8,15),(6,13)
| (-7,-7),(-9,-9)
| (2.5,3.5),(2.5,2.5)
| (12.5,3.5),(12.5,2.5)
| (5.5,-0.5),(5.5,-1.5)
| (-2.6,-31),(-2.6,-32)
| (7.5,15.5),(7.5,14.5)
| (-7.5,-6.5),(-7.5,-7.5)
| (3,3),(3,3)
| (13,3),(13,3)
| (6,-1),(6,-1)
| (-2.1,-31.5),(-2.1,-31.5)
| (8,15),(8,15)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-0,2),(-14,0)
| (0,79.2),(-58.8,0)
| (14,-0),(0,-34)
| (0,40),(0,0)
| (0,0),(0,0)
| (-10,-10),(-30,-30)
| (-7,3),(-21,1)
| (-29.4,118.8),(-88.2,39.6)
| (21,-17),(7,-51)
| (0,60),(0,20)
| (0,0),(0,0)
| (-25,-25),(-25,-35)
| (-17.5,2.5),(-21.5,-0.5)
| (-73.5,104.1),(-108,99)
| (29.5,-42.5),(17.5,-47.5)
| (0,60),(-10,50)
| (0,0),(0,0)
| (-30,-30),(-30,-30)
| (-21,3),(-21,3)
| (-88.2,118.8),(-88.2,118.8)
| (21,-51),(21,-51)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.08,-0),(0,-0.56)
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
| (0.3,0),(0.3,0)
(20 rows)
--
-- Paths
--
SET geqo TO 'off';
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
RESET geqo;
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (-10,0) | ((0,0)) | f
| (-3,4) | ((0,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (-5,-12) | ((0,0)) | f
| (10,10) | ((0,0)) | f
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359017709e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718035418e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077053127e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983794))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887966),(-3.33012701896897,0.500000000081028))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.598076211373729),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048617))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239345139e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983794))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359017709e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718035418e-11),(2.12132034353258,-2.12132034358671),(-4.59307077053127e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181135),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181135),(200,-1.02068239345139e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+-------------------
| <(100,0),100> | (5.1,34.5) | 0.976531926977964
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044151
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773224
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)

View File

@ -1,6 +1,9 @@
--
-- GEOMETRY
--
-- Back off displayed precision a little bit to reduce platform-to-platform
-- variation in results.
SET extra_float_digits TO -3;
--
-- Points
--
@ -28,33 +31,33 @@ SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (5,1)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
| (100,1)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (0,0)
| (5,1)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,0)
| (100,1)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------------
| (1.33333333333333,1.33333333333333)
| (2.33333333333333,1.33333333333333)
two | center
-----+-------------------------------
| (1.33333333333,1.33333333333)
| (2.33333333333,1.33333333333)
(2 rows)
-- "is horizontal" function
@ -106,8 +109,8 @@ ERROR: Unable to identify an operator '#' for types 'lseg' and 'point'
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+---------------------------------------
thirty | f1 | s | closest
--------+------------+-------------------------------+----------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(1,2),(3,4)] | (1,2)
@ -120,18 +123,18 @@ SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (0,0) | [(10,-10),(-3,-4)] | (-2.04878048780488,-4.4390243902439)
| (0,0) | [(10,-10),(-3,-4)] | (-2.0487804878,-4.43902439024)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878049,-4.64390243902439)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390243902,-6.48780487804878)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.0028402365895872,15.384614860264)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258202,15.3864610140472)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812267519,15.3851688427303)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221496,15.3836744976925)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420845634,15.3855375281616)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993741978,15.3827690473092)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878,-4.64390243902)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390244,-6.48780487805)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.00284023658959,15.3846148603)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258,15.386461014)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812268,15.3851688427)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221,15.3836744977)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420846,15.3855375282)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993742,15.3827690473)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(11,22),(33,44)] | (11,22)
@ -147,14 +150,14 @@ SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------------------
| (2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964)
| (71.7106781186548,72.7106781186548),(-69.7106781186548,-68.7106781186548)
| (4.53553390593274,6.53553390593274),(-2.53553390593274,-0.535533905932738)
| (3.12132034355964,4.12132034355964),(-1.12132034355964,-0.121320343559643)
| (107.071067811865,207.071067811865),(92.9289321881345,192.928932188135)
| (170.710678118655,70.7106781186548),(29.2893218813452,-70.7106781186548)
six | box
-----+----------------------------------------------------------------
| (7.12132034356,3.12132034356),(2.87867965644,-1.12132034356)
| (71.7106781187,72.7106781187),(-69.7106781187,-68.7106781187)
| (4.53553390593,6.53553390593),(-2.53553390593,-0.535533905933)
| (3.12132034356,4.12132034356),(-1.12132034356,-0.12132034356)
| (107.071067812,207.071067812),(92.9289321881,192.928932188)
| (181.317279836,82.3172798365),(18.6827201635,-80.3172798365)
(6 rows)
-- translation
@ -252,8 +255,8 @@ SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+-----------------------------------------------------------------------------------
twenty | rotation
--------+----------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (-0.1,-0.1),(-0.3,-0.3)
| (-0.25,-0.25),(-0.25,-0.35)
@ -262,14 +265,14 @@ SELECT '' AS twenty, b.f1 / p.f1 AS rotation
| (0.12,-0.28),(0.04,-0.84)
| (0.26,-0.7),(0.1,-0.82)
| (0.12,-0.84),(0.12,-0.84)
| (0.0651176557643925,0),(0,-0.0483449262493217)
| (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
| (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
| (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
| (-0,0.0828402366863905),(-0.201183431952663,0)
| (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
| (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
| (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
| (0.0651176557644,0),(0,-0.0483449262493)
| (0.0976764836466,-0.0241724631247),(0.0325588278822,-0.072517389374)
| (0.109762715209,-0.0562379754329),(0.0813970697055,-0.0604311578117)
| (0.0976764836466,-0.072517389374),(0.0976764836466,-0.072517389374)
| (-0,0.0828402366864),(-0.201183431953,0)
| (-0.100591715976,0.12426035503),(-0.301775147929,0.0414201183432)
| (-0.251479289941,0.103550295858),(-0.322485207101,0.0739644970414)
| (-0.301775147929,0.12426035503),(-0.301775147929,0.12426035503)
| (0.2,0),(0,0)
| (0.3,0),(0.1,0)
| (0.3,0.05),(0.25,0)
@ -441,27 +444,27 @@ SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.59807621135076,1.50000000000442),(-1.49999999999116,2.59807621135842),(1.53102359078377e-11,3),(1.50000000001768,2.59807621134311),(2.59807621136607,1.4999999999779),(3,-3.06204718156754e-11),(2.59807621133545,-1.50000000003094),(1.49999999996464,-2.59807621137373),(-4.59307077235131e-11,-3),(-1.5000000000442,-2.5980762113278),(-2.59807621138138,-1.49999999995138))
| ((-99,2),(-85.6025403783588,52.0000000001473),(-48.9999999997054,88.602540378614),(1.00000000051034,102),(51.0000000005893,88.6025403781036),(87.6025403788692,51.9999999992634),(101,1.99999999897932),(87.6025403778485,-48.0000000010313),(50.9999999988214,-84.6025403791243),(0.999999998468976,-98),(-49.0000000014732,-84.6025403775933),(-85.6025403793795,-47.9999999983795))
| ((-4,3),(-3.33012701891794,5.50000000000737),(-1.49999999998527,7.3301270189307),(1.00000000002552,8),(3.50000000002946,7.33012701890518),(5.33012701894346,5.49999999996317),(6,2.99999999994897),(5.33012701889242,0.499999999948437),(3.49999999994107,-1.33012701895622),(0.999999999923449,-2),(-1.50000000007366,-1.33012701887966),(-3.33012701896897,0.500000000081028))
| ((-2,2),(-1.59807621135076,3.50000000000442),(-0.499999999991161,4.59807621135842),(1.00000000001531,5),(2.50000000001768,4.59807621134311),(3.59807621136607,3.4999999999779),(4,1.99999999996938),(3.59807621133545,0.499999999969062),(2.49999999996464,-0.59807621137373),(0.999999999954069,-1),(-0.500000000044197,-0.598076211327799),(-1.59807621138138,0.500000000048617))
| ((90,200),(91.3397459621641,205.000000000015),(95.0000000000295,208.660254037861),(100.000000000051,210),(105.000000000059,208.66025403781),(108.660254037887,204.999999999926),(110,199.999999999898),(108.660254037785,194.999999999897),(104.999999999882,191.339745962088),(99.9999999998469,190),(94.9999999998527,191.339745962241),(91.3397459620621,195.000000000162))
| ((0,0),(13.3974596216412,50.0000000001473),(50.0000000002946,86.602540378614),(100.00000000051,100),(150.000000000589,86.6025403781036),(186.602540378869,49.9999999992634),(200,-1.02068239385585e-09),(186.602540377848,-50.0000000010313),(149.999999998821,-86.6025403791243),(99.999999998469,-100),(49.9999999985268,-86.6025403775933),(13.3974596206205,-49.9999999983795))
six | polygon
-----+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((2,1),(2.40192378865,2.5),(3.5,3.59807621135),(5,4),(6.5,3.59807621135),(7.59807621135,2.5),(8,1),(7.59807621135,-0.5),(6.5,-1.59807621135),(5,-2),(3.5,-1.59807621135),(2.40192378865,-0.5))
| ((-99,2),(-85.6025403784,52),(-49,88.6025403784),(1,102),(51,88.6025403784),(87.6025403784,52),(101,2),(87.6025403784,-48),(51,-84.6025403784),(1,-98),(-49,-84.6025403784),(-85.6025403784,-48))
| ((-4,3),(-3.33012701892,5.5),(-1.5,7.33012701892),(1,8),(3.5,7.33012701892),(5.33012701892,5.5),(6,3),(5.33012701892,0.5),(3.5,-1.33012701892),(1,-2),(-1.5,-1.33012701892),(-3.33012701892,0.5))
| ((-2,2),(-1.59807621135,3.5),(-0.5,4.59807621135),(1,5),(2.5,4.59807621135),(3.59807621135,3.5),(4,2),(3.59807621135,0.5),(2.5,-0.598076211353),(1,-1),(-0.5,-0.598076211353),(-1.59807621135,0.5))
| ((90,200),(91.3397459622,205),(95,208.660254038),(100,210),(105,208.660254038),(108.660254038,205),(110,200),(108.660254038,195),(105,191.339745962),(100,190),(95,191.339745962),(91.3397459622,195))
| ((-15,1),(0.40707856479,58.5),(42.5,100.592921435),(100,116),(157.5,100.592921435),(199.592921435,58.5),(215,1),(199.592921435,-56.5),(157.5,-98.5929214352),(100,-114),(42.5,-98.5929214352),(0.40707856479,-56.5))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((-3,0),(-2.12132034355423,2.12132034356506),(1.53102359078377e-11,3),(2.12132034357588,2.1213203435434),(3,-3.06204718156754e-11),(2.12132034353258,-2.12132034358671),(-4.59307077235131e-11,-3),(-2.12132034359753,-2.12132034352175))
| ((-99,2),(-69.7106781184743,72.7106781188352),(1.00000000051034,102),(71.710678119196,72.7106781181134),(101,1.99999999897932),(71.7106781177526,-68.7106781195569),(0.999999998468976,-98),(-69.7106781199178,-68.7106781173917))
| ((-4,3),(-2.53553390592372,6.53553390594176),(1.00000000002552,8),(4.5355339059598,6.53553390590567),(6,2.99999999994897),(4.53553390588763,-0.535533905977846),(0.999999999923449,-2),(-2.53553390599589,-0.535533905869586))
| ((-2,2),(-1.12132034355423,4.12132034356506),(1.00000000001531,5),(3.12132034357588,4.1213203435434),(4,1.99999999996938),(3.12132034353258,-0.121320343586707),(0.999999999954069,-1),(-1.12132034359753,-0.121320343521752))
| ((90,200),(92.9289321881526,207.071067811884),(100.000000000051,210),(107.07106781192,207.071067811811),(110,199.999999999898),(107.071067811775,192.928932188044),(99.9999999998469,190),(92.9289321880082,192.928932188261))
| ((0,0),(29.2893218815257,70.7106781188352),(100.00000000051,100),(170.710678119196,70.7106781181134),(200,-1.02068239385585e-09),(170.710678117753,-70.7106781195569),(99.999999998469,-100),(29.2893218800822,-70.7106781173917))
six | polygon
-----+------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((2,1),(2.87867965644,3.12132034356),(5,4),(7.12132034356,3.12132034356),(8,1),(7.12132034356,-1.12132034356),(5,-2),(2.87867965644,-1.12132034356))
| ((-99,2),(-69.7106781187,72.7106781187),(1,102),(71.7106781187,72.7106781187),(101,2),(71.7106781187,-68.7106781187),(1,-98),(-69.7106781187,-68.7106781187))
| ((-4,3),(-2.53553390593,6.53553390593),(1,8),(4.53553390593,6.53553390593),(6,3),(4.53553390593,-0.535533905933),(1,-2),(-2.53553390593,-0.535533905933))
| ((-2,2),(-1.12132034356,4.12132034356),(1,5),(3.12132034356,4.12132034356),(4,2),(3.12132034356,-0.12132034356),(1,-1),(-1.12132034356,-0.12132034356))
| ((90,200),(92.9289321881,207.071067812),(100,210),(107.071067812,207.071067812),(110,200),(107.071067812,192.928932188),(100,190),(92.9289321881,192.928932188))
| ((-15,1),(18.6827201635,82.3172798365),(100,116),(181.317279836,82.3172798365),(215,1),(181.317279836,-80.3172798365),(100,-114),(18.6827201635,-80.3172798365))
(6 rows)
--
@ -481,10 +484,10 @@ SELECT '' AS six, circle(f1, 50.0)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-------------------------
| <(1,1),1.4142135623731>
| <(2,2),1.4142135623731>
four | circle
------+-----------------------
| <(1,1),1.41421356237>
| <(2,2),1.41421356237>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
@ -492,41 +495,38 @@ SELECT '' AS four, circle(f1)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+--------------------------------------------------------
| <(1.33333333333333,1.33333333333333),2.04168905063636>
| <(2.33333333333333,1.33333333333333),1.47534300379185>
two | circle
-----+-----------------------------------------------
| <(1.33333333333,1.33333333333),2.04168905064>
| <(2.33333333333,1.33333333333),1.47534300379>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, circle, point using <<;
twentyfour | circle | point | distance
------------+----------------+------------+-------------------
| <(100,0),100> | (5.1,34.5) | 0.976531926977964
| <(1,2),3> | (-3,4) | 1.47213595499958
| <(0,0),3> | (-3,4) | 2
| <(100,0),100> | (-3,4) | 3.07764064044151
| <(100,0),100> | (-5,-12) | 5.68348972285122
| <(1,3),5> | (-10,0) | 6.40175425099138
| <(1,3),5> | (10,10) | 6.40175425099138
| <(0,0),3> | (-10,0) | 7
| <(1,2),3> | (-10,0) | 8.18033988749895
| <(1,2),3> | (10,10) | 9.0415945787923
| <(0,0),3> | (-5,-12) | 10
| <(100,0),100> | (-10,0) | 10
| <(0,0),3> | (10,10) | 11.142135623731
| <(1,3),5> | (-5,-12) | 11.1554944214035
| <(1,2),3> | (-5,-12) | 12.2315462117278
| <(1,3),5> | (5.1,34.5) | 26.7657047773224
| <(1,2),3> | (5.1,34.5) | 29.757594539282
| <(0,0),3> | (5.1,34.5) | 31.8749193547455
| <(100,200),10> | (5.1,34.5) | 180.778038568384
| <(100,200),10> | (10,10) | 200.237960416286
| <(100,200),10> | (-3,4) | 211.415898254845
| <(100,200),10> | (0,0) | 213.606797749979
| <(100,200),10> | (-10,0) | 218.254244210267
| <(100,200),10> | (-5,-12) | 226.577682802077
(24 rows)
twentyfour | circle | point | distance
------------+----------------+------------+---------------
| <(1,2),3> | (-3,4) | 1.472135955
| <(5,1),3> | (0,0) | 2.09901951359
| <(5,1),3> | (-3,4) | 5.54400374532
| <(1,3),5> | (-10,0) | 6.40175425099
| <(1,3),5> | (10,10) | 6.40175425099
| <(5,1),3> | (10,10) | 7.29563014099
| <(1,2),3> | (-10,0) | 8.1803398875
| <(1,2),3> | (10,10) | 9.04159457879
| <(1,3),5> | (-5,-12) | 11.1554944214
| <(5,1),3> | (-10,0) | 12.0332963784
| <(1,2),3> | (-5,-12) | 12.2315462117
| <(5,1),3> | (-5,-12) | 13.4012194669
| <(1,3),5> | (5.1,34.5) | 26.7657047773
| <(1,2),3> | (5.1,34.5) | 29.7575945393
| <(5,1),3> | (5.1,34.5) | 30.5001492534
| <(100,200),10> | (5.1,34.5) | 180.778038568
| <(100,200),10> | (10,10) | 200.237960416
| <(100,200),10> | (-3,4) | 211.415898255
| <(100,200),10> | (0,0) | 213.60679775
| <(100,200),10> | (-10,0) | 218.25424421
| <(100,200),10> | (-5,-12) | 226.577682802
(21 rows)

View File

@ -10,32 +10,15 @@ float8/i.86-.*-netbsd=float8-small-is-zero
float8/.*-qnx=float8-exp-three-digits
float8/alpha.*-dec-osf.*:cc=float8-fp-exception
float8/i.86-pc-cygwin=float8-small-is-zero
geometry/.*-bsdi=geometry-bsd-precision
geometry/.*-darwin=geometry-powerpc-darwin
geometry/i.86-.*-freebsd=geometry-positive-zeros-bsd
geometry/i.86-.*-freebsd4.7=geometry-bsd-precision
geometry/i.86-.*-freebsd5=geometry-bsd-precision
geometry/alpha.*-freebsd=geometry-positive-zeros
geometry/i.86-.*-openbsd=geometry-positive-zeros-bsd
geometry/.*-darwin=geometry-positive-zeros
geometry/i.86-.*-freebsd4.[0-5]=geometry-positive-zeros
geometry/alpha.*-freebsd4.[0-5]=geometry-positive-zeros
geometry/i.86-.*-openbsd=geometry-positive-zeros
geometry/sparc-.*-openbsd=geometry-positive-zeros
geometry/.*-irix6=geometry-irix
geometry/.*-netbsd=geometry-positive-zeros
geometry/.*-sysv5.*:cc=geometry-uw7-cc
geometry/.*-sysv5.*:gcc=geometry-uw7-gcc
geometry/alpha.*-dec-osf=geometry-alpha-precision
geometry/hppa.*-hpux9=geometry-positive-zeros
geometry/hppa.*-hpux10=geometry-positive-zeros
geometry/hppa.*-hpux11=geometry-solaris-precision
geometry/i.86-.*-gnulibc=geometry-i86-gnulibc
geometry/i.86-pc-cygwin=geometry-solaris-precision
geometry/i.86-pc-solaris2.7=geometry-solaris-i386-pc
geometry/powerpc-unknown-linux-gnu=geometry-powerpc-linux-gnulibc1
geometry/powerpc.*-aix4=geometry-powerpc-aix4
geometry/powerpc.*-aix5=geometry-powerpc-aix4
geometry/sparc-sun-solaris=geometry-solaris-precision
geometry/sparc.*-linux-gnu=geometry-solaris-precision
geometry/alpha.*-linux-gnu=geometry-solaris-precision
geometry/.*-beos=geometry-intel-beos
geometry/.*-irix6=geometry-positive-zeros
horology/.*-aix4=horology-no-DST-before-1970
horology/.*-aix5=horology-no-DST-before-1970
horology/.*-irix6=horology-no-DST-before-1970

View File

@ -4,7 +4,7 @@
CREATE TABLE CIRCLE_TBL (f1 circle);
INSERT INTO CIRCLE_TBL VALUES ('<(0,0),3>');
INSERT INTO CIRCLE_TBL VALUES ('<(5,1),3>');
INSERT INTO CIRCLE_TBL VALUES ('<(1,2),100>');
@ -14,7 +14,7 @@ INSERT INTO CIRCLE_TBL VALUES ('((1,2),3)');
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>');
INSERT INTO CIRCLE_TBL VALUES ('<(100,0),100>');
INSERT INTO CIRCLE_TBL VALUES ('<(100,1),115>');
-- bad values

View File

@ -2,6 +2,10 @@
-- GEOMETRY
--
-- Back off displayed precision a little bit to reduce platform-to-platform
-- variation in results.
SET extra_float_digits TO -3;
--
-- Points
--