def main():
    workspace = "Z:\GIS220\Final"

    if arcpy.Exists("Z:\GIS220\Final\MidWestEmo.gdb"):
        print("gdb already exists")
    else:
        # Execute CreateFileGDB
        arcpy.CreateFileGDB_management(workspace, "MidWestEmo.gdb")
        print("gdb created")

    # Create Address Locator
    arcpy.CreateAddressLocator_geocoding(
        "General — City State Country", "MidWestEmoChart.csv",
        "'Feature ID' FeatureID VISIBLE NONE;'*From Left' L_F_ADD VISIBLE NONE;'*To Left' L_T_ADD VISIBLE NONE;'*From Right' R_F_ADD VISIBLE NONE;'*To Right' R_T_ADD VISIBLE NONE;'Prefix Direction' PREFIX VISIBLE NONE;'Prefix Type' PRE_TYPE VISIBLE NONE;'*Street Name' NAME VISIBLE NONE;'Suffix Type' TYPE VISIBLE NONE;'Suffix Direction' SUFFIX VISIBLE NONE;'Left City or Place' CITYL VISIBLE NONE;'Right City or Place' CITYR VISIBLE NONE;'Left Zipcode' ZIPL VISIBLE NONE;'Right Zipcode' ZIPR VISIBLE NONE;'Left State' State_Abbr VISIBLE NONE;'Right State' State_Abbr VISIBLE NONE",
        Atlanta_AddressLocator, "", "DISABLED")
def createLocator(info):
    arcpy.env.overwriteOutput = True
    arcpy.env.workspace = info['workspace']

    in_address_locator_style = info['in_address_locator_style']
    in_reference_data = info['in_reference_data']
    in_field_map = info['in_field_map']
    out_address_locator = info['loc_path']
    config_keyword = info['config_keyword']
    in_data = info['in_data']

    print "removing temp files."

    if os.path.isfile(out_address_locator + '.loc'):
        os.remove(out_address_locator + '.loc')

    if os.path.isfile(out_address_locator + '.loc.xml'):
        os.remove(out_address_locator + '.loc.xml')

    if os.path.isfile(out_address_locator + '.lox'):
        os.remove(out_address_locator + '.lox')

    print "Creating the locator: " + out_address_locator + "."
    arcpy.ClearWorkspaceCache_management()

    try:
        arcpy.CreateAddressLocator_geocoding(in_address_locator_style,
                                             in_reference_data, in_field_map,
                                             out_address_locator,
                                             config_keyword)
        print "Succcesfully Created thelocator: " + out_address_locator + "!"
    except:
        print 'Error creating geoccoder : ' + out_address_locator + '.'
        print arcpy.GetMessages(2)
        logger.error('Error creating geoccoder : ' + out_address_locator + '.')
        logger.error(arcpy.GetMessages(2))

    arcpy.ClearWorkspaceCache_management()
    arcpy.env.workspace = ""
Beispiel #3
0
# Create national address locator for street addresses
#
# Author: Nathaniel Price
# Date: May 22, 2018

# Setup ---------------------------------------------------------------------------------------------------------------
# Import system modules
import os
import arcpy
from arcpy import env

# Define output path
OutputPath = 'C://Users//nprice3//Documents//ArcGIS//Address_Locators//'

# Create address locator ----------------------------------------------------------------------------------------------
# Set environment
env.workspace = "E:/QGIS/2016_ADDRFEAT/2018_ADDRFEAT.gdb"

# Create national streets address locator
output = OutputPath + "streets2018//national_streets"
arcpy.CreateAddressLocator_geocoding(
    in_address_locator_style="US Address - Dual Ranges",
    in_reference_data="ADDRFEAT 'Primary Table'",
    in_field_map=
    "'Feature ID' OBJECTID VISIBLE NONE;'*From Left' LFROMHN VISIBLE NONE;'*To Left' LTOHN VISIBLE NONE;'*From Right' RFROMHN VISIBLE NONE;'*To Right' RTOHN VISIBLE NONE;'Prefix Direction' <None> VISIBLE NONE;'Prefix Type' <None> VISIBLE NONE;'*Street Name' FULLNAME VISIBLE NONE;'Suffix Type' <None> VISIBLE NONE;'Suffix Direction' <None> VISIBLE NONE;'Left City or Place' <None> VISIBLE NONE;'Right City or Place' <None> VISIBLE NONE;'Left ZIP Code' ZIPL VISIBLE NONE;'Right ZIP Code' ZIPR VISIBLE NONE;'Left State' <None> VISIBLE NONE;'Right State' <None> VISIBLE NONE",
    out_address_locator=output,
    config_keyword="",
    enable_suggestions="DISABLED")
