18 #define CPL_SUPRESS_CPLUSPLUS //#spellok 20 #include "cpl_string.h" 26 QString driverShortName = GDALGetDriverShortName( driver );
27 if ( driverShortName == QLatin1String(
"SQLite" ) )
32 char **driverMetadata = GDALGetMetadata( driver,
nullptr );
33 return CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE,
false ) &&
34 CSLFetchBoolean( driverMetadata, GDAL_DCAP_RASTER,
false );
39 GDALDriverH hDriverMem = GDALGetDriverByName(
"MEM" );
47 double cellSizeX = extent.
width() / width;
48 double cellSizeY = extent.
height() / height;
49 double geoTransform[6];
51 geoTransform[1] = cellSizeX;
53 geoTransform[3] = extent.
yMinimum() + ( cellSizeY * height );
55 geoTransform[5] = -cellSizeY;
57 GDALSetProjection( hSrcDS.get(), crs.
toWkt().toLatin1().constData() );
58 GDALSetGeoTransform( hSrcDS.get(), geoTransform );
64 double cellSizeX = extent.
width() / width;
65 double cellSizeY = extent.
height() / height;
66 double geoTransform[6];
68 geoTransform[1] = cellSizeX;
70 geoTransform[3] = extent.
yMinimum() + ( cellSizeY * height );
72 geoTransform[5] = -cellSizeY;
74 GDALDriverH hDriver = GDALGetDriverByName(
"GTiff" );
81 gdal::dataset_unique_ptr hDstDS( GDALCreate( hDriver, filename.toLocal8Bit().constData(), width, height, 1, dataType, nullptr ) );
88 GDALSetProjection( hDstDS.get(), crs.
toWkt().toLatin1().constData() );
89 GDALSetGeoTransform( hDstDS.get(), geoTransform );
96 psWarpOptions->hSrcDS = hSrcDS;
97 psWarpOptions->hDstDS = hDstDS;
99 psWarpOptions->nBandCount = 1;
100 psWarpOptions->panSrcBands = (
int * ) CPLMalloc(
sizeof(
int ) * 1 );
101 psWarpOptions->panDstBands = (
int * ) CPLMalloc(
sizeof(
int ) * 1 );
102 psWarpOptions->panSrcBands[0] = 1;
103 psWarpOptions->panDstBands[0] = 1;
105 psWarpOptions->eResampleAlg = resampleAlg;
108 psWarpOptions->pTransformerArg =
109 GDALCreateGenImgProjTransformer( hSrcDS, GDALGetProjectionRef( hSrcDS ),
110 hDstDS, GDALGetProjectionRef( hDstDS ),
112 psWarpOptions->pfnTransformer = GDALGenImgProjTransform;
115 GDALWarpOperation oOperation;
116 oOperation.Initialize( psWarpOptions.get() );
118 oOperation.ChunkAndWarpImage( 0, 0, GDALGetRasterXSize( hDstDS ), GDALGetRasterYSize( hDstDS ) );
120 GDALDestroyGenImgProjTransformer( psWarpOptions->pTransformerArg );
A rectangle specified with double values.
const QgsCoordinateReferenceSystem & crs
std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter > warp_options_unique_ptr
Scoped GDAL warp options.
static bool supportsRasterCreate(GDALDriverH driver)
Reads whether a driver supports GDALCreate() for raster purposes.
double width() const
Returns the width of the rectangle.
static gdal::dataset_unique_ptr createSingleBandMemoryDataset(GDALDataType dataType, QgsRectangle extent, int width, int height, const QgsCoordinateReferenceSystem &crs)
Creates a new single band memory dataset with given parameters.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
This class represents a coordinate reference system (CRS).
QString toWkt() const
Returns a WKT representation of this CRS.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
static gdal::dataset_unique_ptr createSingleBandTiffDataset(QString filename, GDALDataType dataType, QgsRectangle extent, int width, int height, const QgsCoordinateReferenceSystem &crs)
Creates a new single band TIFF dataset with given parameters.
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
static void resampleSingleBandRaster(GDALDatasetH hSrcDS, GDALDatasetH hDstDS, GDALResampleAlg resampleAlg)
Resamples a single band raster to the destination dataset with different resolution (and possibly wit...
double height() const
Returns the height of the rectangle.