Skip to content

Instantly share code, notes, and snippets.

@spilth
Last active October 12, 2023 17:59
Show Gist options
  • Save spilth/ace4ee6953da037df4cf2365974e4502 to your computer and use it in GitHub Desktop.
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
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