我一直在开发一个站点,在MySQL数据库中存储空间数据,比如建筑物、花园等的多边形(纬度和经度)。
我想知道如何在MySQL中检索多边形数据。
我看到了这个链接中也提到了插入多边形数据:http://amper.110mb.com/SPAT/mysql_initgeometry2.htm
但是现在我想知道如何根据某些约束从表中检索数据,例如:
"where latitude < 9.33 and longitude > 22.4"
此外,如何找出一个点是在多边形的内部还是外部?
Here is a page with lots of examples: http://howto-use-mysql-spatial-ext.blogspot.com/
This is one of the examples to retrieve rows which points intersect with a specified bounding box:
SET @bbox = 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))';
SELECT name, AsText(location) FROM Points
WHERE Intersects( location, GeomFromText(@bbox) );
The MySQL documentation says these spatial functions also work with geometries (Looks like a Point is also a Geometry). So you can check if the geometry in the database intersects with the one you specify in the select statement.