NCPP / ocgis

OpenClimateGIS is a set of geoprocessing and calculation tools for CF-compliant climate datasets.
Other
70 stars 19 forks source link

Calculate grid cell area from ocgis.Grid object #480

Closed jhamman closed 6 years ago

jhamman commented 6 years ago

Is there an easy or straight-forward method for getting calculating the grid cell area from a ocgis.Grid object. For example,

x = ocgis.Variable(name='xc', dimensions='dimx', value=ds['lon'].values)
y = ocgis.Variable(name='yc', dimensions='dimy', value=ds['lat'].values)
grid = ocgis.Grid(x, y, crs=ocgis.crs.Spherical())
grid.set_extrapolated_bounds('xc_bounds', 'yc_bounds', 'bounds')
area = grid.get_area()  # 2d array <--- this is what I want

I image there is something like this but I haven't been able to uncover it.

bekozi commented 6 years ago

It's a little buried and we could add a method like that. Right now it's:

# Get the abstraction geometry for the grid (polygon, point).
geom = grid.get_abstraction_geometry()
# Areas are calculated from the Shapely geometries on-demand.
area = geom.area
bekozi commented 6 years ago

@jhamman I think this is resolved so closing. Please reopen if needed!