Skip to content

poseidon-code/DEM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Digital Elevation Model

A simple library for getting ground height (above mean sea level) from provided latitude & longitude using the DEM data of the particular area.

Setting up DEM data

  1. 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

  2. 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

  3. 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;
    }

Reading DEM data

  1. 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
  2. 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;
    }

Operations

  1. 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;
  2. 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;
  3. 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);

File Conversion Operations

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)
  1. .asc to .bin : converts .asc (text) file to .bin (binary) file

    DEM::create_dem_asc_bin("./14_76.asc");
  2. .asc to .csv : converts .asc (text) file to .csv (comma seperated values) file

    DEM::create_dem_asc_csv("./14_76.asc", type);
  3. .bin to .csv : converts .bin (binary) file to .csv (comma seperated values) file

    DEM::create_dem_bin_csv("./14_76.bin", type);
  4. .csv to .bin : converts .csv (comma seperated values) file to .bin (binary) file

    DEM::create_dem_csv_bin("./14_76.csv");

Usage

// 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;
}

Building

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

About

Simple C++ library for managing & working with DEM data.

Topics

Resources

License

Stars

Watchers

Forks