我试图在半打多边形里找到数百万个点。我的代码是:def find_shape(longitude,latitude):
if longitude != 0 and latitude != 0:
point = shapely.geometry.Point(longitude,latitude)
else:
return "Unknown"
for current_shape in all_shapes:
if current_shape['bounding_box'].contains(point):
if current_shape['shape'].contains(point):
return current_shape['properties']['ShapeName']
break
return "Unknown"
我已经阅读了其他有关使用shapely提高多边形点查询性能的问题。他们建议用树。但是,对于有许多多边形(36,000 in one question,100,000 in another)的情况,这似乎很有用,而且不希望在所有多边形上循环。在
我已经设置了一个边界框,如你所见。以下是我的形状设置代码:
^{pr2}$
检查形状的另一个非常简化的版本,即由最大的内接矩形(或三角形)构成的形状,是否有用?在
检查shapely文档,似乎没有这个功能。也许是^{}的设置?当然,我总是希望确保新的简化形状不会超出原始形状的边界,因此我不必对实际形状调用contains()。我也认为我想使新的简化形状尽可能简单