在Python中使用geoJSON指向Polygon [英] Point in Polygon with geoJSON in Python

查看:896
本文介绍了在Python中使用geoJSON指向Polygon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个geoJSON数据库,里面有很多多边形(特别是人口普查区域),而且我有很多很长的经纬度点。

I have a geoJSON database with lots of polygons (census tracts specifically) and I have lots of long,lat points.

我希望有一个高效的Python代码来识别给定坐标所在的人口普查区域,但到目前为止,我的谷歌搜索没有发现任何东西。

I am hoping that there would exist an efficient Python code to identify which census tract a given coordinate is in, however so far my googling hasn't revealed anything.

谢谢!

推荐答案

http://www.mhermans.net/geojson-shapely-geocoding.html\">论文描述了如何做到你想要做的事情。

I found an interesting article describing how to do exactly what you are looking to do.

TL; DR:使用造型

TL;DR: Use Shapely

您会发现这段代码在文章的最后:

You will find this code at the end of the article:

import json
from shapely.geometry import shape, Point
# depending on your version, use: from shapely.geometry import shape, Point

# load GeoJSON file containing sectors
with open('sectors.json') as f:
    js = json.load(f)

# construct point based on lon/lat returned by geocoder
point = Point(-122.7924463, 45.4519896)

# check each polygon to see if it contains the point
for feature in js['features']:
    polygon = shape(feature['geometry'])
    if polygon.contains(point):
        print 'Found containing polygon:', feature

这篇关于在Python中使用geoJSON指向Polygon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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