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.

  • 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

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")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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