import arcpy # Set the outputZFlag environment to Enabled arcpy.env.outputZFlag = "Enabled" # Input feature class inFC = arcpy.GetParameterAsText(0) outFC = arcpy.GetParameterAsText(1) # Create describe desc = arcpy.Describe(inFC) shapefieldname = desc.ShapeFieldName inFCDataType = desc.DataType # Create point list ptList = [] # Create cursor and iterate through objects in feature class rows = arcpy.SearchCursor(inFC) for row in rows: # Create the geometry object "feat" feat = row.getValue(shapefieldname) partnum = 0 # Step through each part of the feature and append vertice coordinates to point list for part in feat: part_list = [] for pnt in feat.getPart(partnum): ptList.append([pnt.X, pnt.Y, pnt.Z]) partnum += 1 # Create point object, point geometry list and iterate through list # and append every coordinate pair to geometry list. pt = arcpy.Point() ptGeoms = [] for p in ptList: pt.X = p[0] pt.Y = p[1] pt.Z = p[2] ptGeoms.append(arcpy.PointGeometry(pt)) # Create point feature class arcpy.management.CopyFeatures(ptGeoms, outFC) # Add XY to point feature class arcpy.management.AddXY(outFC)
Solved! Go to Solution.
# Import arcpy import arcpy # Set the outputZFlag environment to Enabled arcpy.env.outputZFlag = "Enabled" # Input feature class inFC = arcpy.GetParameterAsText(0) outFolder = arcpy.GetParameterAsText(1) outFC = arcpy.GetParameterAsText(2) # Set workspace arcpy.env.workspace = outFolder # Create describe desc = arcpy.Describe(inFC) shapefieldname = desc.ShapeFieldName inFCCoordinateSystem = desc.SpatialReference inFCDataType = desc.DataType # Create point list ptList = [] # Create cursor and iterate through objects in feature class rows = arcpy.SearchCursor(inFC) for row in rows: # Create the geometry object feat = row.getValue(shapefieldname) partnum = 0 # Step through each part of the feature and append vertice coordinates to point list for part in feat: part_list = [] for pnt in feat.getPart(partnum): ptList.append([pnt.X, pnt.Y, pnt.Z]) partnum += 1 # Create table and add fields x, y, z arcpy.management.CreateTable(outFolder, "XY_Table") arcpy.management.AddField("XY_Table", "X", "DOUBLE") arcpy.management.AddField("XY_Table", "Y", "DOUBLE") arcpy.management.AddField("XY_Table", "Z", "DOUBLE") # Create cursor object cur = arcpy.InsertCursor("XY_Table") # Iterate through ptList and insert a new row in table for every coordinate pair in ptList for pt in ptList: row = cur.newRow() row.X = pt[0] row.Y = pt[1] row.Z = pt[2] cur.insertRow(row) # Create XY event layer arcpy.management.MakeXYEventLayer("XY_Table", "X", "Y", "XY_Table_Event") inTableEvent = "XY_Table_Event" # Create point feature class arcpy.management.CopyFeatures(inTableEvent, outFC) # Delete event layer and table arcpy.management.Delete(inTableEvent) arcpy.management.Delete("XY_Table") # Create describe on out data desc2 = arcpy.Describe(outFC) outFCSpatialRef = desc2.SpatialReference outFCSpatialRefName = outFCSpatialRef.name # Check if out data has spatial reference, # if not, project in data spatial reference on out data if outFCSpatialRefName == "Unknown": arcpy.management.DefineProjection(outFC, inFCCoordinateSystem) else: pass
... pt.Z = p[2] ptGeom = arcpy.PointGeometry(pt) ptGeom.hasZ = True ptGeoms.append(ptGeom)
# Import arcpy import arcpy # Set the outputZFlag environment to Enabled arcpy.env.outputZFlag = "Enabled" # Input feature class inFC = arcpy.GetParameterAsText(0) outFolder = arcpy.GetParameterAsText(1) outFC = arcpy.GetParameterAsText(2) # Set workspace arcpy.env.workspace = outFolder # Create describe desc = arcpy.Describe(inFC) shapefieldname = desc.ShapeFieldName inFCCoordinateSystem = desc.SpatialReference inFCDataType = desc.DataType # Create point list ptList = [] # Create cursor and iterate through objects in feature class rows = arcpy.SearchCursor(inFC) for row in rows: # Create the geometry object feat = row.getValue(shapefieldname) partnum = 0 # Step through each part of the feature and append vertice coordinates to point list for part in feat: part_list = [] for pnt in feat.getPart(partnum): ptList.append([pnt.X, pnt.Y, pnt.Z]) partnum += 1 # Create table and add fields x, y, z arcpy.management.CreateTable(outFolder, "XY_Table") arcpy.management.AddField("XY_Table", "X", "DOUBLE") arcpy.management.AddField("XY_Table", "Y", "DOUBLE") arcpy.management.AddField("XY_Table", "Z", "DOUBLE") # Create cursor object cur = arcpy.InsertCursor("XY_Table") # Iterate through ptList and insert a new row in table for every coordinate pair in ptList for pt in ptList: row = cur.newRow() row.X = pt[0] row.Y = pt[1] row.Z = pt[2] cur.insertRow(row) # Create XY event layer arcpy.management.MakeXYEventLayer("XY_Table", "X", "Y", "XY_Table_Event") inTableEvent = "XY_Table_Event" # Create point feature class arcpy.management.CopyFeatures(inTableEvent, outFC) # Delete event layer and table arcpy.management.Delete(inTableEvent) arcpy.management.Delete("XY_Table") # Create describe on out data desc2 = arcpy.Describe(outFC) outFCSpatialRef = desc2.SpatialReference outFCSpatialRefName = outFCSpatialRef.name # Check if out data has spatial reference, # if not, project in data spatial reference on out data if outFCSpatialRefName == "Unknown": arcpy.management.DefineProjection(outFC, inFCCoordinateSystem) else: pass