Inpolygon 3D Array Processing

9 views (last 30 days)
Timo
Timo on 28 Mar 2018
Commented: Timo on 15 Oct 2018
Hello everybody,
I am facing some problems related to the processing of a time series of geospatial data (satellite data). For example I have an array A with 300 rows indicating the latitude and 400 columns representing longitudinal values, both sorted (of course) in ascending order and forming my grid. Thus, I have 120000 values (1 value for each lat/lon combination. So far so good with inpolygon its simple to intersect a shapefile and get the grid cells that lie within this shapefile (and building my area of interest), represented and stored in the variable in. Afterwards it is no problem calculate the mean, sum or whatever I want for this region with:
m=mean(A(in))
s=sum(A(in))
But my problem is that my array A has a third dimension (length 100 for example) indicating the time step (100 months for example), so I want to calculate the mean, sum etc. for this region of my shapefile for each time step resulting in an output vector which stores the mean for each time step (thus an vector m of length 100 where each cell represents the mean for this region for this month). I guess there should a solution but until now I am only able to calculate my quantities of interest for the first time step. I really would appreciate some hints or advices and would be grateful :). If you need additional information or more precise information please let me know.
Thanks in advance

Answers (1)

Timo
Timo on 28 Mar 2018
Edited: Timo on 28 Mar 2018
Sorry for this stupid question :)
Simply do:
for i=1:size(A,3)
t=A(:,:,i);
m=mean(t(in));
s=mean(t(in));
end
Maybe it will still be helpful for someone else :)
Greetings
  2 Comments
Shakir Hussain
Shakir Hussain on 10 Oct 2018
Timo, How did you extract 3D geospatial data with polygon? Can you share the codes here?
Timo
Timo on 15 Oct 2018
Of course. Let us assume you want to check the location of a shapefile within a grid:
shp=shaperead('shapefile location and shapefilename');
xcoord=shp.X
ycoord=shp.Y
xcoord=shp.X
lon=30:0.5:50 %longitude 30° - 50°
lat=10:0.5:45 %latitude 10° - 45°
[X Y]=meshgrid(lon,lat)
inside=inpolygon(X,Y,Xcoord,ycoord); %Gives back a logical array

Sign in to comment.

Categories

Find more on Reference Applications 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!