2

I am trying to convert a weather radar geoTIF to geoJSON using gdal_polygonize.

enter image description here

I am sharing the original .tif on google drive : https://drive.google.com/file/d/1p2eE0QUtNypNjs5Qb9JBfXrDdMd8Ifpb/view?usp=sharing

My command to convert is :

python gdal_polygonize.py -q KEWX_L2_BREF_RAW_20210624_165114.tif -f "GeoJSON" myPolygonizedImage.geojson

It produces a file with lots of data that looks to be correct, but there is no information about the color values. Example of the output for a random polygon :

{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -95.429, 32.3965 ], [ -95.429, 32.394 ], [ -95.4265, 32.394 ], [ -95.4265, 32.3965 ], [ -95.429, 32.3965 ] ] ] } },

Is there a way to also have the script place color value data in the output? I am new to gdal_polygonize - maybe I am not understanding the basics? I am using GDAL 3.1.0, released 2020/05/03.

2
  • What do you imagine the output to be? One polygon per pixel? Jun 28, 2021 at 21:47
  • If every pixel is a different color, yes.
    – David
    Jun 28, 2021 at 21:56

1 Answer 1

1

As documented https://gdal.org/programs/gdal_polygonize.html gdal_polygonize should create an attribute.

This utility creates vector polygons for all connected regions of pixels in the raster sharing a common pixel value. Each polygon is created with an attribute indicating the pixel value of that polygon.

By default the field is named "DN"

I used your command with GDAL 3.1.4 installed with OSGeo4W installer on Windows and I got a result that contains features with DN attribute

{ "type": "Feature", "properties": { "DN": 89 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -98.959, 33.4565 ], [ -98.959, 33.454 ], [ -98.9465, 33.454 ], [ -98.9465, 33.4565 ], [ -98.959, 33.4565 ] ] ] } },

I do not what goes wrong for you.

2
  • What would "89" be? Since there are R,G,B bands, which one is it using? I basically just need gdal to convert the image to geoJSON with a color value (I was hoping it would be smart and put a hex value or something in). I would not understand what 89 is, even if it is working
    – David
    Jun 28, 2021 at 21:36
  • 3
    89 is the value in band 1. In QGIS, open both your GeoJSON layer and your raster, click on it using "Identify features" button in toolbar to confirm my answer. In fact, it seems polygonize works per band (and by default the first one) e.g github.com/OSGeo/gdal/blob/master/gdal/swig/python/gdal-utils/…
    – ThomasG77
    Jun 28, 2021 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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