QGIS API Documentation  2.99.0-Master (19b062c)
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  , mDatumTransformStore( mDestCRS )
38  , mBackgroundColor( Qt::white )
39  , mSelectionColor( Qt::yellow )
40  , mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling | DrawSelection )
41  , mSegmentationTolerance( M_PI_2 / 90 )
42 {
44 
45  updateDerived();
46 }
47 
49 {
50  double ratio = mMagnificationFactor / factor;
51 
52  mMagnificationFactor = factor;
53 
54  double rot = rotation();
55  setRotation( 0.0 );
56 
58  ext.scale( ratio );
59 
60  mRotation = rot;
61  mExtent = ext;
62  mDpi = mDpi / ratio;
63 
64  QgsDebugMsg( QString( "Magnification factor: %1 dpi: %2 ratio: %3" ).arg( factor ).arg( mDpi ).arg( ratio ) );
65 
66  updateDerived();
67 }
68 
70 {
71  return mMagnificationFactor;
72 }
73 
75 {
76  return mExtent;
77 }
78 
79 void QgsMapSettings::setExtent( const QgsRectangle &extent, bool magnified )
80 {
81  QgsRectangle magnifiedExtent = extent;
82 
83  if ( !magnified )
84  magnifiedExtent.scale( 1 / mMagnificationFactor );
85 
86  mExtent = magnifiedExtent;
87 
88  updateDerived();
89 }
90 
92 {
93  return mRotation;
94 }
95 
96 void QgsMapSettings::setRotation( double degrees )
97 {
98  if ( qgsDoubleNear( mRotation, degrees ) )
99  return;
100 
101  mRotation = degrees;
102 
103  // TODO: update extent while keeping scale ?
104  updateDerived();
105 }
106 
107 
109 {
111 
112  if ( extent.isEmpty() || !extent.isFinite() )
113  {
114  mValid = false;
115  return;
116  }
117 
118  // Don't allow zooms where the current extent is so small that it
119  // can't be accurately represented using a double (which is what
120  // currentExtent uses). Excluding 0 avoids a divide by zero and an
121  // infinite loop when rendering to a new canvas. Excluding extents
122  // greater than 1 avoids doing unnecessary calculations.
123 
124  // The scheme is to compare the width against the mean x coordinate
125  // (and height against mean y coordinate) and only allow zooms where
126  // the ratio indicates that there is more than about 12 significant
127  // figures (there are about 16 significant figures in a double).
128 
129  if ( extent.width() > 0 &&
130  extent.height() > 0 &&
131  extent.width() < 1 &&
132  extent.height() < 1 )
133  {
134  // Use abs() on the extent to avoid the case where the extent is
135  // symmetrical about 0.
136  double xMean = ( std::fabs( extent.xMinimum() ) + std::fabs( extent.xMaximum() ) ) * 0.5;
137  double yMean = ( std::fabs( extent.yMinimum() ) + std::fabs( extent.yMaximum() ) ) * 0.5;
138 
139  double xRange = extent.width() / xMean;
140  double yRange = extent.height() / yMean;
141 
142  static const double MIN_PROPORTION = 1e-12;
143  if ( xRange < MIN_PROPORTION || yRange < MIN_PROPORTION )
144  {
145  mValid = false;
146  return;
147  }
148  }
149 
150  double myHeight = mSize.height();
151  double myWidth = mSize.width();
152 
153  if ( !myWidth || !myHeight )
154  {
155  mValid = false;
156  return;
157  }
158 
159  // calculate the translation and scaling parameters
160  double mapUnitsPerPixelY = mExtent.height() / myHeight;
161  double mapUnitsPerPixelX = mExtent.width() / myWidth;
162  mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
163 
164  // calculate the actual extent of the mapCanvas
165  double dxmin = mExtent.xMinimum(), dxmax = mExtent.xMaximum(),
166  dymin = mExtent.yMinimum(), dymax = mExtent.yMaximum(), whitespace;
167 
168  if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
169  {
170  whitespace = ( ( myWidth * mMapUnitsPerPixel ) - mExtent.width() ) * 0.5;
171  dxmin -= whitespace;
172  dxmax += whitespace;
173  }
174  else
175  {
176  whitespace = ( ( myHeight * mMapUnitsPerPixel ) - mExtent.height() ) * 0.5;
177  dymin -= whitespace;
178  dymax += whitespace;
179  }
180 
181  mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
182 
183  // update the scale
186 
188  visibleExtent().center().x(),
189  visibleExtent().center().y(),
190  outputSize().width(),
191  outputSize().height(),
192  mRotation );
193 
194 #if 1 // set visible extent taking rotation in consideration
195  if ( mRotation )
196  {
197  QgsPointXY p1 = mMapToPixel.toMapCoordinates( QPoint( 0, 0 ) );
198  QgsPointXY p2 = mMapToPixel.toMapCoordinates( QPoint( 0, myHeight ) );
199  QgsPointXY p3 = mMapToPixel.toMapCoordinates( QPoint( myWidth, 0 ) );
200  QgsPointXY p4 = mMapToPixel.toMapCoordinates( QPoint( myWidth, myHeight ) );
201  dxmin = std::min( p1.x(), std::min( p2.x(), std::min( p3.x(), p4.x() ) ) );
202  dymin = std::min( p1.y(), std::min( p2.y(), std::min( p3.y(), p4.y() ) ) );
203  dxmax = std::max( p1.x(), std::max( p2.x(), std::max( p3.x(), p4.x() ) ) );
204  dymax = std::max( p1.y(), std::max( p2.y(), std::max( p3.y(), p4.y() ) ) );
205  mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
206  }
207 #endif
208 
209  QgsDebugMsgLevel( QString( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ), qgsDoubleToString( mapUnitsPerPixelY ) ), 5 );
210  QgsDebugMsgLevel( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mSize.width() ), qgsDoubleToString( mSize.height() ) ), 5 );
211  QgsDebugMsgLevel( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ), qgsDoubleToString( mExtent.height() ) ), 5 );
213  QgsDebugMsgLevel( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / myWidth ), qgsDoubleToString( mVisibleExtent.height() / myHeight ) ), 5 );
214  QgsDebugMsgLevel( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / mMapUnitsPerPixel ), qgsDoubleToString( mVisibleExtent.height() / mMapUnitsPerPixel ) ), 5 );
215  QgsDebugMsgLevel( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ), 5 );
216  QgsDebugMsgLevel( QString( "Rotation: %1 degrees" ).arg( mRotation ), 5 );
217 
218  mValid = true;
219 }
220 
221 
223 {
224  return mSize;
225 }
226 
228 {
229  mSize = size;
230 
231  updateDerived();
232 }
233 
235 {
236  return mDpi;
237 }
238 
240 {
241  mDpi = dpi;
242 
243  updateDerived();
244 }
245 
246 
247 QStringList QgsMapSettings::layerIds() const
248 {
249  return _qgis_listQPointerToIDs( mLayers );
250 }
251 
252 
253 QList<QgsMapLayer *> QgsMapSettings::layers() const
254 {
255  return _qgis_listQPointerToRaw( mLayers );
256 }
257 
258 void QgsMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
259 {
260  mLayers = _qgis_listRawToQPointer( layers );
261 }
262 
263 QMap<QString, QString> QgsMapSettings::layerStyleOverrides() const
264 {
265  return mLayerStyleOverrides;
266 }
267 
268 void QgsMapSettings::setLayerStyleOverrides( const QMap<QString, QString> &overrides )
269 {
270  mLayerStyleOverrides = overrides;
271 }
272 
274 {
275  mDestCRS = crs;
278  // Since the map units have changed, force a recalculation of the scale.
279  updateDerived();
280 }
281 
283 {
284  return mDestCRS;
285 }
286 
288 {
290  if ( !params.valid )
291  {
292  return false;
293  }
294  else
295  {
297  return true;
298  }
299 }
300 
301 void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
302 {
303  mFlags = flags;
304 }
305 
307 {
308  if ( on )
309  mFlags |= flag;
310  else
311  mFlags &= ~flag;
312 }
313 
314 QgsMapSettings::Flags QgsMapSettings::flags() const
315 {
316  return mFlags;
317 }
318 
320 {
321  return mFlags.testFlag( flag );
322 }
323 
325 {
326  return mScaleCalculator.mapUnits();
327 }
328 
329 
331 {
332  return mValid;
333 }
334 
336 {
337  return mVisibleExtent;
338 }
339 
341 {
342  QPolygonF poly;
343 
344  const QSize &sz = outputSize();
345  const QgsMapToPixel &m2p = mapToPixel();
346 
347  poly << m2p.toMapCoordinatesF( 0, 0 ).toQPointF();
348  poly << m2p.toMapCoordinatesF( sz.width(), 0 ).toQPointF();
349  poly << m2p.toMapCoordinatesF( sz.width(), sz.height() ).toQPointF();
350  poly << m2p.toMapCoordinatesF( 0, sz.height() ).toQPointF();
351 
352  return poly;
353 }
354 
356 {
357  return mMapUnitsPerPixel;
358 }
359 
360 double QgsMapSettings::scale() const
361 {
362  return mScale;
363 }
364 
365 
367 {
368  return mDatumTransformStore.transformation( layer );
369 }
370 
371 
372 double QgsMapSettings::layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent ) const
373 {
374  QgsRectangle extent = referenceExtent.isEmpty() ? layer->extent() : referenceExtent;
375  QgsPointXY l1( extent.xMinimum(), extent.yMinimum() );
376  QgsPointXY l2( extent.xMaximum(), extent.yMaximum() );
377  double distLayerUnits = std::sqrt( l1.sqrDist( l2 ) );
378  QgsPointXY m1 = layerToMapCoordinates( layer, l1 );
379  QgsPointXY m2 = layerToMapCoordinates( layer, l2 );
380  double distMapUnits = std::sqrt( m1.sqrDist( m2 ) );
381  return distMapUnits / distLayerUnits;
382 }
383 
384 
386 {
387  try
388  {
390  if ( ct.isValid() )
391  {
392  QgsDebugMsg( QString( "sourceCrs = " + ct.sourceCrs().authid() ) );
393  QgsDebugMsg( QString( "destCRS = " + ct.destinationCrs().authid() ) );
394  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
395  extent = ct.transformBoundingBox( extent );
396  }
397  }
398  catch ( QgsCsException &cse )
399  {
400  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
401  }
402 
403  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
404 
405  return extent;
406 }
407 
408 
410 {
411  try
412  {
414  if ( ct.isValid() )
415  {
416  QgsDebugMsg( QString( "sourceCrs = " + ct.sourceCrs().authid() ) );
417  QgsDebugMsg( QString( "destCRS = " + ct.destinationCrs().authid() ) );
418  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
420  }
421  }
422  catch ( QgsCsException &cse )
423  {
424  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
425  }
426 
427  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
428 
429  return extent;
430 }
431 
432 
434 {
435  try
436  {
438  if ( ct.isValid() )
440  }
441  catch ( QgsCsException &cse )
442  {
443  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
444  }
445 
446  return point;
447 }
448 
449 
451 {
452  try
453  {
455  if ( ct.isValid() )
457  }
458  catch ( QgsCsException &cse )
459  {
460  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
461  }
462 
463  return rect;
464 }
465 
466 
468 {
469  try
470  {
472  if ( ct.isValid() )
474  }
475  catch ( QgsCsException &cse )
476  {
477  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
478  }
479 
480  return point;
481 }
482 
483 
485 {
486  try
487  {
489  if ( ct.isValid() )
491  }
492  catch ( QgsCsException &cse )
493  {
494  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
495  }
496 
497  return rect;
498 }
499 
500 
501 
503 {
504  // reset the map canvas extent since the extent may now be smaller
505  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
507  fullExtent.setMinimal();
508 
509  // iterate through the map layers and test each layers extent
510  // against the current min and max values
511  QgsDebugMsgLevel( QString( "Layer count: %1" ).arg( mLayers.count() ), 5 );
512  Q_FOREACH ( const QgsWeakMapLayerPointer &layerPtr, mLayers )
513  {
514  if ( QgsMapLayer *lyr = layerPtr.data() )
515  {
516  QgsDebugMsgLevel( "Updating extent using " + lyr->name(), 5 );
517  QgsDebugMsgLevel( "Input extent: " + lyr->extent().toString(), 5 );
518 
519  if ( lyr->extent().isNull() )
520  continue;
521 
522  // Layer extents are stored in the coordinate system (CS) of the
523  // layer. The extent must be projected to the canvas CS
524  QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() );
525 
526  QgsDebugMsgLevel( "Output extent: " + extent.toString(), 5 );
527  fullExtent.combineExtentWith( extent );
528  }
529  }
530 
531  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
532  {
533  // If all of the features are at the one point, buffer the
534  // rectangle a bit. If they are all at zero, do something a bit
535  // more crude.
536 
537  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
538  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
539  {
540  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
541  }
542  else
543  {
544  const double padFactor = 1e-8;
545  double widthPad = fullExtent.xMinimum() * padFactor;
546  double heightPad = fullExtent.yMinimum() * padFactor;
547  double xmin = fullExtent.xMinimum() - widthPad;
548  double xmax = fullExtent.xMaximum() + widthPad;
549  double ymin = fullExtent.yMinimum() - heightPad;
550  double ymax = fullExtent.yMaximum() + heightPad;
551  fullExtent.set( xmin, ymin, xmax, ymax );
552  }
553  }
554 
555  QgsDebugMsgLevel( "Full extent: " + fullExtent.toString(), 5 );
556  return fullExtent;
557 }
558 
559 
560 void QgsMapSettings::readXml( QDomNode &node )
561 {
562  // set destination CRS
564  QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );
565  if ( !srsNode.isNull() )
566  {
567  srs.readXml( srsNode );
568  }
569  setDestinationCrs( srs );
570 
571  // set extent
572  QDomNode extentNode = node.namedItem( QStringLiteral( "extent" ) );
573  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
574  setExtent( aoi );
575 
576  // set rotation
577  QDomNode rotationNode = node.namedItem( QStringLiteral( "rotation" ) );
578  QString rotationVal = rotationNode.toElement().text();
579  if ( ! rotationVal.isEmpty() )
580  {
581  double rot = rotationVal.toDouble();
582  setRotation( rot );
583  }
584 
585  //render map tile
586  QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral( "rendermaptile" ) );
587  if ( !renderMapTileElem.isNull() )
588  {
589  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == QLatin1String( "1" ) );
590  }
591 
593 }
594 
595 
596 
597 void QgsMapSettings::writeXml( QDomNode &node, QDomDocument &doc )
598 {
599  // units
600  node.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), doc ) );
601 
602  // Write current view extents
603  node.appendChild( QgsXmlUtils::writeRectangle( extent(), doc ) );
604 
605  // Write current view rotation
606  QDomElement rotNode = doc.createElement( QStringLiteral( "rotation" ) );
607  rotNode.appendChild(
608  doc.createTextNode( qgsDoubleToString( rotation() ) )
609  );
610  node.appendChild( rotNode );
611 
612  // destination CRS
613  if ( mDestCRS.isValid() )
614  {
615  QDomElement srsNode = doc.createElement( QStringLiteral( "destinationsrs" ) );
616  node.appendChild( srsNode );
617  mDestCRS.writeXml( srsNode, doc );
618  }
619 
620  //render map tile
621  QDomElement renderMapTileElem = doc.createElement( QStringLiteral( "rendermaptile" ) );
622  QDomText renderMapTileText = doc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
623  renderMapTileElem.appendChild( renderMapTileText );
624  node.appendChild( renderMapTileElem );
625 
626  mDatumTransformStore.writeXml( node, doc );
627 }
double mMagnificationFactor
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
A rectangle specified with double values.
Definition: qgsrectangle.h:39
Base class for all map layer types.
Definition: qgsmaplayer.h:56
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:48
A class to represent a 2D point.
Definition: qgspointxy.h:43
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:1223
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:227
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:36
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.
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:38
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:138
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:213
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.
QgsScaleCalculator mScaleCalculator
const QgsMapToPixel & mapToPixel() const
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double x
Definition: qgspointxy.h:47
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:126
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:43
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:111
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:54
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:116
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:121
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:65
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:145
QgsUnitTypes::DistanceUnit mapUnits() const
Returns current map units.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.