MATLAB Answers

Extract data from NetCDF based on a country border- using X and Y points of country - How to do?

18 views (last 30 days)
Behzad Navidi
Behzad Navidi on 2 Nov 2019
Edited: Behzad Navidi on 3 Nov 2019
Hey all,
I know how to extract data for a range of latitude and longitude from a NetCDF file. Doing this is leading me to have a rectangular on my study region, which some part of it has been offside. Some pixels are outside of the country. See the below figure:
the red line is country borders, and you'll see some pixel are outside.
I tried do overcome this problem and found a shapefile of the country that contains bounding box and X, Y data of all across the boundary.
Now I want to ask you how to use this X and Y (in the 1x1 struct with six fields) to cut my study region from the NetCDF file precisely. or set every pixel outside of the border to NaN.
I'll attach shapefile and my code to read the NetCDF file.
lon = ncread(filename,'longitude'); %reading longitude
lat = ncread(filename,'latitude'); %reading latitude
precipitation = ncread(filename,'precip'); %main variable (3d)
t = ncread(filename,'time'); %read time
precipitation size is : lon x lat x t
So, in summary, I want to know how to set NaN values for any pixel outside of country.
-Thank you


Sign in to comment.

Answers (0)

Sign in to answer this question.