如何从 geoJSON 文件计算多个 MultiPolygons 的面积?

ram*_*sjd 1 python geojson python-3.x

我正在尝试计算 GeoJSON 文件中每个要素(即邻域)的面积。理想情况下,结果将添加为文件中的字段或单独的数据框中,但是我目前甚至无法计算该区域。我的代码如下:

import urllib
import json
from area import area

bdry_url = urllib.request.urlopen("https://data.edmonton.ca/resource/xu6q-xcmj.geojson")
with bdry_url as bdry_file:
    bdry = json.load(bdry_file)


for x in bdry['features']:
    print(area(x))
Run Code Online (Sandbox Code Playgroud)

上面代码的结果是很多 0。area 函数应该“计算任何 GeoJSON 几何图形内的面积”。所以,我不确定我是否只是没有正确地将文件传递给函数,或者函数是否不喜欢文件中的“MultiPolygons”。

当我只print(x)for循环中使用时,输出例如:

{'type': 'Feature', 'geometry': {'type': 'MultiPolygon', 'coordinates': [[[[-113.47970029870794, 53.6152271386194], [-113.47623664663439, 53.61561158319339], [-113.4744820422431, 53.6158162210957], [-113.4731808787134, 53.61590027235317], [-113.4674204545053, 53.61591375444001], [-113.46742798260262, 53.610538856185805], [-113.46743523571406, 53.60691755885339], [-113.46961818955656, 53.60690984975463], [-113.47022601929541, 53.60689581095175], [-113.47086485888067, 53.60685578200864], [-113.4715850828474, 53.606767279197136], [-113.47225008266139, 53.606645830070825], [-113.47373112695321, 53.6063652736457], [-113.47641979230873, 53.6058984811946], [-113.47672620998279, 53.60585027816153], [-113.47791436479508, 53.60576846613057], [-113.48101443948326, 53.605768565180774], [-113.48173969843924, 53.605811862524945], [-113.4824407929969, 53.605915397805376], [-113.48510468465751, 53.606306092276874], [-113.48850157059921, 53.60679389522115], [-113.488933001326, 53.606820031912164], [-113.49168085687263, 53.606784967555676], [-113.49170507787457, 53.60810574183392], [-113.49171395279058, 53.61275181411882], [-113.49179330220164, 53.614032553715944], [-113.48966991380574, 53.6140237367952], [-113.48906656552556, 53.61404155038072], [-113.48794288078807, 53.614190044322235], [-113.48600883911077, 53.61444001996334], [-113.47970029870794, 53.6152271386194]]]]}, 'properties': {'descriptio': 'Evansdale is named for H.M.E. Evans, Mayor of Edmonton in 1918. Mr. Evans was also president of the Edmonton Board of Trade in 1916. Although single detached homes account for 90% of the structures in Evansdale, almost 50% of the dwelling units are locat', 'descriptiv': 'Evansdale', 'name': 'EVANSDALE', 'neighbourh': '2260'}}
Run Code Online (Sandbox Code Playgroud)

Nik*_*nar 5

看起来area图书馆需要几何图形,而不是整个特征。所以试试这个:

for x in bdry['features']:
    print(area(x['geometry']))
Run Code Online (Sandbox Code Playgroud)