当多边形的点是经纬度时,如何计算MySQL数据库中多边形的面积? [英] How Do I Calculate the Area of a Polygon in a MySQL Database When the Polygon's Points are Lat Longs?

查看:55
本文介绍了当多边形的点是经纬度时,如何计算MySQL数据库中多边形的面积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算存储在 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.

我试过了:

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

因为点是经纬度,我得到了奇怪的结果.

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

(我无法切换到 Postgre).有没有办法在 MySQL 中做到这一点?我想以平方米或平方公里或平方英里为单位得到结果——这些都可以.

(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.

推荐答案

您必须将这些纬度和经度转换为更合适的坐标系.

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.

文档说 MySQL "AREA" 函数 将多边形作为其输入.我会说,如果你想要像平方英里这样的面积,你应该将你的纬度/经度坐标转换为具有正确单位(例如英里)的等效表面 (x, y) 坐标.然后将它们传递给 AREA 函数.

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.

这篇关于当多边形的点是经纬度时,如何计算MySQL数据库中多边形的面积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