2

I have an image with the worldfile like this:

0.298582141739
0.000000000000
0.000000000000
-0.298582141739
1283836.327077804830
6134835.890168172310

I think it is the projected coordinate system. I want to convert it to geographic coordinate system, because I want to know the latitude/longitude of each pixel of the image. How to convert that? I check the worldfileread in the matlab, it can read both. But I did not find how to convert.

Could anyone know about that?

0

2 Answers 2

1

The world file encodes the Northing (N) and Easting (E) values relative to a UTM grid, sub-region of the earth in the Universal Transverse Mercator coordinate system.

The wikipedia page for UTM provides the conversions: https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system#Notation

See specifically the section on From UTM coordinates (E,N,Zone,Hemi) to latitude, longitude for the conversion.

1
  • Can you add the relevant part of the wiki page to your answer?
    – JonasV
    Commented Oct 20, 2020 at 9:14
0

The world file format indicates the Northing and Easting values, the last two lines, should be UTM.

Conversion would depend on what software you're using. You indicate MATLAB, so this m-script at the File Exchange would probably work for you:

https://www.mathworks.com/matlabcentral/fileexchange/37605-utm2latlong-geotiff-converter/content/utm2latlong.m

function utm2latlong(source,output,tfwFlag,zone,varargin)

%UTM2LATLONG - converts a tiff file from UTM coordinates into a Lat/Long
%GeoTIFF
%
% This tool converts a UTM GeoTIFF, or tiff with corresponding UTM world
% file, into a Lat/Long GeoTIFF. This function does not require any of
% MATLAB's Mapping Toolbox functions. It uses MATLAB's base functions to
% rewrite the file in the Lat/Long projection. The source tiff file is read
% in and a new GeoTIFF is created with the geographic directory
% information.
%
% However, this function does utilize a few functions currently found on
% MATLAB's File Exchange website (see Required Subfunctions). You should be
% able to search and download these functions on the File Exchange website
% and then run this tool.
%
% Required Subfunctions:
%   geotiffwrite.m by Jimmy Shen (File ID: #27959)
%   utm2ell.m by Mike Craymer (included in his Geodetic Toolbox #15285)
%   rad2deg.m by Mike Craymer (included in his Geodetic Toolbox #15285)
%
% Inputs:
%   source   - string; path to source GeoTiff
%   output   - string; path to output GeoTiff
%   tfwFlag  - logical; indicates whether an accompanying world file is
%                       located in the same directory
%   zone     - scalar; UTM zone (e.g. 4 to indicate Oahu)
%   x_pixel  - scalar; pixel scaling in the x-direction
%   y_pixel  - scalar; pixel scaling in the y-direction (almost always negative)
%   Easting  - scalar; Easting (upper left corner)
%   Northing - scalar; Northing (upper left corner)
%
% Usage:
%   utm2latlong(source,output,tfwFlag,zone,[x_pixel,y_pixel,Easting,Northing])
%
% Example:
%   Consider the NOAA landsat GeoTiff for Oahu found on the following website:
%   http://www.soest.hawaii.edu/coasts/data/oahu/landsat.html
%   It's projection is in UTM coordinates. It has a corresponding .tfw
%   world file. The following converts the file to a Lat/Long GeoTiff:
%
%     source = 'C:\GIS\OAHU\oahu.tif';
%     output = 'C:\GIS\LatLong\oahu_LL.tif';
%     tfwFlag = 1;  % .tfw file included
%     zone = 4;
%     utm2latlong(source,output,tfwFlag,zone);

% Ver. 1.0
% July 23, 2012

% NOTE: MATLAB's imread function does not read in the coordinate
% information from geotiff files.  Thus, a corresponding world file  (.tfw)
% must accompany the .tif file or you must know the information (x_pixel,
% y_pixel, Easting, Northing).

if nargin < 4
    disp('Not enough input arguments. Type help utm2latlong for more information.')
    return
end

%% Get data from .tif and .tfw files
Info = imfinfo(source);
data = imread(source);
if tfwFlag
    % Load .tfw world file
    source_tfw = [source(1:end-3) 'tfw'];
    world_file_data = load(source_tfw);
    % From .tfw world file, we know the pixel scaling and UTM coordinates
    x_pixel = world_file_data(1);   % pixel scale in x-direction
    rot1 = world_file_data(2);      % rotation about y-axis
    rot2 = world_file_data(3);      % rotation about x-axis
    y_pixel = world_file_data(4);   % pixel scale in y-direction
    E1 = world_file_data(5);        % Easting (upper left pixel)
    N1 = world_file_data(6);        % Northing (upper left pixel)
else
    % Check the number of input arguments
    if nargin ~= 8
        disp(['The number of inputs does not match what was expected. ',...
            'Type help utm2latlong for more information.'])
        return
    end
    % Read data from input
    x_pixel = varargin(1);
    y_pixel = varargin(2);
    E1 = varargin(3);
    N1 = varargin(4);
end

% Check that there is no rotation
if (rot1 ~= 0) || (rot2 ~= 0)
    disp('Rotation detected in the .tfw file.  Rotations are not supported.')
    return
end

%% Calculate extent of the image in UTM coordinates
E2 = E1 + x_pixel*Info.Width;
N2 = N1 + y_pixel*Info.Height;

% Convert to lat/long
[lat1,long1] = utm2ell(N1,E1,zone);
lat1 = rad2deg(lat1);
long1 = rad2deg(long1);
[lat2,long2] = utm2ell(N2,E2,zone);
lat2 = rad2deg(lat2);
long2 = rad2deg(long2);

%% Create geotiff file
% (We could use the make_option GUI that comes with the geotiffwrite.m file,
% but to save time this has already been done. The data below is the output
% from calling make_option.)
% [option bbox] = make_option([long1, lat2; long2, lat1]);
bbox = [long1, lat2; long2, lat1];
option.GTModelTypeGeoKey = 2;       % Geographic latitude-longitude System 
option.GTRasterTypeGeoKey = 1;      % Raster pixel is area
option.GeographicTypeGeoKey = 4326; % Geographic Coordinate System - WGS84
option.GTCitationGeoKey = 'Created using the geotiffwrite.m matlab function';
option.FullColor = 1;
geotiffwrite(output, bbox, data, 16, option)

disp(['File saved to: ',output]);

(Code included in case the link goes stale. Full credit to the author Kyle Mayer. Code license)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.