(Python) Rtree intersection and fiona questions

末鹿安然 提交于 2019-12-11 15:32:20

问题


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: #?

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)

回答1:


idx.insert(0, (input_file))

You need to insert coordinates into the tree, not a file name.



来源:https://stackoverflow.com/questions/47299216/python-rtree-intersection-and-fiona-questions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!