i have been developing a site that stores spatial data in mysql database, like that of buildings, gardens, etc. in the form of polygons (latitudes and longitudes).
I want to know how to retrieve polygon data in mysql.
I have seen this sample query to insert a polygon data: http://amper.110mb.com/SPAT/mysql_initgeometry2.htm
But now i want to know how to retrieve data from the table, based on certain constraints like:
"where latitude < 9.33 and longitude > 22.4"
Also how do i find whether a point lies inside or outside of a polygon
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With