File Exchange

image thumbnail


version (8.42 MB) by Aslak Grinsted
Reads a sub region of a geotiff or geojp2 image.


Updated 05 Nov 2015

View License

GEOIMREAD reads a sub region of a geotiff or geojp2 image.

% Syntax

A = geoimread(filename)
A = geoimread(filename,xlim,ylim)
A = geoimread(filename,latlim,lonlim)
A = geoimread(...,buffer)
[A,x,y,I] = geoimread(...)

% Description

A = geoimread(filename) returns the full image given by a filename. This
syntax is equivalent to A = geotiffread(filename).

A = geoimread(filename,xlim,ylim) limits the region of the geotiff file to
the limits given by xlim and ylim, which are map units (usually meters) relative
to the data projection. For example, if the geotiff is projected in Texas Centric
Mapping System/Lambert Conformal coordinates, xlim and ylim will have units of
meters relative to the origin (100 W, 18 N). xlim and ylim can be multimensional,
in which case the limits of the map will be taken as the limits of the limits of
the distribution of all points in xlim, ylim.

A = geoimread(filename,latlim,lonlim) if no values in xlim, ylim exceed
normal values of latitudes and longitudes, geoimread assumes you've entered
limits in geographic coordinates of degrees latitude and longitude. The first
input is latitude, the second input is longitude.

A = geoimread(...,buffer) adds a buffer in map units (usually meters or feet) to the
limits of the region of interest. This may be useful if you want to load an image
surrounding scattered lat/lon data. If you'd like an extra 2 kilometers of image around
your data, enter 2000 as the buffer. If buffer is a two-element vector, the first
element is applied to the left and right extents of the image, and the second element
is applied to the top and bottom extents of the image.

[A,x,y,I] = geoimread(...) also returns pixel center coordinates (x,y) of the
output image and a geotiff info structure I. I is a useful input for projfwd and projinv.

geoimread(...) without any outputs shows the output image A without loading
any data into the workspace.

% Examples:

% Show a whole geotiff:

% Compare results from above to a subset geotiff:
mapx = [765884 766035 766963]; % units are feet
mapy = [2959218 2957723 2958972];

% Or if you have coordinates in lat/lon and you want a 500 foot buffer:
lat = [42.3675288 42.3634246 42.3668397];
lon = [-71.0940009 -71.0934685 -71.0900125];


Cite As

Aslak Grinsted (2020). geoimread (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (13)

Meg Noah

I am receiving the same error as Andre Luiz when trying to read Sentinel 2 .jp2 files. The error occurs because the value of 'lbox' is empty. In my case it occurs on the fifth call to fseek within the while loop that starts on line 278, i.e. it occurs on the fifth call to fread. An alternative solution is to use the SNAP program (or gdal) to export the .jp2 files to geotiff, and then use geotiffread.

I am trying to open geo info from jp2 images took from Sentinel 2 satellite. I am getting the following error:
Error using fseek
Invalid offset.

Error in geoimread>jp2tiffinfo (line 303)

Error in geoimread (line 125)
I = jp2tiffinfo(filename);

Error in Test (line 3)
A = geoimread('temp\T22KGA_20190331T132239_B04_10m.jp2')

when I run the function I'm getting the following error:

undefined function or variable robustgeotiffinfo
error in y1>geoimread (line 32)
I = robustgeotiffinfo (filename);
error in y1(line 6)
t = geoimread('SVDNB_npp_20150201-20150228_75N060W_vcmcfg_v10_c201504281504.avg_rade9h');
and I couldn't fix it if you could help me please ..

thank you.

shuai li

Very useful. Thanks so much.

Shunan Feng

This is a really useful function, thanks! One thing I noticed is that I.SpatialRef.CellExtentInWorld values come out different if I use geoimread from if I use geotiffinfo. I'm not quite sure why this should be, as geoimread uses geotiffinfo to get I in the first place. I wonder if you have any ideas?



Works quick, simple, and moreover: correct. Love it.


Added some workarounds to make some of the functionality work without mapping toolbox.

Further improvements from Chad Greene: Added html example

Renamed and added Misc improvements from Chad Greene:
* More input checking and error messages.
* Clarified syntax and description in header.
and more...

changed description to better reflect the geo jpg2000 features.

added ability to read geojp2 files

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux