Wednesday, 27 November 2019

gdal - Create MBTiles from geojson in raster format


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)`




Answer



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



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...