Graphics Reference
In-Depth Information
tolerance = self.calcTolerance(pos)
searchRect = QgsRectangle(layerPt.x() - tolerance,
layerPt.y() - tolerance,
layerPt.x() + tolerance,
layerPt.y() + tolerance)
request = QgsFeatureRequest()
request.setFilterRect(searchRect)
request.setFlags(QgsFeatureRequest.ExactIntersect)
for feature in self.layer.getFeatures(request):
return feature
return None
We use the tolerance value to define a search rectangle centered around the click point,
and identify the first feature that intersects that rectangle:
Next up is the calcTolerance() method, which calculates how much distance we can
tolerate before a click is considered to be too far away from a vertex or geometry:
def calcTolerance(self, pos):
pt1 = QPoint(pos.x(), pos.y())
pt2 = QPoint(pos.x() + 10, pos.y())
mapPt1,layerPt1 = self.transformCoordinates(pt1)
mapPt2,layerPt2 = self.transformCoordinates(pt2)
tolerance = layerPt2.x() - layerPt1.x()
Search WWH ::




Custom Search