繁体   English   中英

如何使用geojson和shapely确定一个点是否在多边形内

[英]how to determine if a point is inside a polygon using geojson and shapely

我希望在地图上创建一个区域,并能够自动确定点(坐标)是否在该区域内。 在这个例子中,我使用了整个美国的 geojson 文件和纽约市的坐标。

Geojson: https : //github.com/johan/world.geo.json

我已经阅读了匀称的文档,但无法弄清楚为什么我的结果返回 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)

我希望打印包含的坐标,但没有打印任何内容。

您需要交换Point()的值:

point = Point(-74.005974, 40.712776)

您使用的数据集的坐标首先是经度,然后是纬度。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM