Skip to content

Commit 6e0a80a

Browse files
committed
common QgsGdalProviderBase for GDAL and WCS, get native CRS, size if possible
1 parent 058f287 commit 6e0a80a

12 files changed

Lines changed: 649 additions & 587 deletions

‎src/gui/qgsowssourceselect.cpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ void QgsOWSSourceSelect::populateFormats()
159159

160160
// selectedLayersFormats may come in various forms:
161161
// image/tiff, GTiff, GeoTIFF, TIFF, geotiff_int16, geotiff_rgb,
162-
// PNG, GTOPO30, ARCGRID, IMAGEMOSAIC, GEOTIFFINT16
162+
// PNG, GTOPO30, ARCGRID, IMAGEMOSAIC
163+
// and even any string defined in server configuration, for example the
164+
// value used in UMN Mapserver for OUTPUTFORMAT->NAME is used in
165+
// WCS 1.0.0 SupportedFormats/Format
163166

164167
// TODO: It is impossible to cover all possible formats comming from server
165168
// -> enabled all formats, GDAL may be able to open them
@@ -433,6 +436,7 @@ void QgsOWSSourceSelect::on_mLayersTreeWidget_itemSelectionChanged()
433436

434437
void QgsOWSSourceSelect::populateCRS()
435438
{
439+
QgsDebugMsg ("Entered");
436440
mSelectedLayersCRSs = selectedLayersCRSs().toSet();
437441
mCRSGroupBox->setTitle( tr( "Coordinate Reference System (%n available)", "crs count", mSelectedLayersCRSs.count() ) );
438442

@@ -470,6 +474,7 @@ void QgsOWSSourceSelect::populateCRS()
470474
mSelectedCRS = "";
471475
mSelectedCRSLabel->setText( "" );
472476
}
477+
QgsDebugMsg ("mSelectedCRS = " + mSelectedCRS);
473478
mChangeCRSButton->setEnabled( !mSelectedLayersCRSs.isEmpty() );
474479
}
475480

‎src/providers/gdal/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
SET(GDAL_SRCS
2+
qgsgdalproviderbase.cpp
23
qgsgdalprovider.cpp
34
qgsgdaldataitems.cpp
45
)
56
SET(GDAL_MOC_HDRS
7+
qgsgdalproviderbase.h
68
qgsgdalprovider.h
79
qgsgdaldataitems.h
810
)

‎src/providers/gdal/qgsgdalprovider.cpp‎

Lines changed: 8 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* *
1717
***************************************************************************/
1818

19-
2019
#include "qgslogger.h"
20+
#include "qgsgdalproviderbase.h"
2121
#include "qgsgdalprovider.h"
2222
#include "qgsconfig.h"
2323

