Mysql checks whether a vertex falls within the polygon.

Source: Internet
Author: User


In Mysql, to determine whether a point falls within a polygon and about geospatial data, you often need to process the associations between the two spatial data. There are many ways to handle this by writing program algorithms or calling the corresponding functions in the database. In the mysql database, http://dev.mysql.com/doc/refman/5.1/en/functions-for-testing-spatial-relations-between-geometric-objects.html I have made a detailed introduction, but it does not take a specific engineering practice as an example. This article will judge whether a vertex falls within a polygon and simply expand it. Www.2cto.com first, CREATE a simple Geographic Data TABLE, [SQL] CREATE TABLE 'Ci _ special_zone '('id' int (11) NOT NULL auto_increment, 'ploygongeo' text NOT NULL, primary key ('id') ENGINE = MyISAM default charset = utf8; and INSERT several pieces of data [SQL] INSERT INTO ci_special_zone (ploygongeo) VALUES ('polygon (113.547 22.186, 113.549 22.186, 113.549 22.188, 113.547 22.188, 113.547 22.186) '); insert into ci_special_zone (ploygongeo) VALUES ('polygo N (112.547 21.186, 112.549 212.186, 112.549 21.188, 112.547 212.188, 112.547 21.186) '). Finally, run the following SQL statement [SQL] SELECT substring (ploygongeo, 10, length (ploygongeo)-11) from ci_special_zone where MBRContains (PolygonFromText (ploygongeo), PolygonFromText ('point (113.547 22.186) ')> 0 limit 113.547 coordinate Point 22.186 is the longitude and latitude, if a return value exists, it indicates that the coordinate point falls into the range.

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.