Customized swath analyiss and essential data structure

Customized swath area

PyOSP provides several geo-parameter based swath analyses, including elevation, slope, and topographic position index (TPI). However, in real applications, these options may not be sufficient for user to accurately delineate the desired topgraphic object. For example, the intended object may possess roughness>0.5, or curvture<3, among other possibilities that not being covered by PyOSP. In order to deal with this issue, we provide a tip here that allows users to perform customized swath analysis.

We use the same synthetic landscape that being used in the section Fixed-width curvilinear swath profile.

Here, let’s suppose PyOSP does not have elevation-based characterization. We use raster analysis in other software to exact the range of elevation>10, and incoporate the resulted DEM into swath profile analysis.

Step 1. Raster calculation in GIS software

homo_circle

As shown above, we used raster calculation to extract the portion of DEM having that elevation>10.

Step 2. Use fixed-width swath method to generate the swath object

Now, we use fixed-width swath method to generate the swath object bounded by new DEM. As illustrated previously, PyOSP keeps detecting the boundary of DEM to truncate the analysis at the data boundary. Thus, we can set swath width beyond the possible length of profile line, so the swath area will be determined by the DEM range rather than fixed-width.

Note, PyOSP would assume no data area has cell value less then -1e+20. Make sure the raster file satisfy this criteria before the analysis.

[7]:
import pyosp

baseline = pyosp.datasets.get_path("homo_baseline.shp") # the path to baseline shapefile
raster = pyosp.datasets.get_path("homo_elev10.tif")  # the path to raster file

orig = pyosp.Orig_curv(baseline, raster, width=1000,
                       line_stepsize=3, cross_stepsize=None)
