Short version: I need to know how I can convert a .geojson-file to an according .png-file (or any other image format)

long version: I have a .geojson which was created by gdal_polygonize from a .png . I want to make that geojson to a .png again. I tried gdal_rasterize but had an error:

C:\>gdal_rasterize source.geojson destination.png
At least one of -3d, -burn or -a required.

Usage: gdal_rasterize [-b band]* [-i] [-at]
       [-burn value]* | [-a attribute_name] [-3d]
       [-l layername]* [-where expression] [-sql select_statement]
       [-of format] [-a_srs srs_def] [-co "NAME=VALUE"]*
       [-a_nodata value] [-init value]*
       [-te xmin ymin xmax ymax] [-tr xres yres] [-tap] [-ts width height]
       [-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/
             CInt16/CInt32/CFloat32/CFloat64}] [-q]
       <src_datasource> <dst_filename>

I looked here for more information but I don't understand these options. I just want a PNG file. It does not have to contain any information about the SRS and so on. The source.geojson contains many polygons and each polygon has an additional field called 'DN' in which is an HEX-Code of the color of that polygon.

Or do you know another simple method to create an image from a geojson-file?

Edit: As user30184 described in the comments I tried this:

C:\>gdal_rasterize -burn 255 -burn 0 -burn 0 -ts 4950 4090 source.geojson target.tif

And it crated a picture (which is 463 MB..). I could not view it with the Windows Photo Viewer nor with IrfanView but I could inport it in QGIS as a raster file. But the colours are not correct. All polygons have the same color(red) and the "background" is black. I need the colors of each polygon in the image so that I can compare the original image and this created image.

This is the structure of my source.geojson:

"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },

       "features": [
            { "type": "Feature", "properties": { "DN": "#FFFFA5" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 13.28, 52.66 ], [ 13.29, 52.65 ], [ 13.29, 52.66 ], [ 13.28, 52.66 ], [ 13.28, 52.66 ] ] ] } },
            { "type": "Feature", "properties": { "DN": "#FFFFAA" }, "geometry": {    "type": "Polygon", "coordinates": [ [ [ 13.39, 52.64 ], [ 13.39, 52.64 ], [ 13.397, 52.648 ], [ 13.39, 52.65 ], [ 13.39, 52.64 ] ] ] } }

You can see the colour in the 'DN'-field

  • 1
    Try the first example. Burn defines the color of fill. – user30184 Mar 20 '15 at 16:37
  • thank you, I tried but it didn't work. I Updated the question pls look at it again (the Edit:-part) – Selphiron Mar 20 '15 at 16:49
  • It seems as it wants an empty .tiff file in which he can write. How do I create an empty .tiff file? – Selphiron Mar 20 '15 at 18:21
  • 1
    gdal.org/gdal_rasterize.html: Since GDAL 1.8.0, the target GDAL file can be created by gdal_rasterize. Either the -tr or -ts option must be used in that case. – user30184 Mar 20 '15 at 22:50
  • That worked and its almost done. I updated my question again. – Selphiron Mar 21 '15 at 9:57

Your Answer

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

Browse other questions tagged or ask your own question.