# How to calculate intersecting areas of two shapes with one of it having many defining points

5 views (last 30 days)
Beder on 23 Feb 2017
Edited: Beder on 23 Feb 2017
Dear all, I'm currently working on a project, where it is necessary to identify the area of a specific region inside of a grid.
One question to answer would be: How much global radiation is expected in Germany.
Therefore I downloaded shapefiles from GADM with specific regions. Now I want to match the shapefiles with a grid (let's say: 0.5° lat, 1° lon).
currently:
I loop through each region and grid element and create another squared shape of the grid
templon=[ 50 51 51 50 50]; templat= [40 40 40.5 40.5 40];
Then I apply
[x,y]=polybool('intersect',templon,templat,shapelon,shapelat);
which works perfectly fine for small regions. As soon as I have regions which do have a lot of shapelat and shapelon points (e.g. Antarctica, >1 million), it gets incredibly slow (100 sec per polybool operation).
Considering a more detailed grid (0.5 X 2/3), Antarctica consists of nearly 32000 elements. Even when identifying elements completely inside and outside of the shape with "inpolygon" it's just way too much time.
My first possible solution (not able to realize it on my own)
I thought about cropping the shapefile of the region by the upper and lower boundaries of the currently to be calculated grid. This would reduce the number of points for polybool and therefore speed up my calculations. To do this I can not just delete the shapelat and shapelon outside of my gridelement. I also need to close it again (shapes need to have the same start and finishing point, turning clockwise equals a closed surface). If I work on this, how do I ensure:
• that I'm calculating the correct area and not the "negative" one?
• that i delete invalid elements to still ensure that a surface will be created?
But I've figured out some problems: When I move the x-y-elements to my border, it might change the size of the shape, since the shapes are not defined by lines, but only lines drawn in between the dots...
The Question
Is anyone out there who might be able to help me with this issue? I'm sure I'm not the only one who has ever done this. I would greatly appreciate any hint, concern or advice how to deal with this issue. Thank you in advance.

### Categories

Find more on Graphics Performance 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!