当多边形的点是经纬度时,如何在 MySQL 数据库中计算多边形的面积?
如何计算存储在 MySql 数据库中的多边形的面积?多边形的点是经纬度。因此,度数和分钟数似乎引起了问题。
我尝试过:
SELECT AREA( my_polygon )
FROM `my_table`
WHERE name = 'Newport'
因为这些点是经纬度,所以我得到了奇怪的结果。
(我无法切换到 Postgre)。 MySQL 有没有办法做到这一点?我想得到以平方米、平方公里或平方英里为单位的结果——任何一个都可以。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将这些纬度和经度转换为更合适的坐标系。
由于地球是一个球体,因此您正在谈论计算球坐标中的面积。
文档说 MySQL "AREA" 函数 将多边形作为其输入。我想说,如果您想要面积像平方英里这样的东西,您应该将您的纬度/经度坐标转换为具有正确单位(例如英里)的等效表面(x,y)坐标。然后将它们传递到 AREA 函数中。
此链接表明其他人遇到过此问题并已解决。
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.