Beispiel #4
0
# Create King County address locators
# The new address locators will be created in a separate file folder.

# Import system modules
import os, arcpy

rootDir = r'J:\Projects\Geocoding\19GEOCODING'
inDir = r'Setup\3FinalProducts' 
county = 'King'

arcpy.env.workspace = os.path.join(rootDir, inDir, county)

# site address based (point file)
AddressLocator_OutputPath = os.path.join(rootDir, "AddressLocators\\19kin_siteaddr")
arcpy.CreateAddressLocator_geocoding(in_address_locator_style="US Address - Single House", 
                                     in_reference_data="siteaddr.shp 'Primary Table'", 
                                     in_field_map="'Point Address ID' FID VISIBLE NONE;'Street ID' <None> VISIBLE NONE;'*House Number' ADDR_HN VISIBLE NONE;Side <None> VISIBLE NONE;'Full Street Name' <None> VISIBLE NONE;'Prefix Direction' ADDR_PD VISIBLE NONE;'Prefix Type' <None> VISIBLE NONE;'*Street Name' ADDR_SN VISIBLE NONE;'Suffix Type' ADDR_ST VISIBLE NONE;'Suffix Direction' ADDR_SD VISIBLE NONE;'City or Place' <None> VISIBLE NONE;County <None> VISIBLE NONE;State <None> VISIBLE NONE;'State Abbreviation' <None> VISIBLE NONE;'ZIP Code' ZIP5 VISIBLE NONE;'Country Code' <None> VISIBLE NONE;'3-Digit Language Code' <None> VISIBLE NONE;'2-Digit Language Code' <None> VISIBLE NONE;'Admin Language Code' <None> VISIBLE NONE;'Block ID' <None> VISIBLE NONE;'Street Rank' <None> VISIBLE NONE;'Display X' <None> VISIBLE NONE;'Display Y' <None> VISIBLE NONE;'Min X value for extent' <None> VISIBLE NONE;'Max X value for extent' <None> VISIBLE NONE;'Min Y value for extent' <None> VISIBLE NONE;'Max Y value for extent' <None> VISIBLE NONE;'Additional Field' <None> VISIBLE NONE;'Altname JoinID' <None> VISIBLE NONE;'City Altname JoinID' <None> VISIBLE NONE", 
                                     out_address_locator=AddressLocator_OutputPath, 
                                     config_keyword="", 
                                     enable_suggestions="DISABLED")

# street centerline based
AddressLocator_OutputPath = os.path.join(rootDir, "AddressLocators\\19kin_stcl")
arcpy.CreateAddressLocator_geocoding(in_address_locator_style="US Address - Dual Ranges", 
                                     in_reference_data="stcl.shp 'Primary Table'", 
                                     in_field_map="'Feature ID' FID VISIBLE NONE;'*From Left' FRADDL VISIBLE NONE;'*To Left' TOADDL VISIBLE NONE;'*From Right' FRADDR VISIBLE NONE;'*To Right' TOADDR VISIBLE NONE;'Left Parity' <None> VISIBLE NONE;'Right Parity' <None> VISIBLE NONE;'Full Street Name' FULLNAME VISIBLE NONE;'Prefix Direction' DIRPREFIX VISIBLE NONE;'Prefix Type' <None> VISIBLE NONE;'*Street Name' ST_NAME VISIBLE NONE;'Suffix Type' ST_TYPE VISIBLE NONE;'Suffix Direction' DIRSUFFIX VISIBLE NONE;'Left City or Place' <None> VISIBLE NONE;'Right City or Place' <None> VISIBLE NONE;'Left County' <None> VISIBLE NONE;'Right County' <None> VISIBLE NONE;'Left State' <None> VISIBLE NONE;'Right State' <None> VISIBLE NONE;'Left State Abbreviation' <None> VISIBLE NONE;'Right State Abbreviation' <None> VISIBLE NONE;'Left ZIP Code' ZIP_L VISIBLE NONE;'Right ZIP Code' ZIP_R VISIBLE NONE;'Country Code' <None> VISIBLE NONE;'3-Digit Language Code' <None> VISIBLE NONE;'2-Digit Language Code' <None> VISIBLE NONE;'Admin Language Code' <None> VISIBLE NONE;'Left Block ID' <None> VISIBLE NONE;'Right Block ID' <None> VISIBLE NONE;'Left Street ID' <None> VISIBLE NONE;'Right Street ID' <None> VISIBLE NONE;'Street Rank' <None> VISIBLE NONE;'Min X value for extent' <None> VISIBLE NONE;'Max X value for extent' <None> VISIBLE NONE;'Min Y value for extent' <None> VISIBLE NONE;'Max Y value for extent' <None> VISIBLE NONE;'Left Additional Field' <None> VISIBLE NONE;'Right Additional Field' <None> VISIBLE NONE;'Altname JoinID' <None> VISIBLE NONE;'City Altname JoinID' <None> VISIBLE NONE", 
                                     out_address_locator=AddressLocator_OutputPath, 
                                     config_keyword="", 
                                     enable_suggestions="DISABLED")

