Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
mapshow error

Subject: mapshow error

From: Katie

Date: 24 May, 2011 23:50:23

Message: 1 of 8

Hi everybody,
I am working with USGS Seamless Server data and have downloaded the .tif version of the available file types. When I try to plot the data using mapshow I receive the following messages:

??? Error using ==> readMapData>readImageAndWorldFile at 98
A worldfile, with a '.tfw' extension, must accompany the '.tif' file.

Error in ==> readMapData at 49
         [I, cmap, R, info] = readImageAndWorldFile(filename);

Error in ==> importFromFileAndSetDataArgs at 28
   [dataArgs, defaultDisplayType] = readMapData(fcnName, filename);

Error in ==> mapshow at 218
varargin = importFromFileAndSetDataArgs(mfilename, varargin{:});

First things first: the .tfw file is most definitely in the same directory as the .tif file. I've looked online for a solution, but to no avail. Only recently have I discovered the mapping toolbox and I may be making a very trivial mistake. Any help is much appreciated!

Subject: mapshow error

From: Kelly Luetkemeyer

Date: 26 May, 2011 17:54:06

Message: 2 of 8

"Katie" wrote in message <irhg7v$e2h$1@newscl01ah.mathworks.com>...
> Hi everybody,
> I am working with USGS Seamless Server data and have downloaded the .tif version of the available file types. When I try to plot the data using mapshow I receive the following messages:
>
> ??? Error using ==> readMapData>readImageAndWorldFile at 98
> A worldfile, with a '.tfw' extension, must accompany the '.tif' file.

Hi Katie,

I'd like to help you solve your problem, but I need additional information.

As background informaton, mapshow and geoshow can display a TIFF file but they require the .tfw world file in order to determine the spatial referencing information. A .tif file may also be a GeoTIFF file, which in most cases, the referencing information is available in the TIFF tags. However, if the referencing information is not available, the function attemps to obtain that from the .tfw world file.

Can you read the worldfile with the function, worldfileread, and provide the output from that function? It is possible that there is a permission problem with the file.

Do you know if the .tif file is a GeoTIFF file? You can determine that by using the function: geotiffinfo. If the function doesn't error, can you provide that information too?

What type of data from the seamless server did you download? Could you provide a link to the server and/or some reproduction steps? Is the data in the .tif file in projected coordinates?

And finally, what version of MATLAB are you using?

thanks,

-Kelly

Subject: mapshow error

From: Katie

Date: 26 May, 2011 20:40:23

Message: 3 of 8

"Kelly Luetkemeyer" wrote in message <irm43t$iav$1@newscl01ah.mathworks.com>...
> "Katie" wrote in message <irhg7v$e2h$1@newscl01ah.mathworks.com>...
> > Hi everybody,
> > I am working with USGS Seamless Server data and have downloaded the .tif version of the available file types. When I try to plot the data using mapshow I receive the following messages:
> >
> > ??? Error using ==> readMapData>readImageAndWorldFile at 98
> > A worldfile, with a '.tfw' extension, must accompany the '.tif' file.
>
> Hi Katie,
>
> I'd like to help you solve your problem, but I need additional information.
>
> As background informaton, mapshow and geoshow can display a TIFF file but they require the .tfw world file in order to determine the spatial referencing information. A .tif file may also be a GeoTIFF file, which in most cases, the referencing information is available in the TIFF tags. However, if the referencing information is not available, the function attemps to obtain that from the .tfw world file.
>
> Can you read the worldfile with the function, worldfileread, and provide the output from that function? It is possible that there is a permission problem with the file.
>
> Do you know if the .tif file is a GeoTIFF file? You can determine that by using the function: geotiffinfo. If the function doesn't error, can you provide that information too?
>
> What type of data from the seamless server did you download? Could you provide a link to the server and/or some reproduction steps? Is the data in the .tif file in projected coordinates?
>
> And finally, what version of MATLAB are you using?
>
> thanks,
>
> -Kelly

Hi Kelly,
Thanks for the reply! The output from the worldfileread function is:
ans =

         0 -0.0006
    0.0006 0
 -149.8336 68.7503

For the second question, it should be a GeoTIFF file. When I try geotiffinfo, the output is:

 geotiffinfo('68142844.tif')