@@ -91,6 +91,7 @@ int CPL_STDCALL progressCallback( double dfComplete,
9191

9292
QgsGdalProvider::QgsGdalProvider( QString const & uri )
9393
: QgsRasterDataProvider( uri )
94+
, QgsGdalProviderBase()
9495
, mValid( true )
9596
{
9697
QgsDebugMsg( "QgsGdalProvider: constructing with uri '" + uri + "'." );
@@ -99,7 +100,7 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
99100
mGdalBaseDataset = 0;
100101
mGdalDataset = 0;
101102

102-
registerGdalDrivers();
103+
QgsGdalProviderBase::registerGdalDrivers();
103104

104105
// To get buildSupportedRasterFileFilter the provider is called with empty uri
105106
if ( uri.isEmpty() )
@@ -942,88 +943,7 @@ double QgsGdalProvider::maximumValue( int theBandNo ) const
942943
QList<QgsColorRampShader::ColorRampItem> QgsGdalProvider::colorTable( int theBandNumber )const
943944
{
944945
QgsDebugMsg( "entered." );
945-
QList<QgsColorRampShader::ColorRampItem> ct;
946-
947-
948-
//Invalid band number, segfault prevention
949-
if ( 0 >= theBandNumber )
950-
{
951-
QgsDebugMsg( "Invalid parameter" );
952-
return ct;
953-
}
954-
955-
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNumber );
956-
GDALColorTableH myGdalColorTable = GDALGetRasterColorTable( myGdalBand );
957-
958-
if ( myGdalColorTable )
959-
{
960-
QgsDebugMsg( "Color table found" );
961-
int myEntryCount = GDALGetColorEntryCount( myGdalColorTable );
962-
GDALColorInterp myColorInterpretation = GDALGetRasterColorInterpretation( myGdalBand );
963-
QgsDebugMsg( "Color Interpretation: " + QString::number(( int )myColorInterpretation ) );
964-
GDALPaletteInterp myPaletteInterpretation = GDALGetPaletteInterpretation( myGdalColorTable );
965-
QgsDebugMsg( "Palette Interpretation: " + QString::number(( int )myPaletteInterpretation ) );
966-
967-
const GDALColorEntry* myColorEntry = 0;
968-
for ( int myIterator = 0; myIterator < myEntryCount; myIterator++ )
969-
{
970-
myColorEntry = GDALGetColorEntry( myGdalColorTable, myIterator );
971-
972-
if ( !myColorEntry )
973-
{
974-
continue;
975-
}
976-
else
977-
{
978-
//Branch on the color interpretation type
979-
if ( myColorInterpretation == GCI_GrayIndex )
980-
{
981-
QgsColorRampShader::ColorRampItem myColorRampItem;
982-
myColorRampItem.label = "";
983-
myColorRampItem.value = ( double )myIterator;
984-
myColorRampItem.color = QColor::fromRgb( myColorEntry->c1, myColorEntry->c1, myColorEntry->c1, myColorEntry->c4 );
985-
ct.append( myColorRampItem );
986-
}
987-
else if ( myColorInterpretation == GCI_PaletteIndex )
988-
{
989-
QgsColorRampShader::ColorRampItem myColorRampItem;
990-
myColorRampItem.value = ( double )myIterator;
991-
myColorRampItem.label = QString::number( myColorRampItem.value );
992-
//Branch on palette interpretation
993-
if ( myPaletteInterpretation == GPI_RGB )
994-
{
995-
myColorRampItem.color = QColor::fromRgb( myColorEntry->c1, myColorEntry->c2, myColorEntry->c3, myColorEntry->c4 );
996-
}
997-
else if ( myPaletteInterpretation == GPI_CMYK )
998-
{
999-
myColorRampItem.color = QColor::fromCmyk( myColorEntry->c1, myColorEntry->c2, myColorEntry->c3, myColorEntry->c4 );
1000-
}
1001-
else if ( myPaletteInterpretation == GPI_HLS )
1002-
{
1003-
myColorRampItem.color = QColor::fromHsv( myColorEntry->c1, myColorEntry->c3, myColorEntry->c2, myColorEntry->c4 );
1004-
}
1005-
else
1006-
{
1007-
myColorRampItem.color = QColor::fromRgb( myColorEntry->c1, myColorEntry->c1, myColorEntry->c1, myColorEntry->c4 );
1008-
}
1009-
ct.append( myColorRampItem );
1010-
}
1011-
else
1012-
{
1013-
QgsDebugMsg( "Color interpretation type not supported yet" );
1014-
return ct;
1015-
}
1016-
}
1017-
}
1018-
}
1019-
else
1020-
{
1021-
QgsDebugMsg( "No color table found for band " + QString::number( theBandNumber ) );
1022-
return ct;
1023-
}
1024-
1025-
QgsDebugMsg( "Color table loaded successfully" );
1026-
return ct;
946+
return QgsGdalProviderBase::colorTable( mGdalDataset, theBandNumber );
1027947
}
1028948

1029949
QgsCoordinateReferenceSystem QgsGdalProvider::crs()
@@ -1131,65 +1051,18 @@ int QgsGdalProvider::capabilities() const
11311051
return capability;
11321052
}
11331053

1134-
int QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
1135-
{
1136-
switch ( theGdalDataType )
1137-
{
1138-
case GDT_Unknown:
1139-
return QgsRasterDataProvider::UnknownDataType;
1140-
break;
1141-
case GDT_Byte:
1142-
return QgsRasterDataProvider::Byte;
1143-
break;
1144-
case GDT_UInt16:
1145-
return QgsRasterDataProvider::UInt16;
1146-
break;
1147-
case GDT_Int16:
1148-
return QgsRasterDataProvider::Int16;
1149-
break;
1150-
case GDT_UInt32:
1151-
return QgsRasterDataProvider::UInt32;
1152-
break;
1153-
case GDT_Int32:
1154-
return QgsRasterDataProvider::Int32;
1155-
break;
1156-
case GDT_Float32:
1157-
return QgsRasterDataProvider::Float32;
1158-
break;
1159-
case GDT_Float64:
1160-
return QgsRasterDataProvider::Float64;
1161-
break;
1162-
case GDT_CInt16:
1163-
return QgsRasterDataProvider::CInt16;
1164-
break;
1165-
case GDT_CInt32:
1166-
return QgsRasterDataProvider::CInt32;
1167-
break;
1168-
case GDT_CFloat32:
1169-
return QgsRasterDataProvider::CFloat32;
1170-
break;
1171-
case GDT_CFloat64:
1172-
return QgsRasterDataProvider::CFloat64;
1173-
break;
1174-
case GDT_TypeCount:
1175-
// make gcc happy
1176-
break;
1177-
}
1178-
return QgsRasterDataProvider::UnknownDataType;
1179-
}
1180-
11811054
int QgsGdalProvider::srcDataType( int bandNo ) const
11821055
{
11831056
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, bandNo );
11841057
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand );
1185-
return dataTypeFormGdal( myGdalDataType );
1058+
return dataTypeFromGdal( myGdalDataType );
11861059
}
11871060

11881061
int QgsGdalProvider::dataType( int bandNo ) const
11891062
{
11901063
if ( mGdalDataType.size() == 0 ) return QgsRasterDataProvider::UnknownDataType;
11911064

1192-
return dataTypeFormGdal( mGdalDataType[bandNo-1] );
1065+
return dataTypeFromGdal( mGdalDataType[bandNo-1] );
11931066
}
11941067

