Select to view content in your preferred language

arcpy set point every 10 cm hight change on line?

257
0
03-30-2022 12:02 AM
JohannesBierer
Frequent Contributor

Hello,

i've slightly adapted a script of Bera - Stackexchange - https://gis.stackexchange.com/questions/308705/split-a-line-at-a-specific-elevation

It should set a point every 10 cm hight change on a line. The script is somehow working but not very efficient, is there a better way to do it? Originally the script was for one best point on a line ... How not to write single bestpoints to fclass? Any ideas?

# erzeugt Punktshape alle x cm Hoehe entlang Linie

import arcpy
import numpy as np

arcpy.env.overwriteOutput = True

arcpy.env.workspace = r"Path\Berechnung_4.gdb"

fc = r'Path_to_FGDB\Gew_Morre' 
inDGM = r"Path_to_FGDB\dgm01m"

step = 1 # 0.1 in script - Change, as small as possible without making the execution time unacceptably long

arcpy.CheckOutExtension("3D")

Gewaesser_3D = "Gewaesser_3D"
arcpy.InterpolateShape_3d(inDGM, fc, Gewaesser_3D)
arcpy.AddSurfaceInformation_3d(Gewaesser_3D, inDGM, "Z_MIN;Z_MAX", "BILINEAR")

arcpy.CheckInExtension("3D")

with arcpy.da.SearchCursor(Gewaesser_3D,['SHAPE@','Z_MIN','Z_MAX']) as cursor:
    for row in cursor:
        print("valueMin = {} and valueMAx = {}".format(row[1], row[2]))
        arr = np.arange(row[1], row[2], 0.1) # hier Hoehenstufen definieren!
        print(arr)
  
        for r in arr:        

            geom = row[0]
            points = []
            position = 0
            while position < geom.length:
                points.append(geom.positionAlongLine(position))
                position+=step

            bestpoint = min(points, key=lambda x: abs(x.centroid.Z-r))

            strR = round(r, 5)
            print (strR)
            ReplaceRstrR = str(strR).replace(".", "_")
            
            arcpy.CopyFeatures_management(in_features=bestpoint, out_feature_class='bestpoint{}'.format(ReplaceRstrR))

featureclasses = arcpy.ListFeatureClasses("bestpoint*")   

arcpy.Merge_management(featureclasses, "merge_ergebnis_bruchhof_10cm")

 

0 Kudos
0 Replies