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