[QGIS Commit] r15453 - in trunk/qgis/src: core core/raster
providers/gdal
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Mar 12 13:58:43 EST 2011
Author: jef
Date: 2011-03-12 10:58:43 -0800 (Sat, 12 Mar 2011)
New Revision: 15453
Modified:
trunk/qgis/src/core/qgsproject.cpp
trunk/qgis/src/core/raster/qgsrasterlayer.cpp
trunk/qgis/src/providers/gdal/qgsgdalprovider.cpp
Log:
apply #3594
Modified: trunk/qgis/src/core/qgsproject.cpp
===================================================================
--- trunk/qgis/src/core/qgsproject.cpp 2011-03-12 18:57:10 UTC (rev 15452)
+++ trunk/qgis/src/core/qgsproject.cpp 2011-03-12 18:58:43 UTC (rev 15453)
@@ -715,7 +715,7 @@
}
// have the layer restore state that is stored in Dom node
- if ( mapLayer->readXML( node ) )
+ if ( mapLayer->readXML( node ) && mapLayer->isValid() )
{
mapLayer = QgsMapLayerRegistry::instance()->addMapLayer( mapLayer );
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
@@ -746,7 +746,7 @@
vIt->first->createJoinCaches();
vIt->first->updateFieldMap();
//for old symbology, it is necessary to read the symbology again after having the complete field map
- if( !vIt->first->isUsingRendererV2() )
+ if ( !vIt->first->isUsingRendererV2() )
{
vIt->first->readSymbology( vIt->second, errorMessage );
}
Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2011-03-12 18:57:10 UTC (rev 15452)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2011-03-12 18:58:43 UTC (rev 15453)
@@ -2732,7 +2732,6 @@
void QgsRasterLayer::setMinimumMaximumUsingDataset()
{
- double myMinMax[2];
if ( rasterType() == QgsRasterLayer::GrayOrUndefined || drawingStyle() == QgsRasterLayer::SingleBandGray || drawingStyle() == QgsRasterLayer::MultiBandSingleBandGray )
{
QgsRasterBandStats myRasterBandStats = bandStatistics( bandNumber( mGrayBandName ) );
@@ -3182,27 +3181,33 @@
if ( pkeyNode.isNull() )
{
- mProviderKey = "";
+ mProviderKey = "gdal";
}
else
{
QDomElement pkeyElt = pkeyNode.toElement();
mProviderKey = pkeyElt.text();
+ if ( mProviderKey.isEmpty() )
+ {
+ mProviderKey = "gdal";
+ }
}
// Open the raster source based on provider and datasource
- if ( !mProviderKey.isEmpty() )
- {
- // Go down the raster-data-provider paradigm
+ // Go down the raster-data-provider paradigm
- // Collect provider-specific information
+ // Collect provider-specific information
- QDomNode rpNode = layer_node.namedItem( "rasterproperties" );
+ QDomNode rpNode = layer_node.namedItem( "rasterproperties" );
- // Collect sublayer names and styles
- QStringList layers;
- QStringList styles;
+ // Collect sublayer names and styles
+ QStringList layers;
+ QStringList styles;
+ QString format;
+
+ if ( mProviderKey == "wms" )
+ {
QDomElement layerElement = rpNode.firstChildElement( "wmsSublayer" );
while ( !layerElement.isNull() )
{
@@ -3218,28 +3223,28 @@
}
// Collect format
- QString format = rpNode.namedItem( "wmsFormat" ).toElement().text();
-
- // Collect CRS
- setDataProvider( mProviderKey, layers, styles, format, crs().authid() );
+ format = rpNode.namedItem( "wmsFormat" ).toElement().text();
}
- else
- {
- // Go down the monolithic-gdal-provider paradigm
- if ( !readFile( source() ) ) // Data source name set in
- // QgsMapLayer::readXML()
- {
- QgsLogger::warning( QString( __FILE__ ) + ":" + QString( __LINE__ ) +
- " unable to read from raster file " + source() );
- return false;
- }
+ // Collect CRS
+ setDataProvider( mProviderKey, layers, styles, format, crs().authid() );
+ QString theError;
+ bool res = readSymbology( layer_node, theError );
+
+ // old wms settings we need to correct
+ if ( res &&
+ mProviderKey == "wms" &&
+ mDrawingStyle == MultiBandColor &&
+ mRedBandName == TRSTRING_NOT_SET &&
+ mGreenBandName == TRSTRING_NOT_SET &&
+ mBlueBandName == TRSTRING_NOT_SET )
+ {
+ mDrawingStyle = SingleBandColorDataStyle;
+ mGrayBandName = bandName( 1 );
}
- QString theError;
- return readSymbology( layer_node, theError );
-
+ return res;
} // QgsRasterLayer::readXml( QDomNode & layer_node )
/*
@@ -3254,13 +3259,13 @@
QDomElement rasterPropertiesElement = document.createElement( "rasterproperties" );
layer_node.appendChild( rasterPropertiesElement );
- if ( !mProviderKey.isEmpty() )
- {
- QStringList sl = subLayers();
- QStringList sls = mDataProvider->subLayerStyles();
+ QStringList sl = subLayers();
+ QStringList sls = mDataProvider->subLayerStyles();
- QStringList::const_iterator layerStyle = sls.begin();
+ QStringList::const_iterator layerStyle = sls.begin();
+ if ( mProviderKey == "wms" )
+ {
// <rasterproperties><wmsSublayer>
for ( QStringList::const_iterator layerName = sl.begin();
layerName != sl.end();
@@ -3297,7 +3302,6 @@
document.createTextNode( mDataProvider->imageEncoding() );
formatElement.appendChild( formatText );
rasterPropertiesElement.appendChild( formatElement );
-
}
// <mDrawingStyle>
Modified: trunk/qgis/src/providers/gdal/qgsgdalprovider.cpp
===================================================================
--- trunk/qgis/src/providers/gdal/qgsgdalprovider.cpp 2011-03-12 18:57:10 UTC (rev 15452)
+++ trunk/qgis/src/providers/gdal/qgsgdalprovider.cpp 2011-03-12 18:58:43 UTC (rev 15453)
@@ -131,8 +131,7 @@
CPLErrorReset();
if ( mGdalBaseDataset == NULL )
{
- QMessageBox::warning( 0, QObject::tr( "Warning" ),
- QObject::tr( "Cannot open GDAL dataset %1: %2" ).arg( uri ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
+ QgsDebugMsg( QString( "Cannot open GDAL dataset %1: %2" ).arg( uri ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
return;
}
@@ -301,44 +300,44 @@
//ifdefs below to remove compiler warning about unused vars
#ifdef QGISDEBUG
#if 0
- int success;
- double GDALminimum = GDALGetRasterMinimum( myGdalBand, &success );
+ int success;
+ double GDALminimum = GDALGetRasterMinimum( myGdalBand, &success );
- if ( ! success )
- {
- QgsDebugMsg( "myGdalBand->GetMinimum() failed" );
- }
+ if ( ! success )
+ {
+ QgsDebugMsg( "myGdalBand->GetMinimum() failed" );
+ }
- double GDALmaximum = GDALGetRasterMaximum( myGdalBand, &success );
+ double GDALmaximum = GDALGetRasterMaximum( myGdalBand, &success );
- if ( ! success )
- {
- QgsDebugMsg( "myGdalBand->GetMaximum() failed" );
- }
+ if ( ! success )
+ {
+ QgsDebugMsg( "myGdalBand->GetMaximum() failed" );
+ }
- double GDALnodata = GDALGetRasterNoDataValue( myGdalBand, &success );
+ double GDALnodata = GDALGetRasterNoDataValue( myGdalBand, &success );
- if ( ! success )
- {
- QgsDebugMsg( "myGdalBand->GetNoDataValue() failed" );
- }
+ if ( ! success )
+ {
+ QgsDebugMsg( "myGdalBand->GetNoDataValue() failed" );
+ }
- QgsLogger::debug( "GDALminium: ", GDALminimum, __FILE__, __FUNCTION__, __LINE__ );
- QgsLogger::debug( "GDALmaximum: ", GDALmaximum, __FILE__, __FUNCTION__, __LINE__ );
- QgsLogger::debug( "GDALnodata: ", GDALnodata, __FILE__, __FUNCTION__, __LINE__ );
+ QgsLogger::debug( "GDALminium: ", GDALminimum, __FILE__, __FUNCTION__, __LINE__ );
+ QgsLogger::debug( "GDALmaximum: ", GDALmaximum, __FILE__, __FUNCTION__, __LINE__ );
+ QgsLogger::debug( "GDALnodata: ", GDALnodata, __FILE__, __FUNCTION__, __LINE__ );
- double GDALrange[2]; // calculated min/max, as opposed to the
- // dataset provided
+ double GDALrange[2]; // calculated min/max, as opposed to the
+ // dataset provided
- GDALComputeRasterMinMax( myGdalBand, 1, GDALrange );
- QgsLogger::debug( "approximate computed GDALminium:", GDALrange[0], __FILE__, __FUNCTION__, __LINE__, 1 );
- QgsLogger::debug( "approximate computed GDALmaximum:", GDALrange[1], __FILE__, __FUNCTION__, __LINE__, 1 );
+ GDALComputeRasterMinMax( myGdalBand, 1, GDALrange );
+ QgsLogger::debug( "approximate computed GDALminium:", GDALrange[0], __FILE__, __FUNCTION__, __LINE__, 1 );
+ QgsLogger::debug( "approximate computed GDALmaximum:", GDALrange[1], __FILE__, __FUNCTION__, __LINE__, 1 );
- GDALComputeRasterMinMax( myGdalBand, 0, GDALrange );
- QgsLogger::debug( "exactly computed GDALminium:", GDALrange[0] );
- QgsLogger::debug( "exactly computed GDALmaximum:", GDALrange[1] );
+ GDALComputeRasterMinMax( myGdalBand, 0, GDALrange );
+ QgsLogger::debug( "exactly computed GDALminium:", GDALrange[0] );
+ QgsLogger::debug( "exactly computed GDALmaximum:", GDALrange[1] );
- QgsDebugMsg( "starting manual stat computation" );
+ QgsDebugMsg( "starting manual stat computation" );
#endif
#endif
@@ -1184,7 +1183,10 @@
int QgsGdalProvider::bandCount() const
{
- return GDALGetRasterCount( mGdalDataset );
+ if ( mGdalDataset )
+ return GDALGetRasterCount( mGdalDataset );
+ else
+ return 1;
}
int QgsGdalProvider::colorInterpretation( int theBandNo ) const
More information about the QGIS-commit
mailing list