I am migrating a plugin from QGIS 2 to QGIS 3. The following code is QGIS 2:
# Define a mapscale-dependent rectangle about the pick point. pntGeom = QgsGeometry.fromPoint(point) pntBuf = pntGeom.buffer(canvas.mapUnitsPerPixel()*4, 0) rect = pntBuf.boundingBox() # Convert the rectangle coordinates to the layer CRS. layerRect = canvas.mapRenderer().mapToLayerCoordinates(layer, rect) # Select the features that are in the rectangle and return their fids. layer.removeSelection() layer.select(layerRect, True) fids= layer.selectedFeaturesIds()
canvas is a
self.iface.mapCanvas() object and
layer is a
I need this to work in QGIS 3. The
mapRenderer() object is obsolete and it appears the
mapToLayerCoordinates() function is a member of the
QgsMapSettings and requires that the
layer argument "must have type
QgsMapSettings" so my replacement code:
layerRect = QgsMapSettings.mapToLayerCoordinates(layer, rect)
TypeError: QgsMapSettings.mapToLayerCoordinates(): arguments did not match any overloaded call:
overload 1: first argument of unbound method must have type 'QgsMapSettings'
overload 2: first argument of unbound method must have type 'QgsMapSettings'
The ultimate goal is to return any feature ids that are within the bounding box.
How do I resolve this conflict?