Skip to main content
deleted 4 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

The trick is to create a function that access QGIS graphical interface, and that is piped to the query of the select by expression.

  1. Open a function editor (from anywhere, including from field calculator) and create a new function that reads the canvas extent and returns it as a geometry.
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args='auto', group='Custom')
def currentExtent(feature, parent):
    return QgsGeometry.fromRect(iface.mapCanvas().extent())
  1. Open the select by expression and use intersects($geometry,currentExtent()) (or within(..) for entirely contained polygons)

PS: theThe same function can be used in a virtual layer as shown here, that you could eventually modify to compute the buffer.

The trick is to create a function that access QGIS graphical interface, and that is piped to the query of the select by expression.

  1. Open a function editor (from anywhere, including from field calculator) and create a new function that reads the canvas extent and returns it as a geometry.
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args='auto', group='Custom')
def currentExtent(feature, parent):
    return QgsGeometry.fromRect(iface.mapCanvas().extent())
  1. Open the select by expression and use intersects($geometry,currentExtent()) (or within(..) for entirely contained polygons)

PS: the same function can be used in a virtual layer as shown here, that you could eventually modify to compute the buffer.

The trick is to create a function that access QGIS graphical interface, and that is piped to the query of the select by expression.

  1. Open a function editor (from anywhere, including from field calculator) and create a new function that reads the canvas extent and returns it as a geometry.
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args='auto', group='Custom')
def currentExtent(feature, parent):
    return QgsGeometry.fromRect(iface.mapCanvas().extent())
  1. Open the select by expression and use intersects($geometry,currentExtent()) (or within(..) for entirely contained polygons)

The same function can be used in a virtual layer as shown here, that you could eventually modify to compute the buffer.

added 49 characters in body
Source Link
JGH
  • 43.1k
  • 3
  • 46
  • 93

The trick is to create a function that access QGIS graphical interface, and that is piped to the query of the select by expression.

  1. Open a function editor (from anywhere, including from field calculator) and create a new function that reads the canvas extent and returns it as a geometry.
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args='auto', group='Custom')
def currentExtent(feature, parent):
    return QgsGeometry.fromRect(iface.mapCanvas().extent())
  1. Open the select by expression and use intersects( $geometry,currentExtent()) (or within(..) for entirely contained polygons)

PS: the same function can be used in a virtual layer as shown here, that you could eventually modify to compute the buffer.

The trick is to create a function that access QGIS graphical interface, and that is piped to the query of the select by expression.

  1. Open a function editor (from anywhere, including from field calculator) and create a new function that reads the canvas extent and returns it as a geometry.
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args='auto', group='Custom')
def currentExtent(feature, parent):
    return QgsGeometry.fromRect(iface.mapCanvas().extent())
  1. Open the select by expression and use intersects( $geometry,currentExtent())

PS: the same function can be used in a virtual layer as shown here, that you could eventually modify to compute the buffer.

The trick is to create a function that access QGIS graphical interface, and that is piped to the query of the select by expression.

  1. Open a function editor (from anywhere, including from field calculator) and create a new function that reads the canvas extent and returns it as a geometry.
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args='auto', group='Custom')
def currentExtent(feature, parent):
    return QgsGeometry.fromRect(iface.mapCanvas().extent())
  1. Open the select by expression and use intersects($geometry,currentExtent()) (or within(..) for entirely contained polygons)

PS: the same function can be used in a virtual layer as shown here, that you could eventually modify to compute the buffer.

Source Link
JGH
  • 43.1k
  • 3
  • 46
  • 93

The trick is to create a function that access QGIS graphical interface, and that is piped to the query of the select by expression.

  1. Open a function editor (from anywhere, including from field calculator) and create a new function that reads the canvas extent and returns it as a geometry.
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args='auto', group='Custom')
def currentExtent(feature, parent):
    return QgsGeometry.fromRect(iface.mapCanvas().extent())
  1. Open the select by expression and use intersects( $geometry,currentExtent())

PS: the same function can be used in a virtual layer as shown here, that you could eventually modify to compute the buffer.