[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( ...
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:
I hope that information helps you out.
-Kelly
"Matthew " <mattin...@yahoo.com> wrote in message <iuouum$jtl$1...@newscl01ah.mathworks.com>...
"Kelly Luetkemeyer" wrote in message <iuvn0a$f00$1...@newscl01ah.mathworks.com>...
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 " <mattin...@yahoo.com> wrote in message <iv0l96$3kv$1...@newscl01ah.mathworks.com>...
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
"Kelly Luetkemeyer" wrote in message <iv1tab$hu9$1...@newscl01ah.mathworks.com>...