Help Creating a Jump to Google Tool with Python

4295
9
10-01-2010 05:52 AM
jennifersylvester
New Contributor
I am working to create a tool in python that will take the current extent of the map in ArcMap 10 and create a hyperlink to jump to googlemaps at the same location.

In VBA the link was created from this:
  pHyperlink.Link = "http://maps.google.com/maps?ll=" & pPoint.y & "," & pPoint.x
with the point derived from this:
  x = ((pEnvelope.XMax - pEnvelope.XMin) / 2) + pEnvelope.XMin
  y = ((pEnvelope.YMax - pEnvelope.YMin) / 2) + pEnvelope.YMin

How do I replicate this with python?


So far I have:
import webbrowser
url = 'http://www.googlemaps.com/'
webbrowser.open_new_tab(url)

Thanks,
Jenn
0 Kudos
9 Replies
jennifersylvester
New Contributor
got it. it is unprojected NAD83


Script:

import webbrowser, arcpy

mxd = arcpy.mapping.MapDocument("current")
dataFrame = arcpy.mapping.ListDataFrames(mxd)[0]

externalScales = [192000000,96000000,48000000,24000000,12000000,6000000,3000000,1500000,725000,350000,188000,93000,46000,23000,9000,4500,2250]
currentScale = dataFrame.scale
current = 0
previous = 200000000
z = 0
counter = 0

for scale in externalScales:
    #print scale
    current = math.fabs(currentScale - scale)
    if current < previous:
        previous = current
        z = counter
    counter += 1

x = (dataFrame.extent.XMin + dataFrame.extent.XMax)/2
y = (dataFrame.extent.YMin + dataFrame.extent.YMax)/2

thelink = "http://maps.google.com/maps?ll="
thelink = thelink + str(y) + "," + str(x) + "&z=" + str(z)
webbrowser.open_new_tab(thelink)
0 Kudos
jennifersylvester
New Contributor
so, now does anyone know how to convert it to UTM or any other projected coordinate system in python?

thanks
0 Kudos
AaronPaul
New Contributor II
If I have my data in UTM what would be the code for this script?

I think the only piece I'm missing is inserting the correct "externalScales"

I want this function badly, please help 🙂
0 Kudos
jennifersylvester
New Contributor
I still cant figure it out. Ive been busy also and havent had time to work on it. Its really tricky! ill re-post to the thread if i get it working, and you do the same!

It works like a charm in an unprojected dataframe, unfortuantely how often do we use those?
0 Kudos
jennifersylvester
New Contributor
the external scales are the scales used by googlemaps, so you will still need those. in the old VBA code a projection file (one of the core projections that comes with arc) was called that was used to do the conversion, its that part that I am having trouble with in python.
0 Kudos
AaronPaul
New Contributor II
Very helpful, thank you.

Do you know if it's possible to use an address rather than plugging in x, y??
I'd think that Google could take the address and plug in the x, y.

I'm working with parcel data and usually have at minimum address, taxlot #, and (x, y).

I want to select a record and have that record correspond to any of these attributes.

What do u think?
0 Kudos
jennifersylvester
New Contributor
yes, i would think that you could do it much the same way. you need to find how google contructs their links with addresses (you should be able to google it) and instead of plugging in x,y corrdinates, you would construct the link in python using the addresses and the proper formatting. you may not need the scales anymore since they were used to get the correct zoom level (one that correlates to the scale in arc) and an address will go directly to the point

the tricky part will be getting it to read the addresses, you may need to build a model or tool to do this part. im not sure how you plan on doing that part of it, but you can use the code i posted as a jumping off point, but i think in the end you will have something that looks quite different.
0 Kudos
CosminTana
New Contributor
Hi Jenn!

Thanks for your Google Maps extentScales (z = zoomlevels).
Due to your draft, I was able to find a solution.

I created a Toolbox and uploadet it to:
http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=64C4E478-1422-2418-3465-8F28D...

The only thing you have to change is the path to the Projection file.

Let me know if you have any problems running the code...

I am new to Python Scripting, so please excuse if i don't fetch any possible error....

Hope you & everybody else can use this!

Please let me know if anybody has "better" google maps Scales available.

I think we found a simple and nice solution...
0 Kudos
StuartButt
New Contributor

Hi Cosmin,

Your link to the toolbox doesn't work. Could you publish the script you got working please.

0 Kudos