Greetings,
I am experiencing a bit wierd response as I would like to create a polygon object and enter its z-values using arcpy. It seems all goes fine interms of execution but when I try to query the newly created object, the z-values are set to zeros. I am using ArcGIS Desktop 10.2 on windows 7. Here is the code snippet.
# Import system modules import arcpy import time, datetime from time import strftime import sys, traceback, os from arcpy import env from arcpy import da def showMessage(msgText): arcpy.AddMessage(msgText); print msgText def showErrorMessage(msgText): arcpy.AddError(msgText); print msgText def readGeom(inputFC, fieldNames): ## infc = arcpy.GetParameterAsText(0) infc = inputFC # Enter for loop for each feature # # Print the current multipoint's ID for row in arcpy.da.SearchCursor(infc, fieldNames): # showMessage("Feature {0}:".format(row[0])) partnum = 0 # Step through each part of the feature # for part in row[1]: # Print the part number # showMessage("Part {0}:".format(partnum)) # Step through each vertex in the feature # for pnt in part: if pnt: # Print x,y coordinates of current point # showMessage("{0}, {1}, {2}".format(pnt.X, pnt.Y, pnt.Z)) else: # If pnt is None, this represents an interior ring # showMessage("Interior Ring:") partnum += 1 try: aoiCoords = "5581313.715,3090151.188,88;5581925.211,3085259.218,88;5574281.509,3085259.218,22;5570918.28,3091679.929,55;5575198.75,3093208.669,44" template = r"PathTo_abc_POL" arcpy.AddMessage("Starting Processing... " + strftime("%d%b%y")) spatial_reference = arcpy.Describe(template).spatialReference ## env.workspace = out_path ## arcpy.env.overwriteOutput = True; dummyPoint = arcpy.Point() firstPoint = arcpy.Point() pointsArray = arcpy.Array() coordsTokens = aoiCoords.split(';') loopIndex = 0; for coord in coordsTokens: coordValues = coord.split(',') dummyPoint.X = float(coordValues[0]); dummyPoint.Y = float(coordValues[1]); dummyPoint.Z = float(coordValues[2]); ## showMessage("X, Y, Z: " +coordValues[0] + ", " +coordValues[1] + ", " + coordValues[2]) if(loopIndex ==0): firstPoint = dummyPoint loopIndex = loopIndex + 1 pointsArray.add(dummyPoint) #close the polygon pointsArray.add(firstPoint); has_z = "ENABLED" has_m = "DISABLED" aoiPolygon = arcpy.Polygon(pointsArray, spatial_reference, has_z, has_m) out_path = arcpy.env.scratchGDB test1 = "test1" geometry_type = "POLYGON" env.workspace = out_path arcpy.env.overwriteOutput = True; outFCName = arcpy.CreateFeatureclass_management(out_path, test1, geometry_type, template, has_m, has_z, spatial_reference) aoiWMName = outFCName.getOutput(0) cursor = arcpy.da.InsertCursor(test1, ["SHAPE@"]) cursor.insertRow([aoiPolygon]) del cursor desc = arcpy.Describe(test1) arcpy.AddMessage("0: HasZ: " + str(desc.hasZ) + ", HasM: " + str(desc.hasM)) readGeom(test1, ["OID@", "SHAPE@"]) arcpy.AddMessage("Processing completed") except Exception as e: tb = sys.exc_info()[2] tbinfo=traceback.format_tb(tb)[0] strMessages = "Exception Type is: " + str(sys.exc_type) strMessages = strMessages +"\nException Value is: " + str(sys.exc_value) strMessages = strMessages + "\nFailure Info: " + tbinfo arcpy.AddError(strMessages) arcpy.AddError(e.message)
Can someone kindly share any thought or reference on how to fix it? Thanks in advance. Here are the resuts.
Feature 1:
Part 0:
5581313.715, 3090151.188, 0.0
5581925.211, 3085259.218, 0.0
5574281.509, 3085259.218, 0.0
5570918.28, 3091679.929, 0.0
5575198.75, 3093208.669, 0.0
5581313.715, 3090151.188, 0.0