QGIS API Documentation  2.99.0-Master (7705179)
qgsmapsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmapsettings.cpp
3  --------------------------------------
4  Date : December 2013
5  Copyright : (C) 2013 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsmapsettings.h"
17 
18 #include "qgsscalecalculator.h"
19 #include "qgsmaprendererjob.h"
20 #include "qgsmaptopixel.h"
21 #include "qgslogger.h"
22 
23 #include "qgsmessagelog.h"
24 #include "qgsmaplayer.h"
25 #include "qgsmaplayerlistutils.h"
26 #include "qgsproject.h"
27 #include "qgsxmlutils.h"
28 #include "qgsexception.h"
29 #include "qgsgeometry.h"
30 
31 Q_GUI_EXPORT extern int qt_defaultDpiX();
32 
33 
35  : mDpi( qt_defaultDpiX() ) // DPI that will be used by default for QImage instances
36  , mSize( QSize( 0, 0 ) )
37  , mRotation( 0.0 )
38  , mMagnificationFactor( 1.0 )
39  , mDatumTransformStore( mDestCRS )
40  , mBackgroundColor( Qt::white )
41  , mSelectionColor( Qt::yellow )
42  , mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling | DrawSelection )
43  , mImageFormat( QImage::Format_ARGB32_Premultiplied )
44  , mSegmentationTolerance( M_PI_2 / 90 )
45  , mSegmentationToleranceType( QgsAbstractGeometry::MaximumAngle )
46  , mValid( false )
47  , mMapUnitsPerPixel( 1 )
48  , mScale( 1 )
49 {
51 
52  updateDerived();
53 }
54 
56 {
57  double ratio = mMagnificationFactor / factor;
58 
59  mMagnificationFactor = factor;
60 
61  double rot = rotation();
62  setRotation( 0.0 );
63 
65  ext.scale( ratio );
66 
67  mRotation = rot;
68  mExtent = ext;
69  mDpi = mDpi / ratio;
70 
71  QgsDebugMsg( QString( "Magnification factor: %1 dpi: %2 ratio: %3" ).arg( factor ).arg( mDpi ).arg( ratio ) );
72 
73  updateDerived();
74 }
75 
77 {
78  return mMagnificationFactor;
79 }
80 
82 {
83  return mExtent;
84 }
85 
86 void QgsMapSettings::setExtent( const QgsRectangle &extent, bool magnified )
87 {
88  QgsRectangle magnifiedExtent = extent;
89 
90  if ( !magnified )
91  magnifiedExtent.scale( 1 / mMagnificationFactor );
92 
93  mExtent = magnifiedExtent;
94 
95  updateDerived();
96 }
97 
99 {
100  return mRotation;
101 }
102 
103 void QgsMapSettings::setRotation( double degrees )
104 {
105  if ( qgsDoubleNear( mRotation, degrees ) )
106  return;
107 
108  mRotation = degrees;
109 
110  // TODO: update extent while keeping scale ?
111  updateDerived();
112 }
113 
114 
116 {
118 
119  if ( extent.isEmpty() || !extent.isFinite() )
120  {
121  mValid = false;
122  return;
123  }
124 
125  // Don't allow zooms where the current extent is so small that it
126  // can't be accurately represented using a double (which is what
127  // currentExtent uses). Excluding 0 avoids a divide by zero and an
128  // infinite loop when rendering to a new canvas. Excluding extents
129  // greater than 1 avoids doing unnecessary calculations.
130 
131  // The scheme is to compare the width against the mean x coordinate
132  // (and height against mean y coordinate) and only allow zooms where
133  // the ratio indicates that there is more than about 12 significant
134  // figures (there are about 16 significant figures in a double).
135 
136  if ( extent.width() > 0 &&
137  extent.height() > 0 &&
138  extent.width() < 1 &&
139  extent.height() < 1 )
140  {
141  // Use abs() on the extent to avoid the case where the extent is
142  // symmetrical about 0.
143  double xMean = ( std::fabs( extent.xMinimum() ) + std::fabs( extent.xMaximum() ) ) * 0.5;
144  double yMean = ( std::fabs( extent.yMinimum() ) + std::fabs( extent.yMaximum() ) ) * 0.5;
145 
146  double xRange = extent.width() / xMean;
147  double yRange = extent.height() / yMean;
148 
149  static const double MIN_PROPORTION = 1e-12;
150  if ( xRange < MIN_PROPORTION || yRange < MIN_PROPORTION )
151  {
152  mValid = false;
153  return;
154  }
155  }
156 
157  double myHeight = mSize.height();
158  double myWidth = mSize.width();
159 
160  if ( !myWidth || !myHeight )
161  {
162  mValid = false;
163  return;
164  }
165 
166  // calculate the translation and scaling parameters
167  double mapUnitsPerPixelY = mExtent.height() / myHeight;
168  double mapUnitsPerPixelX = mExtent.width() / myWidth;
169  mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
170 
171  // calculate the actual extent of the mapCanvas
172  double dxmin = mExtent.xMinimum(), dxmax = mExtent.xMaximum(),
173  dymin = mExtent.yMinimum(), dymax = mExtent.yMaximum(), whitespace;
174 
175  if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
176  {
177  whitespace = ( ( myWidth * mMapUnitsPerPixel ) - mExtent.width() ) * 0.5;
178  dxmin -= whitespace;
179  dxmax += whitespace;
180  }
181  else
182  {
183  whitespace = ( ( myHeight * mMapUnitsPerPixel ) - mExtent.height() ) * 0.5;
184  dymin -= whitespace;
185  dymax += whitespace;
186  }
187 
188  mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
189 
190  // update the scale
193 
195  visibleExtent().center().x(),
196  visibleExtent().center().y(),
197  outputSize().width(),
198  outputSize().height(),
199  mRotation );
200 
201 #if 1 // set visible extent taking rotation in consideration
202  if ( mRotation )
203  {
204  QgsPointXY p1 = mMapToPixel.toMapCoordinates( QPoint( 0, 0 ) );
205  QgsPointXY p2 = mMapToPixel.toMapCoordinates( QPoint( 0, myHeight ) );
206  QgsPointXY p3 = mMapToPixel.toMapCoordinates( QPoint( myWidth, 0 ) );
207  QgsPointXY p4 = mMapToPixel.toMapCoordinates( QPoint( myWidth, myHeight ) );
208  dxmin = std::min( p1.x(), std::min( p2.x(), std::min( p3.x(), p4.x() ) ) );
209  dymin = std::min( p1.y(), std::min( p2.y(), std::min( p3.y(), p4.y() ) ) );
210  dxmax = std::max( p1.x(), std::max( p2.x(), std::max( p3.x(), p4.x() ) ) );
211  dymax = std::max( p1.y(), std::max( p2.y(), std::max( p3.y(), p4.y() ) ) );
212  mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
213  }
214 #endif
215 
216  QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ), qgsDoubleToString( mapUnitsPerPixelY ) ) );
217  QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mSize.width() ), qgsDoubleToString( mSize.height() ) ) );
218  QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ), qgsDoubleToString( mExtent.height() ) ) );
220  QgsDebugMsg( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / myWidth ), qgsDoubleToString( mVisibleExtent.height() / myHeight ) ) );
221  QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / mMapUnitsPerPixel ), qgsDoubleToString( mVisibleExtent.height() / mMapUnitsPerPixel ) ) );
222  QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ) );
223  QgsDebugMsg( QString( "Rotation: %1 degrees" ).arg( mRotation ) );
224 
225  mValid = true;
226 }
227 
228 
230 {
231  return mSize;
232 }
233 
235 {
236  mSize = size;
237 
238  updateDerived();
239 }
240 
242 {
243  return mDpi;
244 }
245 
247 {
248  mDpi = dpi;
249 
250  updateDerived();
251 }
252 
253 
254 QStringList QgsMapSettings::layerIds() const
255 {
256  return _qgis_listQPointerToIDs( mLayers );
257 }
258 
259 
260 QList<QgsMapLayer *> QgsMapSettings::layers() const
261 {
262  return _qgis_listQPointerToRaw( mLayers );
263 }
264 
265 void QgsMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
266 {
267  mLayers = _qgis_listRawToQPointer( layers );
268 }
269 
270 QMap<QString, QString> QgsMapSettings::layerStyleOverrides() const
271 {
272  return mLayerStyleOverrides;
273 }
274 
275 void QgsMapSettings::setLayerStyleOverrides( const QMap<QString, QString> &overrides )
276 {
277  mLayerStyleOverrides = overrides;
278 }
279 
281 {
282  mDestCRS = crs;
285  // Since the map units have changed, force a recalculation of the scale.
286  updateDerived();
287 }
288 
290 {
291  return mDestCRS;
292 }
293 
295 {
297  if ( !params.valid )
298  {
299  return false;
300  }
301  else
302  {
304  return true;
305  }
306 }
307 
308 void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
309 {
310  mFlags = flags;
311 }
312 
314 {
315  if ( on )
316  mFlags |= flag;
317  else
318  mFlags &= ~flag;
319 }
320 
321 QgsMapSettings::Flags QgsMapSettings::flags() const
322 {
323  return mFlags;
324 }
325 
327 {
328  return mFlags.testFlag( flag );
329 }
330 
332 {
333  return mScaleCalculator.mapUnits();
334 }
335 
336 
338 {
339  return mValid;
340 }
341 
343 {
344  return mVisibleExtent;
345 }
346 
348 {
349  QPolygonF poly;
350 
351  const QSize &sz = outputSize();
352  const QgsMapToPixel &m2p = mapToPixel();
353 
354  poly << m2p.toMapCoordinatesF( 0, 0 ).toQPointF();
355  poly << m2p.toMapCoordinatesF( sz.width(), 0 ).toQPointF();
356  poly << m2p.toMapCoordinatesF( sz.width(), sz.height() ).toQPointF();
357  poly << m2p.toMapCoordinatesF( 0, sz.height() ).toQPointF();
358 
359  return poly;
360 }
361 
363 {
364  return mMapUnitsPerPixel;
365 }
366 
367 double QgsMapSettings::scale() const
368 {
369  return mScale;
370 }
371 
372 
374 {
375  return mDatumTransformStore.transformation( layer );
376 }
377 
378 
379 double QgsMapSettings::layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent ) const
380 {
381  QgsRectangle extent = referenceExtent.isEmpty() ? layer->extent() : referenceExtent;
382  QgsPointXY l1( extent.xMinimum(), extent.yMinimum() );
383  QgsPointXY l2( extent.xMaximum(), extent.yMaximum() );
384  double distLayerUnits = std::sqrt( l1.sqrDist( l2 ) );
385  QgsPointXY m1 = layerToMapCoordinates( layer, l1 );
386  QgsPointXY m2 = layerToMapCoordinates( layer, l2 );
387  double distMapUnits = std::sqrt( m1.sqrDist( m2 ) );
388  return distMapUnits / distLayerUnits;
389 }
390 
391 
393 {
394  try
395  {
397  if ( ct.isValid() )
398  {
399  QgsDebugMsg( QString( "sourceCrs = " + ct.sourceCrs().authid() ) );
400  QgsDebugMsg( QString( "destCRS = " + ct.destinationCrs().authid() ) );
401  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
402  extent = ct.transformBoundingBox( extent );
403  }
404  }
405  catch ( QgsCsException &cse )
406  {
407  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
408  }
409 
410  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
411 
412  return extent;
413 }
414 
415 
417 {
418  try
419  {
421  if ( ct.isValid() )
422  {
423  QgsDebugMsg( QString( "sourceCrs = " + ct.sourceCrs().authid() ) );
424  QgsDebugMsg( QString( "destCRS = " + ct.destinationCrs().authid() ) );
425  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
427  }
428  }
429  catch ( QgsCsException &cse )
430  {
431  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
432  }
433 
434  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
435 
436  return extent;
437 }
438 
439 
441 {
442  try
443  {
445  if ( ct.isValid() )
447  }
448  catch ( QgsCsException &cse )
449  {
450  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
451  }
452 
453  return point;
454 }
455 
456 
458 {
459  try
460  {
462  if ( ct.isValid() )
464  }
465  catch ( QgsCsException &cse )
466  {
467  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
468  }
469 
470  return rect;
471 }
472 
473 
475 {
476  try
477  {
479  if ( ct.isValid() )
481  }
482  catch ( QgsCsException &cse )
483  {
484  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
485  }
486 
487  return point;
488 }
489 
490 
492 {
493  try
494  {
496  if ( ct.isValid() )
498  }
499  catch ( QgsCsException &cse )
500  {
501  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
502  }
503 
504  return rect;
505 }
506 
507 
508 
510 {
511  QgsDebugMsg( "called." );
512 
513  // reset the map canvas extent since the extent may now be smaller
514  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
516  fullExtent.setMinimal();
517 
518  // iterate through the map layers and test each layers extent
519  // against the current min and max values
520  QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayers.count() ) );
521  Q_FOREACH ( const QgsWeakMapLayerPointer &layerPtr, mLayers )
522  {
523  if ( QgsMapLayer *lyr = layerPtr.data() )
524  {
525  QgsDebugMsg( "Updating extent using " + lyr->name() );
526  QgsDebugMsg( "Input extent: " + lyr->extent().toString() );
527 
528  if ( lyr->extent().isNull() )
529  continue;
530 
531  // Layer extents are stored in the coordinate system (CS) of the
532  // layer. The extent must be projected to the canvas CS
533  QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() );
534 
535  QgsDebugMsg( "Output extent: " + extent.toString() );
536  fullExtent.combineExtentWith( extent );
537  }
538  }
539 
540  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
541  {
542  // If all of the features are at the one point, buffer the
543  // rectangle a bit. If they are all at zero, do something a bit
544  // more crude.
545 
546  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
547  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
548  {
549  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
550  }
551  else
552  {
553  const double padFactor = 1e-8;
554  double widthPad = fullExtent.xMinimum() * padFactor;
555  double heightPad = fullExtent.yMinimum() * padFactor;
556  double xmin = fullExtent.xMinimum() - widthPad;
557  double xmax = fullExtent.xMaximum() + widthPad;
558  double ymin = fullExtent.yMinimum() - heightPad;
559  double ymax = fullExtent.yMaximum() + heightPad;
560  fullExtent.set( xmin, ymin, xmax, ymax );
561  }
562  }
563 
564  QgsDebugMsg( "Full extent: " + fullExtent.toString() );
565  return fullExtent;
566 }
567 
568 
569 void QgsMapSettings::readXml( QDomNode &node )
570 {
571  // set destination CRS
573  QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );
574  if ( !srsNode.isNull() )
575  {
576  srs.readXml( srsNode );
577  }
578  setDestinationCrs( srs );
579 
580  // set extent
581  QDomNode extentNode = node.namedItem( QStringLiteral( "extent" ) );
582  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
583  setExtent( aoi );
584 
585  // set rotation
586  QDomNode rotationNode = node.namedItem( QStringLiteral( "rotation" ) );
587  QString rotationVal = rotationNode.toElement().text();
588  if ( ! rotationVal.isEmpty() )
589  {
590  double rot = rotationVal.toDouble();
591  setRotation( rot );
592  }
593 
594  //render map tile
595  QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral( "rendermaptile" ) );
596  if ( !renderMapTileElem.isNull() )
597  {
598  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == QLatin1String( "1" ) );
599  }
600 
602 }
603 
604 
605 
606 void QgsMapSettings::writeXml( QDomNode &node, QDomDocument &doc )
607 {
608  // units
609  node.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), doc ) );
610 
611  // Write current view extents
612  node.appendChild( QgsXmlUtils::writeRectangle( extent(), doc ) );
613 
614  // Write current view rotation
615  QDomElement rotNode = doc.createElement( QStringLiteral( "rotation" ) );
616  rotNode.appendChild(
617  doc.createTextNode( qgsDoubleToString( rotation() ) )
618  );
619  node.appendChild( rotNode );
620 
621  // destination CRS
622  if ( mDestCRS.isValid() )
623  {
624  QDomElement srsNode = doc.createElement( QStringLiteral( "destinationsrs" ) );
625  node.appendChild( srsNode );
626  mDestCRS.writeXml( srsNode, doc );
627  }
628 
629  //render map tile
630  QDomElement renderMapTileElem = doc.createElement( QStringLiteral( "rendermaptile" ) );
631  QDomText renderMapTileText = doc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
632  renderMapTileElem.appendChild( renderMapTileText );
633  node.appendChild( renderMapTileElem );
634 
635  mDatumTransformStore.writeXml( node, doc );
636 }
double mMagnificationFactor
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Base class for all map layer types.
Definition: qgsmaplayer.h:54
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
QgsMapToPixel mMapToPixel
double magnificationFactor() const
Return the magnification factor.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QStringList layerIds() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
#define QgsDebugMsg(str)
Definition: qgslogger.h:37
QgsCoordinateReferenceSystem mDestCRS
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
double y
Definition: qgspointxy.h:47
A class to represent a 2D point.
Definition: qgspointxy.h:42
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
QMap< QString, QString > mLayerStyleOverrides
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer&#39;s CRS
void setOutputDpi(double dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform, const bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
double layerToMapUnits(const QgsMapLayer *layer, const QgsRectangle &referenceExtent=QgsRectangle()) const
Computes an estimated conversion factor between layer and map units: layerUnits * layerToMapUnits = m...
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
void setDestinationCrs(const QgsCoordinateReferenceSystem &destCrs)
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
Definition: qgsxmlutils.cpp:78
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system, which the transform will transform coordinates t...
void setFlags(QgsMapSettings::Flags flags)
Set combination of flags that will be used for rendering.
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Set map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
QList< QgsMapLayer * > layers() const
Get list of layers for map rendering The layers are stored in the reverse order of how they are rende...
Contains parameters for an ellipsoid.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1132
Q_GUI_EXPORT int qt_defaultDpiX()
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:210
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
static EllipsoidParameters ellipsoidParameters(const QString &ellipsoid)
Returns the parameters for the specified ellipsoid.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
virtual QgsRectangle extent() const
Returns the extent of the layer.
QString what() const
Definition: qgsexception.h:48
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
QgsUnitTypes::DistanceUnit mapUnits() const
Get units of map&#39;s geographical coordinates - used for scale calculation.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Return coordinate transform from layer&#39;s CRS to destination CRS.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:35
bool mValid
Whether the actual settings are valid (set in updateDerived())
QgsRectangle extent() const
Return geographical coordinates of the rectangle that should be rendered.
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspointxy.cpp:40
void setOutputSize(QSize size)
Set the size of the resulting map image.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from...
QgsRectangle mExtent
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
Flag
Enumeration of flags that adjust the way the map is rendered.
bool valid
Whether ellipsoid parameters are valid.
void setMagnificationFactor(double factor)
Set the magnification factor.
bool isEmpty() const
Returns true if the rectangle is empty.
double scale() const
Returns the calculated map scale.
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:123
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:198
double mapUnitsPerPixel() const
Return the distance in geographical coordinates that equals to one pixel in the map.
void setMapUnits(QgsUnitTypes::DistanceUnit mapUnits)
Set the map units.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
static QDomElement writeMapUnits(QgsUnitTypes::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
Definition: qgsxmlutils.cpp:66
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer&#39;s CRS to output CRS
void readXml(const QDomNode &parentNode)
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
Abstract base class for all geometries.
QgsScaleCalculator mScaleCalculator
const QgsMapToPixel & mapToPixel() const
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double x
Definition: qgspointxy.h:46
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:111
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:96
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
void combineExtentWith(const QgsRectangle &rect)
Expand the rectangle so that covers both the original rectangle and the given rectangle.
Draw map such that there are no problems between adjacent tiles.
Unknown distance unit.
Definition: qgsunittypes.h:53
double outputDpi() const
Return DPI used for conversion between real world units (e.g.
static void logMessage(const QString &message, const QString &tag=QString(), MessageLevel level=QgsMessageLog::WARNING)
add a message to the instance (and create it if necessary)
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
QMap< QString, QString > layerStyleOverrides() const
Get map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
QString ellipsoid() const
Returns ellipsoid&#39;s acronym.
Transform from destination to source CRS.
double mMapUnitsPerPixel
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const
Transform the point from the source CRS to the destination CRS.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer&#39;s CRS to output CRS
QgsRectangle fullExtent() const
returns current extent of layer set
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Flags flags() const
Return combination of flags used for rendering.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:101
void setLayers(const QList< QgsMapLayer *> &layers)
Set list of layers for map rendering.
QgsCoordinateTransform transformation(const QgsMapLayer *layer, QString srcAuthId=QString(), QString dstAuthId=QString()) const
Will return transform from layer&#39;s CRS to current destination CRS.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:106
Transform from source to destination CRS.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:64
QPolygonF visiblePolygon() const
Return the visible area as a polygon (may be rotated)
void readXml(QDomNode &node)
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
QgsDatumTransformStore mDatumTransformStore
void writeXml(QDomNode &node, QDomDocument &doc)
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer&#39;s CRS
QgsPointXY toMapCoordinatesF(double x, double y) const
Transform device coordinates to map (world) coordinates.
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:36
QSize outputSize() const
Return the size of the resulting map image.
QgsPointXY toMapCoordinates(int x, int y) const
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
QString authid() const
Returns the authority identifier for the CRS.
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:130
QgsUnitTypes::DistanceUnit mapUnits() const
Returns current map units.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.