I have two shapefiles:
Code:
import arcpy#set some environmental variablesarcpy.env.workspace = "C:\Users\Alex\Documents\SoilMoisture"arcpy.env.overwriteOutput = 1#define variables for all necessary feature classes and fieldsstreams = "pathto/str_split_lamb.shp" ## shapefile of stream network split at vertices, in Lambert projection, with Length value field pre-calculatedrainGrid = "pathto/net_test.shp" ## polygons for rain cells, with empty "DRN_LENGTH" fieldcursor = arcpy.UpdateCursor(rainGrid) ## will iterate across every row of the rainfall grid featurefor row in cursor: intStreams = arcpy.Intersect_analysis([streams,rainGrid],"output.shp","ALL","","LINE") ## intStreams becomes all stream segments inside polygon strCursor = arcpy.SearchCursor(intStreams) ##iterate over streams in intersection totalLen = 0 for rowmore in strCursor: totalLen += rowmore.length ## sum all length values into one variable print totalLen # this is just here to check what's going on row.DRN_LENGTH = totalLen ## add value to field cursor.updateRow(row)print "Done!"Any ideas?
أكثر...
- A set of stream (vector line) data
- A fishnet of polygons
Code:
import arcpy#set some environmental variablesarcpy.env.workspace = "C:\Users\Alex\Documents\SoilMoisture"arcpy.env.overwriteOutput = 1#define variables for all necessary feature classes and fieldsstreams = "pathto/str_split_lamb.shp" ## shapefile of stream network split at vertices, in Lambert projection, with Length value field pre-calculatedrainGrid = "pathto/net_test.shp" ## polygons for rain cells, with empty "DRN_LENGTH" fieldcursor = arcpy.UpdateCursor(rainGrid) ## will iterate across every row of the rainfall grid featurefor row in cursor: intStreams = arcpy.Intersect_analysis([streams,rainGrid],"output.shp","ALL","","LINE") ## intStreams becomes all stream segments inside polygon strCursor = arcpy.SearchCursor(intStreams) ##iterate over streams in intersection totalLen = 0 for rowmore in strCursor: totalLen += rowmore.length ## sum all length values into one variable print totalLen # this is just here to check what's going on row.DRN_LENGTH = totalLen ## add value to field cursor.updateRow(row)print "Done!"Any ideas?
أكثر...