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

查看:558
本文介绍了当多边形的点是经纬度时,如何计算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 区域"功能以多边形作为输入.我要说的是,如果您希望面积像平方英里,则应将纬度/经度坐标转换为具有正确单位(例如,英里)的等效曲面(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天全站免登陆