Skip to content

Instantly share code, notes, and snippets.

@cindygis
Created May 2, 2018 11:50
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 cindygis/c55a96e9960fb3936421799c9dd48b04 to your computer and use it in GitHub Desktop.
Save cindygis/c55a96e9960fb3936421799c9dd48b04 to your computer and use it in GitHub Desktop.
Adds a field to a point feature class containing a link to launch Google Maps with directions from the current location of the device to the destination point.
#
# @author Cindy Jayakumar
#
# @date 12/05/2018
#
# Adds a field to a point feature class containing a link
# to launch Google Maps with directions from the current
# location of the device to the destination point.
#
# Can be used for navigating to sites while in the field,
# using Collector.
#
# No error handling for incorrect geometry type etc
#
import arcpy
# Initialise variables
fc = r"C:\Some\Arb\Folder\test.gdb\points"
# Spatial reference must be WGS 1984
sr = arcpy.SpatialReference(4326)
lyr = arcpy.mp.LayerFile(fc)
try:
arcpy.management.AddField(lyr, "LaunchGoogleMaps", "TEXT",field_length=100)
print("Added field.")
except Exception as e:
print(e)
with arcpy.da.UpdateCursor(lyr, ("SHAPE", "LaunchGoogleMaps"), spatial_reference=sr) as cursor:
for row in cursor:
end = "{0},{1}".format(row[0][1], row[0][0])
row[1] = "https://www.google.com/maps/dir/?api=1&destination={}".format(end)
cursor.updateRow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment