In the code sample I provided, this can be done pretty easy changing the function "ExtendPolyline" inserting line 10 setting the Z values for start and end point of the line (at the polygon boundary) to 0 (assuming this is correct) and enabling Z values for the polygon on line 13 in the example below:
def ExtendPolyline(polyline, pnt1, pnt2):
sr = polyline.spatialReference
lst_pnts = []
for part in polyline:
for pnt in part:
lst_pnts.append(pnt)
pnt1.Z, pnt2.Z = 0, 0
lst_pnts.insert(0, pnt1)
lst_pnts.append(pnt2)
return arcpy.Polyline(arcpy.Array(lst_pnts), sr, True, False)
The result viewed in 3D looks like this:
I do notice that near the shore lines (polygon boundary) some values have a Z value greater than 0. Are you sure that the measure Z values of the points used to create the profile lines correspond to the polygon boundary (same date)?
In case you want to continue with the code provided by Joshua Bixby it will be a little more complex since you can't just do this by simply adding the Z=0 property to the point "p"(lines 4 and 10) in the snippet below and changing line 13 to make it Z-aware:
p1, p2 = arr[0], arr[1]
angle = math.atan2(p2.Y - p1.Y, p2.X - p1.X)
p = arcpy.Point(p1.X - dist * math.cos(angle),
p1.Y - dist * math.sin(angle), 0)
arr.insert(0, p)
pn1, pn = arr[len(arr)-2], arr[len(arr)-1]
angle = math.atan2(pn.Y - pn1.Y, pn.X - pn1.X)
p = arcpy.Point(pn.X + dist * math.cos(angle),
pn.Y + dist * math.sin(angle), 0)
arr.append(p)
line = arcpy.Polyline(arr, SR, True, False)
line = line.cut(boundary)[1]
ucur.updateRow([line])
The line start and end before cutting would have the Z set to 0, but will no have as result that the Z value at the shore will be 0. As an alternative, you cut the 3D line, and afterwards, read out the first and last point, set the Z value to 0 and insert them back in the array and create the final 3D polyline:
import math
dist = 500
fc_line = "Pointoline"
fc_poly = "RB_23"
with arcpy.da.SearchCursor(fc_poly, "SHAPE@") as scur:
for poly, in scur:
boundary = poly.boundary()
arcpy.SelectLayerByLocation_management(fc_line, "WITHIN", poly)
with arcpy.da.UpdateCursor(fc_line, "SHAPE@") as ucur:
for line, in ucur:
arr, = line.getPart()
SR = line.spatialReference
p1, p2 = arr[0], arr[1]
angle = math.atan2(p2.Y - p1.Y, p2.X - p1.X)
p = arcpy.Point(p1.X - dist * math.cos(angle),
p1.Y - dist * math.sin(angle))
arr.insert(0, p)
pn1, pn = arr[len(arr)-2], arr[len(arr)-1]
angle = math.atan2(pn.Y - pn1.Y, pn.X - pn1.X)
p = arcpy.Point(pn.X + dist * math.cos(angle),
pn.Y + dist * math.sin(angle))
arr.append(p)
line = arcpy.Polyline(arr, SR, True, False)
line = line.cut(boundary)[1]
arr, = line.getPart()
p1, pn = arr[0], arr[len(arr)-1]
p1.Z, pn.Z = 0, 0
arr.insert(0, p1)
arr.append(pn)
line = arcpy.Polyline(arr, SR, True, False)
ucur.updateRow([line])