QGIS API Documentation  3.9.0-Master (224899f119)
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 {
44 
45  updateDerived();
46 }
47 
49 {
50  double ratio = mMagnificationFactor / factor;
51 
52  mMagnificationFactor = factor;
53 
54  double rot = rotation();
55  setRotation( 0.0 );
56 
58  ext.scale( ratio );
59 
60  mRotation = rot;
61  mExtent = ext;
62  mDpi = mDpi / ratio;
63 
64  QgsDebugMsg( QStringLiteral( "Magnification factor: %1 dpi: %2 ratio: %3" ).arg( factor ).arg( mDpi ).arg( ratio ) );
65 
66  updateDerived();
67 }
68 
70 {
71  return mMagnificationFactor;
72 }
73 
75 {
76  return mExtent;
77 }
78 
79 void QgsMapSettings::setExtent( const QgsRectangle &extent, bool magnified )
80 {
81  QgsRectangle magnifiedExtent = extent;
82 
83  if ( !magnified )
84  magnifiedExtent.scale( 1 / mMagnificationFactor );
85 
86  mExtent = magnifiedExtent;
87 
88  updateDerived();
89 }
90 
92 {
93  return mExtentBuffer;
94 }
95 
96 void QgsMapSettings::setExtentBuffer( const double buffer )
97 {
98  mExtentBuffer = buffer;
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 = ( std::fabs( extent.xMinimum() ) + std::fabs( extent.xMaximum() ) ) * 0.5;
147  double yMean = ( std::fabs( extent.yMinimum() ) + std::fabs( 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  QgsDebugMsgLevel( QStringLiteral( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ), qgsDoubleToString( mapUnitsPerPixelY ) ), 5 );
220  QgsDebugMsgLevel( QStringLiteral( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mSize.width() ), qgsDoubleToString( mSize.height() ) ), 5 );
221  QgsDebugMsgLevel( QStringLiteral( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ), qgsDoubleToString( mExtent.height() ) ), 5 );
223  QgsDebugMsgLevel( QStringLiteral( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / myWidth ), qgsDoubleToString( mVisibleExtent.height() / myHeight ) ), 5 );
224  QgsDebugMsgLevel( QStringLiteral( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / mMapUnitsPerPixel ), qgsDoubleToString( mVisibleExtent.height() / mMapUnitsPerPixel ) ), 5 );
225  QgsDebugMsgLevel( QStringLiteral( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ), 5 );
226  QgsDebugMsgLevel( QStringLiteral( "Rotation: %1 degrees" ).arg( mRotation ), 5 );
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 mDevicePixelRatio;
247 }
248 
250 {
251  mDevicePixelRatio = dpr;
252  updateDerived();
253 }
254 
256 {
257  return outputSize() * mDevicePixelRatio;
258 }
259 
261 {
262  return mDpi;
263 }
264 
266 {
267  mDpi = dpi;
268 
269  updateDerived();
270 }
271 
272 
273 QStringList QgsMapSettings::layerIds() const
274 {
275  return _qgis_listQPointerToIDs( mLayers );
276 }
277 
278 
279 QList<QgsMapLayer *> QgsMapSettings::layers() const
280 {
281  return _qgis_listQPointerToRaw( mLayers );
282 }
283 
284 void QgsMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
285 {
286  // filter list, removing null layers and non-spatial layers
287  auto filteredList = layers;
288  filteredList.erase( std::remove_if( filteredList.begin(), filteredList.end(),
289  []( QgsMapLayer * layer )
290  {
291  return !layer || !layer->isSpatial();
292  } ), filteredList.end() );
293 
294  mLayers = _qgis_listRawToQPointer( filteredList );
295 }
296 
297 QMap<QString, QString> QgsMapSettings::layerStyleOverrides() const
298 {
299  return mLayerStyleOverrides;
300 }
301 
302 void QgsMapSettings::setLayerStyleOverrides( const QMap<QString, QString> &overrides )
303 {
304  mLayerStyleOverrides = overrides;
305 }
306 
308 {
309  mDestCRS = crs;
311  // Since the map units have changed, force a recalculation of the scale.
312  updateDerived();
313 }
314 
316 {
317  return mDestCRS;
318 }
319 
321 {
323  if ( !params.valid )
324  {
325  return false;
326  }
327  else
328  {
330  return true;
331  }
332 }
333 
334 void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
335 {
336  mFlags = flags;
337 }
338 
340 {
341  if ( on )
342  mFlags |= flag;
343  else
344  mFlags &= ~flag;
345 }
346 
347 QgsMapSettings::Flags QgsMapSettings::flags() const
348 {
349  return mFlags;
350 }
351 
353 {
354  return mFlags.testFlag( flag );
355 }
356 
358 {
359  return mScaleCalculator.mapUnits();
360 }
361 
362 
364 {
365  return mValid;
366 }
367 
369 {
370  return mVisibleExtent;
371 }
372 
374 {
375  QPolygonF poly;
376 
377  const QSize &sz = outputSize();
378  const QgsMapToPixel &m2p = mapToPixel();
379 
380  poly << m2p.toMapCoordinates( 0.0, 0.0 ).toQPointF();
381  poly << m2p.toMapCoordinates( static_cast<double>( sz.width() ), 0.0 ).toQPointF();
382  poly << m2p.toMapCoordinates( static_cast<double>( sz.width() ), static_cast<double>( sz.height() ) ).toQPointF();
383  poly << m2p.toMapCoordinates( 0.0, static_cast<double>( sz.height() ) ).toQPointF();
384 
385  return poly;
386 }
387 
389 {
390  return mMapUnitsPerPixel;
391 }
392 
393 double QgsMapSettings::scale() const
394 {
395  return mScale;
396 }
397 
399 {
400 #ifdef QGISDEBUG
401  if ( !mHasTransformContext )
402  QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 );
403 #endif
404 
405  return mTransformContext;
406 }
407 
409 {
410  mTransformContext = context;
411 #ifdef QGISDEBUG
412  mHasTransformContext = true;
413 #endif
414 }
415 
417 {
418  if ( !layer )
419  return QgsCoordinateTransform();
420 
422 }
423 
424 double QgsMapSettings::layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent ) const
425 {
426  return layerTransform( layer ).scaleFactor( referenceExtent );
427 }
428 
429 
431 {
432  try
433  {
435  if ( ct.isValid() )
436  {
437  QgsDebugMsgLevel( QStringLiteral( "sourceCrs = %1" ).arg( ct.sourceCrs().authid() ), 3 );
438  QgsDebugMsgLevel( QStringLiteral( "destCRS = %1" ).arg( ct.destinationCrs().authid() ), 3 );
439  QgsDebugMsgLevel( QStringLiteral( "extent %1" ).arg( extent.toString() ), 3 );
440  extent = ct.transformBoundingBox( extent );
441  }
442  }
443  catch ( QgsCsException &cse )
444  {
445  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
446  }
447 
448  QgsDebugMsgLevel( QStringLiteral( "proj extent = %1 " ).arg( extent.toString() ), 3 );
449 
450  return extent;
451 }
452 
453 
455 {
456  try
457  {
459  if ( ct.isValid() )
460  {
461  QgsDebugMsgLevel( QStringLiteral( "sourceCrs = %1" ).arg( ct.sourceCrs().authid() ), 3 );
462  QgsDebugMsgLevel( QStringLiteral( "destCRS = %1" ).arg( ct.destinationCrs().authid() ), 3 );
463  QgsDebugMsgLevel( QStringLiteral( "extent = %1" ).arg( extent.toString() ), 3 );
465  }
466  }
467  catch ( QgsCsException &cse )
468  {
469  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
470  }
471 
472  QgsDebugMsgLevel( QStringLiteral( "proj extent = %1" ).arg( extent.toString() ), 3 );
473 
474  return extent;
475 }
476 
477 
479 {
480  try
481  {
483  if ( ct.isValid() )
485  }
486  catch ( QgsCsException &cse )
487  {
488  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
489  }
490 
491  return point;
492 }
493 
494 
496 {
497  try
498  {
500  if ( ct.isValid() )
502  }
503  catch ( QgsCsException &cse )
504  {
505  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
506  }
507 
508  return rect;
509 }
510 
511 
513 {
514  try
515  {
517  if ( ct.isValid() )
519  }
520  catch ( QgsCsException &cse )
521  {
522  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
523  }
524 
525  return point;
526 }
527 
528 
530 {
531  try
532  {
534  if ( ct.isValid() )
536  }
537  catch ( QgsCsException &cse )
538  {
539  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
540  }
541 
542  return rect;
543 }
544 
545 
546 
548 {
549  // reset the map canvas extent since the extent may now be smaller
550  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
552  fullExtent.setMinimal();
553 
554  // iterate through the map layers and test each layers extent
555  // against the current min and max values
556  QgsDebugMsgLevel( QStringLiteral( "Layer count: %1" ).arg( mLayers.count() ), 5 );
557  const auto constMLayers = mLayers;
558  for ( const QgsWeakMapLayerPointer &layerPtr : constMLayers )
559  {
560  if ( QgsMapLayer *lyr = layerPtr.data() )
561  {
562  QgsDebugMsgLevel( "Updating extent using " + lyr->name(), 5 );
563  QgsDebugMsgLevel( "Input extent: " + lyr->extent().toString(), 5 );
564 
565  if ( lyr->extent().isNull() )
566  continue;
567 
568  // Layer extents are stored in the coordinate system (CS) of the
569  // layer. The extent must be projected to the canvas CS
570  QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() );
571 
572  QgsDebugMsgLevel( "Output extent: " + extent.toString(), 5 );
573  fullExtent.combineExtentWith( extent );
574  }
575  }
576 
577  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
578  {
579  // If all of the features are at the one point, buffer the
580  // rectangle a bit. If they are all at zero, do something a bit
581  // more crude.
582 
583  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
584  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
585  {
586  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
587  }
588  else
589  {
590  const double padFactor = 1e-8;
591  double widthPad = fullExtent.xMinimum() * padFactor;
592  double heightPad = fullExtent.yMinimum() * padFactor;
593  double xmin = fullExtent.xMinimum() - widthPad;
594  double xmax = fullExtent.xMaximum() + widthPad;
595  double ymin = fullExtent.yMinimum() - heightPad;
596  double ymax = fullExtent.yMaximum() + heightPad;
597  fullExtent.set( xmin, ymin, xmax, ymax );
598  }
599  }
600 
601  QgsDebugMsgLevel( "Full extent: " + fullExtent.toString(), 5 );
602  return fullExtent;
603 }
604 
605 
606 void QgsMapSettings::readXml( QDomNode &node )
607 {
608  // set destination CRS
610  QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );
611  if ( !srsNode.isNull() )
612  {
613  srs.readXml( srsNode );
614  }
615  setDestinationCrs( srs );
616 
617  // set extent
618  QDomNode extentNode = node.namedItem( QStringLiteral( "extent" ) );
619  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
620  setExtent( aoi );
621 
622  // set rotation
623  QDomNode rotationNode = node.namedItem( QStringLiteral( "rotation" ) );
624  QString rotationVal = rotationNode.toElement().text();
625  if ( ! rotationVal.isEmpty() )
626  {
627  double rot = rotationVal.toDouble();
628  setRotation( rot );
629  }
630 
631  //render map tile
632  QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral( "rendermaptile" ) );
633  if ( !renderMapTileElem.isNull() )
634  {
635  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == QLatin1String( "1" ) );
636  }
637 }
638 
639 
640 
641 void QgsMapSettings::writeXml( QDomNode &node, QDomDocument &doc )
642 {
643  // units
644  node.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), doc ) );
645 
646  // Write current view extents
647  node.appendChild( QgsXmlUtils::writeRectangle( extent(), doc ) );
648 
649  // Write current view rotation
650  QDomElement rotNode = doc.createElement( QStringLiteral( "rotation" ) );
651  rotNode.appendChild(
652  doc.createTextNode( qgsDoubleToString( rotation() ) )
653  );
654  node.appendChild( rotNode );
655 
656  // destination CRS
657  if ( mDestCRS.isValid() )
658  {
659  QDomElement srsNode = doc.createElement( QStringLiteral( "destinationsrs" ) );
660  node.appendChild( srsNode );
661  mDestCRS.writeXml( srsNode, doc );
662  }
663 
664  //render map tile
665  QDomElement renderMapTileElem = doc.createElement( QStringLiteral( "rendermaptile" ) );
666  QDomText renderMapTileText = doc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
667  renderMapTileElem.appendChild( renderMapTileText );
668  node.appendChild( renderMapTileElem );
669 }
670 
672 {
673  return mLabelBoundaryGeometry;
674 }
675 
677 {
678  mLabelBoundaryGeometry = boundary;
679 }
680 
682 {
683  mRenderedFeatureHandlers.append( handler );
684 }
685 
686 QList<QgsRenderedFeatureHandlerInterface *> QgsMapSettings::renderedFeatureHandlers() const
687 {
688  return mRenderedFeatureHandlers;
689 }
double mMagnificationFactor
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:79
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.
Definition: qgsrectangle.h:151
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
Returns the magnification factor.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QStringList layerIds() const
Gets list of layer IDs for map rendering The layers are stored in the reverse order of how they are r...
QSize deviceOutputSize() const
Returns the device output size of the map canvas This is equivalent to the output size multiplicated ...
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsCoordinateReferenceSystem mDestCRS
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
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:235
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:265
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer&#39;s CRS
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
void setOutputDpi(double dpi)
Sets DPI used for conversion between real world units (e.g. mm) and pixels.
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)
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:79
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system, which the transform will transform coordinates t...
void setFlags(QgsMapSettings::Flags flags)
Sets combination of flags that will be used for rendering.
QgsGeometry mLabelBoundaryGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:121
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
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
const QgsCoordinateReferenceSystem & crs
void setExtentBuffer(double buffer)
Sets the buffer in map units to use around the visible extent for rendering symbols whose correspondi...
Contains parameters for an ellipsoid.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1617
Q_GUI_EXPORT int qt_defaultDpiX()
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
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
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
Gets units of map&#39;s geographical coordinates - used for scale calculation.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer&#39;s CRS to destination CRS.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:37
QgsGeometry labelBoundaryGeometry() const
Returns the label boundary geometry, which restricts where in the rendered map labels are permitted t...
No simplification can be applied.
bool mValid
Whether the actual settings are valid (set in updateDerived())
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspointxy.h:154
void setOutputSize(QSize size)
Sets 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
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.
Definition: qgsrectangle.h:426
double scale() const
Returns the calculated map scale.
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:225
An interface for classes which provider custom handlers for features rendered as part of a map render...
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).
double mapUnitsPerPixel() const
Returns the distance in geographical coordinates that equals to one pixel in the map.
void setDevicePixelRatio(float dpr)
Sets the device pixel ratio Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" d...
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...
QgsVectorSimplifyMethod mSimplifyMethod
QList< QgsRenderedFeatureHandlerInterface *> renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering the map settings.
double extentBuffer() const
Returns the buffer in map units to use around the visible extent for rendering symbols whose correspo...
static QDomElement writeMapUnits(QgsUnitTypes::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
Definition: qgsxmlutils.cpp:67
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer&#39;s CRS to output CRS
void setLabelBoundaryGeometry(const QgsGeometry &boundary)
Sets the label boundary geometry, which restricts where in the rendered map labels are permitted to b...
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.
float devicePixelRatio() const
Returns device pixel ratio Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" di...
QgsScaleCalculator mScaleCalculator
const QgsMapToPixel & mapToPixel() const
bool isFinite() const
Returns true if the rectangle has finite boundaries.
Definition: qgsrectangle.h:516
double x
Definition: qgspointxy.h:47
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:54
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:162
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:359
Draw map such that there are no problems between adjacent tiles.
Unknown distance unit.
Definition: qgsunittypes.h:65
double outputDpi() const
Returns 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
Gets map of map layer style overrides (key: layer ID, value: style name) where a different style shou...
QString ellipsoid() const
Returns ellipsoid&#39;s acronym.
Transform from destination to source CRS.
double mMapUnitsPerPixel
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).
double scaleFactor(const QgsRectangle &referenceExtent) const
Computes an estimated conversion factor between source and destination units:
Class for doing transforms between two map coordinate systems.
Flags flags() const
Returns combination of flags used for rendering.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
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:172
Transform from source to destination CRS.
void addRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Adds a rendered feature handler to use while rendering the map settings.
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
Returns 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
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:37
QSize outputSize() const
Returns the size of the resulting map image.
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
Definition: qgsrectangle.h:105
QString authid() const
Returns the authority identifier for the CRS.
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:86
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
QgsUnitTypes::DistanceUnit mapUnits() const
Returns current map units.
double calculate(const QgsRectangle &mapExtent, double canvasWidth) const
Calculate the scale denominator.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.