MySQL support for GIS spatial data, including the creation of spatial indexes

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.