origData = r'C:\Documents and Settings\whitley-wayne\Desktop\pointsToPolySerysian2\orig\Reach1B.shp' import arcpy arcpy.env.workspace = r'C:\Documents and Settings\whitley-wayne\Desktop\stage.gdb' arcpy.env.outputCoordinateSystem = origData arcpy.env.overwriteOutput = True # Copy Features # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000035000000 arcpy.CopyFeatures_management(origData, 'Reach1B_lines') # Create Routes # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//003m00000005000000.htm #CreateRoutes_lr (in_line_features, route_id_field, out_feature_class, measure_source, {from_measure_field}, {to_measure_field}, {coordinate_priority}, {measure_factor}, {measure_offset}, {ignore_gaps}, {build_index}) arcpy.CreateRoutes_lr('Reach1B_lines', 'ProfileM', 'Reach1B_routes', 'TWO_FIELDS', 'OID_', 'Shape_Leng') fields = ['LeftBank_ft', 'RightBank_ft'] # Add Field # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000047000000 # AddField_management (in_table, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain}) for field in fields: arcpy.AddField_management('Reach1B_lines', field, 'DOUBLE') # Calculate Field # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000 # CalculateField_management (in_table, field, expression, {expression_type}, {code_block}) for field in fields: exp = '!' + field.split('_')[0] + '!*!Shape_Leng!' arcpy.CalculateField_management('Reach1B_lines', field, exp, 'PYTHON') # Copy Rows # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//0017000000n4000000 # CopyRows_management (in_rows, out_table, {config_keyword}) arcpy.CopyRows_management('Reach1B_lines', 'in_table') # Make Route Event Layer # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Make_Route_Event_Layer/003m00000008000000/ # MakeRouteEventLayer_lr (in_routes, route_id_field, in_table, in_event_properties, out_layer, {offset_field}, {add_error_field}, {add_angle_field}, {angle_type}, {complement_angle}, {offset_direction}, {point_event_type}) in_event_properties = 'ProfileM POINT LeftBank_ft' arcpy.MakeRouteEventLayer_lr('Reach1B_routes', 'ProfileM', 'in_table', in_event_properties, 'LeftBankPts') arcpy.CopyFeatures_management('LeftBankPts', 'LeftBankPoints') in_event_properties = 'ProfileM POINT RightBank_ft' arcpy.MakeRouteEventLayer_lr('Reach1B_routes', 'ProfileM', 'in_table', in_event_properties, 'RightBankPts') arcpy.CopyFeatures_management('RightBankPts', 'RightBankPoints') # ...the channel poly building component: # Array # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Array/000v0000005r000000/ polyArray = arcpy.Array() inputPts = 'LeftBankPoints' # SearchCursor (dataset, {where_clause}, {spatial_reference}, {fields}, {sort_fields}) # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000039000000 rows = arcpy.SearchCursor(inputPts, '', '', '', 'ProfileM A') for row in rows: pnt = row.Shape.getPart() polyArray.add(pnt) inputPts = 'RightBankPoints' rows = arcpy.SearchCursor(inputPts, '', '', '', 'ProfileM D') for row in rows: pnt = row.Shape.getPart() polyArray.add(pnt) # Polygon # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v000000n1000000 polygon = arcpy.Polygon(polyArray) arcpy.CopyFeatures_management(polygon, 'channel') # ...the first/last point extraction from lines, outer poly building component: polyArray.removeAll() inputLns = 'Reach1B_lines' # Polyline # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Polyline/000v000000n2000000/ rows = arcpy.SearchCursor(inputLns, '', '', '', 'ProfileM A') for row in rows: pnt = row.Shape.firstPoint polyArray.add(pnt) rows = arcpy.SearchCursor(inputLns, '', '', '', 'ProfileM D') for row in rows: pnt = row.Shape.lastPoint polyArray.add(pnt) polygon = arcpy.Polygon(polyArray) arcpy.CopyFeatures_management(polygon, 'outer_poly') # ...the check for change in n-vals: rows = arcpy.SearchCursor(inputLns, '', '', '', 'ProfileM A') row = rows.next() Nleft = row.Leftbank_N Nchan = row.channel_N2 Nrght = row.rightbank_ row = rows.next() # list to break polys breakList = [] while row: if row.Leftbank_N != Nleft or row.channel_N2 != Nchan or row.rightbank_ != Nrght: breakList.append(row.ProfileM) Nleft = row.Leftbank_N Nchan = row.channel_N2 Nrght = row.rightbank_ row = rows.next() del row, rows # form feature layer where_clause where_clause = '(' for each in breakList: where_clause = where_clause + str(each) + ', ' # AddFieldDelimiters # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000004n000000 # AddFieldDelimiters (datasource, field) where_clause = arcpy.AddFieldDelimiters(inputLns, 'ProfileM') + ' IN ' + where_clause[0:-2] + ')' # MakeFeatureLayer_management (in_features, out_layer, {where_clause}, {workspace}, {field_info}) arcpy.MakeFeatureLayer_management(inputLns, 'changeN', where_clause) arcpy.CopyFeatures_management('changeN','breakLines') # FeatureToPolygon_management (in_features, out_feature_class, {cluster_tolerance}, {attributes}, {label_features}) inFeatures = ['breakLines','channel','outer_poly'] arcpy.FeatureToPolygon_management(inFeatures,'break_polys')
>>> import arcpy >>> arcpy.env.workspace = r'C:\Documents and Settings\whitley-wayne\Desktop\pointsToPolySerysian\Reach1_Banks' >>> polyArray = arcpy.Array() >>> where_clause = '"FID" > 1131 AND "FID" < 1148' >>> inputPts = "Reach1_Banks.shp" >>> pointsLeft = [] >>> pointsRight = [] >>> points = [] >>> rows = arcpy.SearchCursor(inputPts, where_clause) >>> for row in rows: pnt = row.Shape.getPart() points.append(pnt) >>> for i in range(0,len(points)-1,2): pointsLeft.append(points) pointsRight.append(points[i+1]) >>> len(pointsRight) 8 >>> pointsRight2 = [] >>> for i in range(len(pointsRight)-1,-1,-1): pointsRight2.append(pointsRight) >>> len(pointsRight2) 8 >>> for eachPoint in pointsRight2: pointsLeft.append(eachPoint) >>> len(pointsLeft) 16 >>> cur = arcpy.InsertCursor("testPolys.shp") >>> feat = cur.newRow() >>> for eachPoint in pointsLeft: polyArray.add(eachPoint) >>> feat.Shape = polyArray >>> cur.insertRow(feat) >>> del cur >>>
# these are point objects (no longer text) points = [point1, point2, point3, point4, point5, point6] array = arcpy.Array() for point in points: array.add(point) # close the poly array.add(points[0]) # load the array into geometry object polygon = arcpy.Polygon(array) # Here, you'll probably want an insertcursor to loop and load geometry for multiple features... # But for demo on a single feature, you can use copy features: arcpy.CopyFeatures_management(polygon, r'C:\JustTesting.shp')
# For example say instead of the string list shown, the following is a python list of point objects: >>> points = ['point1', 'point2', 'point3', 'point4', 'point5', 'point6'] # Define 2 new lists to load for left and right sides: >>> pointsLeft = [] >>> pointsRight = [] Now you need a looping mechanism to load the empty lists: >>> for i in range(0,len(points)-1,2): pointsLeft.append(points) pointsRight.append(points[i+1]) # Now the lists are 'segregated' odd and even: >>> print pointsLeft ['point1', 'point3', 'point5'] >>> print pointsRight ['point2', 'point4', 'point6'] # Reverse the order, say on the right, to set up 'connecting' the 2 lines: >>> pointsRight.sort(reverse=True) >>> print pointsRight ['point6', 'point4', 'point2'] # Now the list can be 'mashed' together: >>> for eachPoint in pointsRight: pointsLeft.append(eachPoint) # Still called 'pointsLeft', but it's really a sequence around both sides... >>> print pointsLeft ['point1', 'point3', 'point5', 'point6', 'point4', 'point2'] >>>
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.