QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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( QStringLiteral( "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( QStringLiteral( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ), qgsDoubleToString( mapUnitsPerPixelY ) ), 5 );
209  QgsDebugMsgLevel( QStringLiteral( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mSize.width() ), qgsDoubleToString( mSize.height() ) ), 5 );
210  QgsDebugMsgLevel( QStringLiteral( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ), qgsDoubleToString( mExtent.height() ) ), 5 );
212  QgsDebugMsgLevel( QStringLiteral( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / myWidth ), qgsDoubleToString( mVisibleExtent.height() / myHeight ) ), 5 );
213  QgsDebugMsgLevel( QStringLiteral( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / mMapUnitsPerPixel ), qgsDoubleToString( mVisibleExtent.height() / mMapUnitsPerPixel ) ), 5 );
214  QgsDebugMsgLevel( QStringLiteral( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ), 5 );
215  QgsDebugMsgLevel( QStringLiteral( "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 mDevicePixelRatio;
236 }
237 
239 {
240  mDevicePixelRatio = dpr;
241  updateDerived();
242 }
243 
245 {
246  return outputSize() * mDevicePixelRatio;
247 }
248 
250 {
251  return mDpi;
252 }
253 
255 {
256  mDpi = dpi;
257 
258  updateDerived();
259 }
260 
261 
262 QStringList QgsMapSettings::layerIds() const
263 {
264  return _qgis_listQPointerToIDs( mLayers );
265 }
266 
267 
268 QList<QgsMapLayer *> QgsMapSettings::layers() const
269 {
270  return _qgis_listQPointerToRaw( mLayers );
271 }
272 
273 void QgsMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
274 {
275  // filter list, removing null layers and non-spatial layers
276  auto filteredList = layers;
277  filteredList.erase( std::remove_if( filteredList.begin(), filteredList.end(),
278  []( QgsMapLayer * layer )
279  {
280  return !layer || !layer->isSpatial();
281  } ), filteredList.end() );
282 
283  mLayers = _qgis_listRawToQPointer( filteredList );
284 }
285 
286 QMap<QString, QString> QgsMapSettings::layerStyleOverrides() const
287 {
288  return mLayerStyleOverrides;
289 }
290 
291 void QgsMapSettings::setLayerStyleOverrides( const QMap<QString, QString> &overrides )
292 {
293  mLayerStyleOverrides = overrides;
294 }
295 
297 {
298  mDestCRS = crs;
300  // Since the map units have changed, force a recalculation of the scale.
301  updateDerived();
302 }
303 
305 {
306  return mDestCRS;
307 }
308 
310 {
312  if ( !params.valid )
313  {
314  return false;
315  }
316  else
317  {
319  return true;
320  }
321 }
322 
323 void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
324 {
325  mFlags = flags;
326 }
327 
329 {
330  if ( on )
331  mFlags |= flag;
332  else
333  mFlags &= ~flag;
334 }
335 
336 QgsMapSettings::Flags QgsMapSettings::flags() const
337 {
338  return mFlags;
339 }
340 
342 {
343  return mFlags.testFlag( flag );
344 }
345 
347 {
348  return mScaleCalculator.mapUnits();
349 }
350 
351 
353 {
354  return mValid;
355 }
356 
358 {
359  return mVisibleExtent;
360 }
361 
363 {
364  QPolygonF poly;
365 
366  const QSize &sz = outputSize();
367  const QgsMapToPixel &m2p = mapToPixel();
368 
369  poly << m2p.toMapCoordinates( 0.0, 0.0 ).toQPointF();
370  poly << m2p.toMapCoordinates( static_cast<double>( sz.width() ), 0.0 ).toQPointF();
371  poly << m2p.toMapCoordinates( static_cast<double>( sz.width() ), static_cast<double>( sz.height() ) ).toQPointF();
372  poly << m2p.toMapCoordinates( 0.0, static_cast<double>( sz.height() ) ).toQPointF();
373 
374  return poly;
375 }
376 
378 {
379  return mMapUnitsPerPixel;
380 }
381 
382 double QgsMapSettings::scale() const
383 {
384  return mScale;
385 }
386 
388 {
389 #ifdef QGISDEBUG
390  if ( !mHasTransformContext )
391  QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 );
392 #endif
393 
394  return mTransformContext;
395 }
396 
398 {
399  mTransformContext = context;
400 #ifdef QGISDEBUG
401  mHasTransformContext = true;
402 #endif
403 }
404 
406 {
407  if ( !layer )
408  return QgsCoordinateTransform();
409 
411 }
412 
413 double QgsMapSettings::layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent ) const
414 {
415  return layerTransform( layer ).scaleFactor( referenceExtent );
416 }
417 
418 
420 {
421  try
422  {
424  if ( ct.isValid() )
425  {
426  QgsDebugMsgLevel( QStringLiteral( "sourceCrs = %1" ).arg( ct.sourceCrs().authid() ), 3 );
427  QgsDebugMsgLevel( QStringLiteral( "destCRS = %1" ).arg( ct.destinationCrs().authid() ), 3 );
428  QgsDebugMsgLevel( QStringLiteral( "extent %1" ).arg( extent.toString() ), 3 );
429  extent = ct.transformBoundingBox( extent );
430  }
431  }
432  catch ( QgsCsException &cse )
433  {
434  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
435  }
436 
437  QgsDebugMsgLevel( QStringLiteral( "proj extent = %1 " ).arg( extent.toString() ), 3 );
438 
439  return extent;
440 }
441 
442 
444 {
445  try
446  {
448  if ( ct.isValid() )
449  {
450  QgsDebugMsgLevel( QStringLiteral( "sourceCrs = %1" ).arg( ct.sourceCrs().authid() ), 3 );
451  QgsDebugMsgLevel( QStringLiteral( "destCRS = %1" ).arg( ct.destinationCrs().authid() ), 3 );
452  QgsDebugMsgLevel( QStringLiteral( "extent = %1" ).arg( extent.toString() ), 3 );
454  }
455  }
456  catch ( QgsCsException &cse )
457  {
458  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
459  }
460 
461  QgsDebugMsgLevel( QStringLiteral( "proj extent = %1" ).arg( extent.toString() ), 3 );
462 
463  return extent;
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 point;
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 rect;
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 point;
515 }
516 
517 
519 {
520  try
521  {
523  if ( ct.isValid() )
525  }
526  catch ( QgsCsException &cse )
527  {
528  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
529  }
530 
531  return rect;
532 }
533 
534 
535 
537 {
538  // reset the map canvas extent since the extent may now be smaller
539  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
541  fullExtent.setMinimal();
542 
543  // iterate through the map layers and test each layers extent
544  // against the current min and max values
545  QgsDebugMsgLevel( QStringLiteral( "Layer count: %1" ).arg( mLayers.count() ), 5 );
546  Q_FOREACH ( const QgsWeakMapLayerPointer &layerPtr, mLayers )
547  {
548  if ( QgsMapLayer *lyr = layerPtr.data() )
549  {
550  QgsDebugMsgLevel( "Updating extent using " + lyr->name(), 5 );
551  QgsDebugMsgLevel( "Input extent: " + lyr->extent().toString(), 5 );
552 
553  if ( lyr->extent().isNull() )
554  continue;
555 
556  // Layer extents are stored in the coordinate system (CS) of the
557  // layer. The extent must be projected to the canvas CS
558  QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() );
559 
560  QgsDebugMsgLevel( "Output extent: " + extent.toString(), 5 );
561  fullExtent.combineExtentWith( extent );
562  }
563  }
564 
565  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
566  {
567  // If all of the features are at the one point, buffer the
568  // rectangle a bit. If they are all at zero, do something a bit
569  // more crude.
570 
571  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
572  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
573  {
574  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
575  }
576  else
577  {
578  const double padFactor = 1e-8;
579  double widthPad = fullExtent.xMinimum() * padFactor;
580  double heightPad = fullExtent.yMinimum() * padFactor;
581  double xmin = fullExtent.xMinimum() - widthPad;
582  double xmax = fullExtent.xMaximum() + widthPad;
583  double ymin = fullExtent.yMinimum() - heightPad;
584  double ymax = fullExtent.yMaximum() + heightPad;
585  fullExtent.set( xmin, ymin, xmax, ymax );
586  }
587  }
588 
589  QgsDebugMsgLevel( "Full extent: " + fullExtent.toString(), 5 );
590  return fullExtent;
591 }
592 
593 
594 void QgsMapSettings::readXml( QDomNode &node )
595 {
596  // set destination CRS
598  QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );
599  if ( !srsNode.isNull() )
600  {
601  srs.readXml( srsNode );
602  }
603  setDestinationCrs( srs );
604 
605  // set extent
606  QDomNode extentNode = node.namedItem( QStringLiteral( "extent" ) );
607  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
608  setExtent( aoi );
609 
610  // set rotation
611  QDomNode rotationNode = node.namedItem( QStringLiteral( "rotation" ) );
612  QString rotationVal = rotationNode.toElement().text();
613  if ( ! rotationVal.isEmpty() )
614  {
615  double rot = rotationVal.toDouble();
616  setRotation( rot );
617  }
618 
619  //render map tile
620  QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral( "rendermaptile" ) );
621  if ( !renderMapTileElem.isNull() )
622  {
623  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == QLatin1String( "1" ) );
624  }
625 }
626 
627 
628 
629 void QgsMapSettings::writeXml( QDomNode &node, QDomDocument &doc )
630 {
631  // units
632  node.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), doc ) );
633 
634  // Write current view extents
635  node.appendChild( QgsXmlUtils::writeRectangle( extent(), doc ) );
636 
637  // Write current view rotation
638  QDomElement rotNode = doc.createElement( QStringLiteral( "rotation" ) );
639  rotNode.appendChild(
640  doc.createTextNode( qgsDoubleToString( rotation() ) )
641  );
642  node.appendChild( rotNode );
643 
644  // destination CRS
645  if ( mDestCRS.isValid() )
646  {
647  QDomElement srsNode = doc.createElement( QStringLiteral( "destinationsrs" ) );
648  node.appendChild( srsNode );
649  mDestCRS.writeXml( srsNode, doc );
650  }
651 
652  //render map tile
653  QDomElement renderMapTileElem = doc.createElement( QStringLiteral( "rendermaptile" ) );
654  QDomText renderMapTileText = doc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
655  renderMapTileElem.appendChild( renderMapTileText );
656  node.appendChild( renderMapTileElem );
657 }
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspointxy.h:148
QgsUnitTypes::DistanceUnit mapUnits() const
Gets units of map&#39;s geographical coordinates - used for scale calculation.
double mMagnificationFactor
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Base class for all map layer types.
Definition: qgsmaplayer.h:63
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:425
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.
Definition: qgsrectangle.h:150
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
QgsMapToPixel mMapToPixel
double calculate(const QgsRectangle &mapExtent, double canvasWidth)
Calculate the scale denominator.
double scale() const
Returns the calculated map scale.
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
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
Definition: qgsrectangle.h:515
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:171
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsCoordinateReferenceSystem mDestCRS
QgsUnitTypes::DistanceUnit mapUnits() const
Returns current map units.
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
float devicePixelRatio() const
Returns device pixel ratio Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" di...
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from...
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.
Definition: qgsrectangle.h:234
QMap< QString, QString > mLayerStyleOverrides
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:278
void setOutputDpi(double dpi)
Sets DPI used for conversion between real world units (e.g. mm) and pixels.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
QMap< QString, QString > layerStyleOverrides() const
Gets map of map layer style overrides (key: layer ID, value: style name) where a different style shou...
void setDpi(double dpi)
Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
Definition: qgsxmlutils.cpp:78
void setFlags(QgsMapSettings::Flags flags)
Sets combination of flags that will be used for rendering.
const QgsMapToPixel & mapToPixel() const
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer&#39;s CRS
Flags flags() const
Returns combination of flags 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...
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer&#39;s CRS to destination CRS.
const QgsCoordinateReferenceSystem & crs
Contains parameters for an ellipsoid.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1482
Q_GUI_EXPORT int qt_defaultDpiX()
static EllipsoidParameters ellipsoidParameters(const QString &ellipsoid)
Returns the parameters for the specified ellipsoid.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system, which the transform will transform coordinates t...
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:36
bool mValid
Whether the actual settings are valid (set in updateDerived())
void setOutputSize(QSize size)
Sets the size of the resulting map image.
double magnificationFactor() const
Returns the magnification factor.
QgsRectangle mExtent
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:176
Flag
Enumeration of flags that adjust the way the map is rendered.
bool valid
Whether ellipsoid parameters are valid.
QSize outputSize() const
Returns the size of the resulting map image.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:161
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
void setMagnificationFactor(double factor)
Set the magnification factor.
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:238
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
void setDevicePixelRatio(float dpr)
Sets the device pixel ratio Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" d...
QStringList layerIds() const
Gets list of layer IDs for map rendering The layers are stored in the reverse order of how they are r...
void setMapUnits(QgsUnitTypes::DistanceUnit mapUnits)
Set the map units.
static QDomElement writeMapUnits(QgsUnitTypes::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
Definition: qgsxmlutils.cpp:66
double mapUnitsPerPixel() const
Returns the distance in geographical coordinates that equals to one pixel in the map.
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
Contains information about the context in which a coordinate transform is executed.
QgsScaleCalculator mScaleCalculator
double layerToMapUnits(const QgsMapLayer *layer, const QgsRectangle &referenceExtent=QgsRectangle()) const
Computes an estimated conversion factor between layer and map units: layerUnits * layerToMapUnits = m...
double x
Definition: qgspointxy.h:47
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
double scaleFactor(const QgsRectangle &referenceExtent) const
Computes an estimated conversion factor between source and destination units:
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:53
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
Definition: qgsrectangle.h:358
Draw map such that there are no problems between adjacent tiles.
Unknown distance unit.
Definition: qgsunittypes.h:64
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString what() const
Definition: qgsexception.h:48
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
Transform from destination to source CRS.
double mMapUnitsPerPixel
QString ellipsoid() const
Returns ellipsoid&#39;s acronym.
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
This class represents a coordinate reference system (CRS).
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer&#39;s CRS to output CRS
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
QString authid() const
Returns the authority identifier for the CRS.
Class for doing transforms between two map coordinate systems.
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer&#39;s CRS
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
Transform from source to destination CRS.
QPolygonF visiblePolygon() const
Returns the visible area as a polygon (may be rotated)
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
void readXml(QDomNode &node)
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:201
void writeXml(QDomNode &node, QDomDocument &doc)
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:166
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:36
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
Definition: qgsrectangle.h:104
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform, bool handle180Crossover=false) const SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:70
QSize deviceOutputSize() const
Returns the device output size of the map canvas This is equivalent to the output size multiplicated ...
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:208
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
void setLayers(const QList< QgsMapLayer * > &layers)
Set list of layers for map rendering.