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.
I'm pretty new to ArcPy so advice on creating temporary layers to work with would be very helpful. As a starting point just assume a polylines shapefile. The planned workflow is to rejoin these with the other road data once they've been collapsed.
1 Answer 1
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")
arcpy.Delete_management("newSelectn.shp")
arcpy.Delete_management('selectn')