fork von https://github.com/nilsnolde/OSMtools mit QGIS2 processing erweiterung
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

pointtool.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Feb 06 23:35:16 2017
  4. @author: nnolde
  5. """
  6. from PyQt4.QtCore import pyqtSignal
  7. from PyQt4.QtGui import QCursor, QPixmap,QApplication
  8. from qgis.core import (QgsCoordinateReferenceSystem,
  9. QgsCoordinateTransform,
  10. QgsProject)
  11. from qgis.gui import QgsMapTool
  12. import os
  13. # Find cursor icon in plugin tree
  14. def resolve(name, basepath=None):
  15. if not basepath:
  16. basepath = os.path.dirname(os.path.realpath(__file__))
  17. return os.path.join(basepath, name)
  18. class PointTool(QgsMapTool):
  19. def __init__(self, canvas, button):
  20. QgsMapTool.__init__(self, canvas)
  21. self.canvas = canvas
  22. self.button = button
  23. self.imgdir = resolve('../icon_locate.png')
  24. self.cursor = QCursor(QPixmap(self.imgdir).scaledToWidth(24), 12, 12)
  25. #QApplication.setOverrideCursor(QCursor(QPixmap('../icon_locate.png')))
  26. canvasClicked = pyqtSignal(['QgsPoint', 'QString', 'Qt::MouseButton'])
  27. def canvasReleaseEvent(self, event):
  28. #Get the click and emit a transformed point
  29. # mapSettings() was only introduced in QGIS 2.4, keep compatibility
  30. try:
  31. crsSrc = self.canvas.mapSettings().destinationCrs()
  32. except:
  33. crsSrc = self.canvas.mapRenderer().destinationCrs()
  34. crsWGS = QgsCoordinateReferenceSystem(4326)
  35. point_oldcrs = self.toMapCoordinates(event.pos())
  36. xform = QgsCoordinateTransform(crsSrc, crsWGS)
  37. point_newcrs = xform.transform(point_oldcrs)
  38. QApplication.restoreOverrideCursor()
  39. self.canvasClicked.emit(point_newcrs, self.button, event.button())
  40. def activate(self):
  41. QApplication.setOverrideCursor(self.cursor)
  42. def isZoomTool(self):
  43. return False
  44. def isTransient(self):
  45. return False
  46. def isEditTool(self):
  47. return True