Skip to main content
added 301 characters in body
Source Link
tigerwoulds
  • 617
  • 6
  • 17

Update: Now I am trying to create points every 1000 feet between my existing points if no points currently exist. How can I do this? I'm thinking the Generate Points Along Line tool might work. https://pro.arcgis.com/en/pro-app/tool-reference/data-management/generate-points-along-lines.htm

Update: Now I am trying to create points every 1000 feet between my existing points if no points currently exist. How can I do this? I'm thinking the Generate Points Along Line tool might work. https://pro.arcgis.com/en/pro-app/tool-reference/data-management/generate-points-along-lines.htm

added 496 characters in body
Source Link
tigerwoulds
  • 617
  • 6
  • 17

Update: Was able to figure it out. If I create point feature class that is Z aware the point vertices will have the elevations. Then I can use the AddZInformation tool to transfer those values to the Point's attribute table.

import arcpy
import os
from arcpy import env

arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("Spatial")
env.workspace = r"C:\BFE_Tool\GIS\Tools\BFE_Tool\BFE_Tool.gdb"

streams = 'FY16_Streams_Diss'  # Streams must be dissolved by stream name
outGDB = r'C:\BFE_Tool\GIS\Tools\BFE_Tool\BFE_Tool.gdb'

print ('Interpolating shape...')
stream3D = arcpy.InterpolateShape_3d(r'C:\Test_Data\wsg100x'\GIS\Tools\BFE_Tool\Test_Data\wsg100x', streams, 'FY16_Streams3D')
print ('Interpolate shape done!')

print ('Creating BFE Points...')
try:

    myLayer = stream3D
    prev = -1
    heightDiff = 1
    pntList = list()
    with arcpy.da.SearchCursor(myLayer, ["SHAPE@"]) as cursor:
        for row in cursor:
            geom = row[0][0]  # A whole polyline
            for i, point in enumerate(geom):
                if prev == -1:
                    prev = point.Z
                else:
                    if abs(point.Z - prev) > heightDiff:
                        pntList.append(geom[i - 1])
                        pntList.append(geom[i])
                    prev = point.Z

    if len(pntList) > 0:
        print('Creating Empty point feature class...')
        outFC = arcpy.CreateFeatureclass_management(outGDB, 'BFE_Points', 'POINT'),'', '','ENABLED') # Create Empty Feature Class to store Points 


        # print ('Adding Elevation field to Points...')  # Add field in Points to store Water Surface Grid Elevations
        # arcpy.AddField_management(outFC, 'WS_Elev', 'FLOAT')

        with arcpy.da.InsertCursor(outFC, ["SHAPE@"]) as cursor:
            for point in pntList:
                print(point.Z)
                cursor.insertRow([point])
                print ('Points'Point Created')

    print ('Adding Elevation to Attribute table...') # Add field in Points to store Water Surface Grid Elevations
    arcpy.AddZInformation_3d(outFC, 'Z')

except arcpy.ExecuteError:
    # Geoprocessor threw an error
    print(arcpy.GetMessages(2))

print ('Finished!')
import arcpy
import os
from arcpy import env

arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("Spatial")
env.workspace = r"C:\BFE_Tool.gdb"

streams = 'FY16_Streams_Diss'  # Streams must be dissolved by stream name
outGDB = r'C:\BFE_Tool.gdb'

print('Interpolating shape...')
stream3D = arcpy.InterpolateShape_3d(r'C:\Test_Data\wsg100x', streams, 'FY16_Streams3D')
print('Interpolate shape done!')

print('Creating BFE Points...')
try:

    myLayer = stream3D
    prev = -1
    heightDiff = 1
    pntList = list()
    with arcpy.da.SearchCursor(myLayer, ["SHAPE@"]) as cursor:
        for row in cursor:
            geom = row[0][0]  # A whole polyline
            for i, point in enumerate(geom):
                if prev == -1:
                    prev = point.Z
                else:
                    if abs(point.Z - prev) > heightDiff:
                        pntList.append(geom[i - 1])
                        pntList.append(geom[i])
                    prev = point.Z

    if len(pntList) > 0:
        print('Creating Empty point feature class...')
        outFC = arcpy.CreateFeatureclass_management(outGDB, 'BFE_Points','POINT')  # Create Empty Feature Class to store Points

        print('Adding Elevation field to Points...')  # Add field in Points to store Water Surface Grid Elevations
        arcpy.AddField_management(outFC, 'WS_Elev', 'FLOAT')

        with arcpy.da.InsertCursor(outFC, ["SHAPE@"]) as cursor:
            for point in pntList:
                cursor.insertRow([point])
                print('Points Created')

except arcpy.ExecuteError:
    # Geoprocessor threw an error
    print(arcpy.GetMessages(2))

print('Finished!')

Update: Was able to figure it out. If I create point feature class that is Z aware the point vertices will have the elevations. Then I can use the AddZInformation tool to transfer those values to the Point's attribute table.

import arcpy
import os
from arcpy import env

arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("Spatial")
env.workspace = r"C:\GIS\Tools\BFE_Tool\BFE_Tool.gdb"

streams = 'FY16_Streams_Diss' # Streams must be dissolved by stream name
outGDB = r'C:\GIS\Tools\BFE_Tool\BFE_Tool.gdb'

print ('Interpolating shape...')
stream3D = arcpy.InterpolateShape_3d(r'C:\GIS\Tools\BFE_Tool\Test_Data\wsg100x', streams, 'FY16_Streams3D')
print ('Interpolate shape done!')

print ('Creating BFE Points...')
try:

    myLayer = stream3D
    prev = -1
    heightDiff = 1
    pntList = list()
    with arcpy.da.SearchCursor(myLayer,["SHAPE@"]) as cursor:
        for row in cursor:
            geom = row[0][0] # A whole polyline
            for i,point in enumerate(geom):
                if prev == -1:
                    prev = point.Z
                else:
                    if abs(point.Z - prev) > heightDiff:
                        pntList.append(geom[i-1])
                        pntList.append(geom[i])
                    prev = point.Z

    if len(pntList) > 0:
        print('Creating Empty point feature class...')
        outFC = arcpy.CreateFeatureclass_management(outGDB, 'BFE_Points', 'POINT','', '','ENABLED') # Create Empty Feature Class to store Points 


        # print ('Adding Elevation field to Points...') # Add field in Points to store Water Surface Grid Elevations
        # arcpy.AddField_management(outFC, 'WS_Elev', 'FLOAT')

        with arcpy.da.InsertCursor(outFC, ["SHAPE@"]) as cursor:
            for point in pntList:
                print(point.Z)
                cursor.insertRow([point])
                print ('Point Created')

    print ('Adding Elevation to Attribute table...') # Add field in Points to store Water Surface Grid Elevations
    arcpy.AddZInformation_3d(outFC, 'Z')

except arcpy.ExecuteError:
    # Geoprocessor threw an error
    print(arcpy.GetMessages(2))

print ('Finished!')
Revised title, question, and code based on others comments
Source Link
tigerwoulds
  • 617
  • 6
  • 17

Loop through Z coordinate of Create points along 3D stream and create point where elevation changes by 1ft

Using ArcPy (Python 3), I am trying to create points along a line where the elevation changes by 1 ft between vertices. I wascan successfully able to convert my streamStream Polyline feature class to 3D using a Water Surface Grid and create a Point feature class where the Interpolate Shape toolelevation changes every 1 ft. When I trynow need to printadd the Z coordinateelevation from the vertex to the Point feature class. Can I get this error:

TypeError: 'float' objectdo by using an Update Cursor within the Insert cursor? I'm still pretty new with Python, what I remember from class is not iterablethat it's bad practice to create nested cursors? What other approach could I use to do this?

import arcpy
import os
from arcpy import env

arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("Spatial")
env.workspace = r"Ir"C:\1006\GIS\Tools\BFE_Tool\BFE_Tool\BFE_Tool.gdb"

streams = 'ShadrackChannel''FY16_Streams_Diss'  # Streams must be dissolved by stream name
outGDB = r'C:\BFE_Tool.gdb'

print ('Interpolating shape...')
stream3D = arcpy.InterpolateShape_3d(r'Ir'C:\1006\GIS\Tools\BFE_Tool\Test_Data\wsg100x'\Test_Data\wsg100x', streams, 'ShadrackChannel_3D''FY16_Streams3D')
 
print ('Interpolate shape done!')

print ('Looping'Creating throughBFE polyline.Points...')
try:
# 
 Enter for loop formyLayer each= featurestream3D
for row in  prev = -1
    heightDiff = 1
    pntList = list()
    with arcpy.da.SearchCursor(stream3D, ["OID@"myLayer, "SHAPE@Z"]["SHAPE@"]) as cursor:
    # Print the current polygonfor orrow polyline'sin IDcursor:
    print("Feature {}:".format       geom = row[0][0]  # A whole polyline
            for i, point in enumerate(row[0])geom):
    partnum = 0
          if prev == -1:
    # Step through each part of the feature         prev = point.Z
    for part in row[1]         else:
        # Print the part number
        printif abs("Partpoint.Z {}- prev) > heightDiff:"
                        pntList.formatappend(partnum)geom[i - 1])
 
        # Step through each vertex in the feature         pntList.append(geom[i])
        for pnt in part:
         prev = point.Z

    if pntlen(pntList) > 0:
        print('Creating Empty point feature class...')
    # Print z coordinates ofoutFC current= point
arcpy.CreateFeatureclass_management(outGDB, 'BFE_Points','POINT')  # Create Empty Feature Class to store Points

        print("{}"'Adding Elevation field to Points.format(pnt.Z.')  # Add field in Points to store Water Surface Grid Elevations
        arcpy.AddField_management(outFC, 'WS_Elev', 'FLOAT') 

        with arcpy.da.InsertCursor(outFC, ["SHAPE@"]) as elsecursor:
            for point in pntList:
 # If pnt is None, this represents an interior ring      cursor.insertRow([point])
                print("Interior'Points Ring:"Created') 

except arcpy.ExecuteError:
    # Geoprocessor threw an partnumerror
 += 1  print(arcpy.GetMessages(2))

print ('Done'Finished!')

Also how can I create a point where the elevation changes every 1 foot?

Loop through Z coordinate of stream and create point where elevation changes by 1ft

Using ArcPy (Python 3), I am trying to create points along a line where the elevation changes by 1 ft. I was successfully able to convert my stream to 3D using a Water Surface Grid and the Interpolate Shape tool. When I try to print the Z coordinate I get this error:

TypeError: 'float' object is not iterable

import arcpy
import os
from arcpy import env

arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("Spatial")
env.workspace = r"I:\1006\GIS\Tools\BFE_Tool\BFE_Tool.gdb"

streams = 'ShadrackChannel'

print ('Interpolating shape...')
stream3D = arcpy.InterpolateShape_3d(r'I:\1006\GIS\Tools\BFE_Tool\Test_Data\wsg100x', streams, 'ShadrackChannel_3D')
 
print ('Interpolate shape done!')

print ('Looping through polyline....')

# Enter for loop for each feature
for row in arcpy.da.SearchCursor(stream3D, ["OID@", "SHAPE@Z"]):
    # Print the current polygon or polyline's ID
    print("Feature {}:".format(row[0]))
    partnum = 0

    # Step through each part of the feature
    for part in row[1]:
        # Print the part number
        print("Part {}:".format(partnum))
 
        # Step through each vertex in the feature
        for pnt in part:
            if pnt:
                # Print z coordinates of current point
                print("{}".format(pnt.Z))
            else:
                # If pnt is None, this represents an interior ring
                print("Interior Ring:")

        partnum += 1

print ('Done!')

Also how can I create a point where the elevation changes every 1 foot?

Create points along 3D stream where elevation changes by 1ft

Using ArcPy (Python 3), I am trying to create points along a line where the elevation changes by 1 ft between vertices. I can successfully convert my Stream Polyline feature class to 3D and create a Point feature class where the elevation changes every 1 ft. I now need to add the Z elevation from the vertex to the Point feature class. Can I do by using an Update Cursor within the Insert cursor? I'm still pretty new with Python, what I remember from class is that it's bad practice to create nested cursors? What other approach could I use to do this?

import arcpy
import os
from arcpy import env

arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("Spatial")
env.workspace = r"C:\BFE_Tool.gdb"

streams = 'FY16_Streams_Diss'  # Streams must be dissolved by stream name
outGDB = r'C:\BFE_Tool.gdb'

print('Interpolating shape...')
stream3D = arcpy.InterpolateShape_3d(r'C:\Test_Data\wsg100x', streams, 'FY16_Streams3D')
print('Interpolate shape done!')

print('Creating BFE Points...')
try:
 
    myLayer = stream3D
    prev = -1
    heightDiff = 1
    pntList = list()
    with arcpy.da.SearchCursor(myLayer, ["SHAPE@"]) as cursor:
        for row in cursor:
            geom = row[0][0]  # A whole polyline
            for i, point in enumerate(geom):
                if prev == -1:
                    prev = point.Z
                else:
                    if abs(point.Z - prev) > heightDiff:
                        pntList.append(geom[i - 1])
                        pntList.append(geom[i])
                    prev = point.Z

    if len(pntList) > 0:
        print('Creating Empty point feature class...')
        outFC = arcpy.CreateFeatureclass_management(outGDB, 'BFE_Points','POINT')  # Create Empty Feature Class to store Points

        print('Adding Elevation field to Points...')  # Add field in Points to store Water Surface Grid Elevations
        arcpy.AddField_management(outFC, 'WS_Elev', 'FLOAT') 

        with arcpy.da.InsertCursor(outFC, ["SHAPE@"]) as cursor:
            for point in pntList:
                cursor.insertRow([point])
                print('Points Created') 

except arcpy.ExecuteError:
    # Geoprocessor threw an error
    print(arcpy.GetMessages(2))

print('Finished!')
naming
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65
Loading
Source Link
tigerwoulds
  • 617
  • 6
  • 17
Loading