Hi Thomas,
I understand that you need to calculate the weighted average of some variables across the country, which intersects the regularly spaced quadrilaterals.
In order to resolve your issue please refer to the following steps to calculate the weighted average of variables across the country that intersect the regularly spaced quadrilaterals:
- Read country boundaries from a shapefile using “shaperead”
- Create a polygon for each quad using “polyshape”
- Compute the intersection between quad polygons and country polygons using “intersect”
The following code snippet demonstrates how the intersection between quad polygons and country polygons are calculated using the intersect function:
intersectedPolygons = polyshape.empty;
for i = 1:length(countryData)
intersection = intersect(quadPolygon, countryData(i).Geometry);
if ~isempty(intersection)
intersectedPolygons(end+1) = intersection;
end
end
- Calculate the area of each intersected polygon using “area”
- Use the areas to compute the spatially weighted average of climate variables across each country.
Please refer to the following MathWorks documentation links for more information on ‘shaperead’, ‘polyshape’, ‘polyshape intersect’ and ‘area’:
- https://www.mathworks.com/help/map/ref/shaperead.html
- https://www.mathworks.com/help/matlab/ref/polyshape.html
- https://www.mathworks.com/help/matlab/ref/polyshape.intersect.html
- https://www.mathworks.com/help/matlab/ref/area.html
Hope this helps!