| 341 | |
| 342 | private: |
| 343 | bool Init() |
| 344 | { |
| 345 | #if !(GEOS_GRID_INTERSECTION_AVAILABLE) |
| 346 | if (m_options.pixels == GDALZonalStatsOptions::FRACTIONAL) |
| 347 | { |
| 348 | CPLError(CE_Failure, CPLE_AppDefined, |
| 349 | "Fractional pixel coverage calculation requires a GDAL " |
| 350 | "build against GEOS >= 3.14"); |
| 351 | return false; |
| 352 | } |
| 353 | #endif |
| 354 | |
| 355 | if (m_options.bands.empty()) |
| 356 | { |
| 357 | const int nBands = m_src.GetRasterCount(); |
| 358 | if (nBands == 0) |
| 359 | { |
| 360 | CPLError(CE_Failure, CPLE_AppDefined, |
| 361 | "GDALRasterZonalStats: input dataset has no bands"); |
| 362 | return false; |
| 363 | } |
| 364 | m_options.bands.resize(nBands); |
| 365 | for (int i = 0; i < nBands; i++) |
| 366 | { |
| 367 | m_options.bands[i] = i + 1; |
| 368 | } |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | for (int nBand : m_options.bands) |
| 373 | { |
| 374 | if (nBand <= 0 || nBand > m_src.GetRasterCount()) |
| 375 | { |
| 376 | CPLError(CE_Failure, CPLE_AppDefined, |
| 377 | "GDALRasterZonalStats: Invalid band number: %d", |
| 378 | nBand); |
| 379 | return false; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | { |
| 385 | const auto eSrcType = m_src.GetRasterBand(m_options.bands.front()) |
| 386 | ->GetRasterDataType(); |
| 387 | if (GDALDataTypeIsConversionLossy(eSrcType, m_workingDataType)) |
| 388 | { |
| 389 | CPLError(CE_Failure, CPLE_AppDefined, |
| 390 | "GDALRasterZonalStats: Source data type %s is not " |
| 391 | "supported", |
| 392 | GDALGetDataTypeName(eSrcType)); |
| 393 | return false; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | if (m_weights) |
| 398 | { |
| 399 | if (m_options.weights_band > m_weights->GetRasterCount()) |
| 400 | { |
no test coverage detected