mparkan / Digital-Forestry-Toolbox

A collection of digital forestry tools for Matlab/Octave
http://mparkan.github.io/Digital-Forestry-Toolbox/
GNU General Public License v3.0
46 stars 16 forks source link

ASCread error - Vertical dimension mismatch #2

Closed jakubchr closed 5 years ago

jakubchr commented 5 years ago

Hello,

I am running Octave version 4.4.1 x86_64-w64-mingw32. I have a problem with reading ASC file. I get an error related to ASCRead.m

error: vertical dimensions mismatch (2x1 vs 0x2)
error: called from
    ASCread at line 84 column 8

Here's my script:

addpath(genpath('D:\Octave-4.4.1\DFT\'))

clc
clear
close all

OCTAVE_FLAG = (exist('OCTAVE_VERSION', 'builtin') ~= 0); % determine if system is Matlab or GNU Octave

if OCTAVE_FLAG

    pkg load statistics
    pkg load image
    pkg load io
    pkg load mapping
    more off

end

[chm, refmat] = ASCread('E:\chmASC.asc')

My ASC file is zipped in the attachment. OCTAVE.zip

Thank you! Jakub

mparkan commented 5 years ago

Hello,

it looks like your ASC file has "dx" and "dy" fields in the header which are not currently supported by the ASCread() function.

GDAL does allow the creation of ASC files with "dx" and "dy" attributes for Golden Surfer software (https://www.gdal.org/frmt_various.html), but the standard ESRI grid ASC format does not support non-square pixels and only uses a "cellsize" attribute in the header to define the grid resolution: https://en.wikipedia.org/wiki/Esri_grid

An easy fix, since your pixels are practically square and your dataset covers a small extent, is to replace the following two lines in the header of your file (using a text editor):

dx           0.500043870159
dy           0.499967850811

By

cellsize     0.500043870159

I might add compatibility for Golden Surfer grids in the future.

Cheers Matt

jakubchr commented 5 years ago

Will try that. Thank you!

Jakub