How Do I Calculate the Area of a Polygon in a MySQL Database When the Polygon's Points are Lat Longs?

我的未来我决定 提交于 2019-12-07 05:53:35

问题


How do I calculate the area of a polygon stored in a MySql database? The polygons' points are lat longs. So, degrees and minutes seem to be causing a problem.

I've tried:

SELECT AREA( my_polygon ) 
FROM  `my_table` 
WHERE name =  'Newport'

Because, the points are lat longs, I get weird results.

(I'm not able to switch to Postgre). Is there a way to do this in MySQL? I'd like to get the results in sq. meters or sq. km or sq. miles-- any of these would be fine.


回答1:


You've got to transform those lats and lons into a more appropriate coordinate system.

Since the earth is a sphere, you're talking about calculating an area in spherical coordinates.

The docs say that the MySQL "AREA" function takes a polygon as its input. I would say that if you want area as something like square miles you should convert your lat/lon coordinates into equivalent surface (x, y) coordinates with the right units (e.g., miles). Then pass those into the AREA function.

This link suggests that someone else has had this problem and solved it.



来源:https://stackoverflow.com/questions/3348573/how-do-i-calculate-the-area-of-a-polygon-in-a-mysql-database-when-the-polygons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!