Processing: [#########################] 71 of 71 lineSteps

Step 3. Swath results.

Now we can verify the results by swath profile plot, or exported polygon or polylines.

[8]:
orig.profile_plot()
../_images/notebooks_customized_swath_4_0.svg
[9]:
import matplotlib.pyplot as plt
from pyosp import read_shape

# read the baseline shape
line_shape = read_shape(baseline)
lx, ly = line_shape.xy

# Plot the swath polygon
fig, ax = plt.subplots()
swath_polygon = orig.out_polygon()
px, py = swath_polygon.exterior.xy
ax.plot(px, py)
ax.plot(lx, ly, color='C3', label="Baseline")
ax.set_aspect('equal', adjustable='box')
ax.set_title("Swath polygon")
ax.legend()

# Plot the swath profile lines
fig, ax = plt.subplots()
swath_polylines = orig.out_polylines()
for line in swath_polylines:
    x, y = line.xy
    ax.plot(x, y, color='C1')

ax.plot(lx, ly, color='C3', label="Baseline")
ax.set_aspect('equal', adjustable='box')
ax.set_title("Swath profile lines")
ax.legend()
[9]:
<matplotlib.legend.Legend at 0x7fc020086b80>
../_images/notebooks_customized_swath_5_1.svg
../_images/notebooks_customized_swath_5_2.svg

Notice that all elevation data is above 10, and swath area is bounded by DEM data range. It demonstrates that PyOSP offers users the option to perform customized swath analysis (i.e., roughness, aspect, refief, structure, etc.). This flexibility provides the potential to incorporate any raster classification technique into the swath analysis beyond the default methods in PyOSP.

PyOSP data structure

Now, let’s take a look at structure of most essential data in PyOSP.

  1. Distance

Attibute distance presents an array of baseline points with increasing distance from the starting point.

[10]:
orig.distance
[10]:
array([  0.,   3.,   6.,   9.,  12.,  15.,  18.,  21.,  24.,  27.,  30.,
        33.,  36.,  39.,  42.,  45.,  48.,  51.,  54.,  57.,  60.,  63.,
        66.,  69.,  72.,  75.,  78.,  81.,  84.,  87.,  90.,  93.,  96.,
        99., 102., 105., 108., 111., 114., 117., 120., 123., 126., 129.,
       132., 135., 138., 141., 144., 147., 150., 153., 156., 159., 162.,
       165., 168., 171., 174., 177., 180., 183., 186., 189., 192., 195.,
       198., 201., 204., 207., 210.])
  1. Lines

Lines restore coordinates of points along each profile line, from left hand side to the right. Let’s examine a profile line with index of 9 (distance is 27 from the starting point).

[11]:
orig.lines[9]
[11]:
[[147.66393878283108, 30.266284945875174],
 [148.2435671297984, 30.817674988759467],
 [148.8231954767657, 31.369065031643764],
 [149.402823823733, 31.920455074528054],
 [149.98245217070033, 32.47184511741235],
 [150.56208051766765, 33.02323516029664],
 [151.14170886463495, 33.574625203180936],
 [151.72133721160225, 34.12601524606523],
 [152.30096555856957, 34.67740528894952],
 [152.88059390553687, 35.228795331833815],
 [153.4602222525042, 35.78018537471811],
 [154.0398505994715, 36.3315754176024],
 [154.61947894643882, 36.882965460486695],
 [155.19910729340612, 37.43435550337099],
 [155.77873564037344, 37.98574554625528],
 [156.35836398734074, 38.537135589139574],
 [156.93799233430806, 39.088525632023874],
 [157.51762068127536, 39.63991567490817],
 [158.0972490282427, 40.19130571779246],
 [158.67687737520998, 40.74269576067675],
 [159.2565057221773, 41.294085803561046],
 [159.8361340691446, 41.84547584644534],
 [160.41576241611193, 42.39686588932963],
 [160.99539076307923, 42.948255932213925],
 [161.57501911004655, 43.49964597509822],
 (162.15464745701385, 44.05103601798251),
 [162.73427580398115, 44.602426060866804],
 [163.31390415094847, 45.1538161037511],
 [163.89353249791577, 45.70520614663539],
 [164.4731608448831, 46.25659618951968],
 [165.0527891918504, 46.80798623240398],
 [165.63241753881772, 47.35937627528827],
 [166.21204588578502, 47.91076631817256],
 [166.79167423275234, 48.462156361056856],
 [167.37130257971964, 49.01354640394115],
 [167.95093092668696, 49.56493644682545],
 [168.53055927365426, 50.11632648970974],
 [169.1101876206216, 50.667716532594035],
 [169.68981596758888, 51.21910657547833],
 [170.2694443145562, 51.77049661836262],
 [170.8490726615235, 52.321886661246914],
 [171.42870100849083, 52.87327670413121],
 [172.00832935545813, 53.4246667470155],
 [172.58795770242546, 53.97605678989979],
 [173.16758604939275, 54.527446832784086],
 [173.74721439636005, 55.07883687566838],
 [174.32684274332738, 55.63022691855267],
 [174.9064710902947, 56.18161696143697],
 [175.486099437262, 56.73300700432126],
 [176.0657277842293, 57.28439704720556],
 [176.64535613119662, 57.83578709008985],
 [177.22498447816392, 58.387177132974145],
 [177.80461282513124, 58.93856717585844],
 [178.38424117209854, 59.48995721874273],
 [178.96386951906587, 60.041347261627024],
 [179.54349786603316, 60.59273730451132],
 [180.1231262130005, 61.14412734739561]]
  1. data

Attibute data provides raster values along each profile line. For example, values along the same profile line as presented above.

[12]:
orig.dat[9]
[12]:
[10.366577,
 10.775647,
 10.985182,
 11.849683,
 12.324719,
 12.434934,
 13.207694,
 14.339156,
 14.339156,
 15.918287,
 17.868557,
 18.705082,
 20.37459,
 22.935509,
 23.32269,
 25.494387,
 27.356518,
 28.160154,
 27.377426,
 28.819553,
 27.965193,
 26.129932,
 26.043837,
 26.854143,
 26.317019,
 26.637743,
 27.222136,
 26.62463,
 26.012062,
 24.822708,
 25.181057,
 23.875961,
 22.917784,
 23.280067,
 21.87542,
 20.613186,
 19.87687,
 19.87687,
 19.525146,
 19.106987,
 17.9117,
 18.822304,
 19.342886,
 18.516066,
 19.936953,
 20.327038,
 20.0634,
 18.608377,
 19.296824,
 17.993258,
 16.700563,
 15.849781,
 16.132235,
 14.963792,
 13.446796,
 13.099882,
 11.64522]

Summary

We introduced herein using customized option to perform swath analysis beyond default methods in PyOSP. The afforded flexibility provides the potential to incorporate any raster classification technique into swath analysis. In addition, we walked through essential data attributes of PyOSP swath object, users should be able to further analysis, plot, or conduct other post-processings by making use of numpy, Matplotlib, SciPy, among other Python packages.