Last active
October 12, 2023 17:59
-
-
Save spilth/ace4ee6953da037df4cf2365974e4502 to your computer and use it in GitHub Desktop.
Copy the current QGIS Canvas Extent to the clipboard as a 2D JSON Envelope for ArcGIS REST Service Queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qgis.gui import QgsMessageBar | |
from qgis.PyQt.Qt import QApplication | |
import json | |
crs = QgsProject.instance().crs() | |
extent = iface.mapCanvas().extent() | |
envelope = { | |
"xmin": extent.xMinimum(), | |
"ymin": extent.yMinimum(), | |
"xmax": extent.xMaximum(), | |
"ymax": extent.yMaximum(), | |
"spatialReference": { | |
"wkid": crs.postgisSrid() | |
} | |
} | |
QApplication.clipboard().setText(json.dumps(envelope, indent=2)) | |
iface.messageBar().pushMessage("Copied", "2D JSON Envelope copied to clipboard", Qgis.MessageLevel.Info) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment