Add Attribute Data to Polyline from Point

المشرف العام

Administrator
طاقم الإدارة
I have code that is taking a point dataset and converting into lines based on an ID similar to point to Line. It is also creating 32 new fields in the polyline that I want to populate from the the point data.

Here is how my point data is structured

I want the first point in the line, sorted by PTID, to populate my InvertS1 attributes as seen below,

Then my second point in the line would populate the next set of attributes and so on until the line is completed.

I'm having trouble with where populating these fields goes in the code as well as how to structure it.

Here is my code as it is currently, with no population of the fields and it is working as expected.

import arcpy, os, typesdef convertPoints(): arcpy.env.overwriteOutput = TrueinPts = arcpy.GetParameterAsText(0) #Input point feature classoutFeatures = arcpy.GetParameterAsText(1) #Output polyline feature classculvertID = arcpy.GetParameterAsText(2) #Culvert ID fieldsortField = arcpy.GetParameterAsText(3) #Optional sort field for direction of line#Date_Added = arcpy.GetParameterAsText(4) #The date when survey points were received closeLine = False #Leaves Line Openif culvertID in ["", "#"]: culvertID = Noneif sortField in ["", "#"]: cursorSort = culvertIDelse: if culvertID: cursorSort = culvertID + ";" + sortField else: cursorSort = sortFieldconvertPointsToLine(inPts, outFeatures, culvertID, cursorSort, closeLine)# Add the following fields to the output polyline feature classarcpy.AddField_management(outFeatures, "DateRecieved", "DATE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "Comment", "TEXT", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "InvertS1_ID", "TEXT", "", "", "75", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "InvertS1_PointID", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "InvertS1_Northing", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "InvertS1_Easting", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "InvertS1_Elevation", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "OvertS1_ID", "TEXT", "", "", "75", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "OvertS1_PointID", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "OvertS1_Northing", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "OvertS1_Easting", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "OvertS1_Elevation", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "PavementS1_ID", "TEXT", "", "", "75", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "PavementS1_PointID", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "PavementS1_Northing", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "PavementS1_Easting", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "PavementS1_Elevation", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "InvertS2_ID", "TEXT", "", "", "75", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "InvertS2_PointID", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "InvertS2_Northing", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "InvertS2_Easting", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "InvertS2_Elevation", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "OvertS2_ID", "TEXT", "", "", "75", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "OvertS2_PointID", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "OvertS2_Northing", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "OvertS2_Easting", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "OvertS2_Elevation", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "PavementS2_ID", "TEXT", "", "", "75", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "PavementS2_PointID", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "PavementS2_Northing", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "PavementS2_Easting", "DOUBLE", "", "", "", "", "NULLABLE", "", "")arcpy.AddField_management(outFeatures, "PavementS2_Elevation", "DOUBLE", "", "", "", "", "NULLABLE", "", "")def getZM(propType, hasMZ): envValue = getattr(arcpy.env, propType).upper()if envValue in ['ENABLED', 'DISABLED']: return envValueelse: if hasMZ: return "ENABLED" else: return "DISABLED"def convertPointsToLine(inPts, outFeatures, culvertID, cursorSort, closeLine):try: # Assign empty values to cursor and row objects iCur, sRow, feat = None, None, None desc = arcpy.Describe(inPts) shapeName = desc.shapeFieldName # Create the output feature class # outPath, outFC = os.path.split(outFeatures) arcpy.CreateFeatureclass_management(outPath, outFC, "POLYLINE", "", getZM("outputMFlag", desc.hasM), getZM("outputZFlag", desc.hasZ), inPts) # If there is an culvertID, add the equivalent to the output # if ID: f = arcpy.ListFields(inPts, culvertID)[0] fName = arcpy.ValidateFieldName(f.name, outPath) arcpy.AddField_management(outFeatures, fName, f.type, f.precision, f.scale, f.length, f.aliasName, f.isNullable, f.required, f.domain) # Open an insert cursor for the new feature class # iCur = arcpy.InsertCursor(outFeatures) # Create an array needed to create features # array = arcpy.Array() # Initialize a variable for keeping track of a feature's ID. # ID = -1 fields = shapeName if cursorSort: fields += ";" + cursorSort for sRow in arcpy.gp.SearchCursor(inPts, "", None, fields, cursorSort, arcpy.env.extent): pt = sRow.getValue(shapeName).getPart(0) if culvertID: currentValue = sRow.getValue(culvertID) else: currentValue = None if ID == -1: ID = currentValue if ID currentValue: if array.count >= 2: # To close, add first point to the end # if closeLine: array.add(array.getObject(0)) feat = iCur.newRow() if culvertID: if ID: #in case the value is None/Null feat.setValue(culvertID, ID) feat.setValue(shapeName, array) iCur.insertRow(feat) else: arcpy.AddIDMessage("WARNING", 1059, unicode(ID)) array.removeAll() array.add(pt) ID = currentValue # Add the last feature # if array.count > 1: # To close, add first point to the end # if closeLine: array.add(array.getObject(0)) feat = iCur.newRow() if culvertID: if ID: #in case the value is None/Null feat.setValue(culvertID, currentValue) feat.setValue(shapeName, array) iCur.insertRow(feat) else: arcpy.AddIDMessage("WARNING", 1059, unicode(ID)) array.removeAll()except Exception as err: import traceback arcpy.AddError( traceback.format_exception_only(type(err), err)[0].rstrip())finally: if iCur: del iCur if sRow: del sRow if feat: del feat try: # Update the spatial index(es) # r = arcpy.CalculateDefaultGridIndex_management(outFeatures) arcpy.AddSpatialIndex_management(outFeatures, r.getOutput(0), r.getOutput(1), r.getOutput(2)) except: passif __name__ == '__main__': convertPoints()

أكثر...
 
أعلى