finding shortest distance routes with python based on addresses in a file

3877
1
12-16-2012 09:28 PM
olenagavriliouk
New Contributor
hi,

i am using python to interact with ArcGIS and NetworkAnalyst to print out shortest routes of a set of addresses.  Currently passing lat and lon of a set of addresses (along with an object Id). Found a problem with such routes and ESRI snaps the lat/lon to a wrong street sometimes.  Hence would like to use a complete address instead of lat/lon of the address points (i.e., use unit, street address, town, state ).  What should be something like in the example I found in the doco on Analyst toolset, but I cannot find anything about the structure of the input file and the field names. 

someone please help!!!!

olena
0 Kudos
1 Reply
ramsesmadou
New Contributor
Hi Olena,

Two things.

One, can you share your code for the routing task or direct me to where you found a good tutorial? I am trying to do something similar and can't figure it out quite yet.

Two, not sure if this will help but you could geocode the addresses first (i pasted the python code I use to geocode batches of address below). If there aren't too many addresses in your set you can then check out where they are on a base map and relocate those that are giving you trouble.

Hope that helps,
Ramses

Python scripts to geocode batches of addresses:
'''
Created on Aug 14, 2012

@author: rmadou
This script geocodes batches of addresses

To make this work you must add the geocoding service to ArcCatalog on your local machince. Here are instructions on how to do that:
1. Look in the Catalog Tree for GIS Services.
2. Expand that and select Add ArcGIS Server.
3. In the dialog, choose Use GIS services. Click Next.
4. For the Server URL, type: http://tasks.arcgisonline.com/arcgis/services
5. Press ok. You should now see arcgis on tasks.arcgisonline.com in that GIS servers list.
6. Expand the connection and expand the locators folder. Select and click on the locator you want to use.
7. Copy the full location path from the Location bar at the top of ArcCatalog.

you must also map your data headers to the GeocodeAddresses_geocoding headers

for more information on the arcpy function/s used here see:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/#/Geocode_Addresses/002600000006000000/
'''
import arcpy,time, datetime

#class Geocode():
#    def RunGeoCoding(self):
startTime = time.time()
print "geocoding started at", datetime.datetime.now()
# Set local variables:
address_table = r"UEMs with active permit etc 2013-1-11.TXT"
print "address table loaded"
address_locator = r"GIS Servers\arcgis on tasks.arcgisonline.com\Locators\TA_Address_NA_10.GeocodeServer"
print "address locator loaded"
geocode_result = r"D:\Documents\Eclipse workspaces\PATS\geocode active 4D addresses\src\output shape files\UEM_Go_ON_import_noProblem_2013_01_11.shp"
print "output file created, but not yet populated"

arcpy.GeocodeAddresses_geocoding(address_table, address_locator, "Street Address VISIBLE NONE;City CITY VISIBLE NONE;State State VISIBLE NONE;Zip Zip VISIBLE NONE", geocode_result, "STATIC")
duration=time.time()-startTime
print "done! I took ",duration/60," minutes to run"
0 Kudos