Select to view content in your preferred language

# Convert 3D Polylines from meters to feet

1503
10
04-06-2023 02:11 PM
Labels (2)
Regular Contributor

I have numerous 3D polylines showing various altitude heights from start to end of each polyline. The program they're exported from assumes the altitude values are in meters, so they're multiplied by 3.28084. Is there a way to convert the altitude (z) of the polylines back to feet (IE divide by 3.28084)?

1 Solution

Accepted Solutions
Frequent Contributor

I think you need to do this with python. I asked ChatGPT:

import arcpy

# Set the input feature class
input_fc = r"path\to\your\feature\class"

# Create an arcpy.da.UpdateCursor to iterate through each row in the feature class
with arcpy.da.UpdateCursor(input_fc, ["SHAPE@"]) as cursor:
for row in cursor:

# Get the geometry of the current row
line = row[0]

# Create an empty array to hold the updated vertex coordinates
new_vertices = arcpy.Array()

# Iterate through each part of the line
for part in line:

# Create an empty array to hold the updated part vertices
new_part = arcpy.Array()

# Iterate through each vertex in the part
for vertex in part:

# Get the z-value of the current vertex in meters
z_meters = vertex.Z

# Convert the z-value to feet
z_feet = z_meters * 3.28084

# Create a new Point object with the updated z-value in feet
new_vertex = arcpy.Point(vertex.X, vertex.Y, z_feet)

# Append the new vertex to the updated part
new_part.append(new_vertex)

# Append the updated part to the array of updated vertices
new_vertices.append(new_part)

# Create a new Polyline object with the updated vertex array
# For the record, ChatGPT forgot to add the has_z argument below. It's not perfect!
new_line = arcpy.Polyline(new_vertices, has_z=True)

# Update the geometry of the current row with the new geometry
row[0] = new_line

# Update the cursor to save the changes to the current row
cursor.updateRow(row)

I did a quick test and it worked for me. I ran it from a Notebook in my Pro project

10 Replies
Frequent Contributor

I think you need to do this with python. I asked ChatGPT:

import arcpy

# Set the input feature class
input_fc = r"path\to\your\feature\class"

# Create an arcpy.da.UpdateCursor to iterate through each row in the feature class
with arcpy.da.UpdateCursor(input_fc, ["SHAPE@"]) as cursor:
for row in cursor:

# Get the geometry of the current row
line = row[0]

# Create an empty array to hold the updated vertex coordinates
new_vertices = arcpy.Array()

# Iterate through each part of the line
for part in line:

# Create an empty array to hold the updated part vertices
new_part = arcpy.Array()

# Iterate through each vertex in the part
for vertex in part:

# Get the z-value of the current vertex in meters
z_meters = vertex.Z

# Convert the z-value to feet
z_feet = z_meters * 3.28084

# Create a new Point object with the updated z-value in feet
new_vertex = arcpy.Point(vertex.X, vertex.Y, z_feet)

# Append the new vertex to the updated part
new_part.append(new_vertex)

# Append the updated part to the array of updated vertices
new_vertices.append(new_part)

# Create a new Polyline object with the updated vertex array
# For the record, ChatGPT forgot to add the has_z argument below. It's not perfect!
new_line = arcpy.Polyline(new_vertices, has_z=True)

# Update the geometry of the current row with the new geometry
row[0] = new_line

# Update the cursor to save the changes to the current row
cursor.updateRow(row)

I did a quick test and it worked for me. I ran it from a Notebook in my Pro project

Regular Contributor

Thank you! This worked perfectly!

Frequent Contributor

Hi Kate,

Have you looked at the Data Management -> Features -> Adjust 3D Z tool? It has an option to convert the Z units as well as perform a bulk adjustment on the Z value.

Regards,

Tom

Frequent Contributor

Ah, this is a better solution than mine. My search-fu failed me when I was looking for such a tool.

Frequent Contributor

😊I had only found it over the weekend and saw your response when I was working on some terrain following activities for my drone. Not quite sure how I even found it.

Regular Contributor

I did try this originally, but unfortunately it wasn't adjusting the lines correctly.

Frequent Contributor

Interesting. Can I ask what was off? This tool is central to my process for creating terrain following drone flights now I am a bit concerned.

Regular Contributor

I would calculate Max Z of the polyline before and after using Adjust 3D Z, and the Z remained the same.

For Terrain, I'd be inclined to convert to raster and use raster calculator.

Frequent Contributor

Thank you on both counts. I will have to try.