3

I have a tiff file and I'd like to convert it to mbtiles using python script. In general, I need just select tiff file and convert it to mbtiles to upload it on the map (from python script) but got stuck on the conversion.

I've tried https://github.com/developmentseed/gdal2mb and https://github.com/crschmidt/raster2mb, but as a result I got broken mbtiles (I loaded mbtiles file into QGIS and nothing was shown). In second github link is written : Restrictions Because mbtiles is limited in the profiles it supports, it is only possible to use it to create tilesets from imagery that covers the entire world; imagery which is smaller will create a database successfully, but it will not be in the necessary spherical mercator profile. If you wish to build a tileset, you must first make your image cover the entire world.

Also, gdal_translate rise an error Output driver `MBTILES' not recognised. Are there any more python script for this? Or there is the way to solve issue with raster2mb and gdal_translate?

My GDAL version: GDAL 2.1.3, released 2017/20/01

$ gdalinfo 2.tif

Driver: GTiff/GeoTIFF
Files: 2.tif
Size is 11418, 7692
Coordinate System is:
PROJCS["Google Maps Global Mercator",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.01745329251994328,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Mercator_2SP"],
    PARAMETER["standard_parallel_1",0],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",0],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["Meter",1],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs"],
    AUTHORITY["EPSG","900913"]]
Origin = (34.610612291795853,31.533709086005583)
Pixel Size = (0.000015441030299,-0.000015441030299)
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
  TIFFTAG_XRESOLUTION=820
  TIFFTAG_YRESOLUTION=820
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (  34.6106123,  31.5337091) (  0d 0' 1.12"E,  0d 0' 1.02"N)
Lower Left  (  34.6106123,  31.4149367) (  0d 0' 1.12"E,  0d 0' 1.02"N)
Upper Right (  34.7869180,  31.5337091) (  0d 0' 1.12"E,  0d 0' 1.02"N)
Lower Right (  34.7869180,  31.4149367) (  0d 0' 1.12"E,  0d 0' 1.02"N)
Center      (  34.6987651,  31.4743229) (  0d 0' 1.12"E,  0d 0' 1.02"N)
Band 1 Block=11418x1 Type=Byte, ColorInterp=Red
Band 2 Block=11418x1 Type=Byte, ColorInterp=Green
Band 3 Block=11418x1 Type=Byte, ColorInterp=Blue

$ gdalinfo --formats

Supported Formats:

VRT -raster- (rw+v): Virtual Raster
GTiff -raster- (rw+vs): GeoTIFF
NITF -raster- (rw+vs): National Imagery Transmission Format
RPFTOC -raster- (rovs): Raster Product Format TOC format
ECRGTOC -raster- (rovs): ECRG TOC format
HFA -raster- (rw+v): Erdas Imagine Images (.img)
SAR_CEOS -raster- (rov): CEOS SAR Image
CEOS -raster- (rov): CEOS Image
JAXAPALSAR -raster- (rov): JAXA PALSAR Product Reader (Level 1.1/1.5)
GFF -raster- (rov): Ground-based SAR Applications Testbed File Format (.gff)
ELAS -raster- (rw+v): ELAS
AIG -raster- (rov): Arc/Info Binary Grid
AAIGrid -raster- (rwv): Arc/Info ASCII Grid
GRASSASCIIGrid -raster- (rov): GRASS ASCII Grid
SDTS -raster- (rov): SDTS Raster
DTED -raster- (rwv): DTED Elevation Raster
PNG -raster- (rwv): Portable Network Graphics
JPEG -raster- (rwv): JPEG JFIF
MEM -raster- (rw+): In Memory Raster
JDEM -raster- (rov): Japanese DEM (.mem)
GIF -raster- (rwv): Graphics Interchange Format (.gif)
BIGGIF -raster- (rov): Graphics Interchange Format (.gif)
ESAT -raster- (rov): Envisat Image Format
BSB -raster- (rov): Maptech BSB Nautical Charts
XPM -raster- (rwv): X11 PixMap Format
BMP -raster- (rw+v): MS Windows Device Independent Bitmap
DIMAP -raster- (rov): SPOT DIMAP
AirSAR -raster- (rov): AirSAR Polarimetric Image
RS2 -raster- (ros): RadarSat 2 XML Product
SAFE -raster- (rov): Sentinel-1 SAR SAFE Product
PCIDSK -raster,vector- (rw+v): PCIDSK Database File
PCRaster -raster- (rw+): PCRaster Raster File
ILWIS -raster- (rw+v): ILWIS Raster Map
SGI -raster- (rw+): SGI Image File Format 1.0
SRTMHGT -raster- (rwv): SRTMHGT File Format
Leveller -raster- (rw+): Leveller heightfield
Terragen -raster- (rw+): Terragen heightfield
ISIS3 -raster- (rov): USGS Astrogeology ISIS cube (Version 3)
ISIS2 -raster- (rw+v): USGS Astrogeology ISIS cube (Version 2)
PDS -raster- (rov): NASA Planetary Data System
VICAR -raster- (rov): MIPL VICAR file
TIL -raster- (rov): EarthWatch .TIL
ERS -raster- (rw+v): ERMapper .ers Labelled
L1B -raster- (rovs): NOAA Polar Orbiter Level 1b Data Set
FIT -raster- (rwv): FIT Image
GRIB -raster- (rov): GRIdded Binary (.grb)
RMF -raster- (rw+v): Raster Matrix Format
MSGN -raster- (ro): EUMETSAT Archive native (.nat)
RST -raster- (rw+v): Idrisi Raster A.1
INGR -raster- (rw+v): Intergraph Raster
GSAG -raster- (rwv): Golden Software ASCII Grid (.grd)
GSBG -raster- (rw+v): Golden Software Binary Grid (.grd)
GS7BG -raster- (rw+v): Golden Software 7 Binary Grid (.grd)
COSAR -raster- (rov): COSAR Annotated Binary Matrix (TerraSAR-X)
TSX -raster- (rov): TerraSAR-X Product
COASP -raster- (ro): DRDC COASP SAR Processor Raster
R -raster- (rwv): R Object Data Store
MAP -raster- (rov): OziExplorer .MAP
KMLSUPEROVERLAY -raster- (rwv): Kml Super Overlay
PDF -raster,vector- (w+): Geospatial PDF
CALS -raster- (rw): CALS (Type 1)
SENTINEL2 -raster- (rovs): Sentinel 2
MRF -raster- (rw+v): Meta Raster Format
PNM -raster- (rw+v): Portable Pixmap Format (netpbm)
DOQ1 -raster- (rov): USGS DOQ (Old Style)
DOQ2 -raster- (rov): USGS DOQ (New Style)
GenBin -raster- (rov): Generic Binary (.hdr Labelled)
PAux -raster- (rw+): PCI .aux Labelled
MFF -raster- (rw+v): Vexcel MFF Raster
MFF2 -raster- (rw+): Vexcel MFF2 (HKV) Raster
FujiBAS -raster- (ro): Fuji BAS Scanner Image
GSC -raster- (rov): GSC Geogrid
FAST -raster- (rov): EOSAT FAST Format
BT -raster- (rw+v): VTP .bt (Binary Terrain) 1.3 Format
LAN -raster- (rw+v): Erdas .LAN/.GIS
CPG -raster- (ro): Convair PolGASP
IDA -raster- (rw+v): Image Data and Analysis
NDF -raster- (rov): NLAPS Data Format
EIR -raster- (rov): Erdas Imagine Raw
DIPEx -raster- (rov): DIPEx
LCP -raster- (rwv): FARSITE v.4 Landscape File (.lcp)
GTX -raster- (rw+v): NOAA Vertical Datum .GTX
LOSLAS -raster- (rov): NADCON .los/.las Datum Grid Shift
NTv2 -raster- (rw+vs): NTv2 Datum Grid Shift
CTable2 -raster- (rw+v): CTable2 Datum Grid Shift
ACE2 -raster- (rov): ACE2
SNODAS -raster- (rov): Snow Data Assimilation System
KRO -raster- (rw+v): KOLOR Raw
ROI_PAC -raster- (rw+v): ROI_PAC raster
ENVI -raster- (rw+v): ENVI .hdr Labelled
EHdr -raster- (rw+v): ESRI .hdr Labelled
ISCE -raster- (rw+v): ISCE raster
ARG -raster- (rwv): Azavea Raster Grid format
RIK -raster- (rov): Swedish Grid RIK (.rik)
USGSDEM -raster- (rwv): USGS Optional ASCII DEM (and CDED)
GXF -raster- (ro): GeoSoft Grid Exchange Format
NWT_GRD -raster- (rov): Northwood Numeric Grid Format .grd/.tab
NWT_GRC -raster- (rov): Northwood Classified Grid Format .grc/.tab
ADRG -raster- (rw+vs): ARC Digitized Raster Graphics
SRP -raster- (rovs): Standard Raster Product (ASRP/USRP)
BLX -raster- (rwv): Magellan topo (.blx)
SAGA -raster- (rw+v): SAGA GIS Binary Grid (.sdat)
XYZ -raster- (rwv): ASCII Gridded XYZ
HF2 -raster- (rwv): HF2/HFZ heightfield raster
OZI -raster- (rov): OziExplorer Image File
CTG -raster- (rov): USGS LULC Composite Theme Grid
E00GRID -raster- (rov): Arc/Info Export E00 GRID
ZMap -raster- (rwv): ZMap Plus Grid
NGSGEOID -raster- (rov): NOAA NGS Geoid Height Grids
IRIS -raster- (rov): IRIS data (.PPI, .CAPPi etc)
5

There are few methods to do this:

  1. You can try rio-mbtiles or gdal2mbtiles to write your input raster directly into mbtiles.

  2. GDAL library originaly provides gdal2tiles.py script to generate directories with TMS tiles. Also you can use gdal2tilesp with multiprocessing support. After tiles were generated you can load them into mbtiles database using mbutil.

P.S. Starting with GDAL 2.1, the MBTiles driver has creation and write support for MBTiles datasets. So you can use gdal_translate to generate mbtiles with base zoom level (automaticaly defined). And then use gdaladdo to generate overviews.

2

Gdal_translate is all you need and usage is documented in http://www.gdal.org/frmt_mbtiles.html.

However, you need GDAL version that is compiled with MBTiles and SQlite as MBTiles depends on that. Check if you have the driver with

gdalinfo --formats
  • Thank you for answer. But with gdal_translate I have issue like gis.stackexchange.com/questions/227982/… . On my ubuntu GDAL does not support MBTILES format. Do you know step-by-step instruction how to add SQlite support to GDAl 2.1.3? Could you please help with an example of creation mbtiles because there gdal.org/frmt_mbtiles.html not clear enough how to achieve .mbtiles from common .tiff file. On second PC, where is OS Windows, GDAL supports mbtiles, but rise an error: "Could not find appropriate zoom level" – Davion Mar 4 '17 at 12:49
  • Show gdalinfo from the original image and exact command that you used and I can see if I find something. I do not compile myself so I can't help with that. Ask from gdal-dev mailing lists. – user30184 Mar 4 '17 at 14:01
  • Have you tried to compile with `--with-sqlite3 `? It might be enough for bringing the MBTiles support as it does for geopackage rasters erouault.blogspot.fi/2014/12/… – user30184 Mar 4 '17 at 16:14
  • 1
    So you do not have MBTiles driver. Before you have that you can't do anything. When you have it you will see MBTiles -raster- (rw+v): MBTiles. – user30184 Mar 6 '17 at 10:05
  • 1
    @Davion Sorry, i didn't notice that you are on Ubuntu. You actually don't need nmake.opt. First run apt-get install libspatialite-dev libspatialite5 spatialite-bin sqlite3. Then ./configure --with-spatialite --with-sqlite in the GDAL source folder. then run make and then sudo make install. – Dmitriy Litvinov Mar 9 '17 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.