File Exchange

image thumbnail


version (276 KB) by Chad Greene
Get a logical land mass corresponding to your data.


Updated 05 Dec 2014

View License

This function returns a logical array describing the landness of any given lat/lon arrays. Requires Matlab's Mapping Toolbox.
This function uses Matlab's built-in coast.mat file with inpolygons to determining whether input lat/lons are inside or outside perimeters of land areas.

land = landmask(lat,lon)
land = landmask(...,'landmass')
land = landmask(...,quality)

land = landmask(lat,lon) returns logical land array corresponding to the dimensions of input lat and lon. 1 is land, 0 is not land.

land = landmask(...,'landmass') specifies any of the following regions of mask:

'Africa and Eurasia'
'North and South America'
'Baffin Island'
'Ellesmere Island'
'New Guinea'
'Great Britain'
'Victoria Island'
'New Zealand North Island'
'New Zealand South Island'
'Devon Island'

land = landmask(...,quality) specifies quality from 0 to 100. This option is provided because for large data sets, the land mask function can take quite some time. For example, on my laptop, a calculating 180x360 land mask for all continents takes about 65 seconds at 100% quality. Default quality is 95, which takes about 6 seconds for the same dataset on my laptop. The quality setting is only used when calculating the land mask using all of the world's continents. For single land masses, 100% quality is assumed.

Cite As

Chad Greene (2020). landmask (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

Never mind c.long was right, the code was reading a different coast.mat in my path



Is it possible to mask other regions using this function? e.g Bali, Sumatra, etc

Vijay Sagar

Vijay Sagar

What are the units for each coordinate? Should I use -15 or 345 for 15W?

Chad Greene


Ha, indeed! Good catch!


In the examples in the documentation, I believe the long. for Topeka KS should be -95.69, not 95.69. (It is approx 95.69 West, not East).

The location (39.06,+95.69) is in western China, so
returns 1, but
landmask(39.06,95.69,'North and South America')
returns 0, and
landmask(39.06,95.69,'Africa and Eurasia')
returns 1.

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

Inspired by: How to map sea level rise, Post-glacial rebound

Inspired: borders