A simple library for getting ground height (above mean sea level) from provided latitude & longitude using the DEM data of the particular area.
-
DEM data of the particular area should be available in any supported standard format. The latitude & longitude bounds of the DEM data should be known.
e.g. DEM data available from Bhuvan NRSC - Cartosat -1 : CartoDEM Version-3 R1 -
The downloaded DEM data should be converted to a readable text file using a viable GIS tool as per the guidelines of the DEM data provider or the metadata from the downloaded DEM itself.
e.g.: QGIS can be used to convert the downloaded*.tiff
DEM data to ASCII text file format i.e. produces a*.asc
file -
The text based DEM data should be converted to binary file by using the library.
#inculde "DEM.hpp" int main() { DEM::create_dem_asc_bin("./14_76.asc"); // creates the `*.bin` file at the same directory as that of the `*.asc` file. return 0; }
-
The different parameters of the downloaded DEM data should be known (also available after conversion to ASCII representation) :
- Rows - number of rows in DEM data
- Columns - number of columns in DEM data
- Lower Left Corner Latitude - bottom left latitude of the DEM data
- Lower Left Corner Longitude - bottom left longitude of the DEM data
- Cell Size - distance (in radians) between every DEM values
- No Data Value - invalid DEM value representation
-
File path to the created DEM data binary file (e.g.
"/home/user/DEM/14_76.bin"
)#include "DEM.hpp" int main() { DEM::Type type = DEM::Type(3600, 3600, 14, 76, 0.000277777, INT16_MIN); // nrows, ncols, yllcorner, xllcorner, cellsize, nodata DEM dem = DEM(type, "/home/user/DEM/14_76.bin"); // initialise return 0; }
-
Altitude : returns the DEM height of the given coordinate as it is in DEM data
double Latitude = 14.6705686, Longitude = 76.5106390; short int altitude = dem.altitude(Latitude, Longitude); std::cout << "Height :" << altitude << std::endl;
-
Interpolated Altitude : returns the interpolated DEM height of the given coordinate
double Latitude = 14.6705686, Longitude = 76.5106390; double interpolated_altitude = dem.interpolated_altitude(Latitude, Longitude); std::cout << "Interpolated Height : " << interpolated_altitude << std::endl;
-
Patch : returns an 2D vector of the surrounding DEM data of a valid coordinate.
double Latitude = 14.6705686, Longitude = 76.5106390; unsigned int radius = 10; std::vector<std::vector<short int>> patch = dem.patch(Latitude, Longitude, radius);
These functions converts files to the following formats and saves them in the same directory as that of the input files :
.asc
(text file representation of DEM generated from a GIS application).bin
(file containing DEM data represented in binary format).csv
(comma seperated text file representation of the DEM data for usage with spreadsheets)
-
.asc
to.bin
: converts.asc
(text) file to.bin
(binary) fileDEM::create_dem_asc_bin("./14_76.asc");
-
.asc
to.csv
: converts.asc
(text) file to.csv
(comma seperated values) fileDEM::create_dem_asc_csv("./14_76.asc", type);
-
.bin
to.csv
: converts.bin
(binary) file to.csv
(comma seperated values) fileDEM::create_dem_bin_csv("./14_76.bin", type);
-
.csv
to.bin
: converts.csv
(comma seperated values) file to.bin
(binary) fileDEM::create_dem_csv_bin("./14_76.csv");
// main.cpp
#include "DEM.hpp"
int main() {
DEM::Type type = DEM::Type(3600, 3600, 14, 76, 0.000277777, INT16_MIN); // nrows, ncols, yllcorner, xllcorner, cellsize, nodata
DEM dem = DEM(type, "/home/user/DEM/14_76.bin"); // initialise
return 0;
}
Use CMake
(required) to build both shared and static libraries of DEM.
Open a terminal inside DEM project directory and paste the following commands.
mkdir build
cd build
cmake ..
cmake --build .
MIT License
Copyright © 2023 Pritam Halder