[GIS] Using ArcPy to zoom to Y,X (string) coordinate pair copy/pasted from Google Maps

arcgis-10.0arcgis-desktoparcpygoogle maps

I frequently use google maps to find locations, and paste the coordinates into the "go to XY" toolbar in decimal degrees. It's a bit repetitive to paste the latitude into one box, and the longitude into another. Is there a quicker way of zooming to a location with a string in the "google maps" coordinate format such as:

-29.948153, 146.864276

I was thinking I could make a python tool, but I can only find code for "zoom to selected features" (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s300000003000000)

I'm using ArcGIS Desktop 10.0.

Best Answer

Below is some code that should do the basics of this.

import arcpy

yxCoordString = arcpy.GetParameterAsText(0)
yStr,xStr = yxCoordString.split(",")
xFloat = float(xStr)
yFloat = float(yStr)

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
newExtent = df.extent
newExtent.XMin, newExtent.YMin = xFloat - 0.5, yFloat - 0.5
newExtent.XMax, newExtent.YMax = xFloat + 0.5, yFloat + 0.5
df.extent = newExtent

arcpy.RefreshActiveView()

You just need to Add Script it into a toolbox and then assign a parameter like below:

enter image description here

I have it zooming to a 1 x 1 degree extent by subtracting/adding 0.5 to the entered coordinates but you can set that to whatever you like.

This code takes no account of the coordinates entered being different to the coordinate system of the data frame.