GeometryList = arcpy.CopyFeatures_management(clipRoadsShp, g) # Use geometry/length to get the total length of clipped roads(in meters) # Clip roads w/ selected polygon - for this I will need a search cursorĬlipRoads = outDataPath + 'rdsClip_' + blockEID + '_' + scaleEID + '_' + bufEID + '_' + str(n)Īrcpy.Clip_analysis(Road, "clipLayer", clipRoads) # select single record to use when clippingĪrcpy.SelectLayerByAttribute_management("clipLayer", "NEW_SELECTION", '"Sequence" = \''+ n +'\'') Qrow = arcpy.SearchCursor(eLyrPath, where_clause=expression, fields = "FromPrevTr FromPrevDi") # rQuery = '"Sequence" = \''+ n +'\'' -this line throws errors-Įxpression = arcpy.AddFieldDelimiters(eLyrPath, "Sequence")+ sel With arcpy.da.SearchCursor(eLyrPath, ("Sequence", "FromPrevTr", "FromPrevDi", "POINT_X", "POINT_Y", # use search cursor to grab data row by row #Make a layer from the feature class - needed for selecting records to be used in the clippingĪrcpy.MakeFeatureLayer_management(eLyrPath, "clipLayer") Print 'eLayer: ' + eLayer + ' Block: ' + blockEID + ' Scale: ' + scaleEID + ' BufferType: ' + bufEID # use selected features to clip roads layer & calculate geometryįor dirpath, dirnames, filenames in arcpy.da.Walk(envelopeLyr, datatype = 'FeatureClass', type = 'Polygon'):ĮnvelopeList.append(os.path.join(filename)) # loop through each record in the table - calculate values and. # Step 6 - Calculate totalTime and totalDistance using insert cursor Print 'Buffer: ' + bufShp + ' Block: ' + blockID + ' Scale: ' + scaleID + ' BufferType: ' + bufIDĪrcpy.FeatureEnvelopeToPolygon_management(bufferLyr + bufShp, envelopeLyr + bufID + '_' + blockID + '_' + scaleID, 'SINGLEPART') Print 'Converting round buffers to squares.' # Step 5 - Run feature envelope to polygon on buffer layers # Jump into orderLayers to delete unneeded fields & add XYĪrcpy.DeleteField_management(shp, dropFields)Īrcpy.Buffer_analysis(shp, bufferLyr + 'buf' + '_' + block + '_' + scale, bufDist, 'FULL', 'ROUND', 'NONE', '#')Īrcpy.Buffer_analysis(shp, bufferLyr + 'buf2' + '_' + block + '_' + scale, bufDefault, 'FULL', 'ROUND', 'NONE', '#')įor dpath, dnames, fnames in arcpy.da.Walk(bufferLyr, datatype = 'FeatureClass', type = 'Polygon'): Print 'Order: ' + shp + ', Buffer: ' + bufDist # define buffer distance - double check the buffer distances w/ Sandy (I may need to double these values) # Loop through layers & break name into segments to be used when naming orders lyrs # Step 2 - Loop through route layers and export Order sublayers to orders folder W = csv.writer(f, delimiter=',', lineterminator='\n')įieldNames = ['Block', 'Scale', 'Sequence', 'FromPrevTr', 'FromPrevDi', 'x', 'y', 'bufferDist','totTime', \ # Needed fields: From script ĬSVFile = 'F:\\Workspace\\Sandy\\GM_costAnalysis\\analysis2\\AllTrapsData.csv' # Step 1 - loop through each route layer and do the following processes "CumulViola", "ArriveTime", "SourceID", "SourceOID", "PosAlong", "SideOfEdge", "CurbApproa", "Status"] "CumulDista", "CumulTime", "ArriveCurb", "DepartCurb", "DepartTime", "WaitTime", "ViolationT", "CumulWaitT", \ "PickupQuan", "DeliveryQu", "Revenue", "SpecialtyN", "Assignment", "RouteName", "ViolatedCo", "CumulTrave", \ Road = 'F:\\Workspace\\Sandy\\GM_costAnalysis\\RoadsForSnap\\SDC Edge Source.shp'ĭropFields = ["Descriptio", "ServiceTim", "TimeWind_1", "TimeWind_2", "TimeWind_3", "TimeWindow", "MaxViolati", "MaxViola_1", \ # -set road layer - for use in clip & length OutDataPath = 'F:\\Workspace\\Sandy\\GM_costAnalysis\\analysis2\\ClipRoads\\' OrdersLyr = 'F:\\Workspace\\Sandy\\GM_costAnalysis\\analysis2\\OrdersProjected\\'īufferLyr = 'F:\\Workspace\\Sandy\\GM_costAnalysis\\analysis2\\Buffers\\'ĮnvelopeLyr = 'F:\\Workspace\\Sandy\\GM_costAnalysis\\analysis2\\Envelopes\\' # Set workspace environment - this is where the solved route layers are locatedĪ = 'F:\\Workspace\\Sandy\\GM_costAnalysis\\analysis2\\OrdersProjected\\' export sum length, block name, centroid of Then I calculate length for the clipped roads by adding # which makes a square polygon around the point. The round buffer is converted to a feature envelope # Notes: iterates thru orders shapefiles and creates a buffer This seems to break my code and I am have troubles figuring out why or coming up with a reasonable solution. The code is working except for the arcpy.SelectLayerByAttribute_management line (line 173). The data from the polygon feature class, and the length of the roads for each polygon is output to a CSV file. I am writing code to iterate thru each feature in a polygon feature class and use the selected feature to clip a roads layer and calculate length.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |