Extract the coordinates of shorelines and plot them

6 views (last 30 days)
Hi guys,
I am drawing a world map, and I would like to plot the outline of the coastlines on a specific portion of the map that I desire (e.g. north sea & the baltic).
In order to do this, I am using the INPOLYGON function, to draw a polygon that includes the desired coastlines, such that I can then extract their coordinates and plot them separately. However, this function seems to be removing the NaN values that are present in the original coordinate set, therefore the end result is that the islands become connected by a a line to the shorelines.
Therefore, is there any way to prevent this from happening?
(the code is below)
%Load Data
load coastlines
%Extract areas
%Coordinates
BalticUK_ECA = [-4 62 ; 15 62 ; 20 66 ; 26 66 ; 32.5 57 ; 0 48 ; -5 48 ; -5 50.25 ; -1 52 ;-4 57 ; -5 58 ;
-4 58 ; -4 62] ;
%Indices
[BalticUK_in, BalticUK_on] = inpolygon(coastlon, coastlat, BalticUK_ECA(:,1), BalticUK_ECA(:,2)) ;
%Extraction
BalticUK_lon = coastlon(BalticUK_in) ;
BalticUK_lat = coastlat(BalticUK_in) ;
%Figure
fig = figure ;
fig.Position = [ 100 100 1100 500 ] ;
%Plot
plot(coastlon, coastlat)
hold on
plot(BalticUK_ECA(:,1), BalticUK_ECA(:,2))
hold on
plot(coastlon(BalticUK_in), coastlat(BalticUK_in))
%Formatting
grid on
grid minor
ax = gca ;
ax.XLim = [-6 33] ;
ax.YLim = [47 67] ;
I have tried to edit the INPOLYGON function but it seems to be too difficult and dangerous in my opinion so I have left it as is. Any other ideas?
Thanks in advance for your help,
KMT.

Answers (0)

Community Treasure Hunt

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

Start Hunting!