def __init__(self, stream, interleaved=False): """ stream: an iterable, returning tuples of the form (id,[xmin,xmax,ymin,ymax],object) for now, requires that xmin==xmax, and ymin==ymax For now, only interleaved=False is supported. """ it = iter(stream) self.qsi = qc.QgsSpatialIndex() if interleaved: raise Exception, "No support for interleaved index. You must use xxyy ordering" for feat_id, rect_xxyy, obj in it: self.insert(feat_id, rect=rect_xxyy)
def nearest_neighbor(iface, layer, point): """search the nearest parent feature id""" index = None parentId = None parentFeature = None extent = iface.mapCanvas().extent() # veroorzaakt foutmelding als er niets in het kaartvenster staat, daarom in try/except statement index = QC.QgsSpatialIndex(layer.getFeatures(QC.QgsFeatureRequest(extent))) try: parentId = index.nearestNeighbor(point, 1)[0] parentFeature = next(layer.getFeatures(QC.QgsFeatureRequest(parentId))) parentId = parentFeature["id"] except: # pylint: disable=bare-except pass return parentFeature, parentId
def updateSpatialIndex(self): if self.enableInfoLayerCheckbox.isChecked(): self.infoIndex = core.QgsSpatialIndex () self.progressBar.show() self.progressBar.setRange(0,self.getInfolayer().featureCount ()) infoFeats = self.getInfolayer().getFeatures() processed = 0 for feat in infoFeats: self.infoIndex.insertFeature(feat) self.progressBar.setValue(processed) processed += 1 self.progressBar.hide() self.progressBar.reset() else: self.infoIndex = None