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.

When working with TIGER line shp data at county level scale the labeling of roads, rivers, railroads, etc. is cumbersome due to all of the tiny line segments. Merging the dozens of segments that comprise a particular road or river will result in much cleaner labeling. The only problem is the amount of tedious work this requires. Anyone know of a Python script that will automate this process? It needs to find all records with the same name and merge them into one record. I thought ET Geowizards had a tool for this but can't seem to locate it.

enter image description herescreen shot for better explanation

share|improve this question
1  
You could use the Dissolve Tool based on the FULLNAME field. I'm not certain if the calculate geometry would give you the combined length of segments or not -- worth a shot depending on what you're using the files for. –  Roy Jul 20 '12 at 16:46
2  
If it's all about labeling, you can remove duplicate labels in the Placement Properties dialog of the Labels menu. –  Roy Jul 20 '12 at 16:49
    
the "remove duplicate labels" setting has never worked very well... only maplex which we don't have as ever made some difference... i'm trying the Dissolve right now, it usually displays a percentage of how much is done, not this time... hopefully it doesn't crash working these 178k records... would be very nice if Dissolve accomplishes the task, just seems too easy for some reason. –  sirgeo Jul 20 '12 at 16:57
    
just found another thread that has similar topic: forums.arcgis.com/threads/… –  sirgeo Jul 20 '12 at 16:59
    
Dissolve is still chugging along after 45 minutes... the reason for having longer cleaner polylines is to have County Map-friendly labeling.... i'm going leave Dissolve running and check back on it later, might not be until Monday before i look at the results... thank you for your suggestions. –  sirgeo Jul 20 '12 at 17:35
add comment

1 Answer

If the Dissolve tool suggested in my comment doesn't work this shouldn't be too big a hassle to script.

  1. Get a python list of all unique values in FULLNAME (potentially through use of SearchCursor)
  2. Loop through your FULLNAME to create a whereClause
  3. Use the whereClause in the Select Tool to create a temporary layer for each unique FULLNAME
  4. Merge all of the layers together (they'll already have the same schema)

If there is a computational bottleneck you might run into the same problem as with the Dissolve tool. You can always break your data into chunks to make it more managable.

# Location for temporary files
output = r'...'
tigerFile = r'...'
finalProduct = r'...'

# Limiting the cursor to only the field you need increases efficiency
fullNameValues = arcpy.SearchCursor(tigerFile, '', '', 'FULLNAME')
for name in fullNameValues:
    # Check if name is already in the list
    if name.FULLNAME in fullNameList:
        continue
    else:
        fullNameList.append(name.FULLNAME)

del name, fullNameValues

# Loop through list of unique values
for i in range(0, len(fullNameList)):
    whereClause = '"FULLNAME" = ' + "'" + fullNameList[i] + "'"
    arcpy.Select_management(inFile, output + fullNameList[i], whereClause)

# Merge all of the temporary files
tempFileList = []

#Set workspace for listFiles method
arcpy.env.workspace = output 

for file in arcpy.ListFiles('*.shp'):
    tempFileList.append(output + "\\" + file)
arcpy.Merge_management (tempFileList, finalProduct)
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.