Skip to content

Commit

Permalink
MDEV-4045 Missing OGC Spatial functions.
Browse files Browse the repository at this point in the history
   Missing GIS functions added:
        IsRing()
        PointOnSurface
        PointOnSurface
        Relate
        Distance
        Intersection
        ConvexHull
   Other old OpenGis standard inconsistencies fixed.
  • Loading branch information
Alexey Botchkov committed Nov 27, 2014
1 parent 7b55b67 commit d0d6284
Show file tree
Hide file tree
Showing 9 changed files with 996 additions and 101 deletions.
68 changes: 68 additions & 0 deletions mysql-test/r/gis.result
Expand Up @@ -1326,6 +1326,18 @@ WHERE name = 'Route 5'
AND aliases = 'Main Street';
IsEmpty(centerline)
0
# Conformance Item T12
SELECT IsSimple(shore)
FROM lakes
WHERE name = 'Blue Lake';
IsSimple(shore)
1
# Conformance Item T13
SELECT AsText(ST_Boundary(boundary))
FROM named_places
WHERE name = 'Goose Island';
AsText(ST_Boundary(boundary))
LINESTRING(67 13,67 18,59 18,59 13,67 13)
# Conformance Item T14
SELECT AsText(Envelope(boundary))
FROM named_places
Expand Down Expand Up @@ -1356,6 +1368,17 @@ FROM road_segments
WHERE fid = 102;
AsText(EndPoint(centerline))
POINT(44 31)
SELECT IsClosed(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary)))
FROM named_places
WHERE name = 'Goose Island';
IsClosed(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary)))
1
# Conformance Item T20
SELECT IsRing(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary)))
FROM named_places
WHERE name = 'Goose Island';
IsRing(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary)))
0
# Conformance Item T21
SELECT GLength(centerline)
FROM road_segments
Expand All @@ -1380,6 +1403,11 @@ FROM named_places
WHERE name = 'Goose Island';
AsText(Centroid(boundary))
POINT(63 15.5)
SELECT ST_Contains(boundary, PointOnSurface(boundary))
FROM named_places
WHERE name = 'Goose Island';
ST_Contains(boundary, PointOnSurface(boundary))
1
# Conformance Item T26
SELECT Area(boundary)
FROM named_places
Expand Down Expand Up @@ -1434,6 +1462,12 @@ FROM ponds
WHERE fid = 120;
AsText(Centroid(shores))
POINT(25 42)
# Conformance Item T35
SELECT Contains(shores, PointOnSurface(shores))
FROM ponds
WHERE fid = 120;
Contains(shores, PointOnSurface(shores))
1
# Conformance Item T36
SELECT Area(shores)
FROM ponds
Expand Down Expand Up @@ -1462,6 +1496,20 @@ WHERE streams.name = 'Cam Stream'
AND lakes.name = 'Blue Lake';
ST_Touches(centerline, shore)
1
# Conformance Item T40
SELECT ST_Within(footprint, boundary)
FROM named_places, buildings
WHERE named_places.name = 'Ashton'
AND buildings.address = '215 Main Street';
ST_Within(footprint, boundary)
1
# Conformance Item T41
SELECT ST_Overlaps(forests.boundary, named_places.boundary)
FROM forests, named_places
WHERE forests.name = 'Green Forest'
AND named_places.name = 'Ashton';
ST_Overlaps(forests.boundary, named_places.boundary)
1
# Conformance Item T42
SELECT Crosses(road_segments.centerline, divided_routes.centerlines)
FROM road_segments, divided_routes
Expand All @@ -1483,13 +1531,27 @@ WHERE forests.name = 'Green Forest'
AND named_places.name = 'Ashton';
ST_Contains(forests.boundary, named_places.boundary)
0
# Conformance Item T45
SELECT ST_Relate(forests.boundary, named_places.boundary, 'TTTTTTTTT')
FROM forests, named_places
WHERE forests.name = 'Green Forest'
AND named_places.name = 'Ashton';
ST_Relate(forests.boundary, named_places.boundary, 'TTTTTTTTT')
1
# Conformance Item T46
SELECT ST_Distance(position, boundary)
FROM bridges, named_places
WHERE bridges.name = 'Cam Bridge'
AND named_places.name = 'Ashton';
ST_Distance(position, boundary)
12
# Conformance Item T47
SELECT AsText(ST_Intersection(centerline, shore))
FROM streams, lakes
WHERE streams.name = 'Cam Stream'
AND lakes.name = 'Blue Lake';
AsText(ST_Intersection(centerline, shore))
POINT(52 18)
# Conformance Item T48
SELECT AsText(ST_Difference(named_places.boundary, forests.boundary))
FROM named_places, forests
Expand All @@ -1516,6 +1578,12 @@ FROM buildings, bridges
WHERE ST_Contains(ST_Buffer(bridges.position, 15.0), buildings.footprint) = 1;
count(*)
1
# Conformance Item T52
SELECT AsText(ConvexHull(shore))
FROM lakes
WHERE lakes.name = 'Blue Lake';
AsText(ConvexHull(shore))
POLYGON((48 6,52 18,66 23,73 9,48 6))
DROP DATABASE gis_ogs;
USE test;
#
Expand Down
126 changes: 46 additions & 80 deletions mysql-test/t/gis.test
Expand Up @@ -1119,33 +1119,27 @@ FROM named_places
WHERE name = 'Goose Island';

