You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
7.5 KiB

  1. --source include/have_geometry.inc
  2. #
  3. # Spatial objects
  4. #
  5. --disable_warnings
  6. DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry;
  7. --enable_warnings
  8. CREATE TABLE gis_point (fid INTEGER, g POINT);
  9. CREATE TABLE gis_line (fid INTEGER, g LINESTRING);
  10. CREATE TABLE gis_polygon (fid INTEGER, g POLYGON);
  11. CREATE TABLE gis_multi_point (fid INTEGER, g MULTIPOINT);
  12. CREATE TABLE gis_multi_line (fid INTEGER, g MULTILINESTRING);
  13. CREATE TABLE gis_multi_polygon (fid INTEGER, g MULTIPOLYGON);
  14. CREATE TABLE gis_geometrycollection (fid INTEGER, g GEOMETRYCOLLECTION);
  15. CREATE TABLE gis_geometry (fid INTEGER, g GEOMETRY);
  16. SHOW CREATE TABLE gis_point;
  17. SHOW FIELDS FROM gis_point;
  18. SHOW FIELDS FROM gis_line;
  19. SHOW FIELDS FROM gis_polygon;
  20. SHOW FIELDS FROM gis_multi_point;
  21. SHOW FIELDS FROM gis_multi_line;
  22. SHOW FIELDS FROM gis_multi_polygon;
  23. SHOW FIELDS FROM gis_geometrycollection;
  24. SHOW FIELDS FROM gis_geometry;
  25. INSERT INTO gis_point VALUES
  26. (101, PointFromText('POINT(10 10)')),
  27. (102, PointFromText('POINT(20 10)')),
  28. (103, PointFromText('POINT(20 20)')),
  29. (104, PointFromWKB(AsWKB(PointFromText('POINT(10 20)'))));
  30. INSERT INTO gis_line VALUES
  31. (105, LineFromText('LINESTRING(0 0,0 10,10 0)')),
  32. (106, LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)')),
  33. (107, LineStringFromWKB(LineString(Point(10, 10), Point(40, 10))));
  34. INSERT INTO gis_polygon VALUES
  35. (108, PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')),
  36. (109, PolyFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10))')),
  37. (110, PolyFromWKB(Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0)))));
  38. INSERT INTO gis_multi_point VALUES
  39. (111, MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)')),
  40. (112, MPointFromText('MULTIPOINT(1 1,11 11,11 21,21 21)')),
  41. (113, MPointFromWKB(MultiPoint(Point(3, 6), Point(4, 10))));
  42. INSERT INTO gis_multi_line VALUES
  43. (114, MultiLineStringFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))')),
  44. (115, MLineFromText('MULTILINESTRING((10 48,10 21,10 0))')),
  45. (116, MLineFromWKB(MultiLineString(LineString(Point(1, 2), Point(3, 5)), LineString(Point(2, 5), Point(5, 8), Point(21, 7)))));
  46. INSERT INTO gis_multi_polygon VALUES
  47. (117, MultiPolygonFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')),
  48. (118, MPolyFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')),
  49. (119, MPolyFromWKB(MultiPolygon(Polygon(LineString(Point(0, 3), Point(3, 3), Point(3, 0), Point(0, 3))))));
  50. INSERT INTO gis_geometrycollection VALUES
  51. (120, GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')),
  52. (121, GeometryFromWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))));
  53. INSERT into gis_geometry SELECT * FROM gis_point;
  54. INSERT into gis_geometry SELECT * FROM gis_line;
  55. INSERT into gis_geometry SELECT * FROM gis_polygon;
  56. INSERT into gis_geometry SELECT * FROM gis_multi_point;
  57. INSERT into gis_geometry SELECT * FROM gis_multi_line;
  58. INSERT into gis_geometry SELECT * FROM gis_multi_polygon;
  59. INSERT into gis_geometry SELECT * FROM gis_geometrycollection;
  60. SELECT fid, AsText(g) FROM gis_point ORDER by fid;
  61. SELECT fid, AsText(g) FROM gis_line ORDER by fid;
  62. SELECT fid, AsText(g) FROM gis_polygon ORDER by fid;
  63. SELECT fid, AsText(g) FROM gis_multi_point ORDER by fid;
  64. SELECT fid, AsText(g) FROM gis_multi_line ORDER by fid;
  65. SELECT fid, AsText(g) FROM gis_multi_polygon ORDER by fid;
  66. SELECT fid, AsText(g) FROM gis_geometrycollection ORDER by fid;
  67. SELECT fid, AsText(g) FROM gis_geometry ORDER by fid;
  68. SELECT fid, Dimension(g) FROM gis_geometry ORDER by fid;
  69. SELECT fid, GeometryType(g) FROM gis_geometry ORDER by fid;
  70. SELECT fid, IsEmpty(g) FROM gis_geometry ORDER by fid;
  71. SELECT fid, AsText(Envelope(g)) FROM gis_geometry ORDER by fid;
  72. explain extended select Dimension(g), GeometryType(g), IsEmpty(g), AsText(Envelope(g)) from gis_geometry;
  73. SELECT fid, X(g) FROM gis_point ORDER by fid;
  74. SELECT fid, Y(g) FROM gis_point ORDER by fid;
  75. explain extended select X(g),Y(g) FROM gis_point;
  76. SELECT fid, AsText(StartPoint(g)) FROM gis_line ORDER by fid;
  77. SELECT fid, AsText(EndPoint(g)) FROM gis_line ORDER by fid;
  78. SELECT fid, GLength(g) FROM gis_line ORDER by fid;
  79. SELECT fid, NumPoints(g) FROM gis_line ORDER by fid;
  80. SELECT fid, AsText(PointN(g, 2)) FROM gis_line ORDER by fid;
  81. SELECT fid, IsClosed(g) FROM gis_line ORDER by fid;
  82. explain extended select AsText(StartPoint(g)),AsText(EndPoint(g)),GLength(g),NumPoints(g),AsText(PointN(g, 2)),IsClosed(g) FROM gis_line;
  83. SELECT fid, AsText(Centroid(g)) FROM gis_polygon ORDER by fid;
  84. SELECT fid, Area(g) FROM gis_polygon ORDER by fid;
  85. SELECT fid, AsText(ExteriorRing(g)) FROM gis_polygon ORDER by fid;
  86. SELECT fid, NumInteriorRings(g) FROM gis_polygon ORDER by fid;
  87. SELECT fid, AsText(InteriorRingN(g, 1)) FROM gis_polygon ORDER by fid;
  88. explain extended select AsText(Centroid(g)),Area(g),AsText(ExteriorRing(g)),NumInteriorRings(g),AsText(InteriorRingN(g, 1)) FROM gis_polygon;
  89. SELECT fid, IsClosed(g) FROM gis_multi_line ORDER by fid;
  90. SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon ORDER by fid;
  91. SELECT fid, Area(g) FROM gis_multi_polygon ORDER by fid;
  92. SELECT fid, NumGeometries(g) from gis_multi_point ORDER by fid;
  93. SELECT fid, NumGeometries(g) from gis_multi_line ORDER by fid;
  94. SELECT fid, NumGeometries(g) from gis_multi_polygon ORDER by fid;
  95. SELECT fid, NumGeometries(g) from gis_geometrycollection ORDER by fid;
  96. explain extended SELECT fid, NumGeometries(g) from gis_multi_point;
  97. SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_point ORDER by fid;
  98. SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_line ORDER by fid;
  99. SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_polygon ORDER by fid;
  100. SELECT fid, AsText(GeometryN(g, 2)) from gis_geometrycollection ORDER by fid;
  101. SELECT fid, AsText(GeometryN(g, 1)) from gis_geometrycollection ORDER by fid;
  102. explain extended SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_point;
  103. SELECT g1.fid as first, g2.fid as second,
  104. Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o,
  105. Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t,
  106. Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r
  107. FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second;
  108. explain extended SELECT g1.fid as first, g2.fid as second,
  109. Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o,
  110. Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t,
  111. Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r
  112. FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second;
  113. DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry;
  114. #
  115. # Check that ALTER TABLE doesn't loose geometry type
  116. #
  117. CREATE TABLE t1 (
  118. gp point,
  119. ln linestring,
  120. pg polygon,
  121. mp multipoint,
  122. mln multilinestring,
  123. mpg multipolygon,
  124. gc geometrycollection,
  125. gm geometry
  126. );
  127. SHOW FIELDS FROM t1;
  128. ALTER TABLE t1 ADD fid INT;
  129. SHOW FIELDS FROM t1;
  130. DROP TABLE t1;
  131. create table t1 (a geometry not null);
  132. insert into t1 values (GeomFromText('Point(1 2)'));
  133. -- error 1416
  134. insert into t1 values ('Garbage');
  135. -- error 1416
  136. insert IGNORE into t1 values ('Garbage');
  137. drop table t1;
  138. create table t1 (fl geometry);
  139. --error 1416
  140. insert into t1 values (1);
  141. --error 1416
  142. insert into t1 values (1.11);
  143. --error 1416
  144. insert into t1 values ("qwerty");
  145. --error 1416
  146. insert into t1 values (pointfromtext('point(1,1)'));
  147. drop table t1;
  148. # End of 5.0 tests