How to change land data to NaN?

Hi,
I have plotted a bathymetry and now I'm given coastline and some islands files where I need to use them to define where the land is and then turn the land data to NaN.
How should I do that?
Thanks, Eve

4 Comments

Eve - what is the nature/format of your coastline and islands files? How is this related to your plotted bathymetry data?
Hi Geoff,
I have included my land data in the volume calculation and now my lecturer gave me the xyz files of the land data (i.e. both coastline and islands file). I was asked to use the all those files into my matlab script to tell matlab not to included the land data into the calculation. So, now I do not know how to tell matlab about that. Any ideas?
Thanks,
Eve
Eve - how do you (currently) calculate the volume? What information do you use for that?
Hi Geoff,
I use:
dx*dy*zi(~isnan(zi))
However, my zi includes both land and sea data. So now, I need to remove the land data before I could calculate the volume of bathymetry. I don't know how to tell matlab that my land data are those that falls below the coastline (please see image below)
Thanks,
Eve

Sign in to comment.

Answers (2)

Kelly Kearney
Kelly Kearney on 27 Oct 2014
The inpolygon function will do most of the work. Depending on the scale of your region and the format of the coastlines, you may need to close off polygons, reverse order of vertices, and upsample polygons in order to get the best results; the Mapping Toolbox has several functions ( flatearthpoly, interpm, ispolycw, poly2cw) to help with that.

6 Comments

interpm2 may be used to densify polygons to a given spacing in meters or kilometers.
Hi Chad,
The above image is the bathymetry plot that I've obtained. I was asked to remove the land data (i.e. the data that falls below the coastline) before calculating the volume of my bathymetry.
Any idea how should I do it? I've tried using ginput to select points of an irregular area but I do not know how to proceed from those points selected and making it into an area that I can subtract it from.
Thanks, Eve
Have you looked at inpolygon, as I suggested?
Hi Kelly,
I have looked into that, but I'm still unsure how should I put it into my script. Could you please advise me?
Please find attached my script.
p/s: i find my volume by vol=dx*dy*sum(zi_diff(~isnan(zi_diff) & zi_diff>=1)); %line 84
However, my lecturer do not want me to use *zi_diff>=1* to define the land data. He wants me to find the indices of xi,yi,and zi_diff that falls under the coordinates of coastline. After that, I sub the indices back into the matrix of xi,yi,zi_diff to get the value before I could calculate the volume of the bathymetry. I'm guessing I need to do a loop for that, but I've been trying and still fail.
Hope to hear from you soon! Really need to get this done!
Thanks, Eve
Hi Kelly,
sorry I just realized I forgot to attach my script. :)
Can you upload the coastline file? The answer will depend on whether it contains just the visible line segments you plotted above, or fully-closed polygons. Assuming it's the latter, your code to mask the land points will look something like:
isin = inpolygon(xi, yi, xcoast, ycoast);
zi_diff(isin) = NaN;
But you may need to do some processing of xcoast and ycoast to convert them to closed, clockwise polygons.

Sign in to comment.

Chad Greene
Chad Greene on 5 Dec 2014
Another solution is the landmask function on File Exchange.

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Asked:

on 27 Oct 2014

Answered:

on 5 Dec 2014

Community Treasure Hunt

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

Start Hunting!