11951068
int QgsGdalProvider::bandCount() const
@@ -1203,27 +1076,9 @@ int QgsGdalProvider::bandCount() const
12031076
int QgsGdalProvider::colorInterpretation( int theBandNo ) const
12041077
{
12051078
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
1206-
return GDALGetRasterColorInterpretation( myGdalBand );
1079+
return colorInterpretationFromGdal ( GDALGetRasterColorInterpretation( myGdalBand ) );
12071080
}
12081081

1209-
void QgsGdalProvider::registerGdalDrivers()
1210-
{
1211-
//GDALDestroyDriverManager();
1212-
GDALAllRegister();
1213-
QSettings mySettings;
1214-
QString myJoinedList = mySettings.value( "gdal/skipList", "" ).toString();
1215-
if ( !myJoinedList.isEmpty() )
1216-
{
1217-
QStringList myList = myJoinedList.split( " " );
1218-
for ( int i = 0; i < myList.size(); ++i )
1219-
{
1220-
QgsApplication::skipGdalDriver( myList.at( i ) );
1221-
}
1222-
QgsApplication::applyGdalSkippedDrivers();
1223-
}
1224-
}
1225-
1226-
12271082
bool QgsGdalProvider::isValid()
12281083
{
12291084
QgsDebugMsg( QString( "valid = %1" ).arg( mValid ) );
@@ -1652,8 +1507,6 @@ QGISEXTERN bool isProvider()
16521507
void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString, QStringList & theExtensions, QStringList & theWildcards )
16531508
{
16541509
QgsDebugMsg( "Entered" );
1655-
// first get the GDAL driver manager
1656-
QgsGdalProvider::registerGdalDrivers();
16571510

16581511
// then iterate through all of the supported drivers, adding the
16591512
// corresponding file filter
@@ -1862,7 +1715,7 @@ QGISEXTERN bool isValidRasterFileName( QString const & theFileNameQString, QStri
18621715
{
18631716
GDALDatasetH myDataset;
18641717

1865-
QgsGdalProvider::registerGdalDrivers();
1718+
QgsGdalProviderBase::registerGdalDrivers();
18661719

18671720
CPLErrorReset();
18681721

‎src/providers/gdal/qgsgdalprovider.h‎

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
* *
1717
***************************************************************************/
1818

19-
2019
#ifndef QGSGDALPROVIDER_H
2120
#define QGSGDALPROVIDER_H
2221

23-
2422
#include "qgscoordinatereferencesystem.h"
2523
#include "qgsdataitem.h"
2624
#include "qgsrasterdataprovider.h"
25+
#include "qgsgdalproviderbase.h"
2726
#include "qgsrectangle.h"
2827
#include "qgscolorrampshader.h"
2928
#include "qgsrasterbandstats.h"
@@ -36,18 +35,6 @@
3635

3736
class QgsRasterPyramid;
3837

39-
#define CPL_SUPRESS_CPLUSPLUS
40-
#include <gdal.h>
41-
42-
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
43-
#define TO8F(x) (x).toUtf8().constData()
44-
#define FROM8(x) QString::fromUtf8(x)
45-
#else
46-
#define TO8F(x) QFile::encodeName( x ).constData()
47-
#define FROM8(x) QString::fromLocal8Bit(x)
48-
#endif
49-
50-
5138
/** \ingroup core
5239
* A call back function for showing progress of gdal operations.
5340
*/
@@ -66,7 +53,7 @@ class QgsCoordinateTransform;
6653
to provide access to spatial data residing in a GDAL layers.
6754
6855
*/
69-
class QgsGdalProvider : public QgsRasterDataProvider
56+
class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
7057
{
7158
Q_OBJECT
7259

@@ -187,8 +174,6 @@ class QgsGdalProvider : public QgsRasterDataProvider
187174
int dataType( int bandNo ) const;
188175
int srcDataType( int bandNo ) const;
189176

190-
int dataTypeFormGdal( int theGdalDataType ) const;
191-
192177
int bandCount() const;
193178

194179
int colorInterpretation( int bandNo ) const;
@@ -210,7 +195,6 @@ class QgsGdalProvider : public QgsRasterDataProvider
210195

211196
QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo )const;
212197

213-
214198
/**
215199
* Get metadata in a format suitable for feeding directly
216200
* into a subset of the GUI raster properties "Metadata" tab.
@@ -227,9 +211,6 @@ class QgsGdalProvider : public QgsRasterDataProvider
227211
void setImageCrs( QString const &crs )
228212
{ Q_UNUSED( crs ); }
229213

230-
/** \brief ensures that GDAL drivers are registered, but only once */
231-
static void registerGdalDrivers();
232-
233214
/** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */
234215
QStringList subLayers() const;
235216
static QStringList subLayers( GDALDatasetH dataset );

0 commit comments

Comments
 (0)