Beispiel #5
0
address_fields = "Street address;City city;State state"
points30 = dir_path + name + "_Points30_2.shp"
pblk_points = dir_path + name + "_1930_Pblk_Points_2.shp"

print "Working On: " + name + " Creating Physical Blocks"
##### #Create Physical Blocks# #####
#First Dissolve St_Grid lines
arcpy.Dissolve_management(grid, dissolve_grid, "FULLNAME")
#Second Split Lines at Intersections
arcpy.FeatureToLine_management(dissolve_grid, split_grid)
#Third Create Physical Blocks using Feature to Polygon
arcpy.FeatureToPolygon_management(split_grid, pblocks)
#Finally Add a Physical Block ID
expression = "!FID! + 1"
arcpy.AddField_management(pblocks, "pblk_id", "LONG", 4, "", "", "", "", "")
arcpy.CalculateField_management(pblocks, "pblk_id", expression, "PYTHON_9.3")

print "Working On: " + name + " Geocode"
##### #Geocode Points# #####
#Create Address Locator
arcpy.CreateAddressLocator_geocoding("US Address - Dual Ranges",
                                     reference_data, in_field_map, add_locator,
                                     "")
#Geocode Points
arcpy.GeocodeAddresses_geocoding(addresses, add_locator, address_fields,
                                 points30)
#Attach Pblk ids to points
arcpy.SpatialJoin_analysis(points30, pblocks, pblk_points, "JOIN_ONE_TO_MANY",
                           "KEEP_ALL", "#", "INTERSECT")
print "Finished: " + name
#Create Field Map
field_map="""
"'Feature ID' FID VISIBLE NONE; '*House Number' LocNum VISIBLE NONE;
'Side' <None> VISIBLE NONE;'Prefix Direction' <None> VISIBLE NONE;
'Prefix Type' <None> VISIBLE NONE;'*Street Name' LocName_ne VISIBLE NONE;
'Suffix Type' <None> VISIBLE NONE;'Suffix Direction' <None> VISIBLE NONE;
'City or Place' CITY VISIBLE NONE;'ZIP Code' ZIP VISIBLE NONE;
'State' <None> VISIBLE NONE;'Street ID' <None> VISIBLE NONE;
'Display X' <None> VISIBLE NONE;'Display Y' <None> VISIBLE NONE;
'Min X value for extent' <None> VISIBLE NONE;'Max X value for extent' <None> VISIBLE NONE;
'Min Y value for extent' <None> VISIBLE NONE;'Max Y value for extent' <None> VISIBLE NONE;
'Additional Field' <None> VISIBLE NONE;'Altname JoinID' <None> VISIBLE NONE"""

print "Working on Locator"
arcpy.CreateAddressLocator_geocoding(in_address_locator_style="US Address - Single House", in_reference_data=Orig_Parcel_Table, in_field_map=field_map, out_address_locator=add_locator)

#Geocode Addresses to Parcel Data
print "Working on Geocoding"
arcpy.GeocodeAddresses_geocoding(Addresses, add_locator, address_fields, Stu_Parcel_Points)

