How select/crop geographic region on the basis of lat/lon values?

조회 수: 4 (최근 30일)
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?

채택된 답변

Pranavkumar Mallela
Pranavkumar Mallela 2023년 7월 7일
편집: Pranavkumar Mallela 2023년 7월 27일
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
Pranavkumar Mallela
Pranavkumar Mallela 2023년 7월 7일
편집: Pranavkumar Mallela 2023년 7월 27일
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!
Kamran Afroz
Kamran Afroz 2023년 7월 8일
Hi Pranav,
Thank you for your time and help!
It worked.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by