I am trying to create raster file in the Mbtiles format.

I tried ,

$ gdal_rasterize -ot Byte  -burn 255 -burn 0 -burn 0 -ts 4950 4090 -of MBTiles station.geojson station.mbtiles 

I'm using,

$gdalinfo --version : GDAL 2.1.3, released 2017/20/01

Error:

> ERROR 1: Cannot find min and max zoom_level
> 
> ERROR 6: Could not find an appropriate zoom level that matches raster
> pixel size
> 
> ERROR 6: Only EPSG:3857 supported on MBTiles dataset
> 0...10...20...30...40...50...60...70...80...90...100 - done.
> 
> ERROR 6: IWriteBlock() not supported if georeferencing not set
> 
> ERROR 6: IWriteBlock() not supported if georeferencing not set
> 
> ERROR 6: IWriteBlock() not supported if georeferencing not set

EDIT:

$ ogrinfo station.geojson -so -al

INFO: Open of 'stations.geojson' using driver 'GeoJSON' successful.

Layer name: OGRGeoJSON

Geometry: Point

Feature Count: 86

Extent: (-77.272622, 38.766522) - (-76.842038, 39.119927)

Layer SRS WKT:

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.0174532925199433,

   AUTHORITY["EPSG","9122"]],

AUTHORITY["EPSG","4326"]]

name: String (0.0)

marker-color: String (0.0)

marker-symbol: String (0.0)

line: String (0.0)`

  • What does ogrinfo station.geojson -so -al show? – user30184 Dec 11 '17 at 12:25
  • @user30184 I updated my question as you requested ogrinfo of my geojson – Abhi Dec 13 '17 at 4:21
  • The projection you are using is 4326 but MBtiles are only working with 3857 (epsg.io/3857) as stated in the error message. You should reproject it first. – dan_ke Dec 13 '17 at 8:49
  • thank dan_ke, I converted to EPSG 3857 using ogr2ogr . But still I am getting Below error regarding zoom, ERROR 6: Could not find an appropriate zoom level that matches raster pixel size 0...10...20...30...40...50...60...70...80...90...100 - done. ERROR 6: IWriteBlock() not supported if georeferencing not set ERROR 6: IWriteBlock() not supported if georeferencing not set ERROR 6: IWriteBlock() not supported if georeferencing not set – Abhi Dec 13 '17 at 9:46
  • 2
    you can use github.com/mapbox/tippecanoe to convert the GeoJSON to an .mbtiles file.Check this tool – Francisco Raga Dec 15 '17 at 8:58
up vote 1 down vote accepted
+50

I'm not certain that this is the case, but GeoJSON is not supposed to be any coordinate reference system (CRS) except for WGS (EPSG:4326).

I think you'd better convert it to a Shapefile first. While you're at it, convert it to the right projection:

 ogr2ogr -f "ESRI Shapefile" station.shp station.geojson -s_srs EPSG:4326 -t_srs EPSG:3857

Now what worked for me was rasterizing to TIFF first:

gdal_rasterize -ot Byte -burn 255 -burn 0 -burn 0 -ts 100 100 -of MBTiles station.shp station.mbtiles

(Note I changed the resolution... play with the -ts parameter.)

And now convert that tiff to MBTiles:

gdal_translate station.tiff station.mbtiles -of MBTILES

Output from my dataset of points across Tasmania loaded fine in QGIS, and ended up with this demonic view, strangely:

Tasmania light up with red

  • Alex, I am also facing same blur issue, Might be resolution not working!! – Abhi Dec 19 '17 at 4:25
  • Hey @Abhi, you can change the resolution with the -ts option. Make those numbers higher! – Alex Leith Dec 19 '17 at 23:59

There is an answer in gdal-dev mailing list https://lists.osgeo.org/pipermail/gdal-dev/2017-December/047904.html.

The error message says it all, doesn't it ? MBTiles only accepts a single tiling scheme, with a pre-defined set of zoom levels / resolutions. By default, when gdal_rasterize will initialize the output raster, the chance that it fits to those constraints is extremely unlikely.

Now you may wonder why you can gdal_translate an arbitrary raster as MBTiles. This is because MBTiles (similarly to GeoPackage with a predefined tiling scheme) sheat in its CreateCopy() implementation to invoke the warping engine to reproject/resample to one of the compatible zoom level.

But gdal_rasterize use the Create() interface, so this isn't possible.

Obvious workaround: rasterize to TIF and translate to MBTiles.

It seems to be possible to make gdal_rasterize to write directly into MBTiles file if the resolution matches the tiling schema. I guess that it is possible to solve the resolution mathematically but I just made the initial conversion into TIFF, then into MBTiles, and then I checked with gdalinfo what the pixel size is. With the same pixel size this command did create a MBTiles file despite the error about min and max zoom_level.

gdal_rasterize -ot Byte  -burn 255 -burn 0 -burn 0 -tr 9.55462853
5647032 9.554628535647032 -of MBTiles points_3857.json points_3857_2.mbtiles
ERROR 1: Cannot find min and max zoom_level
0...10...20...30...40...50...60...70...80...90...100 - done.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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