#After Geocode, Attach Points to Parcel Flood Data
print "Working on Attaching Points to Parcels"
Stu_Parcel_Damage= path + "\Shapefiles\Results_92517.gdb\Stu_Parcel_Damage"

#Attach Student points to Parcel Damage
arcpy.SpatialJoin_analysis(Orig_Parcel, Stu_Parcel_Points, Stu_Parcel_Damage, "JOIN_ONE_TO_ONE", "KEEP_ALL", "#", "INTERSECT")

#Select Only Geocoded Features
print "Working on Creating New Selection"
arcpy.env.workspace= path + "\Shapefiles\Results_92517.gdb"
    # 23rd St
    first_n = 7331
    fids_n = []
    fids_s = []

    change_ns("23rd St", first_n, fids_n, fids_s)

#Make sure address locator doesn't already exist - if it does, delete it
add_loc_files = [
    dir_path + '\\' + x for x in os.listdir(dir_path)
    if x.startswith(name + "_addloc")
]
for f in add_loc_files:
    if os.path.isfile(f):
        os.remove(f)

#Create Address Locator
arcpy.CreateAddressLocator_geocoding(
    in_address_locator_style="US Address - Dual Ranges",
    in_reference_data=reference_data,
    in_field_map=field_map,
    out_address_locator=add_locator,
    config_keyword="")
#Geocode Points
arcpy.GeocodeAddresses_geocoding(addresses, add_locator, address_fields,
                                 points30)
#Attach Pblk ids to points
arcpy.SpatialJoin_analysis(points30, pblocks, pblk_points, "JOIN_ONE_TO_MANY",
                           "KEEP_ALL", "#", "INTERSECT")
