Hello,
I am trying to load pairs of XYZ coordinates into an array and add these data to a polyline feature class via the CopyFeatures_management function. The output that I can generate includes the correct X and Y values for each polyline node, but the Z is not added. I have tried everything I can think of to diagnose the error including enabling Z in the workspace.env settings, manually verifying that the point.Z values are being read correctly via the python debugger, etc. As far as I can tell the point class is loaded correctly into the array, but only the X and Y values are passed along to the final shapefile feature class - despite being Z enabled!
Can someone please have a look at the attached code and recommend a solution to this problem? Why on earth is the CopyFeatures function not including the Z values from the array?
Best,
Erich
Here's the Code:
import arcpy, os, cmath, decimal, math, sys, traceback
#various parameters
Workspace = "F:\\Mossel Bay Stuff\\MasterGIS-SAGRID\\Embayment Dune\\temp\\" #sys.argv[1]
arcpy.env.workspace = Workspace #"C:\\Mossel Bay Stuff\\MasterGIS-SAGRID\\Embayment Dune\\temp\\"
arcpy.env.OverwriteOutput = "Enabled"
infile = "F:\\Mossel Bay Stuff\\MasterGIS-SAGRID\\Embayment Dune\\temp\\Overburden_for_python.shp" #sys.argv[2]
rows = arcpy.SearchCursor(infile)
featureList = []
point = arcpy.Point()
array = arcpy.Array()
x = 1
desc = arcpy.Describe(infile)
shapefieldname = desc.ShapeFieldName
spatialreference = "PROJCS['Hartebeesthoek94_Lo23',GEOGCS['GCS_Hartebeesthoek_1994',DATUM['D_Hartebeesthoek_1994',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',23.0],PARAMETER['Scale_Factor',-1.0],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]];-5623200 -10002100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision", "", "0", "0", "0"
Z= "hasZ"
zlist = []
for row in rows:
feat = row.getValue(shapefieldname)
pnt = feat.getPart()
if x == 1:
baseX = pnt.X
baseY = pnt.Y
baseZ = pnt.Z
x = 2
else:
point.X = baseX
point.Y = baseY
point.Z = baseZ
array.add(point)
arcpy.AddMessage("easting= "+str(point.X))
arcpy.AddMessage("northing= "+str(point.Y))
arcpy.AddMessage("elevation= "+str(point.Z))
point.X = pnt.X
point.Y = pnt.Y
point.Z = pnt.Z
array.add(point)
arcpy.AddMessage("easting= "+str(point.X))
arcpy.AddMessage("northing= "+str(point.Y))
arcpy.AddMessage("elevation= "+str(point.Z))
arcpy.env.outputZFlag = "Enabled"
#arcpy.env.outputMFlag = "Enabled"
polyline = arcpy.Polyline(array, spatialreference, Z)
featureList.append(polyline) #reset to append new points
array.removeAll() #clear array for next iteration
#arcpy.CreateFeatureclass_management(Workspace, "F:\\Mossel Bay Stuff\\MasterGIS-SAGRID\\Embayment Dune\\temp\\polylines7.shp", "POLYLINE", "", "DISABLED", "ENABLED", "")
arcpy.CopyFeatures_management(featureList, "F:\\Mossel Bay Stuff\\MasterGIS-SAGRID\\Embayment Dune\\temp\\polylines17.shp")