Question

I'm trying to use USGS DEMs in MATLAB but after reading it in with geotiffread, mapshow produces an error. Based on the documentation, I tried

[A, R] = geotiffread('NED_10340081')
figure
mapshow(A, R);

but I get

Error using mapshow
Expected input number 1, I or X or RGB, to be one of these types:

uint8, uint16, double, logical

Instead its type was single.

Error in validateMapRasterData>parseImageInputs (line 109)
validateattributes(A, {'uint8', 'uint16', 'double', 'logical'}, ...

Error in validateMapRasterData>validateImageComponent (line 93)
[A, R] = parseImageInputs(mapfcnname, dataArgs{:}, cmap, rules );

Error in validateMapRasterData (line 27)
[Z, SpatialRef] =  validateImageComponent(mapfcnname, ...

Error in maprastershow (line 127)
[Z, SpatialRef, displayType, HGpairs] = ...

Error in mapshow (line 231)
h = showFcn(varargin{:});

My matrix A is of type single...is that the problem? and how do I fix this? Here is a download link for the DEM http://snowserver.colorado.edu/pub/fromDominik/NED_10340081.zip Thanks PS I crossposted this at http://www.mathworks.com/matlabcentral/answers/38255-display-usgs-dem-using-geotiffread-and-mapshow

Was it helpful?

Solution 2

I finally figured it out. geotiffread gives a matrix type 'single' but mapshow defaults to show an image which only accepts type 'double' (and some others). So the solution here is to either:

A=double(A);

or

mapshow(A,R,'DisplayType','surface');

OTHER TIPS

Specifying DisplayType is necessary because Matlab distinguishes "images" from continuous raster data. Matlab has an entire Image Processing Toolbox as well as a Mapping Toolbox with distinct functions in each that are often complimentary but come from different development backgrounds. Matlab supports "images" in logical, uint8, uint16, and double class types, and raster (grid) data in single and double.

Also your solution to use 'DisplayType','surface' only worked in your case because you had 'single' data. If, for example, you had created a geotiff image in ArcGis and then tried to read it into Matlab it would come in as int16 and you would get the same error when trying to use mapshow or geoshow, but the 'DisplayType','surface' would not work in this case because that DisplayType does not accept int16. Your solution to convert to double is more general.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top