1

I need to produce a shapefile from a raster. I need to be able to specify either an interval, or manually define the intervals. The input file is a GeoTIFF. I would like to use GDAL and/or Python.

Example raster:

enter image description here

I tried using gdal_contour, which at first glance would have been perfect. However, I want the result to have the same "pixel" definition - that is, the "contours" should maintain the block appearance of the pixels at their extents. For this reason, I can't use gdal_contour, as the results look like this:

enter image description here

Is there another way to do this? My output should be a shapefile that looks like a grid, with only pixels in the same interval connected to each other.

Vince
  • 20,017
  • 15
  • 45
  • 64
Dan
  • 13
  • 4
  • You (may) have two questions here. The first is about reclassifying your raster (specification of intervals) for which you can see http://gis.stackexchange.com/questions/116473/ Contour lines is an interpolation of the point values, not a direct vectorization. For that you can see http://gis.stackexchange.com/questions/128139/ which discusses why it doesn't make sense to directly vectorize a float. However if that's really what you want to do, it can be done. Are you wanting lines or polygons for the vector geometry? – Chris W Jun 14 '15 at 19:08
  • 1
    rasterToContours in the R package raster returns cell edges in a SpatialLinesDataFrame. – mdsumner Jun 14 '15 at 21:10
  • Hey @ChrisW - thanks for the response. My wording probably wasn't great. I want to have the option to specify intervals for the "contours" in my output. So, for instance, 10-30 should be a contour, 31-40 should be one, etc. gdal_contour can do this with the -fl argument. Just want to retain that functionality.

    Anyway, the more important part: yes, I do want to directly polygonize the raster. It's not really an elevation, it represents a specific set of data that must go into the final system in this format. I'll take a look at your second link, looks like it might work. Thanks!

    – Dan Jun 14 '15 at 23:52

1 Answers1

1

Creating contours is an interpolation, which is why your output looks like it does.

You need to reclassify using gdal_calc: http://www.gdal.org/gdal_calc.html

But there is some good information here relating to reclassifying with either gdal or python: Reclassify rasters using GDAL and Python

And then convert to vector using gdal_polygonize: http://www.gdal.org/gdal_polygonize.html

Mike
  • 718
  • 4
  • 8