--echo # Conformance Item T10
# TODO: ST_SRID() alias
SELECT SRID(boundary)
FROM named_places
WHERE name = 'Goose Island';

--echo # Conformance Item T11
# TODO: ST_IsEmpty() alias
SELECT IsEmpty(centerline)
FROM road_segments
WHERE name = 'Route 5'
AND aliases = 'Main Street';

# FIXME: get wrong result:0, expected 1.
#--echo # Conformance Item T12
# TODO: ST_IsSimple() alias
#SELECT IsSimple(shore)
#FROM lakes
#WHERE name = 'Blue Lake';
--echo # Conformance Item T12
SELECT IsSimple(shore)
FROM lakes
WHERE name = 'Blue Lake';

# TODO: WL#2377
#--echo # Conformance Item T13
#SELECT AsText(Boundary((boundary),101)
#FROM named_places
#WHERE name = 'Goose Island';
--echo # Conformance Item T13
SELECT AsText(ST_Boundary(boundary))
FROM named_places
WHERE name = 'Goose Island';

--echo # Conformance Item T14
# TODO: ST_Envelope( ) alias
# FIXME: we get anticlockwise, GIS suggests clockwise
SELECT AsText(Envelope(boundary))
FROM named_places
Expand All @@ -1170,122 +1164,100 @@ FROM road_segments
WHERE fid = 102;

--echo # Conformance Item T18
# TODO: ST_EndPoint
SELECT AsText(EndPoint(centerline))
FROM road_segments
WHERE fid = 102;

# TODO: WL#2377
#--echo # Conformance Item T19
# TODO: ST_LineFromWKB() alias
#SELECT IsClosed(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary)))
#FROM named_places
#WHERE name = 'Goose Island';
SELECT IsClosed(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary)))
FROM named_places
WHERE name = 'Goose Island';

# TODO: WL#2377
#--echo # Conformance Item T20
#SELECT IsRing(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary)))
#FROM named_places
#WHERE name = 'Goose Island';
--echo # Conformance Item T20
SELECT IsRing(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary)))
FROM named_places
WHERE name = 'Goose Island';

--echo # Conformance Item T21
# TODO: ST_Length() alias
SELECT GLength(centerline)
FROM road_segments
WHERE fid = 106;

--echo # Conformance Item T22
# TODO: ST_NumPoints() alias
SELECT NumPoints(centerline)
FROM road_segments
WHERE fid = 102;

--echo # Conformance Item T23
# TODO: ST_PointN() alias
SELECT AsText(PointN(centerline, 1))
FROM road_segments
WHERE fid = 102;

--echo # Conformance Item T24
# TODO: ST_Centroid() alias
SELECT AsText(Centroid(boundary))
FROM named_places
WHERE name = 'Goose Island';

# TODO: WL#2377
#--echo # Conformance Item T25
#SELECT Contains(boundary, PointOnSurface(boundary))
#FROM named_places
#WHERE name = 'Goose Island';
SELECT ST_Contains(boundary, PointOnSurface(boundary))
FROM named_places
WHERE name = 'Goose Island';

--echo # Conformance Item T26
# TODO: ST_Area() alias
SELECT Area(boundary)
FROM named_places
WHERE name = 'Goose Island';

--echo # Conformance Item T27
# TODO: ST_ExteriorRing() alias
SELECT AsText(ExteriorRing(shore))
FROM lakes
WHERE name = 'Blue Lake';

--echo # Conformance Item T28
# TODO: ST_NumInteriorRings() alias
SELECT NumInteriorRings(shore)
FROM lakes
WHERE name = 'Blue Lake';

--echo # Conformance Item T29
# TODO: ST_InteriorRingN() alias
SELECT AsText(InteriorRingN(shore, 1))
FROM lakes
WHERE name = 'Blue Lake';

--echo # Conformance Item T30
# TODO: ST_NumGeometries() alias
SELECT NumGeometries(centerlines)
FROM divided_routes
WHERE name = 'Route 75';