Warning:
/home/user/GPRconductivitypermittivity/68142844.tif:
unknown field with tag 42113 (0xa481) encountered.

ans =

             Filename: [1x92 char]
          FileModDate: '25-May-2011 18:29:04'
             FileSize: 2708367
               Format: 'tif'
        FormatVersion: []
               Height: 450
                Width: 1500
             BitDepth: 32
            ColorType: 'grayscale'
            ModelType: 'ModelTypeGeographic'
                  PCS: ''
           Projection: ''
               MapSys: ''
                 Zone: []
         CTProjection: ''
             ProjParm: []
           ProjParmId: {}
                  GCS: 'NAD83'
                Datum: 'North American Datum 1983'
            Ellipsoid: 'GRS 1980'
            SemiMajor: 6378137
            SemiMinor: 6.3568e+06
                   PM: 'Greenwich'
    PMLongToGreenwich: 0
            UOMLength: ''
    UOMLengthInMeters: 1
             UOMAngle: 'degree'
    UOMAngleInDegrees: 1
            TiePoints: [1x1 struct]
           PixelScale: [3x1 double]
            RefMatrix: [3x2 double]
          BoundingBox: [2x2 double]
         CornerCoords: [1x1 struct]
         GeoTIFFCodes: [1x1 struct]

so there does appear to be information there. The warning always comes up too but it doesn't affect the display if I use imshow and I haven't found any information on it with a general Google search.

As for the source of the data, I used the seamless server viewer from the USGS, which can be found at http://seamless.usgs.gov/website/seamless/viewer.htm . I chose the option from the sidebar that allows you to download the data by coordinates for latitudes 68 degrees, 30 minutes (North) to 68 degrees, 45 minutes (North) and longitudes 149 degrees, 50 minutes (West) and 149 degrees, 0 minutes (West). When the pop-up screen shows up, I selected "Modify Data Request", switched to the National Elevation Data 2 arc-second option, and changed the data type to GeoTIFF, ZIP, HTML. Assorted other files come with the download besides just the .tif and the .twf, including METADATA in .shp (shaperead gives:
ans =

0x1 struct array with fields:
    Geometry
    BoundingBox
    X
    Y), .dbf, .prj, and .shx. I wasn't able to open the .dbf extension in a spreadsheet and I tried to open the .prj file to try to parse the projection (first time I've ever attempted to do this...I'm sure I will have a few hurdles to jump in the process, but I'm trying to figure out the Mathworks support solution http://www.mathworks.com/support/solutions/en/data/1-1P45MT/index.html?product=MG&solution=1-1P45MT as a guide) but received the error "Not a valid deployment project". My version of MATLAB is 7.10.0 (R2010a) and I'm just about at the end of what I know how to do.

Thank you!!
-Katie

Subject: mapshow error

From: Kelly Luetkemeyer

Date: 27 May, 2011 13:35:04

Message: 4 of 8

Hi Katie,

Thanks for your detailed response. I have all the information I need to find out the root cause of the problem.

The coordinates of the data are referenced to a geographic coordinate system, as indicated by this line:

 ModelType: 'ModelTypeGeographic'

You should use geoshow to display the data rather than mapshow.

The .tfw file is valid.

The file contains a gray scale image, with 32 bit-depth and is probably single class type.

Here are some workaround commands that should work for you:

[X, refmat, bbox] = geotiffread('/home/user/GPRconductivitypermittivity/68142844.tif');
figure
geoshow(X, refmat, 'DisplayType', 'surface')
% or you can use 'texturemap' rather than 'surface'

If geotiffread fails, then do the following:

X = imread('/home/user/GPRconductivitypermittivity/68142844.tif');
refmat = worldfileread('/home/user/GPRconductivitypermittivity/68142844.tfw')

I'll post again after I investigate the root cause and download some data from the server.

-Kelly

Subject: mapshow error

From: Kelly Luetkemeyer

Date: 27 May, 2011 14:53:05

Message: 5 of 8

Hi Katie,

I was able to download the same data from the seamless server and I'm using R2010a on a Windows machine. I used a Linux machine to unzip the file.

What type of machine are you using?

In R2010a, I cannot re-create the error that is in the email:
" A worldfile, with a '.tfw' extension, must accompany the '.tif' file."

