[Gdal-dev] [GDAL_Contours]Different gridcellsizes

Frank Warmerdam warmerdam at pobox.com
Thu Mar 2 23:11:51 EST 2006


Paul Meems wrote:
> Hi,
>  
> This is my first post to this list.
>  
> I'm a member of the MapWindow Developing Team (www.mapwindow.org 
> <http://www.mapwindow.org>) and MapWindow (MW) is using GDAL.
> One of the used functions of GDAL is the 'Generate Contours from Grid'.
> Regarding this function I have some questions.
>  
> I want to use it to convert Surfer 7 gridfiles (www.goldensoftware.com 
> <http://www.goldensoftware.com>) to shapefiles. Using the current 
> GDAL_Contour function it is allmost working. A shapefile is produced but 
> because Surfer uses different gridcellsizes for X and Y the created 
> contours are shifted.
> So my question is can GDAL_Contour be altered so it can handle different 
> gridcellsizes?
>  
> The difference between a 'normal' gridfile and a gridfile with different 
> gridcellsizes is in the header:
>  
> A normal gridfile:
> NCOLS 96
> NROWS 83
> XLLCENTER 200022.735
> YLLCENTER 598252.6382
> CELLSIZE 3.49626421052656
> NODATA_VALUE -99
>  
> A different gridcellsizes gridfile:
> NCOLS 96
> NROWS 83
> XLLCENTER 200022.735
> YLLCENTER 598252.6382
> DX 3.49626421052656
> DY 3.50804024390172
> NODATA_VALUE -99
>  
> Notice the DX and DY lines comparing with the CELLSIZE line in the equal 
> one.
> The new gridobject in MW is handling this correctly.

Paul,

I got the impression from your message, and the bugzilla entry at
MapWindow that the core problem was with handling of non-square pixels
in the contour algorithm.  But I tested that and it seemed fine.

What I did find was that the AAIGRID (ASCII Arc/Info Grid) driver
was not support files with DX and DY instead of CELLSIZE.   So I
corrected that in CVS.  The gdal_contour commandline utility now
generates contour lines properly for the grid_with_different_gridsizes.asc
file in your test dataset.

While looking into this, I also saw problem with the nodata handling in
your file.  It turns out -99 was an "interval level" so the contour
algorithm was altering it slightly.  This then defeated the nodata value
check.  So I modified the contour algorithm to not perturb "interval values"
that match the nodata value.

I see also that your .ASC files are floating point, but misidentified
as integer before the bunch of initial values checked are all nodata.
This has been a very long standing flaw in the AAIGRID driver.  For
now you can manually edit the .asc file and add a ".0" after the first
pixel value (ie. change -99 to -99.0) to get it recognised as a floating
point file.

I would like a better fix for this, but I'm still not sure how to avoid
having to read the whole file to see if there are any non-integer values.
And I hate having to read the whole file on open if I can avoid it.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGF, http://osgeo.org




More information about the Gdal-dev mailing list