QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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  QgsDebugMsgLevel( QStringLiteral( "Extent: %1" ).arg( mExtent.asWktCoordinates() ), 5 );
228  QgsDebugMsgLevel( QStringLiteral( "Visible Extent: %1" ).arg( mVisibleExtent.asWktCoordinates() ), 5 );
229 
230  mValid = true;
231 }
232 
233 
235 {
236  return mSize;
237 }
238 
240 {
241  mSize = size;
242 
243  updateDerived();
244 }
245 
247 {
248  return mDevicePixelRatio;
249 }
250 
252 {
253  mDevicePixelRatio = dpr;
254  updateDerived();
255 }
256 
258 {
259  return outputSize() * mDevicePixelRatio;
260 }
261 
263 {
264  return mDpi;
265 }
266 
268 {
269  mDpi = dpi;
270 
271  updateDerived();
272 }
273 
274 
275 QStringList QgsMapSettings::layerIds() const
276 {
277  return _qgis_listQPointerToIDs( mLayers );
278 }
279 
280 
281 QList<QgsMapLayer *> QgsMapSettings::layers() const
282 {
283  return _qgis_listQPointerToRaw( mLayers );
284 }
285 
286 void QgsMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
287 {
288  // filter list, removing null layers and non-spatial layers
289  auto filteredList = layers;
290  filteredList.erase( std::remove_if( filteredList.begin(), filteredList.end(),
291  []( QgsMapLayer * layer )
292  {
293  return !layer || !layer->isSpatial();
294  } ), filteredList.end() );
295 
296  mLayers = _qgis_listRawToQPointer( filteredList );
297 }
298 
299 QMap<QString, QString> QgsMapSettings::layerStyleOverrides() const
300 {
301  return mLayerStyleOverrides;
302 }
303 
304 void QgsMapSettings::setLayerStyleOverrides( const QMap<QString, QString> &overrides )
305 {
306  mLayerStyleOverrides = overrides;
307 }
308 
310 {
311  mDestCRS = crs;
313  // Since the map units have changed, force a recalculation of the scale.
314  updateDerived();
315 }
316 
318 {
319  return mDestCRS;
320 }
321 
323 {
325  if ( !params.valid )
326  {
327  return false;
328  }
329  else
330  {
332  return true;
333  }
334 }
335 
336 void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
337 {
338  mFlags = flags;
339 }
340 
342 {
343  if ( on )
344  mFlags |= flag;
345  else
346  mFlags &= ~flag;
347 }
348 
349 QgsMapSettings::Flags QgsMapSettings::flags() const
350 {
351  return mFlags;
352 }
353 
355 {
356  return mFlags.testFlag( flag );
357 }
358 
360 {
361  return mScaleCalculator.mapUnits();
362 }
363 
364 
366 {
367  return mValid;
368 }
369 
371 {
372  return mVisibleExtent;
373 }
374 
376 {
377  QPolygonF poly;
378 
379  const QSize &sz = outputSize();
380  const QgsMapToPixel &m2p = mapToPixel();
381 
382  poly << m2p.toMapCoordinates( 0.0, 0.0 ).toQPointF();
383  poly << m2p.toMapCoordinates( static_cast<double>( sz.width() ), 0.0 ).toQPointF();
384  poly << m2p.toMapCoordinates( static_cast<double>( sz.width() ), static_cast<double>( sz.height() ) ).toQPointF();
385  poly << m2p.toMapCoordinates( 0.0, static_cast<double>( sz.height() ) ).toQPointF();
386 
387  return poly;
388 }
389 
391 {
392  return mMapUnitsPerPixel;
393 }
394 
395 double QgsMapSettings::scale() const
396 {
397  return mScale;
398 }
399 
401 {
402 #ifdef QGISDEBUG
403  if ( !mHasTransformContext )
404  QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 );
405 #endif
406 
407  return mTransformContext;
408 }
409 
411 {
412  mTransformContext = context;
413 #ifdef QGISDEBUG
414  mHasTransformContext = true;
415 #endif
416 }
417 
419 {
420  if ( !layer )
421  return QgsCoordinateTransform();
422 
424 }
425 
426 double QgsMapSettings::layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent ) const
427 {
428  return layerTransform( layer ).scaleFactor( referenceExtent );
429 }
430 
431 
433 {
434  try
435  {
437  if ( ct.isValid() )
438  {
439  QgsDebugMsgLevel( QStringLiteral( "sourceCrs = %1" ).arg( ct.sourceCrs().authid() ), 3 );
440  QgsDebugMsgLevel( QStringLiteral( "destCRS = %1" ).arg( ct.destinationCrs().authid() ), 3 );
441  QgsDebugMsgLevel( QStringLiteral( "extent %1" ).arg( extent.toString() ), 3 );
442  extent = ct.transformBoundingBox( extent );
443  }
444  }
445  catch ( QgsCsException &cse )
446  {
447  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
448  }
449 
450  QgsDebugMsgLevel( QStringLiteral( "proj extent = %1 " ).arg( extent.toString() ), 3 );
451 
452  return extent;
453 }
454 
455 
457 {
458  try
459  {
461  if ( ct.isValid() )
462  {
463  QgsDebugMsgLevel( QStringLiteral( "sourceCrs = %1" ).arg( ct.sourceCrs().authid() ), 3 );
464  QgsDebugMsgLevel( QStringLiteral( "destCRS = %1" ).arg( ct.destinationCrs().authid() ), 3 );
465  QgsDebugMsgLevel( QStringLiteral( "extent = %1" ).arg( extent.toString() ), 3 );
467  }
468  }
469  catch ( QgsCsException &cse )
470  {
471  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
472  }
473 
474  QgsDebugMsgLevel( QStringLiteral( "proj extent = %1" ).arg( extent.toString() ), 3 );
475 
476  return extent;
477 }
478 
479 
481 {
482  try
483  {
485  if ( ct.isValid() )
487  }
488  catch ( QgsCsException &cse )
489  {
490  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
491  }
492 
493  return point;
494 }
495 
496 
498 {
499  try
500  {
502  if ( ct.isValid() )
504  }
505  catch ( QgsCsException &cse )
506  {
507  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
508  }
509 
510  return rect;
511 }
512 
513 
515 {
516  try
517  {
519  if ( ct.isValid() )
521  }
522  catch ( QgsCsException &cse )
523  {
524  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
525  }
526 
527  return point;
528 }
529 
530 
532 {
533  try
534  {
536  if ( ct.isValid() )
538  }
539  catch ( QgsCsException &cse )
540  {
541  QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
542  }
543 
544  return rect;
545 }
546 
547 
548 
550 {
551  // reset the map canvas extent since the extent may now be smaller
552  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
554  fullExtent.setMinimal();
555 
556  // iterate through the map layers and test each layers extent
557  // against the current min and max values
558  QgsDebugMsgLevel( QStringLiteral( "Layer count: %1" ).arg( mLayers.count() ), 5 );
559  const auto constMLayers = mLayers;
560  for ( const QgsWeakMapLayerPointer &layerPtr : constMLayers )
561  {
562  if ( QgsMapLayer *lyr = layerPtr.data() )
563  {
564  QgsDebugMsgLevel( "Updating extent using " + lyr->name(), 5 );
565  QgsDebugMsgLevel( "Input extent: " + lyr->extent().toString(), 5 );
566 
567  if ( lyr->extent().isNull() )
568  continue;
569 
570  // Layer extents are stored in the coordinate system (CS) of the
571  // layer. The extent must be projected to the canvas CS
572  QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() );
573 
574  QgsDebugMsgLevel( "Output extent: " + extent.toString(), 5 );
575  fullExtent.combineExtentWith( extent );
576  }
577  }
578 
579  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
580  {
581  // If all of the features are at the one point, buffer the
582  // rectangle a bit. If they are all at zero, do something a bit
583  // more crude.
584 
585  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
586  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
587  {
588  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
589  }
590  else
591  {
592  const double padFactor = 1e-8;
593  double widthPad = fullExtent.xMinimum() * padFactor;
594  double heightPad = fullExtent.yMinimum() * padFactor;
595  double xmin = fullExtent.xMinimum() - widthPad;
596  double xmax = fullExtent.xMaximum() + widthPad;
597  double ymin = fullExtent.yMinimum() - heightPad;
598  double ymax = fullExtent.yMaximum() + heightPad;
599  fullExtent.set( xmin, ymin, xmax, ymax );
600  }
601  }
602 
603  QgsDebugMsgLevel( "Full extent: " + fullExtent.toString(), 5 );
604  return fullExtent;
605 }
606 
607 
608 void QgsMapSettings::readXml( QDomNode &node )
609 {
610  // set destination CRS
612  QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );
613  if ( !srsNode.isNull() )
614  {
615  srs.readXml( srsNode );
616  }
617  setDestinationCrs( srs );
618 
619  // set extent
620  QDomNode extentNode = node.namedItem( QStringLiteral( "extent" ) );
621  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
622  setExtent( aoi );
623 
624  // set rotation
625  QDomNode rotationNode = node.namedItem( QStringLiteral( "rotation" ) );
626  QString rotationVal = rotationNode.toElement().text();
627  if ( ! rotationVal.isEmpty() )
628  {
629  double rot = rotationVal.toDouble();
630  setRotation( rot );
631  }
632 
633  //render map tile
634  QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral( "rendermaptile" ) );
635  if ( !renderMapTileElem.isNull() )
636  {
637  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == QLatin1String( "1" ) );
638  }
639 }
640 
641 
642 
643 void QgsMapSettings::writeXml( QDomNode &node, QDomDocument &doc )
644 {
645  // units
646  node.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), doc ) );
647 
648  // Write current view extents
649  node.appendChild( QgsXmlUtils::writeRectangle( extent(), doc ) );
650 
651  // Write current view rotation
652  QDomElement rotNode = doc.createElement( QStringLiteral( "rotation" ) );
653  rotNode.appendChild(
654  doc.createTextNode( qgsDoubleToString( rotation() ) )
655  );
656  node.appendChild( rotNode );
657 
658  // destination CRS
659  if ( mDestCRS.isValid() )
660  {
661  QDomElement srsNode = doc.createElement( QStringLiteral( "destinationsrs" ) );
662  node.appendChild( srsNode );
663  mDestCRS.writeXml( srsNode, doc );
664  }
665 
666  //render map tile
667  QDomElement renderMapTileElem = doc.createElement( QStringLiteral( "rendermaptile" ) );
668  QDomText renderMapTileText = doc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
669  renderMapTileElem.appendChild( renderMapTileText );
670  node.appendChild( renderMapTileElem );
671 }
672 
674 {
675  return mLabelBoundaryGeometry;
676 }
677 
679 {
680  mLabelBoundaryGeometry = boundary;
681 }
682 
684 {
685  mRenderedFeatureHandlers.append( handler );
686 }
687 
688 QList<QgsRenderedFeatureHandlerInterface *> QgsMapSettings::renderedFeatureHandlers() const
689 {
690  return mRenderedFeatureHandlers;
691 }
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:280
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:122
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:1632
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:240
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
QString asWktCoordinates() const
Returns a string representation of the rectangle in WKT format.
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:66
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:77
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.