However, this version of the Mapping Toolbox does not support single datatype directly in mapshow and geoshow. In later versions, we've enhanced the functions. You will need to read the data first.

These command should work for you, as mentioned in the previous post. Here I use the filename from my download:
filename = '45812951.tif';
[X,refmat,bbox] = geotiffread(filename);
X = double(X);
figure('renderer','zbuffer')
geoshow(X,refmat,'DisplayType','texturemap')

Since the coordinates are in latitude and longitude, you can view the data in a projected coordinate system. Here is one way:
figure('Renderer', 'zbuffer')
usamap(X, refmat)
geoshow(X,refmat,'DisplayType','texturemap')

Hopefully, this will help you out, but I'm still puzzled by the error message. Perhaps the data got corrupted from the server or the download or the unzip process?

-Kelly

Subject: mapshow error

From: Katie

Date: 27 May, 2011 20:32:04

Message: 6 of 8

"Kelly Luetkemeyer" wrote in message <irodsh$8m4$1@newscl01ah.mathworks.com>...
> Hi Katie,
>
> I was able to download the same data from the seamless server and I'm using R2010a on a Windows machine. I used a Linux machine to unzip the file.
>
> What type of machine are you using?
>
> In R2010a, I cannot re-create the error that is in the email:
> " A worldfile, with a '.tfw' extension, must accompany the '.tif' file."
>
> However, this version of the Mapping Toolbox does not support single datatype directly in mapshow and geoshow. In later versions, we've enhanced the functions. You will need to read the data first.
>
> These command should work for you, as mentioned in the previous post. Here I use the filename from my download:
> filename = '45812951.tif';
> [X,refmat,bbox] = geotiffread(filename);
> X = double(X);
> figure('renderer','zbuffer')
> geoshow(X,refmat,'DisplayType','texturemap')
>
> Since the coordinates are in latitude and longitude, you can view the data in a projected coordinate system. Here is one way:
> figure('Renderer', 'zbuffer')
> usamap(X, refmat)
> geoshow(X,refmat,'DisplayType','texturemap')
>
> Hopefully, this will help you out, but I'm still puzzled by the error message. Perhaps the data got corrupted from the server or the download or the unzip process?
>
> -Kelly

Hi Kelly,
I'm using a Linux machine both for the unzip and to run Matlab. I suppose there are many steps at which the data could have been corrupted - I'll just fool around with other datasets to see if I can reproduce that error out of curiosity. The commands do exactly what I was hoping to do and the finished product looks great. Thank you so much!
-Katie

Subject: mapshow error

From: Kirk

Date: 10 Jan, 2012 14:20:09

Message: 7 of 8

I have a similar issue, in that I am not sure which function to be using.

My understanding (from the help files) of geoshow() is that it is for lat lon data, and that mapshow() is for unprojected data.

I have a geotiff "foresttype" that when I run geotiffinfo I get:

 geotiffinfo('/Volumes/disk1/home1/kirkw/Desktop/grass_exports/foresttype.tif')
Warning:
/Volumes/disk1/home1/kirkw/Desktop/grass_exports/foresttype.tif:
unknown field with tag 42112 (0xa480) encountered.
Warning:
/Volumes/disk1/home1/kirkw/Desktop/grass_exports/foresttype.tif:
unknown field with tag 42113 (0xa481) encountered.

ans =

             Filename: [1x63 char]
          FileModDate: '09-Jan-2012 08:33:51'
             FileSize: 45921354
               Format: 'tif'
        FormatVersion: []
               Height: 4130
                Width: 5456
             BitDepth: 16
            ColorType: 'indexed'
            ModelType: 'ModelTypeProjected'
                  PCS: ''
           Projection: ''
               MapSys: ''
                 Zone: []
         CTProjection: 'CT_AlbersEqualArea'
             ProjParm: [7x1 double]
           ProjParmId: {7x1 cell}
                  GCS: 'NAD83'
                Datum: 'North American Datum 1983'
            Ellipsoid: 'GRS 1980'
            SemiMajor: 6378137
            SemiMinor: 6.3568e+06
                   PM: 'Greenwich'
    PMLongToGreenwich: 0
            UOMLength: 'metre'
    UOMLengthInMeters: 1
             UOMAngle: 'degree'
    UOMAngleInDegrees: 1
            TiePoints: [1x1 struct]
           PixelScale: [3x1 double]
           SpatialRef: [1x1 spatialref.MapRasterReference]
            RefMatrix: [3x2 double]
          BoundingBox: [2x2 double]
         CornerCoords: [1x1 struct]
         GeoTIFFCodes: [1x1 struct]
          GeoTIFFTags: [1x1 struct]

