Skip to content
Permalink
Browse files

apply #3594

git-svn-id: http://svn.osgeo.org/qgis/trunk@15453 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Mar 12, 2011
1 parent c19e333 commit 251dada485798c6756beff4410b5c7d651292630
Showing with 72 additions and 66 deletions.
  1. +2 −2 src/core/qgsproject.cpp
  2. +37 −33 src/core/raster/qgsrasterlayer.cpp
  3. +33 −31 src/providers/gdal/qgsgdalprovider.cpp
@@ -715,7 +715,7 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
}

// 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 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
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 );
}
@@ -2732,7 +2732,6 @@ void QgsRasterLayer::setMinimumMaximumUsingLastExtent()

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 @@ bool QgsRasterLayer::readXml( QDomNode & layer_node )

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;
QString format;

// Collect sublayer names and styles
QStringList layers;
QStringList styles;
if ( mProviderKey == "wms" )
{
QDomElement layerElement = rpNode.firstChildElement( "wmsSublayer" );
while ( !layerElement.isNull() )
{
@@ -3218,28 +3223,28 @@ bool QgsRasterLayer::readXml( QDomNode & layer_node )
}

// 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;
return readSymbology( layer_node, 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 );
}

return res;
} // QgsRasterLayer::readXml( QDomNode & layer_node )

/*
@@ -3254,13 +3259,13 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
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 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
document.createTextNode( mDataProvider->imageEncoding() );
formatElement.appendChild( formatText );
rasterPropertiesElement.appendChild( formatElement );

}

// <mDrawingStyle>
@@ -131,8 +131,7 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
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 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
//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::dataType( int bandNo ) const

int QgsGdalProvider::bandCount() const
{
return GDALGetRasterCount( mGdalDataset );
if ( mGdalDataset )
return GDALGetRasterCount( mGdalDataset );
else
return 1;
}

int QgsGdalProvider::colorInterpretation( int theBandNo ) const

0 comments on commit 251dada

Please sign in to comment.
You can’t perform that action at this time.