shasi kanth
shasi kanth

Reputation: 7094

Mysql retrieve polygon data

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

Upvotes: 4

Views: 6281

Answers (1)

kayahr
kayahr

Reputation: 22010

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.

Upvotes: 7

Related Questions