Skip to content

Instantly share code, notes, and snippets.

Created June 21, 2016 21:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ThomasG77/4f26bebf7a16e3716ed14f1f83946a99 to your computer and use it in GitHub Desktop.
# coding: utf-8
from PyQt4.QtGui import QMessageBox
from qgis.core import QgsRectangle
from qgis.gui import QgsMapToolEmitPoint
from qgis.utils import iface
canvas = iface.mapCanvas()
main_window = iface.mainWindow()
clickTool = QgsMapToolEmitPoint(canvas)
def my_custom_function(features):
def handle_mouse_down(point, button):
""""Manage selection when clicking on the canevas."""
layers = canvas.layers()
vl_to_query = [l for l in layers if != u'my_layer_name'][0]
w = canvas.mapUnitsPerPixel() * 3
rect = QgsRectangle(
point.x() - w,
point.y() - w,
point.x() + w,
point.y() + w
l_rect = canvas.mapSettings().mapToLayerCoordinates(vl_to_query, rect), False)
feats = vl_to_query.selectedFeatures()
# Do operations using selected features. Here we run a function
# We change the default tool to pan tool
# after the function execution on selected features
"User dialog info",
u"Thanks to select a geographic feature"
Copy link

When am trying to use this code getting an error like "AttributeError: class instance has no attribute 'x' ".
Can you tell me why is this happening
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment