How do you calculate average value of area within a polygon shapefile?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ryan
el 12 de Feb. de 2016
Editada: Chad Greene
el 24 de Feb. de 2016
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 comentarios
Respuesta aceptada
Chad Greene
el 12 de Feb. de 2016
The title of this question and the text of the question seem to be different. I'll try to answer both.
3 comentarios
Chad Greene
el 12 de Feb. de 2016
Editada: Chad Greene
el 24 de Feb. de 2016
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);
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!