I am trying to implement a bounding box via a spatial index and get an error stating that I must either provide coordinates as either (minx, miny, maxx, maxy) or (x,y) for 2D indexes.
I've tried using the R-Tree example from this thread: More Efficient Spatial join in Python without QGIS, ArcGIS, PostGIS, etc
The first time I try to do a spatial index, I have the following value for a point ("Z" is the current value of "i" before my code breaks):
POINT Z (11.52951677300007 0.7729100360000416 -50000)
How can I gracefully get rid of the Z-coordinate to pass on as a 2D coordinate in my "for j" statement? Code snippet is below:
from rtree import index
idx = index.Index() #Create an R-Tree index and store the features in it (bounding box)
for pos, poly in enumerate(polygons):
idx.insert(pos, shape(poly['geometry']).bounds)
for i,pt in enumerate(points): #iterate through the points
point = shape(pt['geometry'])
for j in idx.intersection(point.coords[0]): #iterate through spatial index
if point.within(shape(multi[j]['geometry'])):
discoveredBuildings.append(point['id'])
Best Answer
It is a pure Python problem
With shapely, your 3D point is represented by
Using slicing for example (there are others solutions)
Or
Or ...