0

I'm trying to get my z values from my 3d point layer over to my vertex' on a 3d polyline layer, so I can have lines with slopes in 3d.

I've first done a spatial location by intersect to filter out lines that aren't touching points. I've converted the points to 3d by attribute using their Z-values. I've done the same with the line but with a 0 as a value.

Now I would like for each end of the line to have that points Z-value, so I can get a sloped line in 3d. I've tried seeing if a tool like Add Geometry Attributes and feature to 3d by attributes works, but can't really figure out the proper proces.

I have access to ArcGIS Desktop Advanced 10.5.1, Spatial Analyst and 3D Analyst.

enter image description here

Edit:

After BERA's answer I've tried his code, modified to my workspace:

import arcpy

arcpy.env.workspace = r'D:\ArcGIS Geodatabase\Default.gdb' #Change
polylinefc = 'Vandledning_med_kotepunkt_Sp3' #Change to input line name, have to be in workspace
pointfc = 'Vandledning_med_kotepunkt_Sp1' #Change to input Point name, have to be in workspace

pointzdict = {k:v for k,v in arcpy.da.SearchCursor(pointfc,['SHAPE@XY','SHAPE@Z'])} #Create dictionary of points with XY as key and Z as values

with arcpy.da.UpdateCursor(polylinefc,'SHAPE@') as cursor: #Update Z of polyline vertices where a match is found in point dictionary
    for row in cursor:
        linelist = []
        for part in row[0]:
            partlist=[]
            for pnt in part:
                if (pnt.X,pnt.Y) in pointzdict:
                    partlist.append(arcpy.Point(pnt.X,pnt.Y,pointzdict[(pnt.X,pnt.Y)]))
                else:
                    partlist.append(pnt)
            linelist.append(partlist)
        row[0] = arcpy.Polyline(arcpy.Array(linelist), arcpy.Describe(polylinefc).spatialReference, True)
        cursor.updateRow(row)

However I get the following error:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 14, in <module>
TypeError: 'geoprocessing point object' object is not iterable
  • Thanks for the quick reply @BERA. The Lines I have were split by the point layer, so they should be snapple. I've changed the code to correspond with my enviroment settings, but get the following error: Runtime error Traceback (most recent call last): File "<string>", line 14, in <module> TypeError: 'geoprocessing point object' object is not iterable – FoolzRailer Feb 14 at 8:33
  • Wrong way to access polylines parts. It should be shp.getPart(), i.e compute partCount firtst. – FelixIP Feb 15 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.