@@ -412,7 +412,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
412
412
{
413
413
r1 = mExtent ;
414
414
split = splitLayersExtent ( ml, r1, r2 );
415
- ct = QgsCoordinateTransformCache::instance ()-> transform ( ml-> crs (). authid (), mDestCRS -> authid () );
415
+ ct = tr ( ml );
416
416
mRenderContext .setExtent ( r1 );
417
417
QgsDebugMsg ( " extent 1: " + r1.toString () );
418
418
QgsDebugMsg ( " extent 2: " + r2.toString () );
@@ -742,6 +742,8 @@ void QgsMapRenderer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
742
742
QgsDebugMsg ( " * DestCRS.srsid() = " + QString::number ( crs.srsid () ) );
743
743
if ( *mDestCRS != crs )
744
744
{
745
+ mLayerCoordinateTransformInfo .clear ();
746
+
745
747
QgsRectangle rect;
746
748
if ( !mExtent .isEmpty () )
747
749
{
@@ -1026,6 +1028,27 @@ void QgsMapRenderer::setLayerSet( const QStringList& layers )
1026
1028
{
1027
1029
QgsDebugMsg ( QString ( " Entering: %1" ).arg ( layers.join ( " , " ) ) );
1028
1030
mLayerSet = layers;
1031
+
1032
+ // remove all entries in mLayerCoordinateTransformInfo which are not part of the layer set
1033
+ if ( mLayerCoordinateTransformInfo .size () > 0 )
1034
+ {
1035
+ QSet<QString> layerSet = layers.toSet ();
1036
+ QStringList removeEntries;
1037
+ QHash< QString, QgsLayerCoordinateTransform >::const_iterator lctIt = mLayerCoordinateTransformInfo .constBegin ();
1038
+ for ( ; lctIt != mLayerCoordinateTransformInfo .constEnd (); ++lctIt )
1039
+ {
1040
+ if ( !layerSet.contains ( lctIt.key () ) )
1041
+ {
1042
+ removeEntries.push_back ( lctIt.key () );
1043
+ }
1044
+ }
1045
+
1046
+ QStringList::const_iterator rIt = removeEntries.constBegin ();
1047
+ for ( ; rIt != removeEntries.constEnd (); ++rIt )
1048
+ {
1049
+ mLayerCoordinateTransformInfo .remove ( *rIt );
1050
+ }
1051
+ }
1029
1052
updateFullExtent ();
1030
1053
}
1031
1054
@@ -1101,6 +1124,31 @@ bool QgsMapRenderer::readXML( QDomNode & theNode )
1101
1124
aoi.setYMaximum ( ymax );
1102
1125
1103
1126
setExtent ( aoi );
1127
+
1128
+ mLayerCoordinateTransformInfo .clear ();
1129
+ QDomElement layerCoordTransformInfoElem = theNode.firstChildElement ( " layer_coordinate_transform_info" );
1130
+ if ( !layerCoordTransformInfoElem.isNull () )
1131
+ {
1132
+ QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName ( " layer_coordinate_transform" );
1133
+ QDomElement layerCoordTransformElem;
1134
+ for ( int i = 0 ; i < layerCoordinateTransformList.size (); ++i )
1135
+ {
1136
+ layerCoordTransformElem = layerCoordinateTransformList.at ( i ).toElement ();
1137
+ QString layerId = layerCoordTransformElem.attribute ( " layerid" );
1138
+ if ( layerId.isEmpty () )
1139
+ {
1140
+ continue ;
1141
+ }
1142
+
1143
+ QgsLayerCoordinateTransform lct;
1144
+ lct.srcAuthId = layerCoordTransformElem.attribute ( " srcAuthId" );
1145
+ lct.destAuthId = layerCoordTransformElem.attribute ( " destAuthId" );
1146
+ lct.srcDatumTransform = layerCoordTransformElem.attribute ( " srcDatumTransform" , " -1" ).toInt ();
1147
+ lct.destDatumTransform = layerCoordTransformElem.attribute ( " destDatumTransform" , " -1" ).toInt ();
1148
+ mLayerCoordinateTransformInfo .insert ( layerId, lct );
1149
+ }
1150
+ }
1151
+
1104
1152
return true ;
1105
1153
}
1106
1154
@@ -1170,6 +1218,20 @@ bool QgsMapRenderer::writeXML( QDomNode & theNode, QDomDocument & theDoc )
1170
1218
theNode.appendChild ( srsNode );
1171
1219
destinationCrs ().writeXML ( srsNode, theDoc );
1172
1220
1221
+ // layer coordinate transform infos
1222
+ QDomElement layerCoordTransformInfo = theDoc.createElement ( " layer_coordinate_transform_info" );
1223
+ QHash< QString, QgsLayerCoordinateTransform >::const_iterator coordIt = mLayerCoordinateTransformInfo .constBegin ();
1224
+ for ( ; coordIt != mLayerCoordinateTransformInfo .constEnd (); ++coordIt )
1225
+ {
1226
+ QDomElement layerCoordTransformElem = theDoc.createElement ( " layer_coordinate_transform" );
1227
+ layerCoordTransformElem.setAttribute ( " layerid" , coordIt.key () );
1228
+ layerCoordTransformElem.setAttribute ( " srcAuthId" , coordIt->srcAuthId );
1229
+ layerCoordTransformElem.setAttribute ( " destAuthId" , coordIt->destAuthId );
1230
+ layerCoordTransformElem.setAttribute ( " srcDatumTransform" , QString::number ( coordIt->srcDatumTransform ) );
1231
+ layerCoordTransformElem.setAttribute ( " destDatumTransform" , QString::number ( coordIt->destDatumTransform ) );
1232
+ layerCoordTransformInfo.appendChild ( layerCoordTransformElem );
1233
+ }
1234
+ theNode.appendChild ( layerCoordTransformInfo );
1173
1235
return true ;
1174
1236
}
1175
1237
@@ -1187,7 +1249,24 @@ const QgsCoordinateTransform* QgsMapRenderer::tr( QgsMapLayer *layer )
1187
1249
{
1188
1250
return 0 ;
1189
1251
}
1190
- return QgsCoordinateTransformCache::instance ()->transform ( layer->crs ().authid (), mDestCRS ->authid () );
1252
+
1253
+ QHash< QString, QgsLayerCoordinateTransform >::const_iterator ctIt = mLayerCoordinateTransformInfo .find ( layer->id () );
1254
+ if ( ctIt != mLayerCoordinateTransformInfo .constEnd () )
1255
+ {
1256
+ return QgsCoordinateTransformCache::instance ()->transform ( ctIt->srcAuthId , ctIt->destAuthId , ctIt->srcDatumTransform , ctIt->destDatumTransform );
1257
+ }
1258
+ else
1259
+ {
1260
+ emit datumTransformInfoRequested ( layer, layer->crs ().authid (), mDestCRS ->authid () );
1261
+ }
1262
+
1263
+ // still not present? get coordinate transformation with -1/-1 datum transform as default
1264
+ ctIt = mLayerCoordinateTransformInfo .find ( layer->id () );
1265
+ if ( ctIt == mLayerCoordinateTransformInfo .constEnd () )
1266
+ {
1267
+ return QgsCoordinateTransformCache::instance ()->transform ( layer->crs ().authid (), mDestCRS ->authid (), -1 , -1 );
1268
+ }
1269
+ return QgsCoordinateTransformCache::instance ()->transform ( ctIt->srcAuthId , ctIt->destAuthId , ctIt->srcDatumTransform , ctIt->destDatumTransform );
1191
1270
}
1192
1271
1193
1272
/* * Returns a QPainter::CompositionMode corresponding to a QgsMapRenderer::BlendMode
@@ -1264,4 +1343,14 @@ QgsMapRenderer::BlendMode QgsMapRenderer::getBlendModeEnum( const QPainter::Comp
1264
1343
}
1265
1344
}
1266
1345
1346
+ void QgsMapRenderer::addLayerCoordinateTransform ( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform )
1347
+ {
1348
+ QgsLayerCoordinateTransform lt;
1349
+ lt.srcAuthId = srcAuthId;
1350
+ lt.destAuthId = destAuthId;
1351
+ lt.srcDatumTransform = srcDatumTransform;
1352
+ lt.destDatumTransform = destDatumTransform;
1353
+ mLayerCoordinateTransformInfo .insert ( layerId, lt );
1354
+ }
1355
+
1267
1356
bool QgsMapRenderer::mDrawing = false ;
0 commit comments