Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to collapse parallel polylines (dual carriageways in a shapefile of roads) to single centrelines. I'm aware of cartography's dual lines to centerline tool, but I find Feature To Line (Data Management) slightly more reliable. The challenge is that whichever function is used requires a large tolerance (e.g. 10m+) so must be applied to custom selections of data in order to avoid creating new artifacts between unrelated pairs - hence the need for custom selections, which as far as I can tell these functions can't handle.

Grateful for any advice from high ArcPy wizards on how best to approach this. I'm pretty new to ArcPy so any advice on e.g. creating temporary layers to work with would be very helpful. As a starting point please just assume a polylines shapefile. The planned workflow is to rejoin these with the other road data once they've been collapsed. Many thanks in advance.

share|improve this question
you're not asking how to automatically group the parallels into bins correct? you're asking "once i have the groups how do i automate the remaining process"? – gotchula May 22 '13 at 18:35
Hi @gotchula. I should be able to figure out how to create the groupings, but I don't know what kind of data types/structures are best suited to this sort of operation. – geotheory May 22 '13 at 23:15
up vote 0 down vote accepted

Perhaps not the most elegant solution (based on advice from ArcGIS Forums), but it works for me:

fieldNames = getValueList("shapefile", "FIELD")
fieldNames = map(str, fieldNames)

# blank layer for results called 'merged'
arcpy.CreateFeatureclass_management("C:\\PATH", "merged.shp", "POLYLINE", "shapefile.shp", "SAME_AS_TEMPLATE", "SAME_AS_TEMPLATE", "shapefile.shp")

for each in fieldNames:
    defQuery = "\"FIELD\" = '%s'" % (each)
    # create temporary layer of DCs with same official road identifier
    arcpy.MakeFeatureLayer_management("shapefile", "selectn", defQuery)
    # run centre-line function on the selection and assign to new layer
    arcpy.FeatureToLine_management("selectn", "newSelectn", "20.0 Meters", "ATTRIBUTES")
    arcpy.Append_management("newSelectn", "merged", "NO_TEST")
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.