QGIS API Documentation  2.99.0-Master (585a4d3)
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  mLayers = _qgis_listRawToQPointer( layers );
260 }
261 
262 QMap<QString, QString> QgsMapSettings::layerStyleOverrides() const
263 {
264  return mLayerStyleOverrides;
265 }
266 
267 void QgsMapSettings::setLayerStyleOverrides( const QMap<QString, QString> &overrides )
268 {
269  mLayerStyleOverrides = overrides;
270 }
271 
273 {
274  mDestCRS = crs;
276  // Since the map units have changed, force a recalculation of the scale.
277  updateDerived();
278 }
279 
281 {
282  return mDestCRS;
283 }
284 
286 {
288  if ( !params.valid )
289  {
290  return false;
291  }
292  else
293  {
295  return true;
296  }
297 }
298 
299 void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
300 {
301  mFlags = flags;
302 }
303 
305 {
306  if ( on )
307  mFlags |= flag;
308  else
309  mFlags &= ~flag;
310 }
311 
312 QgsMapSettings::Flags QgsMapSettings::flags() const
313 {
314  return mFlags;
315 }
316 
318 {
319  return mFlags.testFlag( flag );
320 }
321 
323 {
324  return mScaleCalculator.mapUnits();
325 }
326 
327 
329 {
330  return mValid;
331 }
332 
334 {
335  return mVisibleExtent;
336 }
337 
339 {
340  QPolygonF poly;
341 
342  const QSize &sz = outputSize();
343  const QgsMapToPixel &m2p = mapToPixel();
344 
345  poly << m2p.toMapCoordinatesF( 0, 0 ).toQPointF();
346  poly << m2p.toMapCoordinatesF( sz.width(), 0 ).toQPointF();
347  poly << m2p.toMapCoordinatesF( sz.width(), sz.height() ).toQPointF();
348  poly << m2p.toMapCoordinatesF( 0, sz.height() ).toQPointF();
349 
350  return poly;
351 }
352 
354 {
355  return mMapUnitsPerPixel;
356 }
357 
358 double QgsMapSettings::scale() const
359 {
360  return mScale;
361 }
362 
364 {
365 #ifdef QGISDEBUG
366  if ( !mHasTransformContext )
367  qWarning( "No QgsCoordinateTransformContext context set for transform" );
368 #endif
369 
370  return mTransformContext;
371 }
372 
374 {
375  mTransformContext = context;
376 #ifdef QGISDEBUG
377  mHasTransformContext = true;
378 #endif
379 }
380 
382 {
383  if ( !layer )
384  return QgsCoordinateTransform();
385 
387 }
388 
389 double QgsMapSettings::layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent ) const
390 {
391  QgsRectangle extent = referenceExtent.isEmpty() ? layer->extent() : referenceExtent;
392  QgsPointXY l1( extent.xMinimum(), extent.yMinimum() );
393  QgsPointXY l2( extent.xMaximum(), extent.yMaximum() );
394  double distLayerUnits = std::sqrt( l1.sqrDist( l2 ) );
395  QgsPointXY m1 = layerToMapCoordinates( layer, l1 );
396  QgsPointXY m2 = layerToMapCoordinates( layer, l2 );
397  double distMapUnits = std::sqrt( m1.sqrDist( m2 ) );
398  return distMapUnits / distLayerUnits;
399 }
400 
401 
403 {
404  try
405  {
407  if ( ct.isValid() )
408  {
409  QgsDebugMsgLevel( QString( "sourceCrs = " + ct.sourceCrs().authid() ), 3 );
410  QgsDebugMsgLevel( QString( "destCRS = " + ct.destinationCrs().authid() ), 3 );
411  QgsDebugMsgLevel( QString( "extent = " + extent.toString() ), 3 );
412  extent = ct.transformBoundingBox( extent );
413  }
414  }
415  catch ( QgsCsException &cse )
416  {
417  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
418  }
419 
420  QgsDebugMsgLevel( QString( "proj extent = " + extent.toString() ), 3 );
421 
422  return extent;
423 }
424 
425 
427 {
428  try
429  {
431  if ( ct.isValid() )
432  {
433  QgsDebugMsgLevel( QString( "sourceCrs = " + ct.sourceCrs().authid() ), 3 );
434  QgsDebugMsgLevel( QString( "destCRS = " + ct.destinationCrs().authid() ), 3 );
435  QgsDebugMsgLevel( QString( "extent = " + extent.toString() ), 3 );
437  }
438  }
439  catch ( QgsCsException &cse )
440  {
441  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
442  }
443 
444  QgsDebugMsgLevel( QString( "proj extent = " + extent.toString() ), 3 );
445 
446  return extent;
447 }
448 
449 
451 {
452  try
453  {
455  if ( ct.isValid() )
457  }
458  catch ( QgsCsException &cse )
459  {
460  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
461  }
462 
463  return point;
464 }
465 
466 
468 {
469  try
470  {
472  if ( ct.isValid() )
474  }
475  catch ( QgsCsException &cse )
476  {
477  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
478  }
479 
480  return rect;
481 }
482 
483 
485 {
486  try
487  {
489  if ( ct.isValid() )
491  }
492  catch ( QgsCsException &cse )
493  {
494  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
495  }
496 
497  return point;
498 }
499 
500 
502 {
503  try
504  {
506  if ( ct.isValid() )
508  }
509  catch ( QgsCsException &cse )
510  {
511  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
512  }
513 
514  return rect;
515 }
516 
517 
518 
520 {
521  // reset the map canvas extent since the extent may now be smaller
522  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
524  fullExtent.setMinimal();
525 
526  // iterate through the map layers and test each layers extent
527  // against the current min and max values
528  QgsDebugMsgLevel( QString( "Layer count: %1" ).arg( mLayers.count() ), 5 );
529  Q_FOREACH ( const QgsWeakMapLayerPointer &layerPtr, mLayers )
530  {
531  if ( QgsMapLayer *lyr = layerPtr.data() )
532  {
533  QgsDebugMsgLevel( "Updating extent using " + lyr->name(), 5 );
534  QgsDebugMsgLevel( "Input extent: " + lyr->extent().toString(), 5 );
535 
536  if ( lyr->extent().isNull() )
537  continue;
538 
539  // Layer extents are stored in the coordinate system (CS) of the
540  // layer. The extent must be projected to the canvas CS
541  QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() );
542 
543  QgsDebugMsgLevel( "Output extent: " + extent.toString(), 5 );
544  fullExtent.combineExtentWith( extent );
545  }
546  }
547 
548  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
549  {
550  // If all of the features are at the one point, buffer the
551  // rectangle a bit. If they are all at zero, do something a bit
552  // more crude.
553 
554  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
555  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
556  {
557  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
558  }
559  else
560  {
561  const double padFactor = 1e-8;
562  double widthPad = fullExtent.xMinimum() * padFactor;
563  double heightPad = fullExtent.yMinimum() * padFactor;
564  double xmin = fullExtent.xMinimum() - widthPad;
565  double xmax = fullExtent.xMaximum() + widthPad;
566  double ymin = fullExtent.yMinimum() - heightPad;
567  double ymax = fullExtent.yMaximum() + heightPad;
568  fullExtent.set( xmin, ymin, xmax, ymax );
569  }
570  }
571 
572  QgsDebugMsgLevel( "Full extent: " + fullExtent.toString(), 5 );
573  return fullExtent;
574 }
575 
576 
577 void QgsMapSettings::readXml( QDomNode &node )
578 {
579  // set destination CRS
581  QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );
582  if ( !srsNode.isNull() )
583  {
584  srs.readXml( srsNode );
585  }
586  setDestinationCrs( srs );
587 
588  // set extent
589  QDomNode extentNode = node.namedItem( QStringLiteral( "extent" ) );
590  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
591  setExtent( aoi );
592 
593  // set rotation
594  QDomNode rotationNode = node.namedItem( QStringLiteral( "rotation" ) );
595  QString rotationVal = rotationNode.toElement().text();
596  if ( ! rotationVal.isEmpty() )
597  {
598  double rot = rotationVal.toDouble();
599  setRotation( rot );
600  }
601 
602  //render map tile
603  QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral( "rendermaptile" ) );
604  if ( !renderMapTileElem.isNull() )
605  {
606  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == QLatin1String( "1" ) );
607  }
608 }
609 
610 
611 
612 void QgsMapSettings::writeXml( QDomNode &node, QDomDocument &doc )
613 {
614  // units
615  node.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), doc ) );
616 
617  // Write current view extents
618  node.appendChild( QgsXmlUtils::writeRectangle( extent(), doc ) );
619 
620  // Write current view rotation
621  QDomElement rotNode = doc.createElement( QStringLiteral( "rotation" ) );
622  rotNode.appendChild(
623  doc.createTextNode( qgsDoubleToString( rotation() ) )
624  );
625  node.appendChild( rotNode );
626 
627  // destination CRS
628  if ( mDestCRS.isValid() )
629  {
630  QDomElement srsNode = doc.createElement( QStringLiteral( "destinationsrs" ) );
631  node.appendChild( srsNode );
632  mDestCRS.writeXml( srsNode, doc );
633  }
634 
635  //render map tile
636  QDomElement renderMapTileElem = doc.createElement( QStringLiteral( "rendermaptile" ) );
637  QDomText renderMapTileText = doc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
638  renderMapTileElem.appendChild( renderMapTileText );
639  node.appendChild( renderMapTileElem );
640 }
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.