Effacer les filtres
Effacer les filtres

Display netcdf data over specific country

5 vues (au cours des 30 derniers jours)
David du Preez
David du Preez le 18 Mar 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 commentaires
BN
BN le 4 Nov 2019
I have a same problem bro, did you find any solution BTW?
David du Preez
David du Preez le 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

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by