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.

544 lines
22 KiB

  1. SET storage_engine=bdb;
  2. DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry;
  3. CREATE TABLE gis_point (fid INTEGER, g POINT);
  4. CREATE TABLE gis_line (fid INTEGER, g LINESTRING);
  5. CREATE TABLE gis_polygon (fid INTEGER, g POLYGON);
  6. CREATE TABLE gis_multi_point (fid INTEGER, g MULTIPOINT);
  7. CREATE TABLE gis_multi_line (fid INTEGER, g MULTILINESTRING);
  8. CREATE TABLE gis_multi_polygon (fid INTEGER, g MULTIPOLYGON);
  9. CREATE TABLE gis_geometrycollection (fid INTEGER, g GEOMETRYCOLLECTION);
  10. CREATE TABLE gis_geometry (fid INTEGER, g GEOMETRY);
  11. SHOW CREATE TABLE gis_point;
  12. Table Create Table
  13. gis_point CREATE TABLE `gis_point` (
  14. `fid` int(11) default NULL,
  15. `g` point default NULL
  16. ) ENGINE=BerkeleyDB DEFAULT CHARSET=latin1
  17. SHOW FIELDS FROM gis_point;
  18. Field Type Null Key Default Extra
  19. fid int(11) YES NULL
  20. g point YES NULL
  21. SHOW FIELDS FROM gis_line;
  22. Field Type Null Key Default Extra
  23. fid int(11) YES NULL
  24. g linestring YES NULL
  25. SHOW FIELDS FROM gis_polygon;
  26. Field Type Null Key Default Extra
  27. fid int(11) YES NULL
  28. g polygon YES NULL
  29. SHOW FIELDS FROM gis_multi_point;
  30. Field Type Null Key Default Extra
  31. fid int(11) YES NULL
  32. g multipoint YES NULL
  33. SHOW FIELDS FROM gis_multi_line;
  34. Field Type Null Key Default Extra
  35. fid int(11) YES NULL
  36. g multilinestring YES NULL
  37. SHOW FIELDS FROM gis_multi_polygon;
  38. Field Type Null Key Default Extra
  39. fid int(11) YES NULL
  40. g multipolygon YES NULL
  41. SHOW FIELDS FROM gis_geometrycollection;
  42. Field Type Null Key Default Extra
  43. fid int(11) YES NULL
  44. g geometrycollection YES NULL
  45. SHOW FIELDS FROM gis_geometry;
  46. Field Type Null Key Default Extra
  47. fid int(11) YES NULL
  48. g geometry YES NULL
  49. INSERT INTO gis_point VALUES
  50. (101, PointFromText('POINT(10 10)')),
  51. (102, PointFromText('POINT(20 10)')),
  52. (103, PointFromText('POINT(20 20)')),
  53. (104, PointFromWKB(AsWKB(PointFromText('POINT(10 20)'))));
  54. INSERT INTO gis_line VALUES
  55. (105, LineFromText('LINESTRING(0 0,0 10,10 0)')),
  56. (106, LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)')),
  57. (107, LineStringFromWKB(LineString(Point(10, 10), Point(40, 10))));
  58. INSERT INTO gis_polygon VALUES
  59. (108, PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')),
  60. (109, PolyFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10))')),
  61. (110, PolyFromWKB(Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0)))));
  62. INSERT INTO gis_multi_point VALUES
  63. (111, MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)')),
  64. (112, MPointFromText('MULTIPOINT(1 1,11 11,11 21,21 21)')),
  65. (113, MPointFromWKB(MultiPoint(Point(3, 6), Point(4, 10))));
  66. INSERT INTO gis_multi_line VALUES
  67. (114, MultiLineStringFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))')),
  68. (115, MLineFromText('MULTILINESTRING((10 48,10 21,10 0))')),
  69. (116, MLineFromWKB(MultiLineString(LineString(Point(1, 2), Point(3, 5)), LineString(Point(2, 5), Point(5, 8), Point(21, 7)))));
  70. INSERT INTO gis_multi_polygon VALUES
  71. (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)))')),
  72. (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)))')),
  73. (119, MPolyFromWKB(MultiPolygon(Polygon(LineString(Point(0, 3), Point(3, 3), Point(3, 0), Point(0, 3))))));
  74. INSERT INTO gis_geometrycollection VALUES
  75. (120, GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')),
  76. (121, GeometryFromWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))));
  77. INSERT into gis_geometry SELECT * FROM gis_point;
  78. INSERT into gis_geometry SELECT * FROM gis_line;
  79. INSERT into gis_geometry SELECT * FROM gis_polygon;
  80. INSERT into gis_geometry SELECT * FROM gis_multi_point;
  81. INSERT into gis_geometry SELECT * FROM gis_multi_line;
  82. INSERT into gis_geometry SELECT * FROM gis_multi_polygon;
  83. INSERT into gis_geometry SELECT * FROM gis_geometrycollection;
  84. SELECT fid, AsText(g) FROM gis_point ORDER by fid;
  85. fid AsText(g)
  86. 101 POINT(10 10)
  87. 102 POINT(20 10)
  88. 103 POINT(20 20)
  89. 104 POINT(10 20)
  90. SELECT fid, AsText(g) FROM gis_line ORDER by fid;
  91. fid AsText(g)
  92. 105 LINESTRING(0 0,0 10,10 0)
  93. 106 LINESTRING(10 10,20 10,20 20,10 20,10 10)
  94. 107 LINESTRING(10 10,40 10)
  95. SELECT fid, AsText(g) FROM gis_polygon ORDER by fid;
  96. fid AsText(g)
  97. 108 POLYGON((10 10,20 10,20 20,10 20,10 10))
  98. 109 POLYGON((0 0,50 0,50 50,0 50,0 0),(10 10,20 10,20 20,10 20,10 10))
  99. 110 POLYGON((0 0,30 0,30 30,0 0))
  100. SELECT fid, AsText(g) FROM gis_multi_point ORDER by fid;
  101. fid AsText(g)
  102. 111 MULTIPOINT(0 0,10 10,10 20,20 20)
  103. 112 MULTIPOINT(1 1,11 11,11 21,21 21)
  104. 113 MULTIPOINT(3 6,4 10)
  105. SELECT fid, AsText(g) FROM gis_multi_line ORDER by fid;
  106. fid AsText(g)
  107. 114 MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))
  108. 115 MULTILINESTRING((10 48,10 21,10 0))
  109. 116 MULTILINESTRING((1 2,3 5),(2 5,5 8,21 7))
  110. SELECT fid, AsText(g) FROM gis_multi_polygon ORDER by fid;
  111. fid AsText(g)
  112. 117 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)))
  113. 118 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)))
  114. 119 MULTIPOLYGON(((0 3,3 3,3 0,0 3)))
  115. SELECT fid, AsText(g) FROM gis_geometrycollection ORDER by fid;
  116. fid AsText(g)
  117. 120 GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(0 0,10 10))
  118. 121 GEOMETRYCOLLECTION(POINT(44 6),LINESTRING(3 6,7 9))
  119. SELECT fid, AsText(g) FROM gis_geometry ORDER by fid;
  120. fid AsText(g)
  121. 101 POINT(10 10)
  122. 102 POINT(20 10)
  123. 103 POINT(20 20)
  124. 104 POINT(10 20)
  125. 105 LINESTRING(0 0,0 10,10 0)
  126. 106 LINESTRING(10 10,20 10,20 20,10 20,10 10)
  127. 107 LINESTRING(10 10,40 10)
  128. 108 POLYGON((10 10,20 10,20 20,10 20,10 10))
  129. 109 POLYGON((0 0,50 0,50 50,0 50,0 0),(10 10,20 10,20 20,10 20,10 10))
  130. 110 POLYGON((0 0,30 0,30 30,0 0))
  131. 111 MULTIPOINT(0 0,10 10,10 20,20 20)
  132. 112 MULTIPOINT(1 1,11 11,11 21,21 21)
  133. 113 MULTIPOINT(3 6,4 10)
  134. 114 MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))
  135. 115 MULTILINESTRING((10 48,10 21,10 0))
  136. 116 MULTILINESTRING((1 2,3 5),(2 5,5 8,21 7))
  137. 117 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)))
  138. 118 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)))
  139. 119 MULTIPOLYGON(((0 3,3 3,3 0,0 3)))
  140. 120 GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(0 0,10 10))
  141. 121 GEOMETRYCOLLECTION(POINT(44 6),LINESTRING(3 6,7 9))
  142. SELECT fid, Dimension(g) FROM gis_geometry ORDER by fid;
  143. fid Dimension(g)
  144. 101 0
  145. 102 0
  146. 103 0
  147. 104 0
  148. 105 1
  149. 106 1
  150. 107 1
  151. 108 2
  152. 109 2
  153. 110 2
  154. 111 0
  155. 112 0
  156. 113 0
  157. 114 1
  158. 115 1
  159. 116 1
  160. 117 2
  161. 118 2
  162. 119 2
  163. 120 1
  164. 121 1
  165. SELECT fid, GeometryType(g) FROM gis_geometry ORDER by fid;
  166. fid GeometryType(g)
  167. 101 POINT
  168. 102 POINT
  169. 103 POINT
  170. 104 POINT
  171. 105 LINESTRING
  172. 106 LINESTRING
  173. 107 LINESTRING
  174. 108 POLYGON
  175. 109 POLYGON
  176. 110 POLYGON
  177. 111 MULTIPOINT
  178. 112 MULTIPOINT
  179. 113 MULTIPOINT
  180. 114 MULTILINESTRING
  181. 115 MULTILINESTRING
  182. 116 MULTILINESTRING
  183. 117 MULTIPOLYGON
  184. 118 MULTIPOLYGON
  185. 119 MULTIPOLYGON
  186. 120 GEOMETRYCOLLECTION
  187. 121 GEOMETRYCOLLECTION
  188. SELECT fid, IsEmpty(g) FROM gis_geometry ORDER by fid;
  189. fid IsEmpty(g)
  190. 101 0
  191. 102 0
  192. 103 0
  193. 104 0
  194. 105 0
  195. 106 0
  196. 107 0
  197. 108 0
  198. 109 0
  199. 110 0
  200. 111 0
  201. 112 0
  202. 113 0
  203. 114 0
  204. 115 0
  205. 116 0
  206. 117 0
  207. 118 0
  208. 119 0
  209. 120 0
  210. 121 0
  211. SELECT fid, AsText(Envelope(g)) FROM gis_geometry ORDER by fid;
  212. fid AsText(Envelope(g))
  213. 101 POLYGON((10 10,10 10,10 10,10 10,10 10))
  214. 102 POLYGON((20 10,20 10,20 10,20 10,20 10))
  215. 103 POLYGON((20 20,20 20,20 20,20 20,20 20))
  216. 104 POLYGON((10 20,10 20,10 20,10 20,10 20))
  217. 105 POLYGON((0 0,10 0,10 10,0 10,0 0))
  218. 106 POLYGON((10 10,20 10,20 20,10 20,10 10))
  219. 107 POLYGON((10 10,40 10,40 10,10 10,10 10))
  220. 108 POLYGON((10 10,20 10,20 20,10 20,10 10))
  221. 109 POLYGON((0 0,50 0,50 50,0 50,0 0))
  222. 110 POLYGON((0 0,30 0,30 30,0 30,0 0))
  223. 111 POLYGON((0 0,20 0,20 20,0 20,0 0))
  224. 112 POLYGON((1 1,21 1,21 21,1 21,1 1))
  225. 113 POLYGON((3 6,4 6,4 10,3 10,3 6))
  226. 114 POLYGON((10 0,16 0,16 48,10 48,10 0))
  227. 115 POLYGON((10 0,10 0,10 48,10 48,10 0))
  228. 116 POLYGON((1 2,21 2,21 8,1 8,1 2))
  229. 117 POLYGON((28 0,84 0,84 42,28 42,28 0))
  230. 118 POLYGON((28 0,84 0,84 42,28 42,28 0))
  231. 119 POLYGON((0 0,3 0,3 3,0 3,0 0))
  232. 120 POLYGON((0 0,10 0,10 10,0 10,0 0))
  233. 121 POLYGON((3 6,44 6,44 9,3 9,3 6))
  234. explain extended select Dimension(g), GeometryType(g), IsEmpty(g), AsText(Envelope(g)) from gis_geometry;
  235. id select_type table type possible_keys key key_len ref rows Extra
  236. 1 SIMPLE gis_geometry ALL NULL NULL NULL NULL 21
  237. Warnings:
  238. Note 1003 select dimension(`test`.`gis_geometry`.`g`) AS `Dimension(g)`,geometrytype(`test`.`gis_geometry`.`g`) AS `GeometryType(g)`,isempty(`test`.`gis_geometry`.`g`) AS `IsEmpty(g)`,astext(envelope(`test`.`gis_geometry`.`g`)) AS `AsText(Envelope(g))` from `test`.`gis_geometry`
  239. SELECT fid, X(g) FROM gis_point ORDER by fid;
  240. fid X(g)
  241. 101 10
  242. 102 20
  243. 103 20
  244. 104 10
  245. SELECT fid, Y(g) FROM gis_point ORDER by fid;
  246. fid Y(g)
  247. 101 10
  248. 102 10
  249. 103 20
  250. 104 20
  251. explain extended select X(g),Y(g) FROM gis_point;
  252. id select_type table type possible_keys key key_len ref rows Extra
  253. 1 SIMPLE gis_point ALL NULL NULL NULL NULL 4
  254. Warnings:
  255. Note 1003 select x(`test`.`gis_point`.`g`) AS `X(g)`,y(`test`.`gis_point`.`g`) AS `Y(g)` from `test`.`gis_point`
  256. SELECT fid, AsText(StartPoint(g)) FROM gis_line ORDER by fid;
  257. fid AsText(StartPoint(g))
  258. 105 POINT(0 0)
  259. 106 POINT(10 10)
  260. 107 POINT(10 10)
  261. SELECT fid, AsText(EndPoint(g)) FROM gis_line ORDER by fid;
  262. fid AsText(EndPoint(g))
  263. 105 POINT(10 0)
  264. 106 POINT(10 10)
  265. 107 POINT(40 10)
  266. SELECT fid, GLength(g) FROM gis_line ORDER by fid;
  267. fid GLength(g)
  268. 105 24.142135623731
  269. 106 40
  270. 107 30
  271. SELECT fid, NumPoints(g) FROM gis_line ORDER by fid;
  272. fid NumPoints(g)
  273. 105 3
  274. 106 5
  275. 107 2
  276. SELECT fid, AsText(PointN(g, 2)) FROM gis_line ORDER by fid;
  277. fid AsText(PointN(g, 2))
  278. 105 POINT(0 10)
  279. 106 POINT(20 10)
  280. 107 POINT(40 10)
  281. SELECT fid, IsClosed(g) FROM gis_line ORDER by fid;
  282. fid IsClosed(g)
  283. 105 0
  284. 106 1
  285. 107 0
  286. explain extended select AsText(StartPoint(g)),AsText(EndPoint(g)),GLength(g),NumPoints(g),AsText(PointN(g, 2)),IsClosed(g) FROM gis_line;
  287. id select_type table type possible_keys key key_len ref rows Extra
  288. 1 SIMPLE gis_line ALL NULL NULL NULL NULL 3
  289. Warnings:
  290. Note 1003 select astext(startpoint(`test`.`gis_line`.`g`)) AS `AsText(StartPoint(g))`,astext(endpoint(`test`.`gis_line`.`g`)) AS `AsText(EndPoint(g))`,glength(`test`.`gis_line`.`g`) AS `GLength(g)`,numpoints(`test`.`gis_line`.`g`) AS `NumPoints(g)`,astext(pointn(`test`.`gis_line`.`g`,2)) AS `AsText(PointN(g, 2))`,isclosed(`test`.`gis_line`.`g`) AS `IsClosed(g)` from `test`.`gis_line`
  291. SELECT fid, AsText(Centroid(g)) FROM gis_polygon ORDER by fid;
  292. fid AsText(Centroid(g))
  293. 108 POINT(15 15)
  294. 109 POINT(25.416666666667 25.416666666667)
  295. 110 POINT(20 10)
  296. SELECT fid, Area(g) FROM gis_polygon ORDER by fid;
  297. fid Area(g)
  298. 108 100
  299. 109 2400
  300. 110 450
  301. SELECT fid, AsText(ExteriorRing(g)) FROM gis_polygon ORDER by fid;
  302. fid AsText(ExteriorRing(g))
  303. 108 LINESTRING(10 10,20 10,20 20,10 20,10 10)
  304. 109 LINESTRING(0 0,50 0,50 50,0 50,0 0)
  305. 110 LINESTRING(0 0,30 0,30 30,0 0)
  306. SELECT fid, NumInteriorRings(g) FROM gis_polygon ORDER by fid;
  307. fid NumInteriorRings(g)
  308. 108 0
  309. 109 1
  310. 110 0
  311. SELECT fid, AsText(InteriorRingN(g, 1)) FROM gis_polygon ORDER by fid;
  312. fid AsText(InteriorRingN(g, 1))
  313. 108 NULL
  314. 109 LINESTRING(10 10,20 10,20 20,10 20,10 10)
  315. 110 NULL
  316. explain extended select AsText(Centroid(g)),Area(g),AsText(ExteriorRing(g)),NumInteriorRings(g),AsText(InteriorRingN(g, 1)) FROM gis_polygon;
  317. id select_type table type possible_keys key key_len ref rows Extra
  318. 1 SIMPLE gis_polygon ALL NULL NULL NULL NULL 3
  319. Warnings:
  320. Note 1003 select astext(centroid(`test`.`gis_polygon`.`g`)) AS `AsText(Centroid(g))`,area(`test`.`gis_polygon`.`g`) AS `Area(g)`,astext(exteriorring(`test`.`gis_polygon`.`g`)) AS `AsText(ExteriorRing(g))`,numinteriorrings(`test`.`gis_polygon`.`g`) AS `NumInteriorRings(g)`,astext(interiorringn(`test`.`gis_polygon`.`g`,1)) AS `AsText(InteriorRingN(g, 1))` from `test`.`gis_polygon`
  321. SELECT fid, IsClosed(g) FROM gis_multi_line ORDER by fid;
  322. fid IsClosed(g)
  323. 114 0
  324. 115 0
  325. 116 0
  326. SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon ORDER by fid;
  327. fid AsText(Centroid(g))
  328. 117 POINT(55.588527753042 17.426536064114)
  329. 118 POINT(55.588527753042 17.426536064114)
  330. 119 POINT(2 2)
  331. SELECT fid, Area(g) FROM gis_multi_polygon ORDER by fid;
  332. fid Area(g)
  333. 117 1684.5
  334. 118 1684.5
  335. 119 4.5
  336. SELECT fid, NumGeometries(g) from gis_multi_point ORDER by fid;
  337. fid NumGeometries(g)
  338. 111 4
  339. 112 4
  340. 113 2
  341. SELECT fid, NumGeometries(g) from gis_multi_line ORDER by fid;
  342. fid NumGeometries(g)
  343. 114 2
  344. 115 1
  345. 116 2
  346. SELECT fid, NumGeometries(g) from gis_multi_polygon ORDER by fid;
  347. fid NumGeometries(g)
  348. 117 2
  349. 118 2
  350. 119 1
  351. SELECT fid, NumGeometries(g) from gis_geometrycollection ORDER by fid;
  352. fid NumGeometries(g)
  353. 120 2
  354. 121 2
  355. explain extended SELECT fid, NumGeometries(g) from gis_multi_point;
  356. id select_type table type possible_keys key key_len ref rows Extra
  357. 1 SIMPLE gis_multi_point ALL NULL NULL NULL NULL 3
  358. Warnings:
  359. Note 1003 select `test`.`gis_multi_point`.`fid` AS `fid`,numgeometries(`test`.`gis_multi_point`.`g`) AS `NumGeometries(g)` from `test`.`gis_multi_point`
  360. SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_point ORDER by fid;
  361. fid AsText(GeometryN(g, 2))
  362. 111 POINT(10 10)
  363. 112 POINT(11 11)
  364. 113 POINT(4 10)
  365. SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_line ORDER by fid;
  366. fid AsText(GeometryN(g, 2))
  367. 114 LINESTRING(16 0,16 23,16 48)
  368. 115 NULL
  369. 116 LINESTRING(2 5,5 8,21 7)
  370. SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_polygon ORDER by fid;
  371. fid AsText(GeometryN(g, 2))
  372. 117 POLYGON((59 18,67 18,67 13,59 13,59 18))
  373. 118 POLYGON((59 18,67 18,67 13,59 13,59 18))
  374. 119 NULL
  375. SELECT fid, AsText(GeometryN(g, 2)) from gis_geometrycollection ORDER by fid;
  376. fid AsText(GeometryN(g, 2))
  377. 120 LINESTRING(0 0,10 10)
  378. 121 LINESTRING(3 6,7 9)
  379. SELECT fid, AsText(GeometryN(g, 1)) from gis_geometrycollection ORDER by fid;
  380. fid AsText(GeometryN(g, 1))
  381. 120 POINT(0 0)
  382. 121 POINT(44 6)
  383. explain extended SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_point;
  384. id select_type table type possible_keys key key_len ref rows Extra
  385. 1 SIMPLE gis_multi_point ALL NULL NULL NULL NULL 3
  386. Warnings:
  387. Note 1003 select `test`.`gis_multi_point`.`fid` AS `fid`,astext(geometryn(`test`.`gis_multi_point`.`g`,2)) AS `AsText(GeometryN(g, 2))` from `test`.`gis_multi_point`
  388. SELECT g1.fid as first, g2.fid as second,
  389. Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o,
  390. Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t,
  391. Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r
  392. FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second;
  393. first second w c o e d t i r
  394. 120 120 1 1 0 1 0 0 1 0
  395. 120 121 0 0 1 0 0 0 1 0
  396. 121 120 0 0 1 0 0 0 1 0
  397. 121 121 1 1 0 1 0 0 1 0
  398. explain extended SELECT g1.fid as first, g2.fid as second,
  399. Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o,
  400. Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t,
  401. Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r
  402. FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second;
  403. id select_type table type possible_keys key key_len ref rows Extra
  404. 1 SIMPLE g1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
  405. 1 SIMPLE g2 ALL NULL NULL NULL NULL 2
  406. Warnings:
  407. Note 1003 select `test`.`g1`.`fid` AS `first`,`test`.`g2`.`fid` AS `second`,within(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `w`,contains(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `c`,overlaps(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `o`,equals(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `e`,disjoint(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `d`,touches(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `t`,intersects(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `i`,crosses(`test`.`g1`.`g`,`test`.`g2`.`g`) AS `r` from `test`.`gis_geometrycollection` `g1` join `test`.`gis_geometrycollection` `g2` order by `test`.`g1`.`fid`,`test`.`g2`.`fid`
  408. DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry;
  409. CREATE TABLE t1 (
  410. gp point,
  411. ln linestring,
  412. pg polygon,
  413. mp multipoint,
  414. mln multilinestring,
  415. mpg multipolygon,
  416. gc geometrycollection,
  417. gm geometry
  418. );
  419. SHOW FIELDS FROM t1;
  420. Field Type Null Key Default Extra
  421. gp point YES NULL
  422. ln linestring YES NULL
  423. pg polygon YES NULL
  424. mp multipoint YES NULL
  425. mln multilinestring YES NULL
  426. mpg multipolygon YES NULL
  427. gc geometrycollection YES NULL
  428. gm geometry YES NULL
  429. ALTER TABLE t1 ADD fid INT;
  430. SHOW FIELDS FROM t1;
  431. Field Type Null Key Default Extra
  432. gp point YES NULL
  433. ln linestring YES NULL
  434. pg polygon YES NULL
  435. mp multipoint YES NULL
  436. mln multilinestring YES NULL
  437. mpg multipolygon YES NULL
  438. gc geometrycollection YES NULL
  439. gm geometry YES NULL
  440. fid int(11) YES NULL
  441. DROP TABLE t1;
  442. create table t1 (a geometry not null);
  443. insert into t1 values (GeomFromText('Point(1 2)'));
  444. insert into t1 values ('Garbage');
  445. ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
  446. insert IGNORE into t1 values ('Garbage');
  447. ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
  448. drop table t1;
  449. create table t1 (fl geometry not null);
  450. insert into t1 values (1);
  451. ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
  452. insert into t1 values (1.11);
  453. ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
  454. insert into t1 values ("qwerty");
  455. ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
  456. insert into t1 values (pointfromtext('point(1,1)'));
  457. ERROR 23000: Column 'fl' cannot be null
  458. drop table t1;
  459. End of 4.1 tests
  460. CREATE TABLE t1 (name VARCHAR(100), square GEOMETRY);
  461. INSERT INTO t1 VALUES("center", GeomFromText('POLYGON (( 0 0, 0 2, 2 2, 2 0, 0 0))'));
  462. INSERT INTO t1 VALUES("small", GeomFromText('POLYGON (( 0 0, 0 1, 1 1, 1 0, 0 0))'));
  463. INSERT INTO t1 VALUES("big", GeomFromText('POLYGON (( 0 0, 0 3, 3 3, 3 0, 0 0))'));
  464. INSERT INTO t1 VALUES("up", GeomFromText('POLYGON (( 0 1, 0 3, 2 3, 2 1, 0 1))'));
  465. INSERT INTO t1 VALUES("up2", GeomFromText('POLYGON (( 0 2, 0 4, 2 4, 2 2, 0 2))'));
  466. INSERT INTO t1 VALUES("up3", GeomFromText('POLYGON (( 0 3, 0 5, 2 5, 2 3, 0 3))'));
  467. INSERT INTO t1 VALUES("down", GeomFromText('POLYGON (( 0 -1, 0 1, 2 1, 2 -1, 0 -1))'));
  468. INSERT INTO t1 VALUES("down2", GeomFromText('POLYGON (( 0 -2, 0 0, 2 0, 2 -2, 0 -2))'));
  469. INSERT INTO t1 VALUES("down3", GeomFromText('POLYGON (( 0 -3, 0 -1, 2 -1, 2 -3, 0 -3))'));
  470. INSERT INTO t1 VALUES("right", GeomFromText('POLYGON (( 1 0, 1 2, 3 2, 3 0, 1 0))'));
  471. INSERT INTO t1 VALUES("right2", GeomFromText('POLYGON (( 2 0, 2 2, 4 2, 4 0, 2 0))'));
  472. INSERT INTO t1 VALUES("right3", GeomFromText('POLYGON (( 3 0, 3 2, 5 2, 5 0, 3 0))'));
  473. INSERT INTO t1 VALUES("left", GeomFromText('POLYGON (( -1 0, -1 2, 1 2, 1 0, -1 0))'));
  474. INSERT INTO t1 VALUES("left2", GeomFromText('POLYGON (( -2 0, -2 2, 0 2, 0 0, -2 0))'));
  475. INSERT INTO t1 VALUES("left3", GeomFromText('POLYGON (( -3 0, -3 2, -1 2, -1 0, -3 0))'));
  476. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrcontains FROM t1 a1 JOIN t1 a2 ON MBRContains( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  477. mbrcontains
  478. center,small
  479. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrdisjoint FROM t1 a1 JOIN t1 a2 ON MBRDisjoint( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  480. mbrdisjoint
  481. down3,left3,right3,up3
  482. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrequal FROM t1 a1 JOIN t1 a2 ON MBREqual( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  483. mbrequal
  484. center
  485. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrintersect FROM t1 a1 JOIN t1 a2 ON MBRIntersects( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  486. mbrintersect
  487. big,center,down,down2,left,left2,right,right2,small,up,up2
  488. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbroverlaps FROM t1 a1 JOIN t1 a2 ON MBROverlaps( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  489. mbroverlaps
  490. down,left,right,up
  491. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrtouches FROM t1 a1 JOIN t1 a2 ON MBRTouches( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  492. mbrtouches
  493. down2,left2,right2,up2
  494. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrwithin FROM t1 a1 JOIN t1 a2 ON MBRWithin( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  495. mbrwithin
  496. big,center
  497. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS contains FROM t1 a1 JOIN t1 a2 ON Contains( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  498. contains
  499. center,small
  500. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS disjoint FROM t1 a1 JOIN t1 a2 ON Disjoint( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  501. disjoint
  502. down3,left3,right3,up3
  503. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS equals FROM t1 a1 JOIN t1 a2 ON Equals( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  504. equals
  505. center
  506. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS intersect FROM t1 a1 JOIN t1 a2 ON Intersects( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  507. intersect
  508. big,center,down,down2,left,left2,right,right2,small,up,up2
  509. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS overlaps FROM t1 a1 JOIN t1 a2 ON Overlaps( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  510. overlaps
  511. down,left,right,up
  512. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS touches FROM t1 a1 JOIN t1 a2 ON Touches( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  513. touches
  514. down2,left2,right2,up2
  515. SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS within FROM t1 a1 JOIN t1 a2 ON Within( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
  516. within
  517. big,center
  518. SET @vert1 = GeomFromText('POLYGON ((0 -2, 0 2, 0 -2))');
  519. SET @horiz1 = GeomFromText('POLYGON ((-2 0, 2 0, -2 0))');
  520. SET @horiz2 = GeomFromText('POLYGON ((-1 0, 3 0, -1 0))');
  521. SET @horiz3 = GeomFromText('POLYGON ((2 0, 3 0, 2 0))');
  522. SET @point1 = GeomFromText('POLYGON ((0 0))');
  523. SET @point2 = GeomFromText('POLYGON ((-2 0))');
  524. SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS overlaps FROM t1 a1 WHERE Overlaps(a1.square, @vert1) GROUP BY a1.name;
  525. overlaps
  526. SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS overlaps FROM t1 a1 WHERE Overlaps(a1.square, @horiz1) GROUP BY a1.name;
  527. overlaps
  528. SELECT Overlaps(@horiz1, @vert1) FROM DUAL;
  529. Overlaps(@horiz1, @vert1)
  530. 0
  531. SELECT Overlaps(@horiz1, @horiz2) FROM DUAL;
  532. Overlaps(@horiz1, @horiz2)
  533. 1
  534. SELECT Overlaps(@horiz1, @horiz3) FROM DUAL;
  535. Overlaps(@horiz1, @horiz3)
  536. 0
  537. SELECT Overlaps(@horiz1, @point1) FROM DUAL;
  538. Overlaps(@horiz1, @point1)
  539. 0
  540. SELECT Overlaps(@horiz1, @point2) FROM DUAL;
  541. Overlaps(@horiz1, @point2)
  542. 0
  543. DROP TABLE t1;
  544. End of 5.0 tests