Beispiel #8
0
def main():
    """Process entrypoint"""
    descr_msg = 'Rebuild Address Locator for use in geocode service'
    parser = argparse.ArgumentParser(description=descr_msg)
    parser.add_argument('--environment',
                        type=str,
                        help='the environment to deploy to',
                        default='test')
    args = parser.parse_args()
    environment = args.environment.lower()
    print('Environment: ' + environment)
    # Set environment
    config = load_yml('config.' + environment + '.yml')
    print('Config Loaded')
    in_dir = config['input-address-gdb-location']
    print('Input gdb directory: ' + in_dir)

    # Iterate through target servers in yaml config
    for tgt_server in config['target_servers']:
        # https://community.esri.com/thread/186020-start-stop-map-service-arcpy
        # Authentication
        adminUser = tgt_server['username']
        adminPass = tgt_server['password']
        # ArcGIS Server Machine
        server = tgt_server['ip']
        port = '6080'
        # Services e.g. ('FolderName/ServiceName.ServiceType')
        svc = 'geocode/ACT_Address_Locator.GeocodeServer'
        out_dir = tgt_server['output-address-locator-location']

        # Stop server
        if environment != 'optimizer':
            try:
                # Get ArcGIS Server token
                # Token timeout in minutes; default is 60 minutes.
                expiration = 60
                token = getToken(adminUser, adminPass, server, port,
                                 expiration)
                # Perform action on service
                action = 'stop'
                jsonOuput = serviceStartStop(server, port, svc, action, token)
                # Validate JSON object result
                if jsonOuput['status'] == "success":
                    print "{} {} successful".format(action.title(), str(svc))
                else:
                    print "Failed to {} {}".format(action, str(svc))
                    raise Exception(jsonOuput)
            except Exception, err:
                print err

        # Parameters for creating Address Locator
        locator_name = 'ACT_Address_Locator'
        gdb_out = out_dir + '\Geocode.gdb'
        gdb_in = in_dir + '\Geocode.gdb'
        try:
            arcpy.Delete_management(gdb_out)
            print("Deleted: " + gdb_out)
        except:
            print("Not Deleted: " + gdb_out)
        arcpy.Copy_management(gdb_in, gdb_out)
        env.workspace = gdb_out
        in_address_locator_style = 'US Address - Single House Subaddress'
        in_reference_data = "'" + gdb_out + "/Address_Geocodes/Geocode'"    \
                            + " 'Primary Table'"
        ref_data_fld_map = "'Feature ID' OBJECTID VISIBLE NONE;"            \
                            "'House Number Prefix' <None> VISIBLE NONE;"    \
                            "'*House Number' STREET_NUMBER VISIBLE NONE;"   \
                            "'House Number Suffix' <None> VISIBLE NONE;"    \
                            "'Side' <None> VISIBLE NONE;"                   \
                            "'Prefix Direction' <None> VISIBLE NONE;"       \
                            "'Prefix Type' <None> VISIBLE NONE;"            \
                            "'*Street Name' STREET_NAME VISIBLE NONE;"      \
                            "'Suffix Type' STREET_TYPE VISIBLE NONE;"       \
                            "'Suffix Direction' <None> VISIBLE NONE;"       \
                            "'Building Type' <None> VISIBLE NONE;"          \
                            "'Building Unit' <None> VISIBLE NONE;"          \
                            "'SubAddr Type' SUBADDTYPE VISIBLE NONE;"       \
                            "'SubAddr Unit' DOOR_NO VISIBLE NONE;"          \
                            "'City or Place' DIVISION VISIBLE NONE"         \
                            "'ZIP Code' <None> VISIBLE NONE;"               \
                            "'State' <None> VISIBLE NONE;"                  \
                            "'Street ID' <None> VISIBLE NONE;"              \
                            "'Display X' <None> VISIBLE NONE;"              \
                            "'Display Y' <None> VISIBLE NONE;"              \
                            "'Min X value for extent' <None> VISIBLE NONE;" \
                            "'Max X value for extent' <None> VISIBLE NONE;" \
                            "'Min Y value for extent' <None> VISIBLE NONE;" \
                            "'Max Y value for extent' <None> VISIBLE NONE;" \
                            "'Additional Field' <None> VISIBLE NONE;"       \
                            "'Altname JoinID' <None> VISIBLE NONE"
        out_address_locator = os.path.join(out_dir, locator_name)

        # Remove yesterday's address locator
        try:
            os.remove(out_address_locator + '.loc')
            os.remove(out_address_locator + '.loc.xml')
            os.remove(out_address_locator + '.lox')
            print('Previous locator deleted: ' + out_address_locator + '.loc')
        except:
            print('Failed to delete previous locator.')

        # Create new address locator in temp directory using makeTempDir()
        with makeTempDir() as temp_dir:
            temp_locator = os.path.join(temp_dir, locator_name)
            print('Temporary Locator Location: ' + temp_locator)
            print('Processing...')
            arcpy.CreateAddressLocator_geocoding(in_address_locator_style,
                                                 in_reference_data,
                                                 ref_data_fld_map,
                                                 temp_locator, '', 'ENABLED')

            # Move new address locator in place on target server
            print('Moving new locator: ' + out_address_locator)
            if os.path.isfile(temp_locator + '.loc'):
                print('Temporary Locator Exists')
                src_loc = temp_locator
                tgt_loc = out_address_locator
                arcpy.Copy_management(src_loc, tgt_loc)
                print('New locator moved in place')

        # Fix constant values (spelling sensitivity etc) in .loc file
        perform_find_and_replace(out_address_locator + '.loc',
                                 "MinimumMatchScore = 85",
                                 "MinimumMatchScore = 15")
        perform_find_and_replace(out_address_locator + '.loc',
                                 "MinimumCandidateScore = 75",
                                 "MinimumCandidateScore = 15")
        perform_find_and_replace(out_address_locator + '.loc',
                                 "SpellingSensitivity = 80",
                                 "SpellingSensitivity = 15")
        perform_find_and_replace(out_address_locator + '.loc',
                                 "MaxSuggestCandidates = 10",
                                 "MaxSuggestCandidates = 1")

        # start server
        if environment != 'optimizer':
            try:
                # Perform action on service
                action = 'start'
                jsonOuput = serviceStartStop(server, port, svc, action, token)
                # Validate JSON object result
                if jsonOuput['status'] == 'success':
                    print '{} {} successful'.format(action.title(), str(svc))
                else:
                    print 'Failed to {} {}'.format(action, str(svc))
                    raise Exception(jsonOuput)
            except Exception, err:
                print err