The output from worldfileread() is:

>> worldfileread('/Volumes/disk1/home1/kirkw/Desktop/grass_exports/foresttype.tfw')

ans =

   1.0e+06 *

         0 -0.0003
    0.0003 0
   -0.0785 1.5328

Which shows that the model type is projected (albersequalarea). but that the units are meters (not lat lon). Since the file is projected it seems that I should be using geoshow(), but it is not a lat lon file.

I also have a shape file projected in the same way that I need to overlay, and some netcdf data that I also need to project in the same way.

Subject: mapshow error

From: Rob Comer

Date: 11 Jan, 2012 02:13:07

Message: 8 of 8

"Kirk" <kwythers.nospam@umn.edu> wrote in message <jehhep$mio$1@newscl01ah.mathworks.com>...

> My understanding (from the help files) of geoshow() is that it is for lat lon data, and that mapshow() is for unprojected data.

This isn't quite right. Unprojected data and lat-lon data are the same thing, and can be displayed using geoshow. mapshow is for data sets that are already projected.


> I have a geotiff "foresttype" that when I run geotiffinfo I get:
>
> geotiffinfo('/Volumes/disk1/home1/kirkw/Desktop/grass_exports/foresttype.tif')
> Warning:
> /Volumes/disk1/home1/kirkw/Desktop/grass_exports/foresttype.tif:
> unknown field with tag 42112 (0xa480) encountered.
> Warning:
> /Volumes/disk1/home1/kirkw/Desktop/grass_exports/foresttype.tif:
> unknown field with tag 42113 (0xa481) encountered.
>
> ans =
>
> Filename: [1x63 char]
> FileModDate: '09-Jan-2012 08:33:51'
> FileSize: 45921354
> Format: 'tif'
> FormatVersion: []
> Height: 4130
> Width: 5456
> BitDepth: 16
> ColorType: 'indexed'
> ModelType: 'ModelTypeProjected'
> PCS: ''
> Projection: ''
> MapSys: ''
> Zone: []
> CTProjection: 'CT_AlbersEqualArea'
> ProjParm: [7x1 double]
> ProjParmId: {7x1 cell}
> GCS: 'NAD83'
> Datum: 'North American Datum 1983'
> Ellipsoid: 'GRS 1980'
> SemiMajor: 6378137
> SemiMinor: 6.3568e+06
> PM: 'Greenwich'
> PMLongToGreenwich: 0
> UOMLength: 'metre'
> UOMLengthInMeters: 1
> UOMAngle: 'degree'
> UOMAngleInDegrees: 1
> TiePoints: [1x1 struct]
> PixelScale: [3x1 double]
> SpatialRef: [1x1 spatialref.MapRasterReference]
> RefMatrix: [3x2 double]
> BoundingBox: [2x2 double]
> CornerCoords: [1x1 struct]
> GeoTIFFCodes: [1x1 struct]
> GeoTIFFTags: [1x1 struct]
>
> The output from worldfileread() is:
>
> >> worldfileread('/Volumes/disk1/home1/kirkw/Desktop/grass_exports/foresttype.tfw')
>
> ans =
>
> 1.0e+06 *
>
> 0 -0.0003
> 0.0003 0
> -0.0785 1.5328
>
> Which shows that the model type is projected (albersequalarea). but that the units are meters (not lat lon). Since the file is projected it seems that I should be using geoshow(), but it is not a lat lon file.

When a raster is projected, it is not in latitude-longitude; nothing seems inconsistent here. You should use mapshow, not geoshow, when the input data set is already projected. Please see my comment in this thread:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/315812

> I also have a shape file projected in the same way that I need to overlay, and some netcdf data that I also need to project in the same way.

As long as the shape file data and raster are in the same projected coordinate system, you should be able to be able to overlay the shape data by using a second call to mapshow.

Rob Comer
Mapping Toolbox Development
MathWorks

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us