I have a layer with line segments and a layer of polygons (in this case, buffers around points). I need to create a new field for each polygon that contains the total length of all line segments contained within that polygon, including portions of the line segments with the polygon that straddle the borders.
-
Which version of ArcGIS are you using, and are you looking for a point and click solution or a programmatic solution?– blah238Feb 18, 2013 at 21:01
-
I'm using ArcGIS 10. Either programmatic or point-and-click– Nicholas TulachFeb 18, 2013 at 21:04
-
3Possible answer: forums.arcgis.com/threads/30992-SUM-LENGTH-OF-LINES-IN-POLYGONS– Nicholas TulachFeb 18, 2013 at 21:27
1 Answer
A slight modification of the answer linked in the comments would be to do a Summary Statistics to get the SUM of the Shape.Length
field of the intersect feature class, using the FID field of the polygons a case field, and then Join Field that back to the polygon feature class.
In the ArcMap 10.1 Python window, these commands worked for me:
intersection = arcpy.Intersect_analysis("RoadCenterline;SchoolTaxDistrict", r"in_memory\intersect")
arcpy.CalculateField_management(intersection, "SHAPE_Leng", "!shape.length!", "PYTHON_9.3")
summary = arcpy.Statistics_analysis(intersection, r"in_memory\statistics", "SHAPE_Leng SUM", "FID_SchoolTaxDistrict")
arcpy.JoinField_management("SchoolTaxDistrict", "FID", summary, "FID_SchoolTaxDistrict")