Beispiel #9
0
def initial_geocode(
        city_info,
        geo_path,
        hn_ranges=['MIN_LFROMA', 'MIN_RFROMA', 'MAX_LTOADD', 'MAX_RTOADD']):

    city_name, state_abbr, decade = city_info
    city_name = city_name.replace(' ', '')
    state_abbr = state_abbr.upper()

    min_l, max_l, min_r, max_r = hn_ranges

    # Files
    add_locator = geo_path + city_name + "_addloc_" + str(decade)
    addresses = geo_path + city_name + "_" + str(decade) + "_Addresses.csv"
    address_fields = "Street address; City city; State state"
    points = geo_path + city_name + "_" + str(decade) + "_Points.shp"
    reference_data = geo_path + city_name + state_abbr + "_" + str(
        decade) + "_stgrid_edit_Uns2.shp 'Primary Table'"

    # Fix addresses for use in geocoding
    try:
        arcpy.Delete_management(geo_path + "temp.gdb")
    except:
        pass
    arcpy.CreateFileGDB_management(geo_path, "temp.gdb")
    df_addresses_csv = pd.read_csv(addresses)
    df_addresses_dbf = df_addresses_csv.replace(np.nan, '', regex=True)
    x = np.array(np.rec.fromrecords(df_addresses_dbf.values))
    names = df_addresses_dbf.dtypes.index.tolist()
    x.dtype.names = tuple(names)
    arcpy.da.NumPyArrayToTable(
        x,
        geo_path + "temp.gdb/" + city_name + "_" + str(decade) + "_Addresses")
    arcpy.env.workspace = geo_path + "temp.gdb"

    field_map = "'Feature ID' FID VISIBLE NONE; \
	'*From Left' %s VISIBLE NONE; \
	'*To Left' %s  VISIBLE NONE; \
	'*From Right' %s  VISIBLE NONE; \
	'*To Right' %s  VISIBLE NONE; \
	'Prefix Direction' <None> VISIBLE NONE; \
	'Prefix Type' <None> VISIBLE NONE; \
	'*Street Name' FULLNAME VISIBLE NONE; \
	'Suffix Type' '' VISIBLE NONE; \
	'Suffix Direction' <None> VISIBLE NONE; \
	'Left City or Place' CITY VISIBLE NONE; \
	'Right City or Place' CITY VISIBLE NONE; \
	'Left ZIP Code' <None> VISIBLE NONE; \
	'Right ZIP Code' <None> VISIBLE NONE; \
	'Left State' STATE VISIBLE NONE; \
	'Right State' STATE VISIBLE NONE; \
	'Left Street ID' <None> VISIBLE NONE; \
	'Right Street ID' <None> VISIBLE NONE; \
	'Display X' <None> VISIBLE NONE; \
	'Display Y' <None> VISIBLE NONE; \
	'Min X value for extent' <None> VISIBLE NONE; \
	'Max X value for extent' <None> VISIBLE NONE; \
	'Min Y value for extent' <None> VISIBLE NONE; \
	'Max Y value for extent' <None> VISIBLE NONE; \
	'Left parity' <None> VISIBLE NONE; \
	'Right parity' <None> VISIBLE NONE; \
	'Left Additional Field' <None> VISIBLE NONE; \
	'Right Additional Field' <None> VISIBLE NONE; \
	'Altname JoinID' <None> VISIBLE NONE" % (min_l, max_l, min_r, max_r)

    #Make sure address locator doesn't already exist - if it does, delete it
    add_loc_files = [
        geo_path + '/' + x for x in os.listdir(geo_path)
        if x.startswith(city_name + "_addloc")
    ]
    for f in add_loc_files:
        if os.path.isfile(f):
            os.remove(f)

    print("The script is executing the 'CreateAddressLocator' tool")
    #Create Address Locator
    arcpy.CreateAddressLocator_geocoding(
        in_address_locator_style="US Address - Dual Ranges",
        in_reference_data=reference_data,
        in_field_map=field_map,
        out_address_locator=add_locator,
        config_keyword="")
    #Change side offset to maximize quality of physical block matches
    locator_fn = geo_path + '/' + city_name + '_addloc_' + str(decade) + '.loc'
    locator_file = open(locator_fn, 'a')  # open for appending
    locator_file.writelines('SideOffset = 1')
    locator_file.writelines('SideOffsetUnits = Feet')
    locator_file.close()
    print(
        "The script has finished executing the 'CreateAddressLocator' tool and has begun executing the 'GeocodeAddress' tool"
    )
    #Geocode Points
    arcpy.GeocodeAddresses_geocoding(in_table=city_name + "_" + str(decade) +
                                     "_Addresses",
                                     address_locator=add_locator,
                                     in_address_fields=address_fields,
                                     out_feature_class=points)
    #Delete temporary.gdb
    arcpy.Delete_management(geo_path + "temp.gdb/" + city_name + "_" +
                            str(decade) + "_Addresses")
    arcpy.Delete_management(geo_path + "temp.gdb")
    print(
        "The script has finished executing the 'GeocodeAddress' tool and has begun executing the 'SpatialJoin' tool"
    )
