Distinguish land from ocean in harbors

31 views (last 30 days)
Henrik Rohde Nordhus
Henrik Rohde Nordhus on 19 Oct 2022
Commented: Kurt on 4 Feb 2025 at 14:50
I'm trying to distinguish land from ocean in harbors and have tried using the highest resolution maps from gshhs, but it isn't detailed enough. Below are is an example showing that it isn't detailed to the level I want. The one to the left showing th coastline boundaries and the other one showing the geoplot with basemap = 'streets'
Since the map is able to plot in such detail, shown below, I would imagine that it should be able to distingusih land from ocean, just based on the colors.
Appriciate any help here! Thanks in advance.

Answers (2)

Avni Agrawal
Avni Agrawal on 17 Nov 2023
Hi,
I understand that you want to distinguish land and ocean in different color. The 'streets' basemap in MATLAB automatically distinguishes land from ocean by using different colors.
For example, you can use the GSHHS dataset or another high-resolution shoreline dataset to add a coastline to your map. You can then use the 'geoplot' function to display the coastline in a contrasting color.
% Define the latitude and longitude limits of the area of interest
latlim = [33.70 33.78]; % limits for Port of Los Angeles
lonlim = [-118.28 -118.22]; % limits for Port of Los Angeles
% Create a geographic axes and set the basemap to 'streets'
ax = geoaxes;
geobasemap(ax, 'streets');
geolimits(latlim, lonlim)
% Load the GSHHS coastline data and display it on the map
load coastlines
% Add some data to the map (replace this with your own data)
geoplot(ax, [33.73 33.75], [-118.25 -118.24], 'k')
In this code, 'geoaxes' is used to create a geographic axes, `geobasemap` is used to set the basemap to 'streets', and `geolimits` is used to set the latitude and longitude limits of the map. The `load` command is used to load the GSHHS coastline data, and `geoplot` is used to display the coastline on the map.
Please note that the `coastlines` data loaded by MATLAB might not be as high resolution as you need. You would need to replace that with your own high-resolution coastline data.
If you want to distinguish land from ocean more clearly, you could consider using a different basemap that provides more contrast, such as 'satellite' or 'topographic'. You can set the basemap using the `geobasemap` function, like this: `geobasemap(ax, 'satellite');`
% Define the latitude and longitude limits of the area of interest
latlim = [33.70 33.78]; % limits for Port of Los Angeles
lonlim = [-118.28 -118.22]; % limits for Port of Los Angeles
% Create a geographic axes and set the basemap to 'streets'
ax = geoaxes;
geobasemap(ax, 'satellite');
geolimits(latlim, lonlim)
% Load the GSHHS coastline data and display it on the map
load coastlines
% Add some data to the map (replace this with your own data)
geoplot(ax, [33.73 33.75], [-118.25 -118.24], 'k')
Please take a look at this documentation for better understanding:
I hope this helps.
  6 Comments
Kurt
Kurt on 4 Feb 2025 at 14:33
I'm working with digital data. The satellite scans a patch of the Earth and sends back the lat and lon coordinates of each sample point in a 571 x 318 array.
I wanted to use the isinterior() function to tell if a point is inside or outside the shoreline, but it doesn't work with geoaxis data. So in a flash of inspiration I decided to ditch the geoaxis projections and just go with a simple axis, projecting lat and lon on a Mercator map. It works.
gx = axes;
load coastlines;
coast = polyshape(coastlon, coastlat)
plot(gx, coast);
Then as you cycle through each satellite lat/lon array, you call isinterior:
idxLand = isinterior(coast,lon,lat);
landlon = lon(idxLand);
landlat = lat(idxLand);
It works like a charm, without resorting to geo data.

Sign in to comment.


Image Analyst
Image Analyst on 17 Nov 2023
If you want to deal with your picture as a digital image, then you can segment out the water using the Color Thresholder app on the apps tab of the tool ribbon. You can export the function that makes a binary map of the water and then use that to make the water pixels any color that you want. Let me know if you can't figure it out.

Categories

Find more on Geographic Plots in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!