How select/crop geographic region on the basis of lat/lon values?
5 views (last 30 days)
Show older comments
Kamran Afroz
on 7 Jul 2023
Edited: Pranavkumar Mallela
on 27 Jul 2023
I want to select/crop region on the basis of lat/lon.
I have geographical data with dimensions of lat,lon and time from which I want to crop a region using four lat/lon(e.g. LAT: 13,18; LON: 73,76) points like a rectangle.
I have attached my sample data for reference.
Can anyone help me with this problem?
0 Comments
Accepted Answer
Pranavkumar Mallela
on 7 Jul 2023
Edited: Pranavkumar Mallela
on 27 Jul 2023
Hi,
As per my understanding, you are trying to crop a region that is part of the sample data, which includes the 'rf' value over a 100x100 area and 48 time instances.
First use 'ncread' to read the 'rf' variable from the above attached file in the following way:
rf = ncread("test.nc", 'rf');
The variable 'rf' is a 100x100x48 double matrix. To crop a certain geographical region at a given time 't', you can use the following code:
cropped_region = rf(13:18, 73:76, t); % at a given time 't'
For more information regarding selection of data from a matrix, you can refer the following documentation: https://www.mathworks.com/help/matlab/math/array-indexing.html
Hope this helps! Thanks!
3 Comments
Pranavkumar Mallela
on 7 Jul 2023
Edited: Pranavkumar Mallela
on 27 Jul 2023
Hey, thanks for clarifying that.
You can utilize the 'find' function to find the indices of the required latitude and longitude ranges.
The code is as follows:
lat = [1 2 3 4 5 6 7 8 9 10]; % assume this is your latitude data
lon = [1 2 3 4 5 6 7 8 9 10]; % assume this is your longitude data
% Set the required limits here
req_lat_ll = 13; req_lat_ul = 18;
req_lon_ll = 73; req_lon_ul = 76;
lat_ll = find(lat <= req_lat_ll ,1,'last'); % ll = lower limit
lat_ul = find(lat >= req_lat_ul,1,'first'); % ul = upper limit
lon_ll = find(lon <= req_lon_ll ,1,'last');
lon_ul = find(lon >= req_lon_ul,1,'first');
cropped_region = rf(lat_ll:lat_ul, lon_ll:lon_ul, t); % at a given time 't'
Now you should be able to access rainfall using latitude and longitude ranges.
For more information regarding the 'find' function, please refer to this documentation:
Thanks! Hope this helps!
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!