Determine area inside a polygon on a map
Show older comments
I have a 2x2.5 degree grid overlaying the United States. Each grid has a certain value. I want to determine the value for each state in the U.S. by weighing each grid box by how much of a certain state is inside each grid

For example, if I was looking at Texas, I can see that there are some grids that are 100% inside Texas, but there are many other grids that are only partly inside Texas. I would like to weigh those grids by the area covered. I need to do this for every state.
Mapping code:
figure('units','normalized','outerposition',[0 0 1 1], 'visible','on');
ax = usamap('conus');
states = shaperead('usastatelo', 'UseGeoCoords', true,...
'Selector',...
{@(name) ~any(strcmp(name,{'Alaska','Hawaii'})), 'Name'});
geoshow(ax, states,'FaceColor', [0.8 0.8 0.8], 'EdgeColor', [0 0 0])
framem off; gridm off; mlabel off; plabel off
hold on
pcolorm(lat,wrapTo360(lon),data(:,:,day))
hold on
geoshow(ax, states,'FaceColor', 'none', 'EdgeColor', [0 0 0])
colormap(flipud(hot))
h = colorbar('location', 'SouthOutside');
caxis([20 100])
Longitude file (with values denoting the edges of the box) 25x1:
233.7500 233.7500 233.7500 233.7500 233.7500 233.7500 233.7500 233.7500 233.7500 233.7500 233.7500 233.7500 233.7500 233.7500
236.2500 236.2500 236.2500 236.2500 236.2500 236.2500 236.2500 236.2500 236.2500 236.2500 236.2500 236.2500 236.2500 236.2500
238.7500 238.7500 238.7500 238.7500 238.7500 238.7500 238.7500 238.7500 238.7500 238.7500 238.7500 238.7500 238.7500 238.7500
241.2500 241.2500 241.2500 241.2500 241.2500 241.2500 241.2500 241.2500 241.2500 241.2500 241.2500 241.2500 241.2500 241.2500
243.7500 243.7500 243.7500 243.7500 243.7500 243.7500 243.7500 243.7500 243.7500 243.7500 243.7500 243.7500 243.7500 243.7500
246.2500 246.2500 246.2500 246.2500 246.2500 246.2500 246.2500 246.2500 246.2500 246.2500 246.2500 246.2500 246.2500 246.2500
248.7500 248.7500 248.7500 248.7500 248.7500 248.7500 248.7500 248.7500 248.7500 248.7500 248.7500 248.7500 248.7500 248.7500
251.2500 251.2500 251.2500 251.2500 251.2500 251.2500 251.2500 251.2500 251.2500 251.2500 251.2500 251.2500 251.2500 251.2500
253.7500 253.7500 253.7500 253.7500 253.7500 253.7500 253.7500 253.7500 253.7500 253.7500 253.7500 253.7500 253.7500 253.7500
256.2500 256.2500 256.2500 256.2500 256.2500 256.2500 256.2500 256.2500 256.2500 256.2500 256.2500 256.2500 256.2500 256.2500
258.7500 258.7500 258.7500 258.7500 258.7500 258.7500 258.7500 258.7500 258.7500 258.7500 258.7500 258.7500 258.7500 258.7500
261.2500 261.2500 261.2500 261.2500 261.2500 261.2500 261.2500 261.2500 261.2500 261.2500 261.2500 261.2500 261.2500 261.2500
263.7500 263.7500 263.7500 263.7500 263.7500 263.7500 263.7500 263.7500 263.7500 263.7500 263.7500 263.7500 263.7500 263.7500
266.2500 266.2500 266.2500 266.2500 266.2500 266.2500 266.2500 266.2500 266.2500 266.2500 266.2500 266.2500 266.2500 266.2500
268.7500 268.7500 268.7500 268.7500 268.7500 268.7500 268.7500 268.7500 268.7500 268.7500 268.7500 268.7500 268.7500 268.7500
271.2500 271.2500 271.2500 271.2500 271.2500 271.2500 271.2500 271.2500 271.2500 271.2500 271.2500 271.2500 271.2500 271.2500
273.7500 273.7500 273.7500 273.7500 273.7500 273.7500 273.7500 273.7500 273.7500 273.7500 273.7500 273.7500 273.7500 273.7500
276.2500 276.2500 276.2500 276.2500 276.2500 276.2500 276.2500 276.2500 276.2500 276.2500 276.2500 276.2500 276.2500 276.2500
278.7500 278.7500 278.7500 278.7500 278.7500 278.7500 278.7500 278.7500 278.7500 278.7500 278.7500 278.7500 278.7500 278.7500
281.2500 281.2500 281.2500 281.2500 281.2500 281.2500 281.2500 281.2500 281.2500 281.2500 281.2500 281.2500 281.2500 281.2500
283.7500 283.7500 283.7500 283.7500 283.7500 283.7500 283.7500 283.7500 283.7500 283.7500 283.7500 283.7500 283.7500 283.7500
286.2500 286.2500 286.2500 286.2500 286.2500 286.2500 286.2500 286.2500 286.2500 286.2500 286.2500 286.2500 286.2500 286.2500
288.7500 288.7500 288.7500 288.7500 288.7500 288.7500 288.7500 288.7500 288.7500 288.7500 288.7500 288.7500 288.7500 288.7500
291.2500 291.2500 291.2500 291.2500 291.2500 291.2500 291.2500 291.2500 291.2500 291.2500 291.2500 291.2500 291.2500 291.2500
293.7500 293.7500 293.7500 293.7500 293.7500 293.7500 293.7500 293.7500 293.7500 293.7500 293.7500 293.7500 293.7500 293.7500
Latitude file (with values denoting the edges of the box) 25x14:
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
23 25 27 29 31 33 35 37 39 41 43 45 47 49
2 Comments
Looks you already have the data as shapefiles. This is easier with most (all) GIS software. I'd perform the required operations there first and then import to Matlab if you really need to.
Is there a compelling reason for you to want to do this in Matlab? Because mapping is arguably nicer and I'd postulate that it is objectively less of a headache if you do it with actual mapping tools.
SZee
on 4 Sep 2017
Accepted Answer
More Answers (0)
Categories
Find more on Map Display in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!