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 );
126 GDALDriverH myGdalDriver = GDALGetDriverByName( format.toLocal8Bit().constData() );
130 char **GDALmetadata = GDALGetMetadata( myGdalDriver,
nullptr );
131 message += QLatin1String(
"Format Details:\n" );
132 message += QStringLiteral(
" Extension: %1\n" ).arg( CSLFetchNameValue( GDALmetadata, GDAL_DMD_EXTENSION ) );
133 message += QStringLiteral(
" Short Name: %1" ).arg( GDALGetDriverShortName( myGdalDriver ) );
134 message += QStringLiteral(
" / Long Name: %1\n" ).arg( GDALGetDriverLongName( myGdalDriver ) );
135 message += QStringLiteral(
" Help page: http://www.gdal.org/%1\n\n" ).arg( CSLFetchNameValue( GDALmetadata, GDAL_DMD_HELPTOPIC ) );
139 CPLXMLNode *psCOL = CPLParseXMLString( GDALGetMetadataItem( myGdalDriver,
140 GDAL_DMD_CREATIONOPTIONLIST,
"" ) );
141 char *pszFormattedXML = CPLSerializeXMLTree( psCOL );
142 if ( pszFormattedXML )
143 message += QString( pszFormattedXML );
145 CPLDestroyXMLNode( psCOL );
146 if ( pszFormattedXML )
147 CPLFree( pszFormattedXML );
154 char **papszRetList =
nullptr;
155 const auto constList = list;
156 for (
const QString &elem : constList )
158 papszRetList = CSLAddString( papszRetList, elem.toLocal8Bit().constData() );
165 GDALDriverH myGdalDriver = GDALGetDriverByName( format.toLocal8Bit().constData() );
166 if ( ! myGdalDriver )
167 return QStringLiteral(
"invalid GDAL driver" );
171 int ok = GDALValidateCreationOptions( myGdalDriver, papszOptions );
172 CSLDestroy( papszOptions );
175 return QStringLiteral(
"Failed GDALValidateCreationOptions() test" );
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 char ** papszFromStringList(const QStringList &list)
Helper function.
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).
static QString validateCreationOptionsFormat(const QStringList &createOptions, QString format)
Validates creation options for a given format, regardless of layer.
This class represents a coordinate reference system (CRS).
double xMinimum() const
Returns the x minimum value (left side of rectangle).
static QString helpCreationOptionsFormat(QString format)
Gets creation options metadata for a given format.
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.
QString toWkt(WktVariant variant=WKT1_GDAL, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
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.