| 107 | /************************************************************************/ |
| 108 | |
| 109 | CPLErr GDALContourProcessOptions(GDALContourOptions *psOptions, |
| 110 | char ***ppapszStringOptions, |
| 111 | GDALDatasetH *hSrcDS, GDALRasterBandH *hBand, |
| 112 | GDALDatasetH *hDstDS, OGRLayerH *hLayer) |
| 113 | { |
| 114 | |
| 115 | /* -------------------------------------------------------------------- */ |
| 116 | /* Open source raster file. */ |
| 117 | /* -------------------------------------------------------------------- */ |
| 118 | if (!*hSrcDS) |
| 119 | { |
| 120 | *hSrcDS = GDALOpen(psOptions->osSrcDataSource.c_str(), GA_ReadOnly); |
| 121 | } |
| 122 | |
| 123 | if (*hSrcDS == nullptr) |
| 124 | { |
| 125 | CPLError(CE_Failure, CPLE_AppDefined, |
| 126 | "Unable to open source raster file '%s'.", |
| 127 | psOptions->osSrcDataSource.c_str()); |
| 128 | return CE_Failure; |
| 129 | } |
| 130 | |
| 131 | if (!*hBand) |
| 132 | { |
| 133 | *hBand = GDALGetRasterBand(*hSrcDS, psOptions->nBand); |
| 134 | } |
| 135 | |
| 136 | if (*hBand == nullptr) |
| 137 | { |
| 138 | CPLError(CE_Failure, CPLE_AppDefined, |
| 139 | "Band %d does not exist on dataset.", psOptions->nBand); |
| 140 | return CE_Failure; |
| 141 | } |
| 142 | |
| 143 | if (!psOptions->bNoDataSet && !psOptions->bIgnoreNoData) |
| 144 | { |
| 145 | int bNoDataSet; |
| 146 | psOptions->dfNoData = GDALGetRasterNoDataValue(*hBand, &bNoDataSet); |
| 147 | psOptions->bNoDataSet = CPL_TO_BOOL(bNoDataSet); |
| 148 | } |
| 149 | |
| 150 | /* -------------------------------------------------------------------- */ |
| 151 | /* Try to get a coordinate system from the raster. */ |
| 152 | /* -------------------------------------------------------------------- */ |
| 153 | OGRSpatialReferenceH hSRS = GDALGetSpatialRef(*hSrcDS); |
| 154 | |
| 155 | // Dedup lambda to create the layer |
| 156 | auto CreateLayer = [&]() -> OGRLayerH |
| 157 | { |
| 158 | return GDALDatasetCreateLayer( |
| 159 | *hDstDS, psOptions->osNewLayerName.c_str(), hSRS, |
| 160 | psOptions->bPolygonize |
| 161 | ? (psOptions->b3D ? wkbMultiPolygon25D : wkbMultiPolygon) |
| 162 | : (psOptions->b3D ? wkbLineString25D : wkbLineString), |
| 163 | psOptions->aosLayerCreationOptions); |
| 164 | }; |
| 165 | |
| 166 | /* -------------------------------------------------------------------- */ |
no test coverage detected