[gdal-dev] gdal_contour produces extremely tiny/skinny isoline/isopolygon geometry

Rick Harding madsvlad at gmail.com
Wed Jan 4 10:34:18 PST 2023


Hi,

I am using gdal_contour to generate iso-polygons from a hillshade raster
created via the gdal_dem tool. In certain situations, I am seeing a lot of
tiny/narrow polygons and large polygons with long, skinny *whiskers*
protruding out (and sometimes in) . In these cases, the vertices in the
*skinny* areas are less than 1e-07 away from their nearest edge/vertex.

Here is an example of how the tool is being called (GDAL version 3.4.1):
> gdal_contour -p -f GPKG -amin level -nln hillshade -fl 231
295-hillshade-polygon.tif ./295-hillshade-polygons.gpkg

For reference, the hillshade raster has EPSG:4326 defined as its CRS with a
geo-pixel size of (0.044031311154586,-0.044031311154586).

The diagram below depicts a simple example when working through the
marching-squares algorithm by hand with a single threshold level of 231
(prior to the interpolation step):

      229               229              229
          x----------------x----------------x
          |                |                |
          |                |                |
          |     case 2     *      case 1    |
          |               /|\               |
          |              / | \              |
          |             /  |  \             |
      230 x------------*---o---*------------x 230
          |            |  231  |            |
          |            |   |   |            |
          |            |   |   |            |
          |     case 6 |   |   |  case 9    |
          |            |   |   |            |
          |            |  231  |            |
      230 x------------*---o---*------------x 230
          |             \  |  /             |
          |              \ | /              |
          |               \|/               |
          |    case 4      *     case 8     |
          |                |                |
          |                |                |
          x----------------x----------------x
         229              227              226

I would expect the vertices surrounding each of the 231 intensity values to
be coincident, but the final result has the vertices in each set ~8e-08
apart.This leads me to believe there might be some precision issue in
gdal_contour during bipolar edge interpolation?

I ran this same configuration through another isoline generator for
comparison (see https://github.com/rveciana/raster-marching-squares) and
got what I would expect: a degenerate line with two sets of coincident
vertices around each 231 intensity pixel location.

If necessary, I can provide a complete example with the hillshade raster
and the generated polygons.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230104/b97d1ff9/attachment.htm>


More information about the gdal-dev mailing list