AnsweredAssumed Answered

# Polyline NumPy Array to Pandas DataFrame: StElevation and EndElevation?

Question asked by Playa on Jul 14, 2017
Latest reply on Aug 23, 2017 by Dan_Patterson

I have converted a feature class (polylines) to a numpy array and have expoded the polylines to vertices using the "explode_to_points" method. I would like to convert the output numpy array to a pandas dataframe that will replicate the line segments that make up the polyline so that I land up with the following columns:

The table above was achieved by using "Split Line At Vertices". The fields "STElev" and "EndElev" are the Start Elevation and End Elevation of the line segments determined using "Calculate Geometry". The field "STElevation" and "EndElevation" is the change in elevation determined by subtracting the elevation from the first "STElev" which in this case is 355.8495.

The output numpy array from converting my feature class (polylines) and exploding the features to vertices is:

The values are:

[(DrainID, X, Y, Z)....] for each vertice

``'''Created on 01 Jul 2017@author: PeterW'''# import modules and site-packagesimport numpy as npimport pandas as pdfrom pathlib import Pathimport arcpy# set environment settingsarcpy.env.overwriteOutput = True# check out extensionsarcpy.CheckOutExtension("3D")def longestflowpath_3d(dtm, lfp_2d):    """Generate LongestFlowPath 3D    from LongestFlowPath 2D and DTM"""    output_gdb = str(Path(lfp_2d).parents[0])    lfp_3d = "{0}\\{1}".format(output_gdb, "lfp_3d")    lfp_3d = arcpy.InterpolateShape_3d(dtm, lfp_2d, lfp_3d, vertices_only=True)    arcpy.FlipLine_edit(lfp_3d)    return lfp_3ddef area_under_profile(lfp_3d):    """Determine the Equal Area Slope    for each Drainage Area's Longest    Flowpath"""    arr = arcpy.da.FeatureClassToNumPyArray(lfp_3d, ["DrainID", "SHAPE@X", "SHAPE@Y", "SHAPE@Z"], explode_to_points=True)  # @UndefinedVariable    print(arr)def equal_area_slope(dtm, lfp_2d):    """Determine the Equal Area Slope    for each Drainage Area's Longest    Flowpath"""    lfp_3d = longestflowpath_3d(dtm, lfp_2d)    area_under_profile(lfp_3d)if __name__ == "__main__":    dtm = r"E:\Projects\2016\G113665\geoHydro\DTM2\raw1"    lfp_2d = r"E:\Projects\2016\G113665\geoHydro\Model02\Results.gdb\LongestFlowPath_2D_Orig"    equal_area_slope(dtm, lfp_2d)``

My current Python Module

How can I convert the current numpy array to a pandas dataframe that will restructure the vertices (DrainID, X, Y, Z) to (DrainID, STElevation (change in elevation), EndElevation (change in elevation), DistM (Length of segment)?