58 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
61 throw Error(
string(CPLGetLastErrorMsg()));
67 GDALDataType eBufType;
69 for(
int iBand = 0; iBand < GDALGetRasterCount( hDS ); iBand++ )
71 DBG(cerr <<
"In dgal_dds.cc iBand" << endl);
73 GDALRasterBandH hBand = GDALGetRasterBand( hDS, iBand+1 );
79 sprintf( szName,
"band_%d", iBand+1 );
82 oss <<
"band_" << iBand+1;
84 eBufType = GDALGetRasterDataType( hBand );
87 switch( GDALGetRasterDataType( hBand ) )
90 bt =
new Byte( oss.str() );
94 bt =
new UInt16( oss.str() );
98 bt =
new Int16( oss.str() );
102 bt =
new UInt32( oss.str() );
106 bt =
new Int32( oss.str() );
110 bt =
new Float32( oss.str() );
114 bt =
new Float64( oss.str() );
123 bt =
new Float64( oss.str() );
124 eBufType = GDT_Float64;
132 grid =
new GDALGrid( filename, oss.str(), hBand, eBufType );
145 ar =
new GDALArray( oss.str(), 0, filename, hBand, eBufType );
146 ar->add_var_nocopy( bt );
147 ar->append_dim( GDALGetRasterYSize( hDS ),
"northing" );
148 ar->append_dim( GDALGetRasterXSize( hDS ),
"easting" );
150 grid->add_var_nocopy( ar, array );
156 ar =
new GDALArray(
"northing", 0, filename, hBand, eBufType );
157 ar->add_var_nocopy( bt );
158 ar->append_dim( GDALGetRasterYSize( hDS ),
"northing" );
160 grid->add_var_nocopy( ar, maps );
163 ar =
new GDALArray(
"easting", 0, filename, hBand, eBufType );
164 ar->add_var_nocopy( bt );
165 ar->append_dim( GDALGetRasterXSize( hDS ),
"easting" );
167 grid->add_var_nocopy( ar, maps );
169 DBG(cerr <<
"Type of grid: " <<
typeid(grid).name() << endl);
171 dds->add_var_nocopy( grid );
195 Array::Dim_iter p = array->dim_begin();
196 int start = array->dimension_start(p,
true);
197 int stride = array->dimension_stride(p,
true);
198 int stop = array->dimension_stop(p,
true);
201 int start_2 = array->dimension_start(p,
true);
202 int stride_2 = array->dimension_stride(p,
true);
203 int stop_2 = array->dimension_stop(p,
true);
205 if (start + stop + stride == 0) {
208 stop = GDALGetRasterBandYSize(hBand) - 1;
210 if (start_2 + stop_2 + stride_2 == 0) {
213 stop_2 = GDALGetRasterBandXSize(hBand) - 1;
219 int nWinXOff, nWinYOff, nWinXSize, nWinYSize, nBufXSize, nBufYSize;
223 nWinXSize = stop_2 + 1 - start_2;
224 nWinYSize = stop + 1 - start;
226 nBufXSize = (stop_2 - start_2) / stride_2 + 1;
227 nBufYSize = (stop - start) / stride + 1;
232 int nPixelSize = GDALGetDataTypeSize(eBufType) / 8;
233 vector<char> pData(nBufXSize * nBufYSize * nPixelSize);
238 CPLErr eErr = GDALRasterIO(hBand, GF_Read, nWinXOff, nWinYOff, nWinXSize, nWinYSize,
239 &pData[0], nBufXSize, nBufYSize, eBufType, 0, 0);
241 throw Error(
"Error reading: " + array->name());
243 array->val2buf(&pData[0]);
256 Array::Dim_iter p = map->dim_begin();
257 int start = map->dimension_start(p,
true);
258 int stride = map->dimension_stride(p,
true);
259 int stop = map->dimension_stop(p,
true);
261 if (start + stop + stride == 0) {
264 if (map->name() ==
"northing")
265 stop = GDALGetRasterBandYSize(hBand) - 1;
266 else if (map->name() ==
"easting")
267 stop = GDALGetRasterBandXSize(hBand) - 1;
269 throw Error(
"Expected a map named 'northing' or 'easting' but got: " + map->name());
272 int nBufSize = (stop - start) / stride + 1;
285 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
287 if (hDS ==
NULL)
throw Error(
string(CPLGetLastErrorMsg()));
289 double adfGeoTransform[6];
291 if (GDALGetGeoTransform(hDS, adfGeoTransform) != CE_None) {
292 adfGeoTransform[0] = 0.0;
293 adfGeoTransform[1] = 1.0;
294 adfGeoTransform[2] = 0.0;
295 adfGeoTransform[3] = 0.0;
296 adfGeoTransform[4] = 0.0;
297 adfGeoTransform[5] = 1.0;
305 vector<double> padfMap(nBufSize);
307 if (map->name() ==
"northing") {
308 for (
int i = 0, iLine = start; iLine <= stop; iLine += stride) {
309 padfMap[i++] = adfGeoTransform[3] + adfGeoTransform[5] * iLine;
312 else if (map->name() ==
"easting") {
313 for (
int i = 0, iPixel = start; iPixel <= stop; iPixel += stride) {
314 padfMap[i++] = adfGeoTransform[0] + iPixel * adfGeoTransform[1];
318 throw Error(
"Expected a map named 'northing' or 'easting' but got: " + map->name());
320 map->val2buf((
void *) &padfMap[0]);
void gdal_read_dataset_attributes(DAS &dds, const string &filename)
static class NCMLUtil overview
void read_map_array(Array *map, GDALRasterBandH hBand, string filename)
Read one of the Map arrays.
void read_data_array(GDALArray *array, GDALRasterBandH hBand, GDALDataType eBufType)
Read the data array of a DAP2 Grid.
GDALDatasetH gdal_read_dataset_variables(DDS *dds, const string &filename)