Altitude of Bardibas Sindhuli Dhulikhel Road

QGIS
GPS
Track
Elevation
Altitude
Author

Akhilesh Kumar Karna

Published

April 9, 2019

Altitude Graph

Data Used

GPS track data using smartphone - OSMTracker app. The track-point-data was converted to gpkg.

Create line data from track-point

  • Track point was saved to POSTGIS and then polyline data was created by joining two consecutive points using the following SQL.
```{sql}
create table trackline as 
(
select t1.fid, st_makeline(t1.geom, t2.geom) as lgeom,
st_distance(t1.geom, t2.geom) as dist , t2.ele
from track20190409 t1, track20190409 t2
where t2.fid = t1.fid + 1
    )
```
  • Primary key fid was added
  • The postgis table (polyline) was exported again to the geopackage.
  • The geopackage file can be read using the following python code.
  • Distance vs elevation is plotted using Matplotlib
```{python}
#-------------Use fiona, numpy and matplotlib------
import fiona
import matplotlib.pyplot as plt
import numpy as np
#-----------------------------------------------------------
x = []
y = []
i = 0
#------------------------
## Open gpkg layer
#------------------------
with fiona.open('../mystuffs/data/gnss.gpkg', layer='trkline') as layer:
    for feature in layer:
        if (i%500 == 0):
            print(i)
            #~ break
        for key, value in feature['properties'].items():
            if key=='dist':
                if i > 0:
                    x.append(float(value) + x[i-1])
                else:
                    x.append(float(value))
            else:
                y.append(float(value))
        i += 1
xx = np.array(x) * 0.001
yy = np.array(y)
#---------------Plot bar
plt.figure(figsize=[12, 6])
plt.xlabel("Distance from Bardibas(km)")
plt.ylabel("Elevation(m)")
plt.bar(xx, yy)
#---------------Save file-------
plt.savefig("test.svg")
#--------------------------------

```

Plotted graph is shown below. Elevation Plot