Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Pranavkumar Mallela
Pranavkumar Mallela el 7 de Jul. de 2023
Editada: Pranavkumar Mallela el 27 de Jul. de 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 comentarios
Pranavkumar Mallela
Pranavkumar Mallela el 7 de Jul. de 2023
Editada: Pranavkumar Mallela el 27 de Jul. de 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!
Kamran Afroz
Kamran Afroz el 8 de Jul. de 2023
Hi Pranav,
Thank you for your time and help!
It worked.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Earth, Ocean, and Atmospheric Sciences en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by