我希望在地图上创建一个区域,并能够自动确定点(坐标)是否在该区域内。本例中,我使用了整个美国的geojson文件和纽约市的坐标。
Geojson: https://github.com/johan/world.geo.json 我已经阅读了shapely文档,但无法弄清楚为什么我的结果返回False。非常感谢任何帮助。
我希望打印出包含的坐标,但没有任何输出。
Geojson: https://github.com/johan/world.geo.json 我已经阅读了shapely文档,但无法弄清楚为什么我的结果返回False。非常感谢任何帮助。
import json
from shapely.geometry import shape, GeometryCollection, Point
with open('USA.geo.json', 'r') as f:
js = json.load(f)
point = Point(40.712776, -74.005974)
for feature in js['features']:
polygon = shape(feature['geometry'])
if polygon.contains(point):
print ('Found containing polygon:', feature)
我希望打印出包含的坐标,但没有任何输出。