QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
48 void QgsMapSettings::setMagnificationFactor( double factor, const QgsPointXY *center )
49 {
50  double ratio = mMagnificationFactor / factor;
51 
52  mMagnificationFactor = factor;
53 
54  double rot = rotation();
55  setRotation( 0.0 );
56 
58  ext.scale( ratio, center );
59 
60  mRotation = rot;
61  mExtent = ext;
62  mDpi = mDpi / ratio;
63 
64  QgsDebugMsgLevel( QStringLiteral( "Magnification factor: %1 dpi: %2 ratio: %3" ).arg( factor ).arg( mDpi ).arg( ratio ), 3 );
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  QgsDebugMsgLevel( QStringLiteral( "Extent: %1" ).arg( mExtent.asWktCoordinates() ), 5 );
228  QgsDebugMsgLevel( QStringLiteral( "Visible Extent: %1" ).arg( mVisibleExtent.asWktCoordinates() ), 5 );
229  QgsDebugMsgLevel( QStringLiteral( "Magnification factor: %1" ).arg( mMagnificationFactor ), 5 );
230 
231  mValid = true;
232 }
233 
234 
236 {
237  return mSize;
238 }
239 
241 {
242  mSize = size;
243 
244  updateDerived();
245 }
246 
248 {
249  return mDevicePixelRatio;
250 }
251 
253 {
254  mDevicePixelRatio = dpr;
255  updateDerived();
256 }
257 
259 {
260  return outputSize() * mDevicePixelRatio;
261 }
262 
264 {
265  return mDpi;
266 }
267 
269 {
270  mDpi = dpi;
271 
272  updateDerived();
273 }
274 
275 
276 QStringList QgsMapSettings::layerIds() const
277 {
278  return _qgis_listQPointerToIDs( mLayers );
279 }
280 
281 
282 QList<QgsMapLayer *> QgsMapSettings::layers() const
283 {
284  return _qgis_listQPointerToRaw( mLayers );
285 }
286 
287 void QgsMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
288 {
289  // filter list, removing null layers and non-spatial layers
290  auto filteredList = layers;
291  filteredList.erase( std::remove_if( filteredList.begin(), filteredList.end(),
292  []( QgsMapLayer * layer )
293  {
294  return !layer || !layer->isSpatial();
295  } ), filteredList.end() );
296 
297  mLayers = _qgis_listRawToQPointer( filteredList );
298 }
299 
300 QMap<QString, QString> QgsMapSettings::layerStyleOverrides() const
301 {
302  return mLayerStyleOverrides;
303 }
304 
305 void QgsMapSettings::setLayerStyleOverrides( const QMap<QString, QString> &overrides )
306 {
307  mLayerStyleOverrides = overrides;
308 }
309 
311 {
312  mDestCRS = crs;
314  // Since the map units have changed, force a recalculation of the scale.
315  updateDerived();
316 }
317 
319 {
320  return mDestCRS;
321 }
322 
323 bool QgsMapSettings::setEllipsoid( const QString &ellipsoid )
324 {
326  if ( !params.valid )
327  {
328  return false;
329  }
330  else
331  {
333  return true;
334  }
335 }
336 
337 void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
338 {
339  mFlags = flags;
340 }
341 
343 {
344  if ( on )
345  mFlags |= flag;
346  else
347  mFlags &= ~flag;
348 }
349 
350 QgsMapSettings::Flags QgsMapSettings::flags() const
351 {
352  return mFlags;
353 }
354 
356 {
357  return mFlags.testFlag( flag );
358 }
359 
361 {
362  return mScaleCalculator.mapUnits();
363 }
364 
365 
367 {
368  return mValid;
369 }
370 
372 {
373  return mVisibleExtent;
374 }
375 
377 {
378  QPolygonF poly;
379 
380  const QSize &sz = outputSize();
381  const QgsMapToPixel &m2p = mapToPixel();
382 
383  poly << m2p.toMapCoordinates( 0.0, 0.0 ).toQPointF();
384  poly << m2p.toMapCoordinates( static_cast<double>( sz.width() ), 0.0 ).toQPointF();
385  poly << m2p.toMapCoordinates( static_cast<double>( sz.width() ), static_cast<double>( sz.height() ) ).toQPointF();
386  poly << m2p.toMapCoordinates( 0.0, static_cast<double>( sz.height() ) ).toQPointF();
387 
388  return poly;
389 }
390 
392 {
393  return mMapUnitsPerPixel;
394 }
395 
396 double QgsMapSettings::scale() const
397 {
398  return mScale;
399 }
400 
402 {
403 #ifdef QGISDEBUG
404  if ( !mHasTransformContext )
405  QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 );
406 #endif
407 
408  return mTransformContext;
409 }
410 
412 {
413  mTransformContext = context;
414 #ifdef QGISDEBUG
415  mHasTransformContext = true;
416 #endif
417 }
418 
420 {
421  if ( !layer )
422  return QgsCoordinateTransform();
423 
425 }
426 
427 double QgsMapSettings::layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent ) const
428 {
429  return layerTransform( layer ).scaleFactor( referenceExtent );
430 }
431 
432 
434 {
435  try
436  {
438  if ( ct.isValid() )
439  {
440  QgsDebugMsgLevel( QStringLiteral( "sourceCrs = %1" ).arg( ct.sourceCrs().authid() ), 3 );
441  QgsDebugMsgLevel( QStringLiteral( "destCRS = %1" ).arg( ct.destinationCrs().authid() ), 3 );
442  QgsDebugMsgLevel( QStringLiteral( "extent %1" ).arg( extent.toString() ), 3 );
445  }
446  }
447  catch ( QgsCsException &cse )
448  {
449  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
450  }
451 
452  QgsDebugMsgLevel( QStringLiteral( "proj extent = %1 " ).arg( extent.toString() ), 3 );
453 
454  return extent;
455 }
456 
457 
459 {
460  try
461  {
464  if ( ct.isValid() )
465  {
466  QgsDebugMsgLevel( QStringLiteral( "sourceCrs = %1" ).arg( ct.sourceCrs().authid() ), 3 );
467  QgsDebugMsgLevel( QStringLiteral( "destCRS = %1" ).arg( ct.destinationCrs().authid() ), 3 );
468  QgsDebugMsgLevel( QStringLiteral( "extent = %1" ).arg( extent.toString() ), 3 );
470  }
471  }
472  catch ( QgsCsException &cse )
473  {
474  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
475  }
476 
477  QgsDebugMsgLevel( QStringLiteral( "proj extent = %1" ).arg( extent.toString() ), 3 );
478 
479  return extent;
480 }
481 
482 
484 {
485  try
486  {
488  if ( ct.isValid() )
490  }
491  catch ( QgsCsException &cse )
492  {
493  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
494  }
495 
496  return point;
497 }
498 
500 {
501  double x = point.x();
502  double y = point.y();
503  double z = point.z();
504 
505  try
506  {
508  if ( ct.isValid() )
510  }
511  catch ( QgsCsException &cse )
512  {
513  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
514  }
515 
516  return QgsPoint( x, y, z );
517 }
518 
519 
521 {
522  try
523  {
525  if ( ct.isValid() )
527  }
528  catch ( QgsCsException &cse )
529  {
530  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
531  }
532 
533  return rect;
534 }
535 
536 
538 {
539  try
540  {
542  if ( ct.isValid() )
544  }
545  catch ( QgsCsException &cse )
546  {
547  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
548  }
549 
550  return point;
551 }
552 
554 {
555  double x = point.x();
556  double y = point.y();
557  double z = point.z();
558 
559  try
560  {
562  if ( ct.isValid() )
564  }
565  catch ( QgsCsException &cse )
566  {
567  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
568  }
569 
570  return QgsPoint( x, y, z );
571 }
572 
573 
575 {
576  try
577  {
579  if ( ct.isValid() )
581  }
582  catch ( QgsCsException &cse )
583  {
584  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
585  }
586 
587  return rect;
588 }
589 
590 
591 
593 {
594  // reset the map canvas extent since the extent may now be smaller
595  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
598 
599  // iterate through the map layers and test each layers extent
600  // against the current min and max values
601  QgsDebugMsgLevel( QStringLiteral( "Layer count: %1" ).arg( mLayers.count() ), 5 );
602  const auto constMLayers = mLayers;
603  for ( const QgsWeakMapLayerPointer &layerPtr : constMLayers )
604  {
605  if ( QgsMapLayer *lyr = layerPtr.data() )
606  {
607  QgsDebugMsgLevel( "Updating extent using " + lyr->name(), 5 );
608  QgsDebugMsgLevel( "Input extent: " + lyr->extent().toString(), 5 );
609 
610  if ( lyr->extent().isNull() )
611  continue;
612 
613  // Layer extents are stored in the coordinate system (CS) of the
614  // layer. The extent must be projected to the canvas CS
615  QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() );
616 
617  QgsDebugMsgLevel( "Output extent: " + extent.toString(), 5 );
619  }
620  }
621 
622  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
623  {
624  // If all of the features are at the one point, buffer the
625  // rectangle a bit. If they are all at zero, do something a bit
626  // more crude.
627 
628  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
629  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
630  {
631  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
632  }
633  else
634  {
635  const double padFactor = 1e-8;
636  double widthPad = fullExtent.xMinimum() * padFactor;
637  double heightPad = fullExtent.yMinimum() * padFactor;
638  double xmin = fullExtent.xMinimum() - widthPad;
639  double xmax = fullExtent.xMaximum() + widthPad;
640  double ymin = fullExtent.yMinimum() - heightPad;
641  double ymax = fullExtent.yMaximum() + heightPad;
642  fullExtent.set( xmin, ymin, xmax, ymax );
643  }
644  }
645 
646  QgsDebugMsgLevel( "Full extent: " + fullExtent.toString(), 5 );
647  return fullExtent;
648 }
649 
650 
651 void QgsMapSettings::readXml( QDomNode &node )
652 {
653  // set destination CRS
655  QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );
656  if ( !srsNode.isNull() )
657  {
658  srs.readXml( srsNode );
659  }
660  setDestinationCrs( srs );
661 
662  // set extent
663  QDomNode extentNode = node.namedItem( QStringLiteral( "extent" ) );
664  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
665  setExtent( aoi );
666 
667  // set rotation
668  QDomNode rotationNode = node.namedItem( QStringLiteral( "rotation" ) );
669  QString rotationVal = rotationNode.toElement().text();
670  if ( ! rotationVal.isEmpty() )
671  {
672  double rot = rotationVal.toDouble();
673  setRotation( rot );
674  }
675 
676  //render map tile
677  QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral( "rendermaptile" ) );
678  if ( !renderMapTileElem.isNull() )
679  {
680  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == QLatin1String( "1" ) );
681  }
682 }
683 
684 
685 
686 void QgsMapSettings::writeXml( QDomNode &node, QDomDocument &doc )
687 {
688  // units
689  node.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), doc ) );
690 
691  // Write current view extents
692  node.appendChild( QgsXmlUtils::writeRectangle( extent(), doc ) );
693 
694  // Write current view rotation
695  QDomElement rotNode = doc.createElement( QStringLiteral( "rotation" ) );
696  rotNode.appendChild(
697  doc.createTextNode( qgsDoubleToString( rotation() ) )
698  );
699  node.appendChild( rotNode );
700 
701  // destination CRS
702  if ( mDestCRS.isValid() )
703  {
704  QDomElement srsNode = doc.createElement( QStringLiteral( "destinationsrs" ) );
705  node.appendChild( srsNode );
706  mDestCRS.writeXml( srsNode, doc );
707  }
708 
709  //render map tile
710  QDomElement renderMapTileElem = doc.createElement( QStringLiteral( "rendermaptile" ) );
711  QDomText renderMapTileText = doc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
712  renderMapTileElem.appendChild( renderMapTileText );
713  node.appendChild( renderMapTileElem );
714 }
715 
717 {
718  return mLabelBoundaryGeometry;
719 }
720 
722 {
723  mLabelBoundaryGeometry = boundary;
724 }
725 
727 {
728  mClippingRegions.append( region );
729 }
730 
731 void QgsMapSettings::setClippingRegions( const QList<QgsMapClippingRegion> &regions )
732 {
733  mClippingRegions = regions;
734 }
735 
736 QList<QgsMapClippingRegion> QgsMapSettings::clippingRegions() const
737 {
738  return mClippingRegions;
739 }
740 
742 {
743  mRenderedFeatureHandlers.append( handler );
744 }
745 
746 QList<QgsRenderedFeatureHandlerInterface *> QgsMapSettings::renderedFeatureHandlers() const
747 {
748  return mRenderedFeatureHandlers;
749 }
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:89
QgsMapSettings::mLayers
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
Definition: qgsmapsettings.h:693
QgsMapSettings::mMagnificationFactor
double mMagnificationFactor
Definition: qgsmapsettings.h:690
QgsMapSettings::setDestinationCrs
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
Definition: qgsmapsettings.cpp:310
QgsRectangle::isFinite
bool isFinite() const
Returns true if the rectangle has finite boundaries.
Definition: qgsrectangle.h:527
QgsVectorSimplifyMethod::NoSimplification
@ NoSimplification
No simplification can be applied.
Definition: qgsvectorsimplifymethod.h:39
QgsRectangle::height
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
QgsPointXY::y
double y
Definition: qgspointxy.h:48
QgsMapSettings::setLabelBoundaryGeometry
void setLabelBoundaryGeometry(const QgsGeometry &boundary)
Sets the label boundary geometry, which restricts where in the rendered map labels are permitted to b...
Definition: qgsmapsettings.cpp:721
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsXmlUtils::writeRectangle
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
Definition: qgsxmlutils.cpp:81
QgsMapSettings::mapToLayerCoordinates
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
Definition: qgsmapsettings.cpp:537
QgsCoordinateReferenceSystem::mapUnits
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
Definition: qgscoordinatereferencesystem.h:209
QgsMapClippingRegion
A map clipping region (in map coordinates and CRS).
Definition: qgsmapclippingregion.h:32
qgsscalecalculator.h
QgsMapSettings::setFlag
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
Definition: qgsmapsettings.cpp:342
QgsScaleCalculator::setMapUnits
void setMapUnits(QgsUnitTypes::DistanceUnit mapUnits)
Set the map units.
Definition: qgsscalecalculator.cpp:38
QgsMapSettings::mScale
double mScale
Definition: qgsmapsettings.h:719
QgsMapSettings::readXml
void readXml(QDomNode &node)
Definition: qgsmapsettings.cpp:651
QgsRectangle::combineExtentWith
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Definition: qgsrectangle.h:359
QgsMapSettings::mValid
bool mValid
Whether the actual settings are valid (set in updateDerived())
Definition: qgsmapsettings.h:716
QgsMapSettings::outputSize
QSize outputSize() const
Returns the size of the resulting map image.
Definition: qgsmapsettings.cpp:235
QgsScaleCalculator::setDpi
void setDpi(double dpi)
Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations.
Definition: qgsscalecalculator.cpp:29
QgsMapSettings::layerTransform
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
Definition: qgsmapsettings.cpp:419
QgsMapSettings::setRotation
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
Definition: qgsmapsettings.cpp:106
QgsMapSettings::extentBuffer
double extentBuffer() const
Returns the buffer in map units to use around the visible extent for rendering symbols whose correspo...
Definition: qgsmapsettings.cpp:91
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
QgsUnitTypes::DistanceUnknownUnit
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
qt_defaultDpiX
Q_GUI_EXPORT int qt_defaultDpiX()
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsMapToPixel::setParameters
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
Definition: qgsmaptopixel.cpp:163
qgsmaptopixel.h
QgsScaleCalculator::calculate
double calculate(const QgsRectangle &mapExtent, double canvasWidth) const
Calculate the scale denominator.
Definition: qgsscalecalculator.cpp:50
QgsMapSettings::flags
Flags flags() const
Returns combination of flags used for rendering.
Definition: qgsmapsettings.cpp:350
QgsMapSettings::devicePixelRatio
float devicePixelRatio() const
Returns device pixel ratio Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" di...
Definition: qgsmapsettings.cpp:247
QgsRectangle::center
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Definition: qgsrectangle.h:230
QgsPointXY::x
Q_GADGET double x
Definition: qgspointxy.h:47
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsMapSettings::mSimplifyMethod
QgsVectorSimplifyMethod mSimplifyMethod
Definition: qgsmapsettings.h:733
QgsMapSettings::outputExtentToLayerExtent
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer's CRS
Definition: qgsmapsettings.cpp:458
QgsRectangle::yMinimum
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
QgsMapSettings::hasValidSettings
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
Definition: qgsmapsettings.cpp:366
QgsMapSettings::setClippingRegions
void setClippingRegions(const QList< QgsMapClippingRegion > &regions)
Sets the list of clipping regions to apply to the map.
Definition: qgsmapsettings.cpp:731
QgsMapSettings::fullExtent
QgsRectangle fullExtent() const
returns current extent of layer set
Definition: qgsmapsettings.cpp:592
QgsMapSettings::writeXml
void writeXml(QDomNode &node, QDomDocument &doc)
Definition: qgsmapsettings.cpp:686
QgsMapSettings::ellipsoid
QString ellipsoid() const
Returns ellipsoid's acronym.
Definition: qgsmapsettings.h:288
QgsPoint::z
double z
Definition: qgspoint.h:43
QgsMapSettings::mapUnitsPerPixel
double mapUnitsPerPixel() const
Returns the distance in geographical coordinates that equals to one pixel in the map.
Definition: qgsmapsettings.cpp:391
QgsRectangle::setMinimal
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:151
QgsMapSettings::layerExtentToOutputExtent
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
Definition: qgsmapsettings.cpp:433
QgsPointXY::toQPointF
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspointxy.h:154
QgsMapSettings::magnificationFactor
double magnificationFactor() const
Returns the magnification factor.
Definition: qgsmapsettings.cpp:69
QgsMapSettings::layerStyleOverrides
QMap< QString, QString > layerStyleOverrides() const
Gets map of map layer style overrides (key: layer ID, value: style name) where a different style shou...
Definition: qgsmapsettings.cpp:300
QgsMapSettings::mExtentBuffer
double mExtentBuffer
Definition: qgsmapsettings.h:687
QgsMapSettings::QgsMapSettings
QgsMapSettings()
Definition: qgsmapsettings.cpp:34
QgsVectorSimplifyMethod::setSimplifyHints
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:49
QgsScaleCalculator::mapUnits
QgsUnitTypes::DistanceUnit mapUnits() const
Returns current map units.
Definition: qgsscalecalculator.cpp:44
QgsMapSettings::setOutputDpi
void setOutputDpi(double dpi)
Sets DPI used for conversion between real world units (e.g. mm) and pixels.
Definition: qgsmapsettings.cpp:268
QgsMapSettings::mSize
QSize mSize
Definition: qgsmapsettings.h:683
QgsEllipsoidUtils::ellipsoidParameters
static EllipsoidParameters ellipsoidParameters(const QString &ellipsoid)
Returns the parameters for the specified ellipsoid.
Definition: qgsellipsoidutils.cpp:41
qgsmapsettings.h
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
QgsMapToPixel::toMapCoordinates
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
Definition: qgsmaptopixel.cpp:108
QgsCoordinateTransform::transform
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
Definition: qgscoordinatetransform.cpp:239
QgsCoordinateTransform::isValid
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
Definition: qgscoordinatetransform.cpp:892
QgsCoordinateReferenceSystem::readXml
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
Definition: qgscoordinatereferencesystem.cpp:2018
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsCoordinateTransform::ReverseTransform
@ ReverseTransform
Transform from destination to source CRS.
Definition: qgscoordinatetransform.h:61
QgsMapSettings::updateDerived
void updateDerived()
Definition: qgsmapsettings.cpp:118
QgsCoordinateTransform::transformBoundingBox
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.
Definition: qgscoordinatetransform.cpp:511
qgsDoubleToString
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:275
QgsRenderedFeatureHandlerInterface
An interface for classes which provider custom handlers for features rendered as part of a map render...
Definition: qgsrenderedfeaturehandlerinterface.h:47
QgsMapSettings::mEllipsoid
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
Definition: qgsmapsettings.h:701
QgsMapSettings::extent
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
Definition: qgsmapsettings.cpp:74
QgsCoordinateTransform::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system, which the transform will transform coordinates t...
Definition: qgscoordinatetransform.cpp:234
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
QgsMapSettings::addRenderedFeatureHandler
void addRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Adds a rendered feature handler to use while rendering the map settings.
Definition: qgsmapsettings.cpp:741
QgsRectangle::scale
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
Definition: qgsrectangle.h:235
QgsPoint::y
double y
Definition: qgspoint.h:42
QgsCoordinateTransform::sourceCrs
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from.
Definition: qgscoordinatetransform.cpp:229
QgsCsException
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
QgsMapSettings::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
Definition: qgsmapsettings.cpp:401
QgsMapSettings::rotation
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
Definition: qgsmapsettings.cpp:101
QgsMapSettings::mDevicePixelRatio
float mDevicePixelRatio
Definition: qgsmapsettings.h:684
QgsMapSettings::mRotation
double mRotation
Definition: qgsmapsettings.h:689
QgsCoordinateTransform::setBallparkTransformsAreAppropriate
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
Definition: qgscoordinatetransform.cpp:935
QgsCoordinateReferenceSystem::writeXml
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
Definition: qgscoordinatereferencesystem.cpp:2123
QgsXmlUtils::writeMapUnits
static QDomElement writeMapUnits(QgsUnitTypes::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
Definition: qgsxmlutils.cpp:69
QgsMapSettings::mTransformContext
QgsCoordinateTransformContext mTransformContext
Definition: qgsmapsettings.h:725
QgsMapSettings::setDevicePixelRatio
void setDevicePixelRatio(float dpr)
Sets the device pixel ratio Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" d...
Definition: qgsmapsettings.cpp:252
QgsEllipsoidUtils::EllipsoidParameters::valid
bool valid
Whether ellipsoid parameters are valid.
Definition: qgsellipsoidutils.h:42
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:315
QgsMapSettings::mapUnits
QgsUnitTypes::DistanceUnit mapUnits() const
Gets units of map's geographical coordinates - used for scale calculation.
Definition: qgsmapsettings.cpp:360
QgsMapSettings::setMagnificationFactor
void setMagnificationFactor(double factor, const QgsPointXY *center=nullptr)
Set the magnification factor.
Definition: qgsmapsettings.cpp:48
QgsMapSettings::Flag
Flag
Enumeration of flags that adjust the way the map is rendered.
Definition: qgsmapsettings.h:302
QgsException::what
QString what() const
Definition: qgsexception.h:48
QgsMapSettings::mFlags
Flags mFlags
Definition: qgsmapsettings.h:706
qgsmaplayer.h
QgsCoordinateReferenceSystem::authid
QString authid() const
Returns the authority identifier for the CRS.
Definition: qgscoordinatereferencesystem.cpp:1321
QgsMapSettings::visiblePolygon
QPolygonF visiblePolygon() const
Returns the visible area as a polygon (may be rotated)
Definition: qgsmapsettings.cpp:376
QgsPoint::x
Q_GADGET double x
Definition: qgspoint.h:41
QgsCoordinateReferenceSystem::isValid
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Definition: qgscoordinatereferencesystem.cpp:924
qgsmaprendererjob.h
QgsMapSettings::setFlags
void setFlags(QgsMapSettings::Flags flags)
Sets combination of flags that will be used for rendering.
Definition: qgsmapsettings.cpp:337
QgsWeakMapLayerPointer
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1688
QgsMapSettings::scale
double scale() const
Returns the calculated map scale.
Definition: qgsmapsettings.cpp:396
QgsMapSettings::mDestCRS
QgsCoordinateReferenceSystem mDestCRS
Definition: qgsmapsettings.h:699
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
QgsMapSettings::mLayerStyleOverrides
QMap< QString, QString > mLayerStyleOverrides
Definition: qgsmapsettings.h:694
QgsMapSettings::setTransformContext
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
Definition: qgsmapsettings.cpp:411
QgsMapSettings::RenderMapTile
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
Definition: qgsmapsettings.h:311
QgsMapSettings::mVisibleExtent
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
Definition: qgsmapsettings.h:717
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
qgsxmlutils.h
QgsCoordinateTransform::ForwardTransform
@ ForwardTransform
Transform from source to destination CRS.
Definition: qgscoordinatetransform.h:60
QgsMapSettings::setLayers
void setLayers(const QList< QgsMapLayer * > &layers)
Set list of layers for map rendering.
Definition: qgsmapsettings.cpp:287
QgsRectangle::toString
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
Definition: qgsrectangle.cpp:127
QgsMapSettings::mDpi
double mDpi
Definition: qgsmapsettings.h:681
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsMapSettings::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
Definition: qgsmapsettings.cpp:318
QgsMapSettings::mMapUnitsPerPixel
double mMapUnitsPerPixel
Definition: qgsmapsettings.h:718
QgsCoordinateTransform::scaleFactor
double scaleFactor(const QgsRectangle &referenceExtent) const
Computes an estimated conversion factor between source and destination units:
Definition: qgscoordinatetransform.cpp:1139
QgsEllipsoidUtils::EllipsoidParameters
Contains parameters for an ellipsoid.
Definition: qgsellipsoidutils.h:40
QgsMapSettings::deviceOutputSize
QSize deviceOutputSize() const
Returns the device output size of the map canvas This is equivalent to the output size multiplicated ...
Definition: qgsmapsettings.cpp:258
QgsMapSettings::mLabelBoundaryGeometry
QgsGeometry mLabelBoundaryGeometry
Definition: qgsmapsettings.h:731
QgsRectangle::yMaximum
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
qgsgeometry.h
QgsMapSettings::testFlag
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
Definition: qgsmapsettings.cpp:355
QgsMapSettings::addClippingRegion
void addClippingRegion(const QgsMapClippingRegion &region)
Adds a new clipping region to the map settings.
Definition: qgsmapsettings.cpp:726
QgsMapSettings::mScaleCalculator
QgsScaleCalculator mScaleCalculator
Definition: qgsmapsettings.h:722
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsMapToPixel
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:38
QgsMapSettings::setLayerStyleOverrides
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...
Definition: qgsmapsettings.cpp:305
QgsRectangle::width
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsRectangle::set
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
Definition: qgsrectangle.h:105
QgsMessageLog::logMessage
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).
Definition: qgsmessagelog.cpp:27
QgsMapSettings::renderedFeatureHandlers
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering the map settings.
Definition: qgsmapsettings.cpp:746
QgsRectangle::asWktCoordinates
QString asWktCoordinates() const
Returns a string representation of the rectangle in WKT format.
Definition: qgsrectangle.cpp:104
QgsMapSettings::layers
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
Definition: qgsmapsettings.cpp:282
QgsMapSettings::mMapToPixel
QgsMapToPixel mMapToPixel
Definition: qgsmapsettings.h:723
qgsexception.h
QgsMapSettings::clippingRegions
QList< QgsMapClippingRegion > clippingRegions() const
Returns the list of clipping regions to apply to the map.
Definition: qgsmapsettings.cpp:736
QgsMapSettings::layerToMapUnits
double layerToMapUnits(const QgsMapLayer *layer, const QgsRectangle &referenceExtent=QgsRectangle()) const
Computes an estimated conversion factor between layer and map units: layerUnits * layerToMapUnits = m...
Definition: qgsmapsettings.cpp:427
QgsMapSettings::setOutputSize
void setOutputSize(QSize size)
Sets the size of the resulting map image.
Definition: qgsmapsettings.cpp:240
qgsmaplayerlistutils.h
qgslogger.h
QgsMapSettings::outputDpi
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
Definition: qgsmapsettings.cpp:263
QgsMapSettings::labelBoundaryGeometry
QgsGeometry labelBoundaryGeometry() const
Returns the label boundary geometry, which restricts where in the rendered map labels are permitted t...
Definition: qgsmapsettings.cpp:716
QgsMapSettings::visibleExtent
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
Definition: qgsmapsettings.cpp:371
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:53
QgsMapSettings::layerToMapCoordinates
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
Definition: qgsmapsettings.cpp:483
QgsMapSettings::setExtent
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
Definition: qgsmapsettings.cpp:79
QgsRectangle::isEmpty
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:437
QgsMapSettings::mapToPixel
const QgsMapToPixel & mapToPixel() const
Definition: qgsmapsettings.h:436
qgsproject.h
QgsMapSettings::setEllipsoid
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
Definition: qgsmapsettings.cpp:323
QgsMapSettings::layerIds
QStringList layerIds() const
Gets list of layer IDs for map rendering The layers are stored in the reverse order of how they are r...
Definition: qgsmapsettings.cpp:276
QgsMapSettings::mExtent
QgsRectangle mExtent
Definition: qgsmapsettings.h:686
QgsMapSettings::setExtentBuffer
void setExtentBuffer(double buffer)
Sets the buffer in map units to use around the visible extent for rendering symbols whose correspondi...
Definition: qgsmapsettings.cpp:96
qgsmessagelog.h
QgsXmlUtils::readRectangle
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:39
QgsCoordinateTransform::transformInPlace
void transformInPlace(double &x, double &y, double &z, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
Transforms an array of x, y and z double coordinates in place, from the source CRS to the destination...
Definition: qgscoordinatetransform.cpp:313