简体   繁体   中英

Mysql: find polygon within certain radius

In my database I have polygons stored. Now I need to search all the polygons that are within a certain radius. Even if the polygon is only a small part inside the region, then it should be included inside the results (so once there is a minimal match, there is a match).

What is the best way to do this? I have been thinking about creating another polygon and search everything that intersects this, but don't know if this is a valid method?

Yes, I think it is the best approach. You can create a polygon using ST_BUFFER and then you can use ST_INTERSECT to find if polygons will intersect your polygon.

May be you can also do it using ST_DISTANCE . It will calculate minimum distance of a point from polygon.

Select ST_DISTANCE(polygons,POINT(x, y)) as distance, polygon_id from your_polygon_table WHERE distance <= 10 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM