(Python)Rtree交集和Fiona问题 [英] (Python) Rtree intersection and fiona questions
问题描述
我正在尝试为一个相交处创建一个函数,其中输入文件位于某个市区内,并且使用查询框来创建一个输出文件,该文件的相交处仅包含在该查询框中找到的建筑物.
I'm trying to create a function for an intersection where the input file is of some urban area, and a query box is used to create an output file that has the intersection containing just the buildings found in that query box.
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]
count = 0
with fiona.open(input_file, 'w') as out_file : #?
for building in out_file: #?
到目前为止,我的代码是否正确还不知道,但是我有两个直接的问题: 首先,我不知道如何用Fiona打开要在输出中生成的输入shapefile和新的(剪切的)shapefile.我想循环显示索引列表,选择所需建筑物,然后将其写入新文件"out_file"中.其次,我得到一个错误:
No idea if my code is right so far, but I have two immediate problems: First, I don't know how to open with Fiona the input shapefile and the new (clipped) shapefile that I want to produce in output. I want to cycle the list of indices, select the desired buildings, and write them in the new file 'out_file'. Second, I get an error:
RTreeError: Coordinates must be in the form (minx, miny, maxx, maxy)
推荐答案
idx.insert(0, (input_file))
您需要在树中插入坐标,而不是文件名.
You need to insert coordinates into the tree, not a file name.
这篇关于(Python)Rtree交集和Fiona问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!