Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

geotiffwrite

773 views
Skip to first unread message

Matthew

unread,
Jul 3, 2011, 1:33:10 AM7/3/11
to
Hi, I am having a bit of trouble with geotiffread and geotiffwrite. Seems like it should be easy to use both...Here's my code:

[x,r]=geotiffread('boston.tif');
geotiffwrite('outfile.tif',x,r);

but this code does not work. the result is shown below.
Suggestions appreciated !
Thanks Matt

-----
??? Error using ==> geotiffwrite>validateR at 967
The input, R, is a spatialref.MapRasterReference object indicating that you
are working in a projected coordinate system. If so, then specify a
projected coordinate system by setting the appropriate values for the
'CoordRefSysCode' or 'GeoKeyDirectoryTag' optional parameters.

Error in ==> geotiffwrite>validateInputs at 353
R = validateR(R, size(A), hasColorMap, type);

Error in ==> geotiffwrite at 233
[filename, A, cmap, R, Params] = validateInputs( ...

Kelly Luetkemeyer

unread,
Jul 5, 2011, 3:00:26 PM7/5/11
to
Hi Matthew,

In response to your question:

> I am having a bit of trouble with geotiffread and geotiffwrite. Seems like it should be easy > to use both...Here's my code:
>
> [x,r]=geotiffread('boston.tif');
> geotiffwrite('outfile.tif',x,r);
>
> but this code does not work.

It would seem natural that the code would work as listed. Indeed it would work as listed above if the coordinates of the image in the boston.tif file were geographic. However, the coordinates are in a projected coordinate system. In thise case, you need to specify additional information to write the file correctly, as indicated by the error message. You need to supply the projection information which can be obtained from the function GEOTIFFINFO.

Here is what you can do:

[X, R] = geotiffread('boston.tif');
info = geotiffinfo('boston.tif');
geotiffwrite('outfile.tif', X, R, ...
'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);

You can see more details in the demo "Exporting Images and Raster Grid to GeoTIFF" found in the section, "Example 4: Write a Cropped Imagefrom a GeoTIFF File" shown here:

http://www.mathworks.com/products/mapping/demos.html?file=/products/demos/shipping/map/mapexgeotiff.html#24

I hope that information helps you out.

-Kelly

"Matthew " <mattin...@yahoo.com> wrote in message <iuouum$jtl$1...@newscl01ah.mathworks.com>...

Matthew

unread,
Jul 5, 2011, 11:08:07 PM7/5/11
to
Thanks that is indeed very helpful ! - Matt

"Kelly Luetkemeyer" wrote in message <iuvn0a$f00$1...@newscl01ah.mathworks.com>...

Matthew

unread,
Jul 5, 2011, 11:37:10 PM7/5/11
to
Hi, I've run into another problem with my geotiff file, which is somewhat different than the boston.tif file.
In my file, there is no GeoTiffTags.
Below, I am showing the result from geotiffwrite.
When I used the command [x,R]=geotiffread(...) it comes back with R=[].
So how should I use the geotiffwrite command?
Thanks Matt

Filename: [1x107 char]
FileModDate: 'XX'
FileSize: 259071
Format: 'tif'
FormatVersion: []
Height: 178
Width: 361
BitDepth: 32
ColorType: 'grayscale'
ModelType: 'ModelTypeProjected'
PCS: 'WGS 84 / UTM zone XXN'
Projection: 'UTM zone XXN'
MapSys: 'UTM_NORTH'
Zone: XX
CTProjection: 'CT_TransverseMercator'
ProjParm: [7x1 double]
ProjParmId: {7x1 cell}
GCS: 'WGS 84'
Datum: 'World Geodetic System 1984'
Ellipsoid: 'WGS 84'
SemiMajor: 6378137
SemiMinor: 6.3568e+06
PM: 'Greenwich'
PMLongToGreenwich: 0
UOMLength: 'metre'
UOMLengthInMeters: 1
UOMAngle: 'degree'
UOMAngleInDegrees: 1
TiePoints: [1x1 struct]
PixelScale: [3x1 double]
RefMatrix: [3x2 double]
BoundingBox: [2x2 double]
CornerCoords: [1x1 struct]
GeoTIFFCodes: [1x1 struct]

---

Matthew

unread,
Jul 5, 2011, 11:47:11 PM7/5/11
to
Also I just noticed that the command geotiffinfo('boston.tif') doesn't appear to have GeoTiffTags either. So there seems to be a problem with that example.
Thanks Matt

"Matthew " <mattin...@yahoo.com> wrote in message <iv0l96$3kv$1...@newscl01ah.mathworks.com>...

Kelly Luetkemeyer

unread,
Jul 6, 2011, 11:00:27 AM7/6/11
to
Hi Matt,

In response to your question:

> Also I just noticed that the command geotiffinfo('boston.tif') doesn't appear to have

> GeoTiffTags either. So there seems to be a problem with that example.

What version of MATLAB are you running?

Would you mind sending the output of

version

and

v = ver('map')

GEOTIFFWRITE was included in R2011a in the Mapping Toolbox. This version also included the new field, GeoTIFFTags, in the output of GEOTIFFINFO.

If you are running R2011a, you should see the following:

info = geotiffinfo('boston.tif')

Filename: [1x88 char]
FileModDate: '13-May-2011 22:28:45'
FileSize: 38729900
Format: 'tif'
FormatVersion: []
Height: 2881
Width: 4481
BitDepth: 8
ColorType: 'truecolor'
ModelType: 'ModelTypeProjected'
PCS: 'NAD83 / Massachusetts Mainland'
Projection: 'SPCS83 Massachusetts Mainland zone (meters)'
MapSys: 'STATE_PLANE_83'
Zone: 2001
CTProjection: 'CT_LambertConfConic_2SP'


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: 'US survey foot'
UOMLengthInMeters: 0.3048


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]
ImageDescription: '"GeoEye"'

thanks,
-Kelly

Matthew

unread,
Jul 6, 2011, 11:40:28 AM7/6/11
to
Thanks Kelly! Now I am at work and I find that it is working now, as you write. So I guess I must have used on older version on my home computer.
- Matt


"Kelly Luetkemeyer" wrote in message <iv1tab$hu9$1...@newscl01ah.mathworks.com>...

Alison W.

unread,
Mar 14, 2017, 2:53:08 PM3/14/17
to
Hi Kelly et al,

My problem is a variation on this theme. I need to write out data in a GeoTIFF format that will be read by another application, specifically Quick Terrain Viewer. When I use the example below, I can write and read the new file in MATLAB but not in my other application. (Error is something about an unrecognized format)

Any suggestions are welcome

-Alison
0 new messages