Filter löschen
Filter löschen

Display netcdf data over specific country

2 Ansichten (letzte 30 Tage)
David du Preez
David du Preez am 18 Mär. 2019
Kommentiert: David du Preez am 4 Nov. 2019
I have a netcdf file containg data for a region over southern africa. I only want to plot the data over South Africa and not the rest of the region.
Using the borders function and changing the transparency I have almost got the map that I want except that the data is still displayed over the ocean. How can I mask out the ocean region
% Draw nc varibale on map of SA
ncfile = 'OMI-Aura_L3-OMUVBd_2004m1001_v003-2016m0525t164359.he5.nc';
long_uv = ncread(ncfile,'lon');
lat_uv = ncread(ncfile,'lat');
uvi = ncread(ncfile,'UVindex');
% Plot variable
[X,Y] = meshgrid(long_uv,lat_uv);
colormap jet
pcolor(X,Y,uvi');
shading interp
h= colorbar('horiz');
xlabel(h,'UVI');
hold on
% Plot SA map over variable
[lat,lon] = borders('south africa');
pgon = polyshape(lon,lat,'simplify',false);
plot(pgon,'FaceColor','none','FaceAlpha',0)
clear lat lon pgon
hold all
% Zimbabwe
[lat,lon] = borders('zimbabwe');
pgon = polyshape(lon,lat,'simplify',false);
plot(pgon,'FaceColor','white','FaceAlpha',1)
clear lat lon pgon
hold all
% Nambia
[lat,lon] = borders('Namibia');
pgon = polyshape(lon,lat,'simplify',false);
plot(pgon,'FaceColor','white','FaceAlpha',1)
clear lat lon pgon
hold all
% Botswana
[lat,lon] = borders('botswana');
pgon = polyshape(lon,lat,'simplify',false);
plot(pgon,'FaceColor','white','FaceAlpha',1)
clear lat lon pgon
hold all
% Mozambique
[lat,lon] = borders('mozambique');
pgon = polyshape(lon,lat,'simplify',false);
plot(pgon,'FaceColor','white','FaceAlpha',1)
clear lat lon pgon
% Lesotho
[lat,lon] = borders('lesotho');
pgon = polyshape(lon,lat,'simplify',false);
plot(pgon,'FaceColor','white','FaceAlpha',1)
clear lat lon pgon
% Swaziland
[lat,lon] = borders('swaziland');
pgon = polyshape(lon,lat,'simplify',false);
plot(pgon,'FaceColor','white','FaceAlpha',1)
clear lat lon pgon
  2 Kommentare
BN
BN am 4 Nov. 2019
I have a same problem bro, did you find any solution BTW?
David du Preez
David du Preez am 4 Nov. 2019
Yes. Get the latitudes and longtiudes of the countries using the borders function and then look at this answer https://ch.mathworks.com/matlabcentral/answers/486421-change-color-outside-region-of-polyshape

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by