{"id":21975078,"url":"https://github.com/watergis/dem2terrainrgb","last_synced_at":"2025-04-28T15:39:39.857Z","repository":{"id":37713258,"uuid":"320414095","full_name":"watergis/dem2terrainrgb","owner":"watergis","description":"This module is to convert DEM to terrain RGB raster tiles.","archived":false,"fork":false,"pushed_at":"2023-06-22T14:39:55.000Z","size":21,"stargazers_count":74,"open_issues_count":1,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-30T05:43:05.888Z","etag":null,"topics":["dem","python","terrain-rgb"],"latest_commit_sha":null,"homepage":"","language":"Python","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/watergis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["JinIgarashi"],"open_collective":"watergis","custom":["https://www.paypal.me/jinigarashi"]}},"created_at":"2020-12-10T23:22:16.000Z","updated_at":"2024-09-27T13:47:34.000Z","dependencies_parsed_at":"2023-12-08T21:44:29.433Z","dependency_job_id":null,"html_url":"https://github.com/watergis/dem2terrainrgb","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":"0.16666666666666663","last_synced_commit":"ba4eed3dbbdadee678a1cdf1e2737f038fb1836e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watergis%2Fdem2terrainrgb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watergis%2Fdem2terrainrgb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watergis%2Fdem2terrainrgb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watergis%2Fdem2terrainrgb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/watergis","download_url":"https://codeload.github.com/watergis/dem2terrainrgb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226717556,"owners_count":17670890,"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","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":["dem","python","terrain-rgb"],"created_at":"2024-11-29T15:49:34.696Z","updated_at":"2024-11-29T15:49:35.265Z","avatar_url":"https://github.com/watergis.png","language":"Python","funding_links":["https://github.com/sponsors/JinIgarashi","https://opencollective.com/watergis","https://www.paypal.me/jinigarashi"],"categories":[],"sub_categories":[],"readme":"# dem2terrainrgb\n![GitHub](https://img.shields.io/github/license/watergis/dem2terrainrgb)\n\nThis module is to convert DEM to terrain RGB raster tiles.\n\n## Installation\n\n```\ncd dem2terrainrgb\npipenv install\n```\n\n## Usage\n\n```\n$ python main.py -h\nusage: dem2terrainrgb.py --dem {dem file path} --dist {output directory path} --tmp {temporary directory path} --webp --remove_png --zoom {min-max zoom}\n\nThis module is to convert DEM to terrain RGB raster tiles.\n\noptional arguments:\n  -h, --help    show this help message and exit\n  --dem DEM     Original DEM file. It must be already reprojected to EPSG:3857 before converting.\n  --dist DIST   Output directory for tiles\n  --tmp TMP     Temporary work directory\n  --webp        Use this option if you want to convert PNG to webp tiles\n  --remove_png  Use '--webp' option together. If this option is used, it will remove all of original PNG tiles.\n  --zoom ZOOM   Specify min-max zoom level for tiles. Default is 5-15.\n```\n\nThe below is an example command. Before executing this module, you must reproject your DEM to EPSG:3857 coordinates by using GDAL or QGIS.\n```\npipenv shell\npython main.py --dem ./data/rwanda_dem_EPSG3857_10m.tif --dist ./tiles --webp --zoom 5-15\n```\n\nFinally, you can delete all of xml files under tiles folder.\n```\nfind ./tiles -name \"*.xml\" -exec bash -c 'rm \"$1\"' - '{}' \\;\n```\n\n## Validation\n\nIf you want to validate processed tiff image, you can command like below.\n\n```\n$ rio info --indent 2 ./data/rwanda_dem_EPSG3857_10m_without_nodata.tif\n```\n\n\u003cdetails\u003e\n\n```json\n{\n  \"blockxsize\": 256,\n  \"blockysize\": 256,\n  \"bounds\": [\n    3223733.0877,\n    -316437.17616185057,\n    3439718.7685284764,\n    -115768.6321\n  ],\n  \"colorinterp\": [\n    \"gray\"\n  ],\n  \"compress\": \"deflate\",\n  \"count\": 1,\n  \"crs\": \"EPSG:3857\",\n  \"descriptions\": [\n    null\n  ],\n  \"driver\": \"GTiff\",\n  \"dtype\": \"uint16\",\n  \"height\": 19992,\n  \"indexes\": [\n    1\n  ],\n  \"interleave\": \"band\",\n  \"lnglat\": [\n    29.92940323722318,\n    -1.9409140983431143\n  ],\n  \"mask_flags\": [\n    [\n      \"all_valid\"\n    ]\n  ],\n  \"nodata\": null,\n  \"res\": [\n    10.037442179964515,\n    10.037442179964515\n  ],\n  \"shape\": [\n    19992,\n    21518\n  ],\n  \"tiled\": true,\n  \"transform\": [\n    10.037442179964515,\n    0.0,\n    3223733.0877,\n    0.0,\n    -10.037442179964515,\n    -115768.6321,\n    0.0,\n    0.0,\n    1.0\n  ],\n  \"units\": [\n    null\n  ],\n  \"width\": 21518\n}\n```\n\u003c/details\u003e\n\nFor verifying the elevation data, you may do the below command.\n\n```\n$ gdallocationinfo -wgs84 ./data/rwanda_dem_EPSG3857_10m_RGB.tif 29.7363 -2.2313\nReport:\n  Location: (8617P,13218L)\n  Band 1:\n    Value: 1\n  Band 2:\n    Value: 199\n  Band 3:\n    Value: 250\n(rwanda_terrain)\n```\n\nFormula is like this:\n\n```\nheight = -10000 + ((R * 256 * 256 + G * 256 + B) * 0.1)\n```\n\n## Convert to MBTiles\n\nYou can use mb-util module to convert tilesets into a mbtiles container.\n\n```\n$ mb-util --image_format=png --scheme=xyz ./tiles/ ./tilesets/rwanda_dem_EPSG3857_10m.mbtiles\n```\n\nIf you want to create mbtiles from webp tiles, the command should be like below.\n```\n$ mb-util --image_format=webp --scheme=xyz ./tiles/ ./tilesets/rwanda_dem_EPSG3857_10m_webp.mbtiles\n```\n\nBefore running `mb-util`, don't forget to put `metadata.json` under `tiles` folder. The below is an example of content for `metadata.json`.\n\n```json\n{\n  \"name\": \"Rwanda 10m Terrain RGB Tileset\",\n  \"description\": \"Rwanda 10m Terrain RGB Tileset, CC-BY-4.0: Water and Sanitation Corporation (WASAC), Rwanda\",\n  \"version\": \"1\"\n}\n```\n\n## Tile hosting\n\nYou can upload tilesets to Github pages for hosting. If you would like to host tiles on your own server, you may be able to use [mbtilesserver](https://github.com/consbio/mbtileserver).\n\nAfter installing `mbtileserver`,\n\n```\n~/go/bin/mbtileserver --verbose\n```\n\nit will automatically find mbtiles under `tilesets` folder, then access to [http://localhost:8000/services](http://localhost:8000/services). You will see the following response.\n\n```json\n[\n    {\n        \"imageType\": \"png\",\n        \"url\": \"http://localhost:8000/services/rwanda_dem_EPSG3857_10m\",\n        \"name\": \"Rwanda 10m Terrain RGB Tileset\"\n    }\n]\n```\n\nAfter that, continue to access [http://localhost:8000/services/rwanda_dem_EPSG3857_10m](http://localhost:8000/services/rwanda_dem_EPSG3857_10m) and see more detailed information.\n\n```json\n{\n    \"description\": \"Rwanda 10m Terrain RGB Tileset, CC-BY-4.0: Water and Sanitation Corporation (WASAC), Rwanda\",\n    \"format\": \"png\",\n    \"map\": \"http://localhost:8000/services/rwanda_dem_EPSG3857_10m/map\",\n    \"maxzoom\": 15,\n    \"minzoom\": 5,\n    \"name\": \"Rwanda 10m Terrain RGB Tileset\",\n    \"scheme\": \"xyz\",\n    \"tilejson\": \"2.1.0\",\n    \"tiles\": [\n        \"http://localhost:8000/services/rwanda_dem_EPSG3857_10m/tiles/{z}/{x}/{y}.png\"\n    ],\n    \"version\": \"1\"\n}\n```\n\nTileset URL will be as below.\n```\nhttp://localhost:8000/services/rwanda_dem_EPSG3857_10m/tiles/{z}/{x}/{y}.png\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatergis%2Fdem2terrainrgb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwatergis%2Fdem2terrainrgb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatergis%2Fdem2terrainrgb/lists"}