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.

Is there a way using python (ArcPy) or ArcGIS 10.1 tools to collect consecutive line segments having the same elevation value and appending/merging/generating one single line from them? Each resulting line will have the same elevation value as the original segments.

Sorry, supporting image blocked for guest post.

share|improve this question
Have a look at the dissolve tool and set the dissolve by field to the elevation field. –  Hornbydd Jun 10 '13 at 17:31
Not a bad idea. But I'm not sure that will work with each unique line. We might have multiple lines that are the same elevation, but in very different locations. I don't want them all seen as 1 line. –  user18980 Jun 10 '13 at 19:14
Have you looked at the help for this tool? If you set the unsplit_lines option... –  Hornbydd Jun 10 '13 at 19:58
Well, I just tried several times. I'm getting plagued with the typical AGIS crashes! I'm trying this on a file geodatabase copy of my contours for a county ~ 700 sq mi and 148867 rows. Not sure why it's crashing now...but trying Dissolve tool with different options –  user18980 Jun 11 '13 at 17:26
Did you try running Repair Geometry on it first? –  Kirk Kuykendall Jun 26 '13 at 18:13

2 Answers 2

If you are familiar with python scripts, I wrote the following code for this exact problem I was having last month. You can create a script tool in ArcToolbox to execute the script. When Dissolve or Unsplit line tools have numerous records, it tends to bog down and crash. I'm guessing this is because "This tool will use a tiling process to handle very large datasets for better performance and scalability. For more details, see Geoprocessing with large datasets." Whatever ESRI says, it does not improve performance. I ran this on multiple shapefiles with over 400,000 total records. The dissolve tool ran for over 72 hrs and still did not finish. My script took less than 10 minutes.

Essentially, the tool breaks your elevation contours into shapefiles of the same value (i.e. 15 shapefiles for elevations 1ft - 15ft if your contours are 1 ft contours like mine). It also compensates for negative values (I have sites near the coast). The shapes are then merged, dissolved, and multipart to singlepart breaks separate lines into individual records. You can modify the dissolve_fields variable and field name throughout the code (I've marked the locations) to cater to your needs. I hope it helps.

# Contour_Merge_And_Dissolve.py

# Import modules
import arcpy
from arcpy import env

# Define functions
def min_max(featureClass, fieldName):
    listItems = []
    rows = arcpy.SearchCursor(featureClass)
    for row in rows:
    del rows
    listMin = listItems[0]
    listMax = listItems[-1]
    return listMin, listMax

# Arguments
contourList = arcpy.GetParameterAsText(0) #input shapefiles, ElevationContours
outFolder = arcpy.GetParameterAsText(1) #output folder

# set workspace and overwrite option
arcpy.env.workspace = outFolder
arcpy.env.overwriteOutput = True
arcpy.env.outputZFlag = "Disabled"
arcpy.env.outputMFlag = "Disabled"

# local variables
dissolveFields = ["ELEV_FT"] # change field name here

# Process: Merge
arcpy.AddMessage("Merging contours...")
arcpy.Merge_management(contourList, "contour_merge.shp")

# Get Min/Max values of ELEV_FT field
ft_min, ft_max = min_max("contour_merge.shp", "ELEV_FT") # change field name here
ft_range = ft_max - ft_min

arcpy.AddMessage("ELEV_FT MIN: " + str(ft_min))
arcpy.AddMessage("ELEV_FT MAX: " + str(ft_max))

# Set progressor
arcpy.SetProgressor("step", "Breaking apart contours...", 0, ft_range, 1)
arcpy.AddMessage("Breaking apart contours...")

# Break apart and dissolve for each ELEV_FT value
mergeList = []
counter = ft_min
while counter <= ft_max:
    arcpy.SetProgressorLabel("Breaking out " + str(counter) + "ft contours...")
    arcpy.AddMessage("Attempting " + str(counter) + "ft contours...")
    counter_str = str(counter)
    counter_str = counter_str.replace("-", "neg")
    thisLyr = "elev_" + counter_str + "_lyr"
    thisDis = "elev_" + counter_str + "_dissolve.shp"
    where_clause = '"ELEV_FT" = ' + str(counter) # change field name here
    # Make Layer
    arcpy.management.MakeFeatureLayer("contour_merge.shp", thisLyr)
    # Select by attributes
    arcpy.SelectLayerByAttribute_management(thisLyr, "NEW_SELECTION", where_clause)
    # Dissolve Layer to new shape
    arcpy.Dissolve_management(thisLyr, thisDis, dissolveFields, "", "SINGLE_PART", "DISSOLVE_LINES")
    # Add to mergeList
    counter += 1


# Merge contours
arcpy.AddMessage("Merging dissolved layers...")
arcpy.Merge_management(mergeList, "contour_dissolve.shp")

# Multipart to singlepart
arcpy.AddMessage("Converting multipart to singlepart...")
arcpy.MultipartToSinglepart_management("contour_dissolve.shp", "contour_singlepart.shp")

# Clean up
for shape in mergeList:
share|improve this answer

Dissolve based on the elevation, with the multi_part parameter set to "SINGLE_PART".

Or you could dissolve normally and then Explode multi-part features.

share|improve this answer

Your Answer


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.