Replies: 2 comments 8 replies
-
you need to select a
e.g 👇 (I needed to encode the URL to make sure it worked)
Then I'm not sure the WMS can return the original data, I think they will return PNG tiles 🤷
|
Beta Was this translation helpful? Give feedback.
-
Following the above discussion, I stumbled across an older repo meant to stream and act as a middleware for DEM related data, dem-tiler by @kylebarron - a fork of cogeo-mosaic-tiler which relies on pymartini or pydelatin to encode on-the-fly elevation to quantized-mesh, maybe also under the devseed umbrella. I wanted to see if it would be doable to add this as a dem-algorithm within titiler, with the most prominent difference being that the data processed by the algorithm is not image but quantized-mesh. I've added dependencies (could probably be optional dependencies instead) Quick note the output could also be vector contours based on gdal_contour and tippecanoe for contours MVT creation, the same way dem-tiler does it as well. from pymartini import Martini
import quantized_mesh_encoder
import BytesIO
class QuantizedMesh(BaseAlgorithm):
"""Encode DEM into QuantizedMesh (with pymartini)."""
title: str = "QuantizedMesh"
description: str = "Encode DEM into QuantizedMesh (Cesium Terrain format)."
# parameters
mesh_max_error: float = Field(10.0, ge=1.0, le=100.0)
# metadata
input_nbands: int = 1
# OUTPUT IS ACTUALLY A QUANTIZED-MESH RATHER THAN AN IMAGE
output_nbands: int = 3
output_dtype: str = "uint8"
def __call__(self, img: ImageData) -> ImageData:
"""Encode DEM into QuantizedMesh (with pymartini).
Code from dem-tiler (MIT) https://github.com/kylebarron/dem-tiler/blob/b10d1f61cf89c1a24af5643d0bd4ddee87c52508/dem_tiler/handlers/app.py#L235-L307
"""
# Could also use pydelatin instead of pymartini
mesh_max_error: 10.0
tile_size = 256
tile = img.array[0].astype(numpy.float64)
martini = Martini(tile_size + 1)
mar_tile = martini.create_tile(tile)
vertices, triangles = mar_tile.get_mesh(mesh_max_error) # mesh_max_error)
with BytesIO() as f:
quantized_mesh_encoder.encode(f, vertices, triangles)
f.seek(0)
return ("OK", "application/vnd.quantized-mesh", f.read())
# return ImageData(
# numpy.ma.stack([r, g, b]).astype(self.output_dtype),
# assets=img.assets,
# crs=img.crs,
# bounds=img.bounds,
# ) |
Beta Was this translation helpful? Give feedback.
-
First of all, sorry for the lengthy read. Original context, the french OSM community is trying to circumvent the (probably temporary) lack of readability of some IGN-produced hillshades, by ingesting new endpoints from the geoplateforme geoservices. A potential contender would eventually be terrain elevation data and upcoming Lidar-HD derived DSM/DEM/DTM products. Long thread here.
After seeing on-the-fly titiler algorithms (really 🤯 feature), I wanted to give them a shot and try to apply custom hillshade to a TMS/XYZ endpoint rather than an existing COG tileset - to have an endpoint that would work on the whole France country rather than having to change the url for each regional assembled COG.
I know, this is a bit of a stretch, I might have been a bit ambitious following another original discussion using GDAL drivers like
GDAL_WMS
as titilerurl
param (copy-pasted below) which resulted in the following valid titiler endpoints.It was not an easy task to find true altitude DEMs (most endpoints are composited colored-elevation + hillshade , or Mapzen/Terrarium encoded elevation products like AWS Open Data Terrain tiles), but I finally stumbled on the spanish DEM below. Here is the URL I've come-up with:
The request is currently failing with:
No such band index: 1
, and I'm not really sure why, hence opening this discussion. Also, would it make sense to add another input param tohillshade
algorithm so it could ingest not only raw float elevation (or byte8 with z-exaggeration), but also Mapzen/Terrarium encoded altitude? Thanks as always for the impressive titiler!Beta Was this translation helpful? Give feedback.
All reactions