You can use the Official Example
https://google-developers.appspot.com/maps/documentation/javascript/examples/elevation-paths
The Code is well documented so should be easy (with javascript knowledge) to use your own paths to calculate values.
Takes an array of ElevationResult objects, draws the path on the map
and plots the elevation profile on a Visualization API ColumnChart.
THE KEY PART OF THIS IS: You can specifiy the number of samples along that path - in this case 256
// Create a PathElevationRequest object using this array.
// Ask for 256 samples along that path.
var pathRequest = {
'path': path,
'samples': 256
Notes:
Values are in Meters
Elevation API is required to be used with Google Services
Example Request:
http://maps.googleapis.com/maps/api/elevation/xml?locations=48.856908,2.352426&sensor=false
<ElevationResponse><status>OK</status><result><location><lat>48.8569080</lat><lng>2.3524260</lng></location><elevation>32.0345688</elevation><resolution>9.5439520</resolution></result></ElevationResponse>
If you load your LineString gpx/geojson
ogr2ogr -f "PostgreSQL" PG:"dbname=" linestring.geojson
and DEM tiff into PostGIS (replace XXXX with EPSG code, eg for WGS84 use 4326)
raster2pgsql -d -C -I -M -s XXXX -t auto dem.tiff dem
you can then use ST_Segmentize to add extra vertices at the resolution of your DEM (gdalinfo's Pixel Size), then ST_DumpPoints to convert the LineString to a bunch of points,
CREATE TABLE line_points AS select (ST_DumpPoints(ST_Segmentize(wkb_geometry, 5))).*, 0.0 AS ele from line;
then ST_Value to get the elevation at each point,
CREATE INDEX ON line_points USING gist (geom);
UPDATE line_points SET ele = (SELECT ST_Value(dem.rast, geom) AS ele FROM dem WHERE ST_Intersects(line_points.geom, dem.rast) ORDER BY ele LIMIT 1);
then update the geometry to include the elevation
UPDATE line_points SET geom = ST_MakePoint(ST_X(geom), ST_Y(geom), ele);
then ST_MakeLine to reconstruct the points with elevation back into a LineString.
CREATE AGGREGATE array_accum (anyelement)
(
sfunc = array_append,
stype = anyarray,
initcond = '{}'
);
CREATE TABLE linez AS SELECT ST_MakeLine(array_accum(geom)) AS geom FROM (SELECT * FROM line_points ORDER BY path) AS line;
Export back to GeoJSON/CSV/etc:
ogr2ogr -f GeoJSON linez.geojson PG: linez
This could be optimised to generate multiple profiles in bulk, so you're only calling each SQL statement once.
Best Answer
The SRTM DEM has a ground resolution of 30 meters (1 arc-second), see https://en.wikipedia.org/wiki/Shuttle_Radar_Topography_Mission#Highest_Resolution_Global_Release and references.
So the elevation is "averaged" over a 30x30 meter square. Average in quotes because it is not a mathematical operation, but a physical result of the backscattering of the radar beam used. SRTM heights can be quite wrong in steep terrain. See for example Agrawal et al., VALIDATING SRTM DEM WITH DIFFERENTIAL GPS MEASUREMENTS – A CASE STUDY WITH DIFFERENT TERRAINS .
Note that this is a hilly region and not steep mountain slopes.
Mukul et al. (Mukul, M., Srivastava, V., Jade, S. et al. Uncertainties in the Shuttle Radar Topography Mission (SRTM) Heights: Insights from the Indian Himalaya and Peninsula. Sci Rep 7, 41672 (2017). https://doi.org/10.1038/srep41672) find
So yes, what you see is the imperfect SRTM height model.
Maybe you can get a higher resolution DEM from somewhere?`
Also, how do you know that Google Maps places the peak at the exact, correct location? Maybe they also generated the peak markers from a postprocessing of a (different) DEM?