@@ -54,6 +54,8 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer )
54
54
, mPageHeight( 210 )
55
55
, mSpaceBetweenPages( 10 )
56
56
, mPrintAsRaster( false )
57
+ , mGenerateWorldFile( false )
58
+ , mWorldFileMap( 0 )
57
59
, mUseAdvancedEffects( true )
58
60
, mSelectionTolerance( 0.0 )
59
61
, mSnapToGrid( false )
@@ -81,6 +83,8 @@ QgsComposition::QgsComposition()
81
83
mPageHeight( 210 ),
82
84
mSpaceBetweenPages( 10 ),
83
85
mPrintAsRaster( false ),
86
+ mGenerateWorldFile( false ),
87
+ mWorldFileMap( 0 ),
84
88
mUseAdvancedEffects( true ),
85
89
mSelectionTolerance( 0.0 ),
86
90
mSnapToGrid( false ),
@@ -420,6 +424,12 @@ bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc )
420
424
compositionElem.setAttribute ( " printResolution" , mPrintResolution );
421
425
compositionElem.setAttribute ( " printAsRaster" , mPrintAsRaster );
422
426
427
+ compositionElem.setAttribute ( " generateWorldFile" , mGenerateWorldFile ? 1 : 0 );
428
+ if ( mGenerateWorldFile && mWorldFileMap )
429
+ {
430
+ compositionElem.setAttribute ( " worldFileMap" , mWorldFileMap ->id () );
431
+ }
432
+
423
433
compositionElem.setAttribute ( " alignmentSnap" , mAlignmentSnap ? 1 : 0 );
424
434
compositionElem.setAttribute ( " alignmentSnapTolerance" , mAlignmentSnapTolerance );
425
435
@@ -505,6 +515,8 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
505
515
mPrintAsRaster = compositionElem.attribute ( " printAsRaster" ).toInt ();
506
516
mPrintResolution = compositionElem.attribute ( " printResolution" , " 300" ).toInt ();
507
517
518
+ mGenerateWorldFile = compositionElem.attribute ( " generateWorldFile" , " 0" ).toInt () == 1 ? true : false ;
519
+
508
520
updatePaperItems ();
509
521
510
522
return true ;
@@ -2174,3 +2186,64 @@ bool QgsComposition::nearestItem( const QMap< double, const QgsComposerItem* >&
2174
2186
}
2175
2187
}
2176
2188
2189
+ void QgsComposition::computeWorldFileParameters ( double p[6 ] ) const
2190
+ {
2191
+ //
2192
+ // Word file parameters : affine transformation parameters from pixel coordinates to map coordinates
2193
+
2194
+ if ( !mWorldFileMap )
2195
+ {
2196
+ return ;
2197
+ }
2198
+
2199
+ QRectF brect = mWorldFileMap ->boundingRect ();
2200
+ QgsRectangle extent = mWorldFileMap ->extent ();
2201
+
2202
+ double alpha = mWorldFileMap ->rotation () / 180 * M_PI;
2203
+
2204
+ double xr = extent.width () / brect.width ();
2205
+ double yr = extent.height () / brect.height ();
2206
+
2207
+ double XC = extent.center ().x ();
2208
+ double YC = extent.center ().y ();
2209
+
2210
+ // get the extent for the page
2211
+ double xmin = extent.xMinimum () - mWorldFileMap ->transform ().dx () * xr;
2212
+ double ymax = extent.yMaximum () + mWorldFileMap ->transform ().dy () * yr;
2213
+ QgsRectangle paperExtent ( xmin, ymax - paperHeight () * yr, xmin + paperWidth () * xr, ymax );
2214
+
2215
+ double X0 = paperExtent.xMinimum ();
2216
+ double Y0 = paperExtent.yMinimum ();
2217
+
2218
+ int widthPx = ( int )( printResolution () * paperWidth () / 25.4 );
2219
+ int heightPx = ( int )( printResolution () * paperHeight () / 25.4 );
2220
+
2221
+ double Ww = paperExtent.width () / widthPx;
2222
+ double Hh = paperExtent.height () / heightPx;
2223
+
2224
+ // scaling matrix
2225
+ double s[6 ];
2226
+ s[0 ] = Ww;
2227
+ s[1 ] = 0 ;
2228
+ s[2 ] = X0;
2229
+ s[3 ] = 0 ;
2230
+ s[4 ] = -Hh;
2231
+ s[5 ] = Y0 + paperExtent.height ();
2232
+
2233
+ // rotation matrix
2234
+ double r[6 ];
2235
+ r[0 ] = cos ( alpha );
2236
+ r[1 ] = -sin ( alpha );
2237
+ r[2 ] = XC * ( 1 - cos ( alpha ) ) + YC * sin ( alpha );
2238
+ r[3 ] = sin ( alpha );
2239
+ r[4 ] = cos ( alpha );
2240
+ r[5 ] = - XC * sin ( alpha ) + YC * ( 1 - cos ( alpha ) );
2241
+
2242
+ // result = rotation x scaling = rotation(scaling(X))
2243
+ p[0 ] = r[0 ] * s[0 ] + r[1 ] * s[3 ];
2244
+ p[1 ] = r[0 ] * s[1 ] + r[1 ] * s[4 ];
2245
+ p[2 ] = r[0 ] * s[2 ] + r[1 ] * s[5 ] + r[2 ];
2246
+ p[3 ] = r[3 ] * s[0 ] + r[4 ] * s[3 ];
2247
+ p[4 ] = r[3 ] * s[1 ] + r[4 ] * s[4 ];
2248
+ p[5 ] = r[3 ] * s[2 ] + r[4 ] * s[5 ] + r[5 ];
2249
+ }
0 commit comments