CREATE TABLETb_geo (IDINT PRIMARY KEYAuto_increment,nameVARCHAR( -) not NULL, PNT Point not NULL, SPATIALINDEX' Spatidx ' (' PNT ')<!--1. Create a spatial index when creating a table --) ENGINE=MYISAMDEFAULTCHARSET=UTF8;<!--The database table engine is set to Myisam--><!--2. Create an index on a table that already exists--<!--ALTER TABLE tb_geo ADD SPATIAL INDEX spatidx (PNT);<!--3. Create an index using the creation index statement with the following syntax-<!--CREATE SPATIAL INDEX spatidx on T7 (g)--<!--Delete Index --<!--ALTER TABLE book DROP INDEX uniqididx --<!--Table Description Information --DESCRIBE Tb_geo;<!--inserting data --INSERT into' Tb_geo 'VALUES(NULL,'a test string', Pointfromtext ('Point (a)'));<!--Query -SELECTId,name,astext (PNT) fromTb_geo;SELECTId,name,x (PNT), Y (PNT) fromTb_geo;<!--Spatial Query Example --SELECTAstext (PNT) fromTb_geoWHEREMbrwithin (Pnt,geomfromtext ('Polygon ((0 0,0 30,30 30,30 0,0 0))'));<!--Delete Table --DROP TABLETb_geo;<!--several spatial object comparison methods --SET @g1 =Geomfromtext ('Polygon ((0 0,0 3,3 3,3 0,0 0))');SET @g2 =Geomfromtext ('Point (1 1)');<!--Note: The comparison is the outsourced envelope Geometry type Object--<!--contains -SELECTMbrcontains (@g1,@g2), Mbrcontains (@g2,@g1), Mbrcontains (@g1,@g1);<!--is included -SELECTMbrwithin (@g2,@g1), Mbrwithin (@g1,@g2);<!--do not intersect --SELECTMbrdisjoint (@g1,@g2);<!--Equal --SELECTMbrequal (@g1,@g2);<!--intersect -SELECTMbrintersects (@g1,@g2);<!--overlap --SELECTMbroverlaps (@g1,@g2);<!--Tangent -to-SELECTMbrtouches (@g1,@g2);
MySQL support for GIS spatial data, including the creation of spatial indexes