File Exchange

image thumbnail

landmask

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

21 Downloads

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.

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

Description
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:

'Antarctica'
'Africa and Eurasia'
'North and South America'
'Greenland'
'Australia'
'Baffin Island'
'Ellesmere Island'
'New Guinea'
'Great Britain'
'Borneo'
'Honshu'
'Victoria Island'
'Celebes'
'New Zealand North Island'
'Sumatra'
'Madagascar'
'Iceland'
'New Zealand South Island'
'Newfoundland'
'Luzon'
'Devon Island'
'Ireland'
'Cuba'
'Java'
'Mindanao'

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 (2021). landmask (https://www.mathworks.com/matlabcentral/fileexchange/48661-landmask), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)

Chad Greene

@Howard: You are correct. This dataset uses Matlab's default coastline, which is very coarse resolution, and even though the Antarctic outline is very common in many mapping programs, it's absolutely lousy. For example, this function returns true for the Filchner-Ronne Ice Shelf, but false for the Ross Ice Shelf.

A better dataset, and a much faster function is found in the "island" function in my Climate Data Toolbox for Matlab. That will return true for all ice shelves. If you want to distinguish between ice shelves and other Antarctic surface types, check out the isiceshelf and istidal functions in my Antarctic Boundaries package https://www.mathworks.com/matlabcentral/fileexchange/60246, which you could apply separately from the rest of your global dataset by processing everything north of 60S with island, and everything south of 60S with istidal or isopenocean.

Howard

This is a neat application; I used it to determine Land or Ocean for a global dataset with 10,512 pairs of geographic lat/lon combinations at a 2.5x2.5 degree resolution; it worked very well, but the values returned for large parts of Antarctica that are land (1), came back as Ocean (0). Not sure if this is because it considers the frozen water covering the land surface of Antarctica as ocean, but I was just wondering if anyone else has run into this.

Chad Greene

@Yukun Sun: With the Climate Data Toolbox for Matlab you can use the borders function to get coordinates of the borders of Hawaii, and inpolygon to determine if any points are inside the borders of Hawaii. Here's an example:

[Lat,Lon] = cdtgrid(0.1); % a grid of geo coords at 0.1 degree resolution
[lat,lon] = borders('hawaii');
hi = inpolygon(Lon,Lat,lon,lat);
imagescn(Lon,Lat,hi)

Yukun Sun

It looks like the coast.mat does not have data for Guam, Hawaii, and some small islands. I have some locations to be checked over Guam and Hawaii. Does anyone know how to resolve this?

Rodrigo Duran

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

A.B.R

A.B.R

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?

Rachel Weihs

Apurva Deshpande

Chad Greene

Ian,

Ha, indeed! Good catch!

Ian

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
landmask(39.06,95.69)
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
Acknowledgements

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

Inspired: borders

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

landmask/html/