Skip to content

Commit

Permalink
Fix loading of datum transformation from project
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Oct 21, 2013
1 parent 162d8ab commit e2148bc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
63 changes: 33 additions & 30 deletions src/core/qgsmaprenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,14 +736,16 @@ bool QgsMapRenderer::hasCrsTransformEnabled() const
return mProjectionsEnabled;
}

void QgsMapRenderer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs )
void QgsMapRenderer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs, bool refreshCoordinateTransformInfo )
{
QgsDebugMsg( "* Setting destCRS : = " + crs.toProj4() );
QgsDebugMsg( "* DestCRS.srsid() = " + QString::number( crs.srsid() ) );
if ( *mDestCRS != crs )
{
mLayerCoordinateTransformInfo.clear();

if ( refreshCoordinateTransformInfo )
{
mLayerCoordinateTransformInfo.clear();
}
QgsRectangle rect;
if ( !mExtent.isEmpty() )
{
Expand Down Expand Up @@ -1043,7 +1045,7 @@ void QgsMapRenderer::setLayerSet( const QStringList& layers )
mLayerSet = layers;

//remove all entries in mLayerCoordinateTransformInfo which are not part of the layer set
if ( mLayerCoordinateTransformInfo.size() > 0 )
/*if ( mLayerCoordinateTransformInfo.size() > 0 )
{
QSet<QString> layerSet = layers.toSet();
QStringList removeEntries;
Expand All @@ -1061,7 +1063,7 @@ void QgsMapRenderer::setLayerSet( const QStringList& layers )
{
mLayerCoordinateTransformInfo.remove( *rIt );
}
}
}*/
updateFullExtent();
}

Expand Down Expand Up @@ -1105,11 +1107,36 @@ bool QgsMapRenderer::readXML( QDomNode & theNode )
element = projNode.toElement();
setProjectionsEnabled( element.text().toInt() );

//load coordinate transform into
mLayerCoordinateTransformInfo.clear();
QDomElement layerCoordTransformInfoElem = theNode.firstChildElement( "layer_coordinate_transform_info" );
if ( !layerCoordTransformInfoElem.isNull() )
{
QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName( "layer_coordinate_transform" );
QDomElement layerCoordTransformElem;
for ( int i = 0; i < layerCoordinateTransformList.size(); ++i )
{
layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement();
QString layerId = layerCoordTransformElem.attribute( "layerid" );
if ( layerId.isEmpty() )
{
continue;
}

QgsLayerCoordinateTransform lct;
lct.srcAuthId = layerCoordTransformElem.attribute( "srcAuthId" );
lct.destAuthId = layerCoordTransformElem.attribute( "destAuthId" );
lct.srcDatumTransform = layerCoordTransformElem.attribute( "srcDatumTransform", "-1" ).toInt();
lct.destDatumTransform = layerCoordTransformElem.attribute( "destDatumTransform", "-1" ).toInt();
mLayerCoordinateTransformInfo.insert( layerId, lct );
}
}

// set destination CRS
QgsCoordinateReferenceSystem srs;
QDomNode srsNode = theNode.namedItem( "destinationsrs" );
srs.readXML( srsNode );
setDestinationCrs( srs );
setDestinationCrs( srs, false );

// set extent
QgsRectangle aoi;
Expand Down Expand Up @@ -1138,30 +1165,6 @@ bool QgsMapRenderer::readXML( QDomNode & theNode )

setExtent( aoi );

mLayerCoordinateTransformInfo.clear();
QDomElement layerCoordTransformInfoElem = theNode.firstChildElement( "layer_coordinate_transform_info" );
if ( !layerCoordTransformInfoElem.isNull() )
{
QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName( "layer_coordinate_transform" );
QDomElement layerCoordTransformElem;
for ( int i = 0; i < layerCoordinateTransformList.size(); ++i )
{
layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement();
QString layerId = layerCoordTransformElem.attribute( "layerid" );
if ( layerId.isEmpty() )
{
continue;
}

QgsLayerCoordinateTransform lct;
lct.srcAuthId = layerCoordTransformElem.attribute( "srcAuthId" );
lct.destAuthId = layerCoordTransformElem.attribute( "destAuthId" );
lct.srcDatumTransform = layerCoordTransformElem.attribute( "srcDatumTransform", "-1" ).toInt();
lct.destDatumTransform = layerCoordTransformElem.attribute( "destDatumTransform", "-1" ).toInt();
mLayerCoordinateTransformInfo.insert( layerId, lct );
}
}

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaprenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject
bool hasCrsTransformEnabled() const;

//! sets destination coordinate reference system
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs, bool refreshCoordinateTransformInfo = true );

//! returns CRS of destination coordinate reference system
const QgsCoordinateReferenceSystem& destinationCrs() const;
Expand Down

0 comments on commit e2148bc

Please sign in to comment.