Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

So I have never posted here before. I have used the site a lot for help so many thanks to all the great contributors. So, I have used ArcGIS online to perform batch geocoding (18,000) records and it works great. Extremely fast and accurate. It does however chew up a LOT of credits. This is something I cannot sustain in the long term. To avoid that credit drain I would like to split my table out by the "State" Column and geocode individual states and then merge back together. The free online geocoder can handle smaller datasets and by breaking down by state I think I could acheive this. So far I have:

import arcpy
fc ="C:\GISProjects\ALLMembers\LEE_AllMembers.gdb\LeeMembers_Sort"
field = "State"
myList=set([row.getValue(field) for row in arcpy.SearchCursor(fc)])
for row in myList:
    print myList

This works and returns the set of values. I guess I"m wondering now how to take those values and arcpy.TabletoTable_Conversion? From there I could geocode each separate table and merge the results.

any help is much appreciated!

share|improve this question
    
What is your original input and what is your expected output? –  gm70560 May 17 '13 at 14:14
3  
TableToTable_Conversion takes a where clause, so you could just query a unique list of states, and loop over this in python calling TableToTable_Conversion with a where clause "State = '" + current_state + "'" –  Matthew Plourde May 17 '13 at 14:33
add comment

2 Answers

up vote 1 down vote accepted

I will assume you have many records per state that need to be geocoded, in which case you do not want to do this one record at a time, but in batches.

you can tweak your code a little to do this.

import arcpy
states = []
fc ="C:\GISProjects\ALLMembers\LEE_AllMembers.gdb\LeeMembers_Sort"
field = "State"
myList=set([row.getValue(field) for row in arcpy.SearchCursor(fc)])
for row in myList:
    if myList not in states:
        states.append(myList) # this will give you a list of the results of your search cursor

counter=0
for state in states:
    output_name='output_'+str(counter)
    arcpy.TableToTabel_conversion(input_table, output_path, output_name,""" "State" = '""" +state +"""'""") 
    counter+=1

You will need to define the input/output parameters (input_table, output_path), but this should give you an output file for each of the states in your input data

share|improve this answer
    
You want to reduce the list of states to unique states with states = list(set(states)). Otherwise, this creates a table for every instance of a state. –  Matthew Plourde May 17 '13 at 18:15
    
@Hotpepper Thanks so much for the help! I heeded all of your advice but am having one hiccup along the way. I am getting an error message TypeError: cannot concatenate 'str' and 'int' objects "output_name='output_'+counter –  Emerson Chew May 20 '13 at 16:56
    
ah, sorry about that, I updated the script with str(counter) which should change the format of the counter variable to a string so it will concatenate properly. –  Hotpepper May 20 '13 at 17:45
    
@Hotpepper again, thanks for the help! That corrected the concantenate str and int objects. I'm now getting a "cannot concatenate 'str' and 'set' objects. Any advice? Thanks so much in advance! –  Emerson Chew May 21 '13 at 16:28
    
@Hotpepper I got it man! found another post regarding string and 'set' or 'list' concatenation. I changed states.append('myList') and it worked. Thanks for all your help! –  Emerson Chew May 21 '13 at 16:36
add comment

If you had a shapefile contained in a folder (note a *.gdb), then Split Layer By Attributes would do the job. In any event, the code contained the scripts associated with the toolbox should provide sufficient background as to how accomplish this task.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.