Skip to content

Instantly share code, notes, and snippets.

@monkeybutter
Created November 22, 2016 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monkeybutter/769a24bcf87682171eb87ac05c9347c5 to your computer and use it in GitHub Desktop.
Save monkeybutter/769a24bcf87682171eb87ac05c9347c5 to your computer and use it in GitHub Desktop.
#include "gdal.h"
#include "ogr_core.h"
#include "ogr_srs_api.h"
#include "cpl_conv.h"
#include <assert.h>
char *WGS84WKT = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]";
int
main()
{
GDALAllRegister();
GDALDatasetH hSrcDS;
GDALRasterBandH hBand;
int nBlockXSize, nBlockYSize;
float *pafBlock;
// Src Dataset
hSrcDS = GDALOpen("/path/to/chirps/file/chirps-v2.0.2015.dekads.nc", GA_ReadOnly);
GDALSetProjection(hSrcDS, WGS84WKT);
hBand = GDALGetRasterBand(hSrcDS, 35);
nBlockXSize = 500;
nBlockYSize = 500;
pafBlock = (float *) CPLMalloc(sizeof(float)*nBlockXSize*nBlockYSize);
GDALRasterIO(hBand, GF_Read, 0, 0, nBlockXSize, nBlockYSize, pafBlock, nBlockXSize, nBlockYSize, GDT_Float32, 0, 0);
GDALClose(hSrcDS);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment