Search code examples
d3.jsmapsgisgdaltopojson

How to convert GIS rasters into vector polygons?


How to turn raster GIS files (tiff) into .json ?

Bostock's example used some JSON data to feed his D3.geom.contour plugin. But how to convert a GIS raster, let's say a tiny 11px/15px tiff image, into a JSON.

Final .JSON code such: [EDIT: this is NOT the topojson format]

[
[103,104,104,105,105,106,106,106,107,107,106],
[104,104,105,105,106,106,107,107,107,107,107],
[104,105,105,106,106,107,107,108,108,108,108],
[105,105,106,106,107,107,108,108,109,109,109],
[105,106,106,107,107,108,108,109,109,110,110],
[106,106,107,107,107,108,109,109,110,110,111],
[106,107,107,108,108,108,109,110,110,111,112],
[107,107,108,108,109,109,110,110,112,113,114],
[107,108,108,109,109,110,111,112,114,115,116],
[107,108,109,109,110,110,110,113,115,117,118],
[107,108,109,109,110,110,110,112,115,117,119],
[108,108,109,109,110,110,110,112,115,118,121],
[108,109,109,110,110,111,112,114,117,120,124],
[108,109,110,110,110,113,114,116,119,122,126],
[108,109,110,110,112,115,116,118,122,124,128]
]

Note: .shp to .json: There is already a tutorial on how turning shapefiles into lighter topojson, but not useful to here.


Solution

  • I don't think you can do it directly, it's probably a several step process:

    Process

    Convert .tiff -> .shp

    gdal_contour -a elev input.tif output.shp -i 10.0
    

    Convert .shp -> .json (topojson)

    topojson input.shp -o output.json 
    

    Resources