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