-1
我想创建一个交叉点的函数,其中输入文件是一些城市区域中的建筑物,并且查询框用于创建仅包含建筑物的交叉点在该查询框区域中找到。交叉点的R树查询/边界框
import matplotlib.pyplot as plt
import matplotlib as mpl
from mpl_toolkits.basemap import Basemap
import fiona
import fiona.crs
import rtree
input_file = 'se_england_clean.shp'
out_file = 'se_england_out'
file_index = 'Rtree_index_east.idx'
query_box = [-0.0957870483,51.5134165224,-0.08664608,51.5192383994]
def write_clipped_file(name_file_in, out_file, file_index):
idx = rtree.index.Index(file_index)
idx.insert(0, (input_file))
list(idx.intersection((query_box)))[0]
with fiona.open(input_file, 'w') as out_file :
for building in idx:
out_file.write(building)
我得到一个错误
RTreeError: Coordinates must be in the form (minx, miny, maxx, maxy) or (x, y) for 2D indexes
不知道为什么它不工作,我已经试过坐标的不同组合。边框的格式可以在这里找到,只要使用CSV格式,使一个框伦敦:
http://boundingbox.klokantech.com/
我想用一个小包围盒在伦敦,然后找到多少来自INPUT_FILE建筑在该框内相交。后来我打算使用底图来可视化它。除了查询框,我的代码是否有正确的想法?
基本上我试图打开一个新的索引,并选择与query_box相交的所有建筑物。返回的值应该是我想要显示的建筑物的索引列表。
然后,我用Fiona打开输入形状文件和我想在输出中生成的新(剪切)shapefile文件。通过在索引列表上循环,我尝试选择所需的建筑物并将它们写入新文件'out_file'中。
重复的[(Python)Rtree交集和fiona问题](https://stackoverflow.com/questions/47299216/python-rtree-intersection-and-fiona-questions) - 不要重新发布你的问题,而不修复甚至基本的错误。 –