Skip to content

Commit

Permalink
common QgsGdalProviderBase for GDAL and WCS, get native CRS, size if …
Browse files Browse the repository at this point in the history
…possible
  • Loading branch information
blazek committed Jul 11, 2012
1 parent 058f287 commit 6e0a80a
Show file tree
Hide file tree
Showing 12 changed files with 649 additions and 587 deletions.
7 changes: 6 additions & 1 deletion src/gui/qgsowssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ void QgsOWSSourceSelect::populateFormats()

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

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

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

Expand Down Expand Up @@ -470,6 +474,7 @@ void QgsOWSSourceSelect::populateCRS()
mSelectedCRS = "";
mSelectedCRSLabel->setText( "" );
}
QgsDebugMsg ("mSelectedCRS = " + mSelectedCRS);
mChangeCRSButton->setEnabled( !mSelectedLayersCRSs.isEmpty() );
}

Expand Down
2 changes: 2 additions & 0 deletions src/providers/gdal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
SET(GDAL_SRCS
qgsgdalproviderbase.cpp
qgsgdalprovider.cpp
qgsgdaldataitems.cpp
)
SET(GDAL_MOC_HDRS
qgsgdalproviderbase.h
qgsgdalprovider.h
qgsgdaldataitems.h
)
Expand Down
163 changes: 8 additions & 155 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* *
***************************************************************************/


#include "qgslogger.h"
#include "qgsgdalproviderbase.h"
#include "qgsgdalprovider.h"
#include "qgsconfig.h"

Expand Down Expand Up @@ -91,6 +91,7 @@ int CPL_STDCALL progressCallback( double dfComplete,

QgsGdalProvider::QgsGdalProvider( QString const & uri )
: QgsRasterDataProvider( uri )
, QgsGdalProviderBase()
, mValid( true )
{
QgsDebugMsg( "QgsGdalProvider: constructing with uri '" + uri + "'." );
Expand All @@ -99,7 +100,7 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
mGdalBaseDataset = 0;
mGdalDataset = 0;

registerGdalDrivers();
QgsGdalProviderBase::registerGdalDrivers();

// To get buildSupportedRasterFileFilter the provider is called with empty uri
if ( uri.isEmpty() )
Expand Down Expand Up @@ -942,88 +943,7 @@ double QgsGdalProvider::maximumValue( int theBandNo ) const
QList<QgsColorRampShader::ColorRampItem> QgsGdalProvider::colorTable( int theBandNumber )const
{
QgsDebugMsg( "entered." );
QList<QgsColorRampShader::ColorRampItem> ct;


//Invalid band number, segfault prevention
if ( 0 >= theBandNumber )
{
QgsDebugMsg( "Invalid parameter" );
return ct;
}

GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNumber );
GDALColorTableH myGdalColorTable = GDALGetRasterColorTable( myGdalBand );

if ( myGdalColorTable )
{
QgsDebugMsg( "Color table found" );
int myEntryCount = GDALGetColorEntryCount( myGdalColorTable );
GDALColorInterp myColorInterpretation = GDALGetRasterColorInterpretation( myGdalBand );
QgsDebugMsg( "Color Interpretation: " + QString::number(( int )myColorInterpretation ) );
GDALPaletteInterp myPaletteInterpretation = GDALGetPaletteInterpretation( myGdalColorTable );
QgsDebugMsg( "Palette Interpretation: " + QString::number(( int )myPaletteInterpretation ) );

const GDALColorEntry* myColorEntry = 0;
for ( int myIterator = 0; myIterator < myEntryCount; myIterator++ )
{
myColorEntry = GDALGetColorEntry( myGdalColorTable, myIterator );

if ( !myColorEntry )
{
continue;
}
else
{
//Branch on the color interpretation type
if ( myColorInterpretation == GCI_GrayIndex )
{
QgsColorRampShader::ColorRampItem myColorRampItem;
myColorRampItem.label = "";
myColorRampItem.value = ( double )myIterator;
myColorRampItem.color = QColor::fromRgb( myColorEntry->c1, myColorEntry->c1, myColorEntry->c1, myColorEntry->c4 );
ct.append( myColorRampItem );
}
else if ( myColorInterpretation == GCI_PaletteIndex )
{
QgsColorRampShader::ColorRampItem myColorRampItem;
myColorRampItem.value = ( double )myIterator;
myColorRampItem.label = QString::number( myColorRampItem.value );
//Branch on palette interpretation
if ( myPaletteInterpretation == GPI_RGB )
{
myColorRampItem.color = QColor::fromRgb( myColorEntry->c1, myColorEntry->c2, myColorEntry->c3, myColorEntry->c4 );
}
else if ( myPaletteInterpretation == GPI_CMYK )
{
myColorRampItem.color = QColor::fromCmyk( myColorEntry->c1, myColorEntry->c2, myColorEntry->c3, myColorEntry->c4 );
}
else if ( myPaletteInterpretation == GPI_HLS )
{
myColorRampItem.color = QColor::fromHsv( myColorEntry->c1, myColorEntry->c3, myColorEntry->c2, myColorEntry->c4 );
}
else
{
myColorRampItem.color = QColor::fromRgb( myColorEntry->c1, myColorEntry->c1, myColorEntry->c1, myColorEntry->c4 );
}
ct.append( myColorRampItem );
}
else
{
QgsDebugMsg( "Color interpretation type not supported yet" );
return ct;
}
}
}
}
else
{
QgsDebugMsg( "No color table found for band " + QString::number( theBandNumber ) );
return ct;
}

QgsDebugMsg( "Color table loaded successfully" );
return ct;
return QgsGdalProviderBase::colorTable( mGdalDataset, theBandNumber );
}

QgsCoordinateReferenceSystem QgsGdalProvider::crs()
Expand Down Expand Up @@ -1131,65 +1051,18 @@ int QgsGdalProvider::capabilities() const
return capability;
}

int QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
{
switch ( theGdalDataType )
{
case GDT_Unknown:
return QgsRasterDataProvider::UnknownDataType;
break;
case GDT_Byte:
return QgsRasterDataProvider::Byte;
break;
case GDT_UInt16:
return QgsRasterDataProvider::UInt16;
break;
case GDT_Int16:
return QgsRasterDataProvider::Int16;
break;
case GDT_UInt32:
return QgsRasterDataProvider::UInt32;
break;
case GDT_Int32:
return QgsRasterDataProvider::Int32;
break;
case GDT_Float32:
return QgsRasterDataProvider::Float32;
break;
case GDT_Float64:
return QgsRasterDataProvider::Float64;
break;
case GDT_CInt16:
return QgsRasterDataProvider::CInt16;
break;
case GDT_CInt32:
return QgsRasterDataProvider::CInt32;
break;
case GDT_CFloat32:
return QgsRasterDataProvider::CFloat32;
break;
case GDT_CFloat64:
return QgsRasterDataProvider::CFloat64;
break;
case GDT_TypeCount:
// make gcc happy
break;
}
return QgsRasterDataProvider::UnknownDataType;
}

int QgsGdalProvider::srcDataType( int bandNo ) const
{
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, bandNo );
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand );
return dataTypeFormGdal( myGdalDataType );
return dataTypeFromGdal( myGdalDataType );
}

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

return dataTypeFormGdal( mGdalDataType[bandNo-1] );
return dataTypeFromGdal( mGdalDataType[bandNo-1] );
}

int QgsGdalProvider::bandCount() const
Expand All @@ -1203,27 +1076,9 @@ int QgsGdalProvider::bandCount() const
int QgsGdalProvider::colorInterpretation( int theBandNo ) const
{
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
return GDALGetRasterColorInterpretation( myGdalBand );
return colorInterpretationFromGdal ( GDALGetRasterColorInterpretation( myGdalBand ) );
}

void QgsGdalProvider::registerGdalDrivers()
{
//GDALDestroyDriverManager();
GDALAllRegister();
QSettings mySettings;
QString myJoinedList = mySettings.value( "gdal/skipList", "" ).toString();
if ( !myJoinedList.isEmpty() )
{
QStringList myList = myJoinedList.split( " " );
for ( int i = 0; i < myList.size(); ++i )
{
QgsApplication::skipGdalDriver( myList.at( i ) );
}
QgsApplication::applyGdalSkippedDrivers();
}
}


bool QgsGdalProvider::isValid()
{
QgsDebugMsg( QString( "valid = %1" ).arg( mValid ) );
Expand Down Expand Up @@ -1652,8 +1507,6 @@ QGISEXTERN bool isProvider()
void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString, QStringList & theExtensions, QStringList & theWildcards )
{
QgsDebugMsg( "Entered" );
// first get the GDAL driver manager
QgsGdalProvider::registerGdalDrivers();

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

QgsGdalProvider::registerGdalDrivers();
QgsGdalProviderBase::registerGdalDrivers();

CPLErrorReset();

Expand Down
23 changes: 2 additions & 21 deletions src/providers/gdal/qgsgdalprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
* *
***************************************************************************/


#ifndef QGSGDALPROVIDER_H
#define QGSGDALPROVIDER_H


#include "qgscoordinatereferencesystem.h"
#include "qgsdataitem.h"
#include "qgsrasterdataprovider.h"
#include "qgsgdalproviderbase.h"
#include "qgsrectangle.h"
#include "qgscolorrampshader.h"
#include "qgsrasterbandstats.h"
Expand All @@ -36,18 +35,6 @@

class QgsRasterPyramid;

#define CPL_SUPRESS_CPLUSPLUS
#include <gdal.h>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#define FROM8(x) QString::fromUtf8(x)
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#define FROM8(x) QString::fromLocal8Bit(x)
#endif


/** \ingroup core
* A call back function for showing progress of gdal operations.
*/
Expand All @@ -66,7 +53,7 @@ class QgsCoordinateTransform;
to provide access to spatial data residing in a GDAL layers.
*/
class QgsGdalProvider : public QgsRasterDataProvider
class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
{
Q_OBJECT

Expand Down Expand Up @@ -187,8 +174,6 @@ class QgsGdalProvider : public QgsRasterDataProvider
int dataType( int bandNo ) const;
int srcDataType( int bandNo ) const;

int dataTypeFormGdal( int theGdalDataType ) const;

int bandCount() const;

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

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


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

/** \brief ensures that GDAL drivers are registered, but only once */
static void registerGdalDrivers();

/** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */
QStringList subLayers() const;
static QStringList subLayers( GDALDatasetH dataset );
Expand Down
Loading

0 comments on commit 6e0a80a

Please sign in to comment.