www.gusucode.com > map 案例源码 matlab代码程序 > map/ReadAndWriteTIFFFileContainingRPCMetadataExample.m
%% Read and Write TIFF File Containing RPC Metadata % This example shows how to read a file containing RPC metadata, modify the % file, and then write the file, including the RPC metadata in the new % file. To illustrate this process, the example first creates a sample TIFF % file containing RPC Metadata. %% Create a Sample TIFF File with RPC Metadata % Create a sample test TIFF file containing RPC metadata. For this test % file, create a toy image and a referencing object associated with the % image. % Copyright 2015 The MathWorks, Inc. myimage = zeros(180,360); latlim = [-90 90]; lonlim = [-180 180]; R = georefcells(latlim,lonlim,size(myimage)); %% % Create an |RPCCoefficientTag| metadata object and set some fields with % typical values. The toolbox uses the |RPCCoefficientTag| object to % represent RPC metadata in human readable form. rpctag = map.geotiff.RPCCoefficientTag; rpctag.LineOffset = 1; rpctag.SampleOffset = 1; rpctag.LineScale = 2; rpctag.SampleScale = 2; rpctag.GeodeticHeightScale = 500; %% % Write the image, the associated referencing object, and the % |RPCCoefficentTag| object to a file. geotiffwrite('myfile',myimage,R,'RPCCoefficientTag',rpctag) %% Read the Metadata and Image Data from the Sample TIFF File % Read the metadata and the image data from the test file. |geotiffinfo| % returns the RPC metadata in the GeoTIFFTags field of the structure % returned. info = geotiffinfo('myfile'); [imagedata, R] = geotiffread('myfile'); %% Write Modified Image Data and RPC Metadata to File % First modify the image data read from the file. For example, set all the % zero-valued pixels to 1 in the image. imagedata(imagedata==0)= 1; %% % Write the modified image to a file, along with the RPC metadata from % the original file. geotiffwrite('myfile2',imagedata,R,... 'RPCCoefficientTag',info.GeoTIFFTags.RPCCoefficientTag)