azavea / loam

Javascript wrapper for GDAL in the browser
Apache License 2.0
215 stars 16 forks source link

Convert (gdal_translate) to mbtiles #88

Closed LuukMoret closed 2 years ago

LuukMoret commented 2 years ago

Is it possible to convert to mbtiles? I currently have GTiff working but when I try to convert to mbtiles I get an error when calling the bytes() function.

const dataset = await file.convert(['-of', 'GTiff', '-a_srs', 'EPSG:4326', '-a_ullr', upperLeftX, upperLeftY, upperRightX, upperRightY]);
const fileBytes: Uint16Array = await dataset.bytes();
loam.js:1 Uncaught (in promise) Error: Error in GDALTranslate: ZMap: ZMap Plus Grid 
   at Worker.o2.onmessage (loam.js:1) 
   o2.onmessage @ loam.js:1 
   await in o2.onmessage (async)
ddohler commented 2 years ago

Currently, not as configured. The GDAL docs specify that GDAL must be compiled with SQLite support in order to support this format. The version of gdal-js that Loam uses by default is not compiled with SQLite support. This is to minimize the bundle size, but it means that some formats are not supported.

It should be possible to make a custom build of gdal-js that supports SQLite, and use it to create mbtiles. I know that other people have used Emscripten to compile SQLite, so I don't know of any reason it wouldn't work in this case as well, but I haven't tried it myself.

LuukMoret commented 2 years ago

Alright great, thanks for the quick answer!