gina-alaska / dans-gdal-scripts

A number of utilities for use in conjunction with GDAL.
http://www.gina.alaska.edu/projects/gina-tools/
Other
158 stars 42 forks source link

Smooth edges on gdal_trace_outline #2

Closed systemed closed 10 years ago

systemed commented 11 years ago

gdal_trace_outline is a godsend but tends to produce very jagged edges from SRTM data. Applying the Douglas-Peucker simplification results in sharp bends at corners and unnatural-looking shapes. Turning this off produces sawtooth edges.

It would be good to have more 'natural'-looking smoothing, similar to the output produced (in raster form) by gdaldem.

There are some ideas in this thread (which is how I found gdal_trace_outline!). Right now I'm using a combination of ogr2ogr and Mapnik's line-smooth, which produces reasonable results, but it would be better to have it in gdal_trace_outline.

dstahlke commented 11 years ago

Richard,

Is the ugliness only apparent when you zoom in to the scale of individual pixels? It is my guess that this is the case. There is currently no option in gdal_trace_outline to do this directly. If your goal is to have a polygon that looks nice at this level of detail, then here is a proposed solution (untested):

  1. convert your image to a bitmap image (black and white, no gray)
  2. expand the resolution of this image by a factor of 10 or more (if this will fit in memory!) using your favorite type of interpolation (probably cubic or lanczos, definitely not nearest neighbor or linear).
    This can be done using gdalwarp, or your favorite image editor application. Optionally hit it with a Gaussian blur.
  3. threshold this image to again be black and white (no gray). The outline should hopefully be smooth.
  4. run gdal_trace_outline, trying various settings for the "-dp-toler" flag. Maybe set dp-toler to be equal to the amount you expanded the resolution by, or perhaps twice this amount.

If the ugliness is apparent at larger scales (not just at the scale of a couple of pixels) then something is wrong and you should send me a portion of your image that reproduces the problem.

There is a program called "potrace" (http://potrace.sourceforge.net/) that creates artistically nice looking vector images from bitmaps. I have never used it, but there is a possibility that it may work well for your purposes.

On 07/15/2013 10:28 AM, Richard Fairhurst wrote:

gdal_trace_outline is a godsend but tends to produce very jagged edges from SRTM data. Applying the Douglas-Peucker simplification results in sharp bends at corners and unnatural-looking shapes. Turning this off produces sawtooth edges.

It would be good to have more 'natural'-looking smoothing, similar to the output produced (in raster form) by gdaldem.

There are some ideas in this thread http://osgeo-org.1560.x6.nabble.com/gdal-dev-gdal-polygonize-and-polygon-edges-td5035292.html (which is how I found gdal_trace_outline!). Right now I'm using a combination of ogr2ogr and Mapnik's line-smooth, which produces reasonable results, but it would be better to have it in gdal_trace_outline.

— Reply to this email directly or view it on GitHub https://github.com/gina-alaska/dans-gdal-scripts/issues/2.