I have tried a different approach and got it to work. Actually what I am trying to accomplish is to convert line file to 3D based on points. As it is not possible to snap 3D in ArcMap the lines constructed from surveying points in ArcMap are placed on zero elevation. After the lines are constructed, I am using the point file to change the elevation on the vertexes to the original one. The working script can be seen here:
import arcpy
shapeFileFolder = "folder where the files are located"
fileToProcess = "line or polygon file"
fileWith3DPoints = "file with 3D points which were used to construct the lines"
arcpy.env.workspace = shapeFileFolder
arcpy.env.overwriteOutput = True
def convertTo3D(fc, zPoints):
# Dictionary to hold the point coordinates (key: x,y coord, value: z coord)
zCoordDict = {}
# Create an array which will hold geometries of point feature class
fields = ["SHAPE@X","SHAPE@Y","SHAPE@Z"]
with arcpy.da.SearchCursor(zPoints, fields) as cursor:
for row in cursor:
# round the coordinates to 3 decimal places
xCoord = round(row[0], 3)
yCoord = round(row[1], 3)
zCoord = round(row[2], 3)
# add key:value for current point to the dictionary
zCoordDict[str(xCoord) + "," + str(yCoord)] = zCoord
# Update Z coord in input file
fields = ["SHAPE@X","SHAPE@Y","SHAPE@Z"]
cursor = arcpy.da.UpdateCursor(fc, fields, None, None, True)
for row in cursor:
# Get x,y coordinates of current point
xCoord = str(round(row[0],3))
yCoord = str(round(row[1],3))
newZCoord = zCoordDict[xCoord +"," + yCoord]
print "New Z coordinate for current point is %s" % (newZCoord)
row[2] = newZCoord
cursor.updateRow(row)
# Run the function
convertTo3D(fileToProcess, fileWith3DPoints)