Beispiel #10
0
def geocode(geo_path,
            city_name,
            add,
            sg,
            vm,
            sg_vm,
            fl,
            tl,
            fr,
            tr,
            cal_street,
            cal_city,
            cal_state,
            addfield,
            al,
            g_address,
            g_city,
            g_state,
            gr,
            no_side_offset=True):
    print(
        "Step 1 of 3: The 'Geocode' function has started and the program has started to implement the intersect function"
    )
    arcpy.Intersect_analysis(in_features=[sg, vm],
                             out_feature_class=sg_vm,
                             join_attributes="ALL")
    print(
        "Step 2 of 3: The program has finished implementing the intersect function and has begun creating the address locator"
    )
    #Make sure address locator doesn't already exist - if it does, delete it
    add_loc_files = [
        geo_path + '\\' + x for x in os.listdir(geo_path)
        if x.startswith(al.split('/')[-1] + '.')
    ]
    for f in add_loc_files:
        if os.path.isfile(f):
            os.remove(f)
    arcpy.CreateAddressLocator_geocoding(
        in_address_locator_style="US Address - Dual Ranges",
        in_reference_data=sg_vm,
        in_field_map="'Feature ID' <None> VISIBLE NONE;\
													'*From Left' " + fl + " VISIBLE NONE;\
													'*To Left' " + tl + " VISIBLE NONE;\
													'*From Right' " + fr + " VISIBLE NONE;\
													'*To Right' " + tr + " VISIBLE NONE;\
													'Prefix Direction' <None> VISIBLE NONE;\
													'Prefix Type' <None> VISIBLE NONE;\
													'*Street Name' " + cal_street + " VISIBLE NONE;\
													'Suffix Type' <None> VISIBLE NONE;\
													'Suffix Direction' <None> VISIBLE NONE;\
													'Left City or Place' " + cal_city + " VISIBLE NONE;\
													'Right City or Place' " + cal_city + " VISIBLE NONE;\
													'Left ZIP Code' <None> VISIBLE NONE;\
													'Right ZIP Code' <None> VISIBLE NONE;\
													'Left State' " + cal_state + " VISIBLE NONE;\
													'Right State' " + cal_state + " VISIBLE NONE;\
													'Left Street ID' <None> VISIBLE NONE;\
													'Right Street ID' <None> VISIBLE NONE;\
													'Display X' <None> VISIBLE NONE;\
													'Display Y' <None> VISIBLE NONE;\
													'Min X value for extent' <None> VISIBLE NONE;\
													'Max X value for extent' <None> VISIBLE NONE;\
													'Min Y value for extent' <None> VISIBLE NONE;\
													'Max Y value for extent' <None> VISIBLE NONE;\
													'Left parity' <None> VISIBLE NONE;\
													'Right parity' <None> VISIBLE NONE;\
													'Left Additional Field' " + addfield + " VISIBLE NONE;\
													'Right Additional Field' " + addfield + " VISIBLE NONE;\
													'Altname JoinID' <None> VISIBLE NONE",
        out_address_locator=al)

    if no_side_offset:
        locator_fn = al + '.loc'
        locator_file = open(locator_fn, 'a')  # open for appending
        locator_file.writelines('SideOffset = 0')
        locator_file.writelines('SideOffsetUnits = Feet')
        locator_file.close()

    print(
        "Step 3 of 3: The program has finished creating the address locator and has started the geocoding process"
    )

    arcpy.GeocodeAddresses_geocoding(in_table=add,
                                     address_locator=al,
                                     in_address_fields="Street " + g_address +
                                     " VISIBLE NONE;\
			City " + g_city + " VISIBLE NONE;\
			State " + g_state + " VISIBLE NONE",
                                     out_feature_class=gr,
                                     out_relationship_type="STATIC")

    print(
        "The program has finished the geocoding process and 'Geocode' function is complete"
    )