--echo # Conformance Item T31
# TODO: ST_GeometryN() alias
SELECT AsText(GeometryN(centerlines, 2))
FROM divided_routes
WHERE name = 'Route 75';

--echo # Conformance Item T32
# TODO: ST_IsClosed() alias
SELECT IsClosed(centerlines)
FROM divided_routes
WHERE name = 'Route 75';

--echo # Conformance Item T33
# TODO: ST_Length() alias
SELECT GLength(centerlines)
FROM divided_routes
WHERE name = 'Route 75';

--echo # Conformance Item T34
# TODO: ST_Centroid() alias
SELECT AsText(Centroid(shores))
FROM ponds
WHERE fid = 120;

# TODO: WL#2377
#--echo # Conformance Item T35
#SELECT Contains(shores, PointOnSurface(shores))
#FROM ponds
#WHERE fid = 120;
--echo # Conformance Item T35
SELECT Contains(shores, PointOnSurface(shores))
FROM ponds
WHERE fid = 120;

--echo # Conformance Item T36
# TODO: ST_Area() alias
SELECT Area(shores)
FROM ponds
WHERE fid = 120;

--echo # Conformance Item T37
# TODO: ST_PolyFromText() alias
SELECT ST_Equals(boundary,
PolyFromText('POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )',1))
FROM named_places
Expand All @@ -1303,22 +1275,19 @@ FROM streams, lakes
WHERE streams.name = 'Cam Stream'
AND lakes.name = 'Blue Lake';

# FIXME: wrong result: get 0, expected 1
#--echo # Conformance Item T40
#SELECT ST_Within(boundary, footprint)
#FROM named_places, buildings
#WHERE named_places.name = 'Ashton'
#AND buildings.address = '215 Main Street';
--echo # Conformance Item T40
SELECT ST_Within(footprint, boundary)
FROM named_places, buildings
WHERE named_places.name = 'Ashton'
AND buildings.address = '215 Main Street';

# FIXME: wrong result: get 0, expected 1
#--echo # Conformance Item T41
#SELECT ST_Overlaps(forests.boundary, named_places.boundary)
#FROM forests, named_places
#WHERE forests.name = 'Green Forest'
#AND named_places.name = 'Ashton';
--echo # Conformance Item T41
SELECT ST_Overlaps(forests.boundary, named_places.boundary)
FROM forests, named_places
WHERE forests.name = 'Green Forest'
AND named_places.name = 'Ashton';

--echo # Conformance Item T42
# FIXME: TODO: ST_Crosses() alias
SELECT Crosses(road_segments.centerline, divided_routes.centerlines)
FROM road_segments, divided_routes
WHERE road_segments.fid = 102
Expand All @@ -1336,25 +1305,23 @@ FROM forests, named_places
WHERE forests.name = 'Green Forest'
AND named_places.name = 'Ashton';

# TODO: WL#2377
#--echo # Conformance Item T45
#SELECT Relate(forests.boundary, named_places.boundary, 'TTTTTTTTT')
#FROM forests, named_places
#WHERE forests.name = 'Green Forest'
#AND named_places.name = 'Ashton';
--echo # Conformance Item T45
SELECT ST_Relate(forests.boundary, named_places.boundary, 'TTTTTTTTT')
FROM forests, named_places
WHERE forests.name = 'Green Forest'
AND named_places.name = 'Ashton';

--echo # Conformance Item T46
SELECT ST_Distance(position, boundary)
FROM bridges, named_places
WHERE bridges.name = 'Cam Bridge'
AND named_places.name = 'Ashton';

# FIXME: wrong result: NULL, expected 12
#--echo # Conformance Item T47
#SELECT AsText(ST_Intersection(centerline, shore))
#FROM streams, lakes
#WHERE streams.name = 'Cam Stream'
#AND lakes.name = 'Blue Lake';
--echo # Conformance Item T47
SELECT AsText(ST_Intersection(centerline, shore))
FROM streams, lakes
WHERE streams.name = 'Cam Stream'
AND lakes.name = 'Blue Lake';

--echo # Conformance Item T48
SELECT AsText(ST_Difference(named_places.boundary, forests.boundary))
Expand All @@ -1379,11 +1346,10 @@ SELECT count(*)
FROM buildings, bridges
WHERE ST_Contains(ST_Buffer(bridges.position, 15.0), buildings.footprint) = 1;

# TODO: WL#2377
#--echo # Conformance Item T52
#SELECT AsText(ConvexHull(shore))
#FROM lakes
#WHERE lakes.name = 'Blue Lake';
--echo # Conformance Item T52
SELECT AsText(ConvexHull(shore))
FROM lakes
WHERE lakes.name = 'Blue Lake';

DROP DATABASE gis_ogs;
USE test;
Expand Down

0 comments on commit d0d6284

Please sign in to comment.