Select by attribute then exporting selection

1872
21
Jump to solution
01-30-2012 05:30 AM
NathanBaylot1
New Contributor
arcpy.TableToTable_conversion("Master_TAHI", "C:\\Users\\D2148\\Documents\\Maps\\Parish Roads\\TAHI_LRS\\Parish_roads\\TAHI_parish\\FIPS", "FIPS001", "\"FIPS PARIS\" = '001'")

I am trying to select by attributes in a .dbf table then export it out to a new .dbf with the selected features only. I am having a problem executing this file. It keeps saying there is a error. The maximum record length has been exceeded. The file only has 87000 records.

Also, once this is figured out. How do I continue to go to the next select by attribute using a while statement. I need it to go to the FIPS PARIS = 127 and each FIPS is odd starting with 001 (eg. 001,003,005...)

If the table to table way doesn't work, any suggestions would be helpful. Thanks.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor
However, it will not loop anymore


Your loop is incorrect. You don't need a counter or while loop.

FIPSlist = ('001', '003', '005') for fip in FIPSlist:     query = "FIPS_PARIS ='" + fip + "'"     arcpy.TableSelect_analysis("Master_TAHI", FIPS + r"\FIPS" + fip + ".dbf",query)

View solution in original post

0 Kudos
21 Replies
markdenil
Occasional Contributor III
Well, to start; neither your input nor output is a obviously a dBase file. A dBase file has a .dbf extension.
Arc has to be told you are working with a dbase input and expect a dBase output.
0 Kudos
NathanBaylot1
New Contributor
This is used inside of arcmap, the master tahi file was selected in the python window from drop down and the output I changed to "FIPS001.dbf", This still did not work. So, what I did was run it through the toolbox command with the window pop up and did the same parameters. This still came up with the exceeded records error.
0 Kudos
BruceNielsen
Occasional Contributor III
I'm not sure the changes I made to your TableToTable command will solve the error you're getting, but here is how you can set up a loop for all odd numbers from 1 to 127. It will make the appropriate changes to the output file name, and the where clause:
for i in range(1,129,2):
    fipString=str(i).zfill(3)
    arcpy.TableToTable_conversion("Master_TAHI", "C:\\Users\\D2148\\Documents\\Maps\\Parish Roads\\TAHI_LRS\\Parish_roads\\TAHI_parish\\FIPS", "FIPS%s.dbf" % fipString, "\"FIPS PARIS\" = '%s'" % fipString)

0 Kudos
NathanBaylot1
New Contributor
FIPS = "C:\\Users\\D2148\\Documents\\Maps\\FIPS"       # I changed the destination for a shorter path name
c = 0
FIPSlist = ['001', '003', '005', '007', '009', '011', '013',
        '015', '017', '019', '021', '023', '025', '027',
        '029', '031', '033', '035', '037', '039', '041',
        '043', '045', '047', '049', '051', '053', '055',
        '057', '059', '061', '063', '065', '067', '069',
        '071', '073', '075', '077', '079', '081', '083',
        '085', '087', '089', '091', '093', '095', '097',
        '099', '101', '103', '105', '107', '109', '111',
        '113', '115', '117', '119', '121', '123', '125',
        '127']
while c < len(FIPSlist):
    arcpy.TableToTable_conversion("Master_TAHI",FIPS,"FIPS" + FIPSlist + ".dbf","FIPS_PARIS" = "'" + FIPSlist + "'") #I'm thinking this is the problem with to many ", but I need it to automate choosing the next number. I also think that it is a string and the program won't take it.
    c = c + 1

This is what I came up with because the number part would not be correct because it needs the 001,003, 005 and so forth.
This code comes up with
Runtime error <type 'exceptions.SyntaxError'>: keyword can't be an expression (<string>, line 14)


0 Kudos
NathanBaylot1
New Contributor
I also tried your way bruce but it did not work
0 Kudos
curtvprice
MVP Esteemed Contributor
. I am having a problem executing this file. It keeps saying there is a error. The maximum record length has been exceeded. The file only has 87000 records.


The error has to do with the record length, not the number of records. Dbase tables have some pretty serious limitations compared to GDB tables -- I suspect that is your issue.



  • Field names cannot be longer than 10 characters.

  • The maximum record length for an attribute is 4,000 bytes. The record length is the number of bytes used to define all the fields, not the number of bytes used to store the actual values.

  • The maximum number of fields is 255. A conversion to shapefile will convert the first 255 fields if this limit is exceeded.

  • The dBASE file must contain at least one field. When you create a new shapefile or dBASE table, an integer ID field is created as a default.

  • dBASE files do not support type blob, guid, global ID, coordinate ID, or raster field types.

  • dBASE files have little SQL support aside from a WHERE clause.

  • Attribute indexes are deleted when you save edits, and you must re-create them from scratch.


Arc 10 Help: Geoprocessing considerations for shapefile output
0 Kudos
ChrisSnyder
Regular Contributor III
How about:

inputTable = r"C:\temp\test\mytable.dbf"
outputWorkspace = r"C:\temp\test"
fipsLlist = ['001', '003', '005', '007', '009', '011', '013', 
'015', '017', '019', '021', '023', '025', '027', 
'029', '031', '033', '035', '037', '039', '041', 
'043', '045', '047', '049', '051', '053', '055', 
'057', '059', '061', '063', '065', '067', '069', 
'071', '073', '075', '077', '079', '081', '083', 
'085', '087', '089', '091', '093', '095', '097', 
'099', '101', '103', '105', '107', '109', '111', 
'113', '115', '117', '119', '121', '123', '125', 
'127']
for fip in fipsList:
   arcpy.TableSelect_analysis(inputTable, outputWorkspace + "\\fips_" + str(fip) + ".dbf", ","FIPS_PARIS = " +  "'" + fip + "'")  
0 Kudos
NathanBaylot1
New Contributor
I ran my most recent code and got the correct outcome except the fact it did not select the attributes needed for each file.
i just tried the code without the "FIPS_PARISH" = '', attribute selection. It created the files correctly.
0 Kudos
NathanBaylot1
New Contributor
How about:

inputTable = r"C:\temp\test\mytable.dbf"
outputWorkspace = r"C:\temp\test"
fipsLlist = ['001', '003', '005', '007', '009', '011', '013', 
'015', '017', '019', '021', '023', '025', '027', 
'029', '031', '033', '035', '037', '039', '041', 
'043', '045', '047', '049', '051', '053', '055', 
'057', '059', '061', '063', '065', '067', '069', 
'071', '073', '075', '077', '079', '081', '083', 
'085', '087', '089', '091', '093', '095', '097', 
'099', '101', '103', '105', '107', '109', '111', 
'113', '115', '117', '119', '121', '123', '125', 
'127']
for fip in fipsList:
   arcpy.TableSelect_analysis(inputTable, outputWorkspace + "\\fips_" + str(fip) + ".dbf", ","FIPS_PARIS = " +  "'" + fip + "'")  

arc doesn't recognize the last part as an expression, just as a string.
0 Kudos