isciences / exactextract

Fast and accurate raster zonal statistics
Apache License 2.0
259 stars 33 forks source link

Support extraction from multiple bands of a raster #19

Closed kongdd closed 9 months ago

kongdd commented 4 years ago

One of my nc file has the dimension of [nlon, nlat, ntime], ntime = 365. However, when using exactextract, only the data of the first date was extracted.

dbaston commented 4 years ago

How did you load the nc file?

kongdd commented 4 years ago

By the following command:

exactextract -r temp:NETCDF:ET_LISFLOOD.nc:Evap \
    -p Selected_Elasticity_10YThre.shp \
    -f name -s "mean(temp)" -o ET_LISFLOOD2.csv
dbaston commented 4 years ago

Oops, I saw this in my email and thought it was referring to https://github.com/isciences/exactextractr . Currently the command-line version processes only a single band. You can specify the band manually, e.g., temp:NETCDF:ET_LISFLOOD.nc:Evap[2], and loop over all bands.

If you want to easily process all of the bands at once, maybe give the R package a try.

Here is a minimal example of the R usage: https://gist.github.com/dbaston/26e8b739dd2549cf1a4c9718981354d3

kongdd commented 4 years ago

Thanks for your script.

relima commented 2 years ago

So, is there any solution for exactextract to retrieve data from multiple dates from a netcdf file?

dbaston commented 2 years ago

Currently you'd need to either loop through the bands or use the R package.

relima commented 2 years ago

Got it. The program is awesome -- very fast. For python it may be a good replacement for rasterstats, which is very good too, but terrible slow.