Geographic Information Systems Asked on March 19, 2021
I’m not "fluent" in PyQGIS but thanks to some tutorials I managed to put togheter a plugin that acquires the clicked point’s coordinates and saves a QRcode containing the link to google maps for that point.
The plugin works fine but it needs to be reloaded every time because when I swich to other tasks (like selecting elements) and then come back to the plugin my mouse pointer doesn’t change shape to a cross as it should, so I think that there is some problem with the command QgsMapToolEmitPoint(canvas)
.
This is a snippet
from pyproj import Proj, transform
from qgis.core import QgsProject, Qgis
from qgis.utils import iface
from qgis.gui import QgsMapToolEmitPoint
import qrcode
from pathlib import Path
epsg=32632
def display_point( pointTool ):
#print(epsg)
inProj = Proj(init='epsg:%s'%epsg)
outProj = Proj(init='epsg:4326')
x1,y1 = pointTool[0],pointTool[1]
x2,y2 = transform(inProj,outProj,x1,y1)
#creates folder QR if doesn't exist
Path(QgsProject.instance().readPath("./")+'/QR').mkdir(parents=True, exist_ok=True)
img = qrcode.make('https://www.google.com/maps?q=%f,%f' %(y2,x2))
img.save(QgsProject.instance().readPath("./")+'/QR/%f,%f.png' %(y2,x2))
link = 'https://www.google.com/maps?q=%f,%f' %(y2,x2)
path = QgsProject.instance().readPath("./")+'/QR'
iface.messageBar().pushMessage('Link: %s ' %link, ' %s' %path, level=Qgis.Success, duration=10)
canvas = iface.mapCanvas()
# this QGIS tool emits a QgsPoint after each click on the map canvas
pointTool = QgsMapToolEmitPoint(canvas)
#left click runs display_point
pointTool.canvasClicked.connect( display_point )
canvas.setMapTool( pointTool )
Do I miss something that resets everything without reloading?
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP