pinxau1000/Matlab-Google-Elevation-API

Get a area elevation profile easily. Efficient usage of Google Elevation API.
199 téléchargements
Mise à jour 13 jan. 2021

Matlab Script to get a elevation profile along a path defined between two points with n resolution samples.
Check the Project on Github: https://github.com/pinxau1000/Matlab-Google-Elevation-API
Example Usage:
[elevation, resolution, latitudes, longitudes] =
getElevationsPath(latitude1, longitude1, latitude2, longitude2,
resolution, 'key', 'YOUR-API-KEY');
Returns <resolution> points of elevation, resolution, latitudes and
longitudes from the path from Point1(latitude1, longitude1) to Point2
(latitude2, longitude2).

------------------------------------------------------------------------
Example:
Get an area profile. Area vertex are:
VERTEX LAT LONG
Up Left Corner: 39.549937, -8.819350
Up Right Corner: 39.549937, -8.761150
Down Left Corner: 39.505018, -8.819350
Down Right Corner: 39.505018, -8.761150

clearvars;
clc;

SAMPLES = 100;
API_KEY = 'YOUR-API-KEY'; % Read https://developers.google.com/maps/documentation/elevation/get-api-key

Coord1 = [39.549937, -8.819350];
Coord2 = [39.505018, -8.761150];

try
load(['backup_' num2str(SAMPLES)]);

% Sucess loaded but the number of samples are different or the
% coordinates are different. Need to request elevations again.
if length(lat_map)~=SAMPLES || lat_map(1)~=Coord1(1) || lng_map(1)~=Coord1(2) ...
|| lat_map(length(lat_map),1)~=Coord2(1) || lng_map(1,length(lng_map))~=Coord2(2)

disp('Requesting Elevations to Google');

lat = linspace(Coord1(1), Coord2(1), SAMPLES); %Latitude Points

% Preallocating memory for speed improvement
elevation_map = NaN(SAMPLES, SAMPLES);
resolution_map = NaN(SAMPLES, SAMPLES);
lat_map = NaN(SAMPLES, SAMPLES);
lng_map = NaN(SAMPLES, SAMPLES);

% Gets the area elevations.
for r=1:length(lat)
[elevation_map(r,:), resolution_map(r,:), lat_map(r,:), lng_map(r,:)] = getElevationsPath(lat(r), Coord1(2), lat(r), Coord2(2), SAMPLES, 'key', API_KEY);
end

save(['backup_' num2str(SAMPLES)], 'elevation_map', 'resolution_map', 'lat_map', 'lng_map');
end
catch

disp('Requesting Elevations to Google');

lat = linspace(Coord1(1), Coord2(1), SAMPLES); %Latitude Points

% Preallocating memory for speed improvement
elevation_map = NaN(SAMPLES, SAMPLES);
resolution_map = NaN(SAMPLES, SAMPLES);
lat_map = NaN(SAMPLES, SAMPLES);
lng_map = NaN(SAMPLES, SAMPLES);

% Gets the area elevations.
for r=1:length(lat)
[elevation_map(r,:), resolution_map(r,:), lat_map(r,:), lng_map(r,:)] = getElevationsPath(lat(r), Coord1(2), lat(r), Coord2(2), SAMPLES, 'key', API_KEY);
end

save(['backup_' num2str(SAMPLES)], 'elevation_map', 'resolution_map', 'lat_map', 'lng_map');
end

disp('Displaying Data');

% Displays the data
figure('Name','Elevation');

subplot(2,1,1);
meshc(lng_map(1,:), lat_map(:,1), elevation_map);
title('Elevation profile from Serra de Aire e Candeeiros');
xlabel('Latitude (º)');
ylabel('Longitude (º)');
zlabel('Elevation (m)');
colorbar;

subplot(2,1,2);
meshc(lng_map(1,:), lat_map(:,1), resolution_map);
title('Resolution of the Elevation Data of Serra de Aire e Candeeiros');
xlabel('Latitude (º)');
ylabel('Longitude (º)');
zlabel('Resolution (m)');

------------------------------------------------------------------------

MAIN ADVANTAGES (compares to getElevations from Jarek Tuszynski):
- Only consumes one API request for n resolution points between the
path, instead of x API request from the n points from the request
of the original script;
- Easier to use in some cases, mainly when you need to get a
elevation profile of a big area (elevation profile line by line)

THIS SCRIPT IS A MODIFIED VERSION OF GetElevation Script from:
Author: Jarek Tuszynski (jaroslaw.w.tuszynski@leidos.com)
Documentation: https://developers.google.com/maps/documentation/elevation/

MODIFIED VERSION AUTHOR: José Rosa
Github: https://github.com/pinxau1000/Matlab-Google-Elevation-API
Tested on Matlab R2017a

A resolution value, indicating the maximum distance between data points
from which the elevation was interpolated, in meters. This property will
be missing if the resolution is not known. Note that elevation data becomes
more coarse (larger resolution values) when multiple points are passed.
To obtain the most accurate elevation value for a point, it should be queried
independently.

Citation pour cette source

pinxau1000 (J. Rosa) (2024). pinxau1000/Matlab-Google-Elevation-API (https://github.com/pinxau1000/Matlab-Google-Elevation-API), GitHub. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2017a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur Geology dans Help Center et MATLAB Answers
Remerciements

Inspiré par : getElevations(latitude, longitude, varargin)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Les versions qui utilisent la branche GitHub par défaut ne peuvent pas être téléchargées

Version Publié le Notes de version
1.0.0.0

Added more description about the function.

Pour consulter ou signaler des problèmes liés à ce module complémentaire GitHub, accédez au dépôt GitHub.
Pour consulter ou signaler des problèmes liés à ce module complémentaire GitHub, accédez au dépôt GitHub.