Skip to content

Instantly share code, notes, and snippets.

@mtravis
Created June 27, 2015 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtravis/e7aee748a4779996aa42 to your computer and use it in GitHub Desktop.
Save mtravis/e7aee748a4779996aa42 to your computer and use it in GitHub Desktop.
QGIS Python Function to get map canvas center
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface
@qgsfunction(args=0, group='Custom')
def mapCenter(value1,feature, parent):
x = str(int(iface.mapCanvas().extent().center().x()))
y = str(int(iface.mapCanvas().extent().center().y()))
point = x + ',' + y
return point
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment