How do you calculate average value of area within a polygon shapefile?
조회 수: 12 (최근 30일)
이전 댓글 표시
Hi all,
I have a high resolution data grid across the U.S.. I would like to find the average value of all data points within each U.S. county. I was thinking I could possibly derive this from a shapefile (.shp) of all the U.S. counties.
Any thoughts, leads, ideas would be greatly appreciated!
Ryan
댓글 수: 0
채택된 답변
Chad Greene
2016년 2월 12일
The title of this question and the text of the question seem to be different. I'll try to answer both.
댓글 수: 3
Chad Greene
2016년 2월 12일
편집: Chad Greene
2016년 2월 24일
I think you're right on track. The inpolygon function will do exactly what you need and it will work in projected coordinates or geo coordinates. Just make sure your grid coordinates match the shapefile coordinates.
The shaperead function will return geo coordinates or projected coordinates if your shapefile has a georeferencing matrix, use the UseGeoCoords,true or UseGeoCoords,false option depending on which you prefer. You can also use mfwdtran or minvtran to transform the coordinates of your grid. There are lots of ways to skin this cat, just make sure your grid and shapefile coordinates are both geo coordinates or they're both projected coordinates.
If you use projected coordinates maybe your grid has these coordinates:
[X,Y] = meshgrid(1:1000,500:1000);
and the outline of a state is given by x and y. All the indices of your grid Z inside the outline of the state will be given by
ind = inpolygon(X,Y,x,y);
The mean of all Z values inside x,y is then
mean(Z(ind))
If your grid is referenced to LAT,LON it'll look like this:
[LON,LAT] = meshgrid(-120:-65,25:45);
ind = inpolygon(LON,LAT,lon,lat);
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!