I get your point, the Interpolate Shape—Help | ArcGIS Desktop tool creates a 3D polyline and inserts vertices using the sample distance which normally corresponds to the cellsize of the DEM. This will create the line that follows the surface and does not respect the rule that only at vertices of the line should be taken into consideration.
The way to resolve this, is using some Python code. The code below will iterate all the vertices of the line and create a 3D polyline featureclass (maintaining all the attributes) and convert the vertices to 3D using the elevation from the DEM/DSM:
import arcpy
def main():
import os
arcpy.env.overwriteOutput = True
fc_in = r'C:\GeoNet\Polyline3D\data.gdb\my2Dpipeline'
fc_out = r'C:\GeoNet\Polyline3D\data.gdb\my3Dresult'
dem = r'C:\GeoNet\Polyline3D\data.gdb\DEM'
z_offset = 2
sr = arcpy.Describe(fc_in).spatialReference
ws, fc_name = os.path.split(fc_out)
arcpy.CreateFeatureclass_management(ws, fc_name, "POLYLINE", fc_in, "DISABLED", "ENABLED", sr)
flds = getFields(fc_in)
with arcpy.da.InsertCursor(fc_out, flds) as curs_out:
with arcpy.da.SearchCursor(fc_in, flds) as curs:
for row in curs:
pnts_3d = []
polyline_in = row[0]
for part in polyline_in:
for pnt in part:
z = getValueFromDEM(dem, pnt)
pnt_3d = arcpy.Point(pnt.X, pnt.Y, z + z_offset)
pnts_3d.append(pnt_3d)
polyline_out = arcpy.Polyline(arcpy.Array(pnts_3d), sr, True, False)
row_out = list(row)
row_out[0] = polyline_out
row_out = tuple(row_out)
curs_out.insertRow(row_out)
def getValueFromDEM(dem, pnt):
pnt_txt = "{0} {1}".format(pnt.X, pnt.Y)
result = arcpy.GetCellValue_management(dem, pnt_txt)
elevation = float(result.getOutput(0).replace(',', '.'))
return elevation
def getFields(fc):
flds = [fld.name for fld in arcpy.ListFields(fc)]
fld_shp = arcpy.Describe(fc).ShapeFieldname
flds.remove(fld_shp)
flds.insert(0, 'SHAPE@')
return flds
if __name__ == '__main__':
main()
Below a 3D view of the result:
- the red line is the result of the interpolate shape tool
- the blue line is the result of the script
- the black points are the vertices of the input line.