問題描述
如何計算存儲在 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數據庫中多邊形的面積?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!