{"id":20286356,"url":"https://github.com/poseidon-code/dem","last_synced_at":"2025-07-28T19:08:28.191Z","repository":{"id":212325486,"uuid":"731235622","full_name":"poseidon-code/DEM","owner":"poseidon-code","description":"Simple C++ library for managing \u0026 working with DEM data.","archived":false,"fork":false,"pushed_at":"2024-09-28T17:53:46.000Z","size":582,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T04:12:26.934Z","etag":null,"topics":["cpp20","dem","digital-elevation-model","gis","qgis"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poseidon-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-13T16:21:47.000Z","updated_at":"2025-02-23T15:05:12.000Z","dependencies_parsed_at":"2023-12-17T17:35:31.943Z","dependency_job_id":"3c477dac-dbef-4192-8710-b2c0471d07f6","html_url":"https://github.com/poseidon-code/DEM","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"3277a9191b6a089693bdea9011973456ae664fa0"},"previous_names":["poseidon-code/dem"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/poseidon-code/DEM","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poseidon-code%2FDEM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poseidon-code%2FDEM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poseidon-code%2FDEM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poseidon-code%2FDEM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poseidon-code","download_url":"https://codeload.github.com/poseidon-code/DEM/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poseidon-code%2FDEM/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267569649,"owners_count":24109116,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp20","dem","digital-elevation-model","gis","qgis"],"created_at":"2024-11-14T14:33:44.366Z","updated_at":"2025-07-28T19:08:28.167Z","avatar_url":"https://github.com/poseidon-code.png","language":"C++","readme":"# Digital Elevation Model\n\nA simple library for accessing elevation values from provided latitude \u0026 longitude\nusing the DEM data of the particular area.\n\n## Project Setup (CMake)\n\n**Prerequisites**\n\n1. CMake _(version 3.25 or above)_\n2. C++ compiler with support for C++ 20 standard (or above)\n\n```cmake\n# CMakeLists.txt (at the root of your project)\n\ncmake_minimum_required(VERSION 3.25)\nproject(Test LANGUAGES C CXX)\n\nset(CMAKE_CXX_STANDARD 20) # C++ standard 20 or above\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\n\n# including the downloaded DEM library (\u003cproject_root\u003e/external/DEM)\nadd_subdirectory(external/DEM)\n\nadd_executable(${PROJECT_NAME} main.cpp)\ntarget_include_directories(${PROJECT_NAME} PUBLIC ${LIBDEM_INCLUDE_DIRECTORIES}) # include DEM headers\ntarget_link_libraries(${PROJECT_NAME} PUBLIC DEM) # links DEM\n```\n\n## Setting up DEM data\n\n1. DEM data of the particular area should be available in any supported standard format.\n   The latitude \u0026 longitude bounds of the DEM data should be known.\\\n   _e.g. DEM data available from [Bhuvan NRSC](https://bhuvan-app3.nrsc.gov.in/data/download/index.php) - Cartosat -1 : CartoDEM Version-3 R1_\n\n2. The downloaded DEM data should be converted to a readable text file using a viable GIS tool\n   as per the guidelines of the DEM data provider or the metadata from the downloaded DEM itself.\\\n   _e.g.: [QGIS](https://qgis.org/en/site/) can be used to convert the downloaded `*.tiff` DEM data to ASCII text file format i.e. produces a `*.asc` file_\n\n3. The text based DEM data should be converted to binary file by using the library.\n\n    ```cpp\n    #inculde \"DEM/Utility.hpp\"\n\n    int main() {\n        // creates the `*.bin` file at the same directory as that of the `*.asc` file.\n        Utility\u003cint16_t, std::endian::big\u003e::create_dem_asc_bin(\"./14_76.asc\");\n        // Utility\u003cdatatype = int16_t, endiannnes = std::endian::big\u003e : writes 2 byte signed integer\n        // values with big-endian (endianness = std::endian::big) byte order\n        // (default: endianness = std::endian::native)\n\n        return 0;\n    }\n    ```\n\n## DEM Operations\n\n1. The different parameters of the downloaded DEM data should be known (also available after conversion to ASCII representation) :\n\n    - Rows - _number of rows in DEM data_\n    - Columns - _number of columns in DEM data_\n    - Lower Left Corner Latitude - _bottom left latitude of the DEM data_\n    - Lower Left Corner Longitude - _bottom left longitude of the DEM data_\n    - Cell Size - _distance (in radians) between every DEM values_\n    - No Data Value - _invalid DEM value representation_\n\n2. File path to the created DEM data binary file _(e.g. `\"/home/user/DEM/14_76.bin\"`)_\n\n    ```cpp\n    #include \"DEM/DEM.hpp\"\n\n    int main() {\n        // DEM\u003cdatatype = int16_t, endiannnes = std::endian::big\u003e : writes 2 byte signed integer\n        // values with big-endian (endianness = std::endian::big) byte order\n        // (default: endianness = std::endian::native)\n\n        DEM\u003cint16_t, std::endian::big\u003e::Type type = DEM::Type(3600, 3600, 14, 76, 0.000277777, INT16_MIN); // nrows, ncols, yllcorner, xllcorner, cellsize, nodata\n\n        // the byte order of the '*.bin' file should be known\n        DEM\u003cint16_t, std::endian::big\u003e dem(type, \"/home/user/DEM/14_76.bin\"); // initialise\n\n        return 0;\n    }\n    ```\n\n### Operations\n\n1. **Altitude** : returns the DEM height of the given coordinate as the type as in DEM data\n\n    ```cpp\n    float Latitude = 14.6705686, Longitude = 76.5106390;\n\n    auto altitude = dem.altitude(Latitude, Longitude);\n    std::cout \u003c\u003c \"Height :\" \u003c\u003c altitude \u003c\u003c std::endl;\n    ```\n\n2. **Interpolated Altitude** : returns the interpolated DEM height of the given coordinate\n\n    ```cpp\n    float Latitude = 14.6705686, Longitude = 76.5106390;\n\n    float interpolated_altitude = dem.interpolated_altitude(Latitude, Longitude);\n    std::cout \u003c\u003c \"Interpolated Height : \" \u003c\u003c interpolated_altitude \u003c\u003c std::endl;\n    ```\n\n## Utility Operations\n\nThese functions converts files to the following formats and saves them in the same directory as that of the input files :\n\n-   `.asc` _(text file representation of DEM generated from a GIS application)_\n-   `.bin` _(file containing DEM data represented in binary format)_\n-   `.csv` _(comma seperated text file representation of the DEM data for usage with spreadsheets)_\n\n1. **`.asc` to `.bin`** : converts `.asc` _(text)_ file to `.bin` _(binary)_ file\n\n    ```cpp\n    Utility\u003cint16_t, std::endian::big\u003e::create_dem_asc_bin(\"./14_76.asc\");\n    ```\n\n2. **`.asc` to `.csv`** : converts `.asc` _(text)_ file to `.csv` _(comma seperated values)_ file\n\n    ```cpp\n    Utility\u003cint16_t, std::endian::big\u003e::create_dem_asc_csv(\"./14_76.asc\", type);\n    ```\n\n3. **`.bin` to `.csv`** : converts `.bin` _(binary)_ file to `.csv` _(comma seperated values)_ file\n\n    ```cpp\n    Utility\u003cint16_t, std::endian::big\u003e::create_dem_bin_csv(\"./14_76.bin\", type);\n    ```\n\n4. **`.csv` to `.bin`** : converts `.csv` _(comma seperated values)_ file to `.bin` _(binary)_ file\n\n    ```cpp\n    Utility\u003cint16_t, std::endian::big\u003e::create_dem_csv_bin(\"./14_76.csv\");\n    ```\n\n## Usage\n\n```cpp\n// main.cpp\n#include \"DEM/DEM.hpp\"\n\nint main() {\n    DEM\u003cint16_t, std::endian::big\u003e::Type type = DEM::Type(3600, 3600, 14, 76, 0.000277777, INT16_MIN); // nrows, ncols, yllcorner, xllcorner, cellsize, nodata\n    DEM\u003cint16_t, std::endian::big\u003e dem = DEM(type, \"/home/user/DEM/14_76.bin\"); // initialise\n\n    return 0;\n}\n```\n\n## Map Operations\n\nCreates a grid of DEM data which can be dynamically loaded into memory at runtime\nwhen accessing a coordinate which is not bounded by the currently loaded DEM data.\n\n1. Create a mapping of DEM files to coordinates.\n\n    ```cpp\n    #include \"DEM/Map.hpp\"\n\n    int main() {\n        // Map\u003cdatatype = int16_t, endiannnes = std::endian::big\u003e : writes 2 byte signed integer\n        // values with big-endian (endianness = std::endian::big) byte order\n        // (default: endianness = std::endian::native)\n\n        Map\u003cint16_t, std::endian::big\u003e::Grid grid;\n        grid[{14, 76}] = {{3600, 3600, 14, 76, 0.000277777, INT16_MIN}, \"/home/user/DEM/14_76.bin\"};\n        grid[{14, 77}] = {{3600, 3600, 14, 77, 0.000277777, INT16_MIN}, \"/home/user/DEM/14_77.bin\"};\n        grid[{14, 78}] = {{3600, 3600, 14, 78, 0.000277777, INT16_MIN}, \"/home/user/DEM/14_77.bin\"};\n\n        Map\u003cint16_t, std::endian::big\u003e map(grid); // initialise\n\n        return 0;\n    }\n    ```\n\n    **OR**, dynamically create grid from DEM files in a directory \\\n    _(**NOTE** : all the DEM files in the directory must conform to `\u003clatitude\u003e_\u003clongitude\u003e.bin` file name and must have same properties (`nrows`, `ncols`, `cellsize`, `nodata`))\\_\n\n    ```cpp\n    #include \"DEM/Map.hpp\"\n\n    int main() {\n        Map\u003cint16_t, std::endian::big\u003e::Grid grid = Map\u003cint16_t, true\u003e::initialize(\"/home/user/DEM/\", 3600, 3600, 0.00027777, INT16_MIN); // `/` (`\\\\` in Windows) required at end of the directory path\n\n        Map\u003cint16_t, std::endian::big\u003e map(grid); // initialise\n\n        return 0;\n    }\n    ```\n\n### Operations\n\n1. **Altitude** : returns the DEM height of the given coordinate as the type as in DEM data\n\n    ```cpp\n    float Latitude = 14.6705686, Longitude = 76.5106390;\n\n    auto altitude = map.altitude(Latitude, Longitude);\n    std::cout \u003c\u003c \"Height :\" \u003c\u003c altitude \u003c\u003c std::endl;\n    ```\n\n2. **Interpolated Altitude** : returns the interpolated DEM height of the given coordinate\n\n    ```cpp\n    float Latitude = 14.6705686, Longitude = 76.5106390;\n\n    float interpolated_altitude = map.interpolated_altitude(Latitude, Longitude);\n    std::cout \u003c\u003c \"Interpolated Height : \" \u003c\u003c interpolated_altitude \u003c\u003c std::endl;\n    ``\n    ```\n\n# [MIT License](./LICENSE)\n\nCopyright (c) 2023 Pritam Halder\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\ndocumentation files (the \"Software\"), to deal in the Software without restriction, including without\nlimitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the\nSoftware, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\nTO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\nTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF\nCONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposeidon-code%2Fdem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposeidon-code%2Fdem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposeidon-code%2Fdem/lists"}