python画圆及其内接多边形_使⽤PythonShapely查找多边形
的最⼤内接矩形
别吃哑巴亏
我试图在六个多边形中找到数百万个点.这是我的代码:
def find_shape(longitude,latitude):
if longitude != 0 and latitude != 0:
point = ry.Point(longitude,latitude)
世界上最大的蚊子el:
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"逍遥游朗读
我已经阅读了其他⼀些问题,这些问题涉及提⾼形状上的多边形点查询的性能.他们建议Rtrees.但是,似乎这对于有多个多边形(36,000 in one question,100,000 in another)的情况很有⽤,并且不希望将它们全部循环.
正如你所看到的,我已经设置了⼀个边界框.这是我的形状设置代码:
with fiona.open(SHAPEFILE) as f_col:三年级竖式
all_shapes = []
for shapefile_record in f_col:
current_shape = {}注射丰唇
current_shape['shape'] = ry.asShape(shapefile_record['geometry'])
minx, miny, maxx, maxy = current_shape['shape'].bounds
current_shape['bounding_box'] = ry.box(minx, miny, maxx, maxy)
current_shape['properties'] = shapefile_record['properties']
all_shapes.append(current_shape)
还要检查另⼀个⾮常简化的形状版本,即由最⼤的内切矩形(或三⾓形)构成的形状是否有⽤?
检查匀称的⽂档,似乎没有这个功能.也许是simplify()的⼀些设定?当然,我总是希望确保新的简化形状不会超出原始形状的范围,因此我不必在实际形状上调⽤contains().我还认为我希望尽可能简化新的简化形状,以提⾼速度.
任何其他建议也赞赏.谢谢!
编辑:在等待回复时,我已经想到了创建符合我要求的简化形状的想法:
current_shape['simple_shape'] = current_shape['shape'].simplify(.5)
林俊杰祖籍
current_shape['simple_shape'] = current_shape['simple_shape'].interction(current_shape['shape'])
以下是我在测试每个点时如何使⽤它: