GeocodingTools.py
def execute(self, parameters, messages):
        """The source code of the tool."""
        # get input feature
        inFeature = parameters[0].valueAsText
        addressExists = parameters[1].value
        addressField = parameters[2].valueAsText
        service = parameters[3].valueAsText
        # create the address field if it does not exist
        if addressExists is False:
            arcpy.AddField_management(inFeature, "Address", "TEXT", "", "", 150, "", "NULLABLE")
            addressField = "Address"
        # search for addresses and populate field
        if service == "Google":
            from geopy.geocoders import GoogleV3
            geolocator = GoogleV3()
            with arcpy.da.UpdateCursor(inFeature, [addressField, "SHAPE@Y", "SHAPE@X"], "", "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984") as ADDR:
                for row in ADDR:
                    try:
                        queryString = str(row[1]) + "," + str(row[2])
                        location = geolocator.reverse(queryString, exactly_one=True)
                        row[0] = location.address[:-5]
                        ADDR.updateRow(row)
                        arcpy.AddMessage("Matched: " + location.address[:-5])
                        arcpy.GetMessages()
                    except IndexError:
                        arcpy.AddMessage("No Match: " + queryString)
                        arcpy.GetMessages()

        if service == "OpenStreetMap":
            from geopy.geocoders import Nominatim
            geolocator = Nominatim(country_bias="United States of America")
            with arcpy.da.UpdateCursor(inFeature, [addressField, "SHAPE@Y", "SHAPE@X"], "", "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984") as ADDR:
                for row in ADDR:
                    try:
                        queryString = str(row[1]) + "," + str(row[2])
                        location = geolocator.reverse(queryString, exactly_one=True)
                        row[0] = location.address[:location.address.rfind(",")]
                        ADDR.updateRow(row)
                        arcpy.AddMessage("Matched: " + location.address[:location.address.rfind(",")])
                        arcpy.GetMessages()
                    except IndexError:
                        arcpy.AddMessage("No Match: " + queryString)
                        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
        addressExists = parameters[1].value
        addressField = parameters[2].valueAsText
        service = parameters[3].valueAsText
        if addressExists is False:
            arcpy.AddField_management(inFeature, "Address", "TEXT", "", "", 150, "", "NULLABLE")
            addressField = "Address"
        if service == "Google":
            from geopy.geocoders import GoogleV3
            geolocator = GoogleV3()
            with arcpy.da.UpdateCursor(inFeature, [addressField, "SHAPE@Y", "SHAPE@X"], "", "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984") as ADDR:
                for row in ADDR:
                    try:
                        queryString = str(row[1]) + "," + str(row[2])
                        location = geolocator.reverse(queryString, exactly_one=True)
                        row[0] = location.address[:-5]
                        ADDR.updateRow(row)
                        arcpy.AddMessage("Matched: " + location.address[:-5])
                        arcpy.GetMessages()
                    except IndexError:
                        arcpy.AddMessage("No Match: " + queryString)
                        arcpy.GetMessages()
        if service == "OpenStreetMap":
            from geopy.geocoders import Nominatim
            geolocator = Nominatim(country_bias="United States of America")
            with arcpy.da.UpdateCursor(inFeature, [addressField, "SHAPE@Y", "SHAPE@X"], "", "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984") as ADDR:
                for row in ADDR:
                    try:
                        queryString = str(row[1]) + "," + str(row[2])
                        location = geolocator.reverse(queryString, exactly_one=True)
                        row[0] = location.address[:location.address.rfind(",")]
                        ADDR.updateRow(row)
                        arcpy.AddMessage("Matched: " + location.address[:location.address.rfind(",")])
                        arcpy.GetMessages()
                    except IndexError:
                        arcpy.AddMessage("No Match: " + queryString)
                        arcpy.GetMessages()
def execute ( self , parameters , messages ) : inFeature = parameters [ 0 ] . valueAsText addressExists = parameters [ 1 ] . value addressField = parameters [ 2 ] . valueAsText service = parameters [ 3 ] . valueAsText if addressExists is False : arcpy . AddField_management ( inFeature , "Address" , "TEXT" , "" , "" , 150 , "" , "NULLABLE" ) addressField = "Address" if service == "Google" : from geopy . geocoders import GoogleV3 geolocator = GoogleV3 ( ) with arcpy . da . UpdateCursor ( inFeature , [ addressField , "SHAPE@Y" , "SHAPE@X" ] , "" , "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984" ) as ADDR : for row in ADDR : try : queryString = str ( row [ 1 ] ) + "," + str ( row [ 2 ] ) location = geolocator . reverse ( queryString , exactly_one = True ) row [ 0 ] = location . address [ : - 5 ] ADDR . updateRow ( row ) arcpy . AddMessage ( "Matched: " + location . address [ : - 5 ] ) arcpy . GetMessages ( ) except IndexError : arcpy . AddMessage ( "No Match: " + queryString ) arcpy . GetMessages ( ) if service == "OpenStreetMap" : from geopy . geocoders import Nominatim geolocator = Nominatim ( country_bias = "United States of America" ) with arcpy . da . UpdateCursor ( inFeature , [ addressField , "SHAPE@Y" , "SHAPE@X" ] , "" , "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984" ) as ADDR : for row in ADDR : try : queryString = str ( row [ 1 ] ) + "," + str ( row [ 2 ] ) location = geolocator . reverse ( queryString , exactly_one = True ) row [ 0 ] = location . address [ : location . address . rfind ( "," ) ] ADDR . updateRow ( row ) arcpy . AddMessage ( "Matched: " + location . address [ : location . address . rfind ( "," ) ] ) arcpy . GetMessages ( ) except IndexError : arcpy . AddMessage ( "No Match: " + queryString ) 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