GeocodingTools.py
def execute(self, parameters, messages):
        """The source code of the tool."""
        # get input feature
        inFeature = parameters[0].valueAsText
        coordinatesExists = parameters[1].value
        addressField = parameters[2].valueAsText
        latField = parameters[3].valueAsText
        lonField = parameters[4].valueAsText
        service = parameters[5].valueAsText
        # create the address field if it does not exist
        if coordinatesExists is False:
            arcpy.AddField_management(inFeature, "Lat", "DOUBLE", "", "", 12, "", "NULLABLE")
            latField = "Lat"
            arcpy.AddField_management(inFeature, "Lon", "DOUBLE", "", "", 12, "", "NULLABLE")
            lonField = "Lon"
        # search for addresses and populate field
        if service == "Google":
            from geopy.geocoders import GoogleV3
            geolocator = GoogleV3()
            with arcpy.da.UpdateCursor(inFeature, [addressField, latField, lonField]) as ADDR:
                for row in ADDR:
                    try:
                        location = geolocator.geocode(row[0])
                        row[1] = location.latitude
                        row[2] = location.longitude
                        ADDR.updateRow(row)
                        arcpy.AddMessage("Matched: " + row[0])
                        arcpy.GetMessages()
                    except IndexError:
                        arcpy.AddMessage("No Match: " + row[0])
                        arcpy.GetMessages()

        if service == "OpenStreetMap":
            from geopy.geocoders import Nominatim
            geolocator = Nominatim(country_bias="United States of America")
            with arcpy.da.UpdateCursor(inFeature, [addressField, latField, lonField]) as ADDR:
                for row in ADDR:
                    try:
                        location = geolocator.geocode(row[0])
                        row[1] = location.latitude
                        row[2] = location.longitude
                        ADDR.updateRow(row)
                        arcpy.AddMessage("Matched: " + row[0])
                        arcpy.GetMessages()
                    except IndexError:
                        arcpy.AddMessage("No Match: " + row[0])
                        arcpy.GetMessages()
The source code of the tool.
The source code of the tool.
The source code of the tool .
def execute(self, parameters, messages):
        inFeature = parameters[0].valueAsText
        coordinatesExists = parameters[1].value
        addressField = parameters[2].valueAsText
        latField = parameters[3].valueAsText
        lonField = parameters[4].valueAsText
        service = parameters[5].valueAsText
        if coordinatesExists is False:
            arcpy.AddField_management(inFeature, "Lat", "DOUBLE", "", "", 12, "", "NULLABLE")
            latField = "Lat"
            arcpy.AddField_management(inFeature, "Lon", "DOUBLE", "", "", 12, "", "NULLABLE")
            lonField = "Lon"
        if service == "Google":
            from geopy.geocoders import GoogleV3
            geolocator = GoogleV3()
            with arcpy.da.UpdateCursor(inFeature, [addressField, latField, lonField]) as ADDR:
                for row in ADDR:
                    try:
                        location = geolocator.geocode(row[0])
                        row[1] = location.latitude
                        row[2] = location.longitude
                        ADDR.updateRow(row)
                        arcpy.AddMessage("Matched: " + row[0])
                        arcpy.GetMessages()
                    except IndexError:
                        arcpy.AddMessage("No Match: " + row[0])
                        arcpy.GetMessages()
        if service == "OpenStreetMap":
            from geopy.geocoders import Nominatim
            geolocator = Nominatim(country_bias="United States of America")
            with arcpy.da.UpdateCursor(inFeature, [addressField, latField, lonField]) as ADDR:
                for row in ADDR:
                    try:
                        location = geolocator.geocode(row[0])
                        row[1] = location.latitude
                        row[2] = location.longitude
                        ADDR.updateRow(row)
                        arcpy.AddMessage("Matched: " + row[0])
                        arcpy.GetMessages()
                    except IndexError:
                        arcpy.AddMessage("No Match: " + row[0])
                        arcpy.GetMessages()
def execute ( self , parameters , messages ) : inFeature = parameters [ 0 ] . valueAsText coordinatesExists = parameters [ 1 ] . value addressField = parameters [ 2 ] . valueAsText latField = parameters [ 3 ] . valueAsText lonField = parameters [ 4 ] . valueAsText service = parameters [ 5 ] . valueAsText if coordinatesExists is False : arcpy . AddField_management ( inFeature , "Lat" , "DOUBLE" , "" , "" , 12 , "" , "NULLABLE" ) latField = "Lat" arcpy . AddField_management ( inFeature , "Lon" , "DOUBLE" , "" , "" , 12 , "" , "NULLABLE" ) lonField = "Lon" if service == "Google" : from geopy . geocoders import GoogleV3 geolocator = GoogleV3 ( ) with arcpy . da . UpdateCursor ( inFeature , [ addressField , latField , lonField ] ) as ADDR : for row in ADDR : try : location = geolocator . geocode ( row [ 0 ] ) row [ 1 ] = location . latitude row [ 2 ] = location . longitude ADDR . updateRow ( row ) arcpy . AddMessage ( "Matched: " + row [ 0 ] ) arcpy . GetMessages ( ) except IndexError : arcpy . AddMessage ( "No Match: " + row [ 0 ] ) arcpy . GetMessages ( ) if service == "OpenStreetMap" : from geopy . geocoders import Nominatim geolocator = Nominatim ( country_bias = "United States of America" ) with arcpy . da . UpdateCursor ( inFeature , [ addressField , latField , lonField ] ) as ADDR : for row in ADDR : try : location = geolocator . geocode ( row [ 0 ] ) row [ 1 ] = location . latitude row [ 2 ] = location . longitude ADDR . updateRow ( row ) arcpy . AddMessage ( "Matched: " + row [ 0 ] ) arcpy . GetMessages ( ) except IndexError : arcpy . AddMessage ( "No Match: " + row [ 0 ] ) arcpy . GetMessages ( )
The source code of the tool.
The source code of the tool .
"""The source code of the tool.""" # get input feature # create the address field if it does not exist # search for addresses and populate field
self
parameters
messages