QGIS API Documentation  2.99.0-Master (08c2e66)
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 "qgscsexception.h"
29 #include "qgsgeometry.h"
30 
31 Q_GUI_EXPORT extern int qt_defaultDpiX();
32 
33 
35  : mDpi( qt_defaultDpiX() ) // DPI that will be used by default for QImage instances
36  , mSize( QSize( 0, 0 ) )
37  , mExtent()
38  , mRotation( 0.0 )
39  , mMagnificationFactor( 1.0 )
40  , mProjectionsEnabled( false )
41  , mDestCRS( QgsCoordinateReferenceSystem::fromSrsId( GEOCRS_ID ) ) // WGS 84
42  , mDatumTransformStore( mDestCRS )
43  , mBackgroundColor( Qt::white )
44  , mSelectionColor( Qt::yellow )
45  , mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling | DrawSelection )
46  , mImageFormat( QImage::Format_ARGB32_Premultiplied )
47  , mSegmentationTolerance( M_PI_2 / 90 )
48  , mSegmentationToleranceType( QgsAbstractGeometry::MaximumAngle )
49  , mValid( false )
50  , mVisibleExtent()
51  , mMapUnitsPerPixel( 1 )
52  , mScale( 1 )
53 {
54  updateDerived();
55 
56  // set default map units - we use WGS 84 thus use degrees
58 }
59 
61 {
62  double ratio = mMagnificationFactor / factor;
63 
64  mMagnificationFactor = factor;
65 
66  double rot = rotation();
67  setRotation( 0.0 );
68 
70  ext.scale( ratio );
71 
72  mRotation = rot;
73  mExtent = ext;
74  mDpi = mDpi / ratio;
75 
76  QgsDebugMsg( QString( "Magnification factor: %1 dpi: %2 ratio: %3" ).arg( factor ).arg( mDpi ).arg( ratio ) );
77 
78  updateDerived();
79 }
80 
82 {
83  return mMagnificationFactor;
84 }
85 
87 {
88  return mExtent;
89 }
90 
91 void QgsMapSettings::setExtent( const QgsRectangle& extent, bool magnified )
92 {
93  QgsRectangle magnifiedExtent = extent;
94 
95  if ( !magnified )
96  magnifiedExtent.scale( 1 / mMagnificationFactor );
97 
98  mExtent = magnifiedExtent;
99 
100  updateDerived();
101 }
102 
104 {
105  return mRotation;
106 }
107 
108 void QgsMapSettings::setRotation( double degrees )
109 {
110  if ( qgsDoubleNear( mRotation, degrees ) ) return;
111 
112  mRotation = degrees;
113 
114  // TODO: update extent while keeping scale ?
115  updateDerived();
116 }
117 
118 
120 {
122 
123  if ( extent.isEmpty() || !extent.isFinite() )
124  {
125  mValid = false;
126  return;
127  }
128 
129  // Don't allow zooms where the current extent is so small that it
130  // can't be accurately represented using a double (which is what
131  // currentExtent uses). Excluding 0 avoids a divide by zero and an
132  // infinite loop when rendering to a new canvas. Excluding extents
133  // greater than 1 avoids doing unnecessary calculations.
134 
135  // The scheme is to compare the width against the mean x coordinate
136  // (and height against mean y coordinate) and only allow zooms where
137  // the ratio indicates that there is more than about 12 significant
138  // figures (there are about 16 significant figures in a double).
139 
140  if ( extent.width() > 0 &&
141  extent.height() > 0 &&
142  extent.width() < 1 &&
143  extent.height() < 1 )
144  {
145  // Use abs() on the extent to avoid the case where the extent is
146  // symmetrical about 0.
147  double xMean = ( qAbs( extent.xMinimum() ) + qAbs( extent.xMaximum() ) ) * 0.5;
148  double yMean = ( qAbs( extent.yMinimum() ) + qAbs( extent.yMaximum() ) ) * 0.5;
149 
150  double xRange = extent.width() / xMean;
151  double yRange = extent.height() / yMean;
152 
153  static const double MIN_PROPORTION = 1e-12;
154  if ( xRange < MIN_PROPORTION || yRange < MIN_PROPORTION )
155  {
156  mValid = false;
157  return;
158  }
159  }
160 
161  double myHeight = mSize.height();
162  double myWidth = mSize.width();
163 
164  if ( !myWidth || !myHeight )
165  {
166  mValid = false;
167  return;
168  }
169 
170  // calculate the translation and scaling parameters
171  double mapUnitsPerPixelY = mExtent.height() / myHeight;
172  double mapUnitsPerPixelX = mExtent.width() / myWidth;
173  mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
174 
175  // calculate the actual extent of the mapCanvas
176  double dxmin = mExtent.xMinimum(), dxmax = mExtent.xMaximum(),
177  dymin = mExtent.yMinimum(), dymax = mExtent.yMaximum(), whitespace;
178 
179  if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
180  {
181  whitespace = (( myWidth * mMapUnitsPerPixel ) - mExtent.width() ) * 0.5;
182  dxmin -= whitespace;
183  dxmax += whitespace;
184  }
185  else
186  {
187  whitespace = (( myHeight * mMapUnitsPerPixel ) - mExtent.height() ) * 0.5;
188  dymin -= whitespace;
189  dymax += whitespace;
190  }
191 
192  mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
193 
194  // update the scale
197 
199  visibleExtent().center().x(),
200  visibleExtent().center().y(),
201  outputSize().width(),
202  outputSize().height(),
203  mRotation );
204 
205 #if 1 // set visible extent taking rotation in consideration
206  if ( mRotation )
207  {
208  QgsPoint p1 = mMapToPixel.toMapCoordinates( QPoint( 0, 0 ) );
209  QgsPoint p2 = mMapToPixel.toMapCoordinates( QPoint( 0, myHeight ) );
210  QgsPoint p3 = mMapToPixel.toMapCoordinates( QPoint( myWidth, 0 ) );
211  QgsPoint p4 = mMapToPixel.toMapCoordinates( QPoint( myWidth, myHeight ) );
212  dxmin = std::min( p1.x(), std::min( p2.x(), std::min( p3.x(), p4.x() ) ) );
213  dymin = std::min( p1.y(), std::min( p2.y(), std::min( p3.y(), p4.y() ) ) );
214  dxmax = std::max( p1.x(), std::max( p2.x(), std::max( p3.x(), p4.x() ) ) );
215  dymax = std::max( p1.y(), std::max( p2.y(), std::max( p3.y(), p4.y() ) ) );
216  mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
217  }
218 #endif
219 
220  QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ), qgsDoubleToString( mapUnitsPerPixelY ) ) );
221  QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mSize.width() ), qgsDoubleToString( mSize.height() ) ) );
222  QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ), qgsDoubleToString( mExtent.height() ) ) );
224  QgsDebugMsg( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / myWidth ), qgsDoubleToString( mVisibleExtent.height() / myHeight ) ) );
225  QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / mMapUnitsPerPixel ), qgsDoubleToString( mVisibleExtent.height() / mMapUnitsPerPixel ) ) );
226  QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ) );
227  QgsDebugMsg( QString( "Rotation: %1 degrees" ).arg( mRotation ) );
228 
229  mValid = true;
230 }
231 
232 
234 {
235  return mSize;
236 }
237 
239 {
240  mSize = size;
241 
242  updateDerived();
243 }
244 
246 {
247  return mDpi;
248 }
249 
251 {
252  mDpi = dpi;
253 
254  updateDerived();
255 }
256 
257 
258 QStringList QgsMapSettings::layerIds() const
259 {
260  return _qgis_listQPointerToIDs( mLayers );
261 }
262 
263 
264 QList<QgsMapLayer*> QgsMapSettings::layers() const
265 {
266  return _qgis_listQPointerToRaw( mLayers );
267 }
268 
269 void QgsMapSettings::setLayers( const QList<QgsMapLayer*>& layers )
270 {
271  mLayers = _qgis_listRawToQPointer( layers );
272 }
273 
274 QMap<QString, QString> QgsMapSettings::layerStyleOverrides() const
275 {
276  return mLayerStyleOverrides;
277 }
278 
279 void QgsMapSettings::setLayerStyleOverrides( const QMap<QString, QString>& overrides )
280 {
281  mLayerStyleOverrides = overrides;
282 }
283 
285 {
286  mProjectionsEnabled = enabled;
287 }
288 
290 {
291  return mProjectionsEnabled;
292 }
293 
294 
296 {
297  mDestCRS = crs;
299 }
300 
302 {
303  return mDestCRS;
304 }
305 
306 
308 {
310 
311  // Since the map units have changed, force a recalculation of the scale.
312  updateDerived();
313 }
314 
315 void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
316 {
317  mFlags = flags;
318 }
319 
321 {
322  if ( on )
323  mFlags |= flag;
324  else
325  mFlags &= ~flag;
326 }
327 
328 QgsMapSettings::Flags QgsMapSettings::flags() const
329 {
330  return mFlags;
331 }
332 
334 {
335  return mFlags.testFlag( flag );
336 }
337 
339 {
340  return mScaleCalculator.mapUnits();
341 }
342 
343 
345 {
346  return mValid;
347 }
348 
350 {
351  return mVisibleExtent;
352 }
353 
355 {
356  QPolygonF poly;
357 
358  const QSize& sz = outputSize();
359  const QgsMapToPixel& m2p = mapToPixel();
360 
361  poly << m2p.toMapCoordinatesF( 0, 0 ).toQPointF();
362  poly << m2p.toMapCoordinatesF( sz.width(), 0 ).toQPointF();
363  poly << m2p.toMapCoordinatesF( sz.width(), sz.height() ).toQPointF();
364  poly << m2p.toMapCoordinatesF( 0, sz.height() ).toQPointF();
365 
366  return poly;
367 }
368 
370 {
371  return mMapUnitsPerPixel;
372 }
373 
374 double QgsMapSettings::scale() const
375 {
376  return mScale;
377 }
378 
379 
381 {
382  return mDatumTransformStore.transformation( layer );
383 }
384 
385 
386 double QgsMapSettings::layerToMapUnits( QgsMapLayer *layer, const QgsRectangle& referenceExtent ) const
387 {
388  QgsRectangle extent = referenceExtent.isEmpty() ? layer->extent() : referenceExtent;
389  QgsPoint l1( extent.xMinimum(), extent.yMinimum() );
390  QgsPoint l2( extent.xMaximum(), extent.yMaximum() );
391  double distLayerUnits = std::sqrt( l1.sqrDist( l2 ) );
392  QgsPoint m1 = layerToMapCoordinates( layer, l1 );
393  QgsPoint m2 = layerToMapCoordinates( layer, l2 );
394  double distMapUnits = std::sqrt( m1.sqrDist( m2 ) );
395  return distMapUnits / distLayerUnits;
396 }
397 
398 
400 {
401  if ( hasCrsTransformEnabled() )
402  {
403  try
404  {
406  if ( ct.isValid() )
407  {
408  QgsDebugMsg( QString( "sourceCrs = " + ct.sourceCrs().authid() ) );
409  QgsDebugMsg( QString( "destCRS = " + ct.destinationCrs().authid() ) );
410  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
411  extent = ct.transformBoundingBox( extent );
412  }
413  }
414  catch ( QgsCsException &cse )
415  {
416  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
417  }
418  }
419 
420  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
421 
422  return extent;
423 }
424 
425 
427 {
428  if ( hasCrsTransformEnabled() )
429  {
430  try
431  {
433  if ( ct.isValid() )
434  {
435  QgsDebugMsg( QString( "sourceCrs = " + ct.sourceCrs().authid() ) );
436  QgsDebugMsg( QString( "destCRS = " + ct.destinationCrs().authid() ) );
437  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
439  }
440  }
441  catch ( QgsCsException &cse )
442  {
443  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
444  }
445  }
446 
447  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
448 
449  return extent;
450 }
451 
452 
454 {
455  if ( hasCrsTransformEnabled() )
456  {
457  try
458  {
460  if ( ct.isValid() )
462  }
463  catch ( QgsCsException &cse )
464  {
465  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
466  }
467  }
468  else
469  {
470  // leave point without transformation
471  }
472  return point;
473 }
474 
475 
477 {
478  if ( hasCrsTransformEnabled() )
479  {
480  try
481  {
483  if ( ct.isValid() )
485  }
486  catch ( QgsCsException &cse )
487  {
488  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
489  }
490  }
491  else
492  {
493  // leave point without transformation
494  }
495  return rect;
496 }
497 
498 
500 {
501  if ( hasCrsTransformEnabled() )
502  {
503  try
504  {
506  if ( ct.isValid() )
508  }
509  catch ( QgsCsException &cse )
510  {
511  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
512  }
513  }
514  else
515  {
516  // leave point without transformation
517  }
518  return point;
519 }
520 
521 
523 {
524  if ( hasCrsTransformEnabled() )
525  {
526  try
527  {
529  if ( ct.isValid() )
531  }
532  catch ( QgsCsException &cse )
533  {
534  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
535  }
536  }
537  return rect;
538 }
539 
540 
541 
543 {
544  QgsDebugMsg( "called." );
545 
546  // reset the map canvas extent since the extent may now be smaller
547  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
549  fullExtent.setMinimal();
550 
551  // iterate through the map layers and test each layers extent
552  // against the current min and max values
553  QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayers.count() ) );
554  Q_FOREACH ( const QgsWeakMapLayerPointer& layerPtr, mLayers )
555  {
556  if ( QgsMapLayer* lyr = layerPtr.data() )
557  {
558  QgsDebugMsg( "Updating extent using " + lyr->name() );
559  QgsDebugMsg( "Input extent: " + lyr->extent().toString() );
560 
561  if ( lyr->extent().isNull() )
562  continue;
563 
564  // Layer extents are stored in the coordinate system (CS) of the
565  // layer. The extent must be projected to the canvas CS
566  QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() );
567 
568  QgsDebugMsg( "Output extent: " + extent.toString() );
569  fullExtent.unionRect( extent );
570  }
571  }
572 
573  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
574  {
575  // If all of the features are at the one point, buffer the
576  // rectangle a bit. If they are all at zero, do something a bit
577  // more crude.
578 
579  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
580  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
581  {
582  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
583  }
584  else
585  {
586  const double padFactor = 1e-8;
587  double widthPad = fullExtent.xMinimum() * padFactor;
588  double heightPad = fullExtent.yMinimum() * padFactor;
589  double xmin = fullExtent.xMinimum() - widthPad;
590  double xmax = fullExtent.xMaximum() + widthPad;
591  double ymin = fullExtent.yMinimum() - heightPad;
592  double ymax = fullExtent.yMaximum() + heightPad;
593  fullExtent.set( xmin, ymin, xmax, ymax );
594  }
595  }
596 
597  QgsDebugMsg( "Full extent: " + fullExtent.toString() );
598  return fullExtent;
599 }
600 
601 
602 void QgsMapSettings::readXml( QDomNode& node )
603 {
604  // set units
605  QDomNode mapUnitsNode = node.namedItem( QStringLiteral( "units" ) );
606  QgsUnitTypes::DistanceUnit units = QgsXmlUtils::readMapUnits( mapUnitsNode.toElement() );
607  setMapUnits( units );
608 
609  // set projections flag
610  QDomNode projNode = node.namedItem( QStringLiteral( "projections" ) );
611  setCrsTransformEnabled( projNode.toElement().text().toInt() );
612 
613  // set destination CRS
615  QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );
616  srs.readXml( srsNode );
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 
641 }
642 
643 
644 
645 void QgsMapSettings::writeXml( QDomNode& node, QDomDocument& doc )
646 {
647  // units
648  node.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), doc ) );
649 
650  // Write current view extents
651  node.appendChild( QgsXmlUtils::writeRectangle( extent(), doc ) );
652 
653  // Write current view rotation
654  QDomElement rotNode = doc.createElement( QStringLiteral( "rotation" ) );
655  rotNode.appendChild(
656  doc.createTextNode( qgsDoubleToString( rotation() ) )
657  );
658  node.appendChild( rotNode );
659 
660  // projections enabled
661  QDomElement projNode = doc.createElement( QStringLiteral( "projections" ) );
662  projNode.appendChild( doc.createTextNode( QString::number( hasCrsTransformEnabled() ) ) );
663  node.appendChild( projNode );
664 
665  // destination CRS
666  QDomElement srsNode = doc.createElement( QStringLiteral( "destinationsrs" ) );
667  node.appendChild( srsNode );
668  destinationCrs().writeXml( srsNode, doc );
669 
670  //render map tile
671  QDomElement renderMapTileElem = doc.createElement( QStringLiteral( "rendermaptile" ) );
672  QDomText renderMapTileText = doc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
673  renderMapTileElem.appendChild( renderMapTileText );
674  node.appendChild( renderMapTileElem );
675 
676  mDatumTransformStore.writeXml( node, doc );
677 }
QgsUnitTypes::DistanceUnit mapUnits() const
Get units of map&#39;s geographical coordinates - used for scale calculation.
void unionRect(const QgsRectangle &rect)
Updates rectangle to include passed argument.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform, const bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
double mMagnificationFactor
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
A rectangle specified with double values.
Definition: qgsrectangle.h:36
Base class for all map layer types.
Definition: qgsmaplayer.h:52
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
double y
Definition: qgspoint.h:148
bool isEmpty() const
test if rectangle is empty.
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
QgsMapToPixel mMapToPixel
double scale() const
Return the calculated scale of the map.
QgsRectangle fullExtent() const
returns current extent of layer set
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:202
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
QgsCoordinateReferenceSystem mDestCRS
QgsUnitTypes::DistanceUnit mapUnits() const
Returns current map units.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from...
QMap< QString, QString > mLayerStyleOverrides
void scale(double scaleFactor, const QgsPoint *c=nullptr)
Scale the rectangle around its center point.
QgsCoordinateTransform transformation(QgsMapLayer *layer) const
Will return transform from layer&#39;s CRS to current destination CRS.
void setOutputDpi(double dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
QMap< QString, QString > layerStyleOverrides() const
Get map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
void setDestinationCrs(const QgsCoordinateReferenceSystem &destCrs)
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
Definition: qgsxmlutils.cpp:78
void setFlags(QgsMapSettings::Flags flags)
Set combination of flags that will be used for rendering.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
const QgsMapToPixel & mapToPixel() const
Flags flags() const
Return combination of flags used for rendering.
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Set map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
double rotation() const
Return the rotation of the resulting map image Units are clockwise degrees.
QgsCoordinateTransform layerTransform(QgsMapLayer *layer) const
Return coordinate transform from layer&#39;s CRS to destination CRS.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:976
double layerToMapUnits(QgsMapLayer *layer, const QgsRectangle &referenceExtent=QgsRectangle()) const
Computes an estimated conversion factor between layer and map units: layerUnits * layerToMapUnits = m...
Q_GUI_EXPORT int qt_defaultDpiX()
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:198
#define M_PI_2
Definition: util.cpp:45
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system, which the transform will transform coordinates t...
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void set(const QgsPoint &p1, const QgsPoint &p2)
Set the rectangle from two QgsPoints.
QList< QgsMapLayer * > layers() const
Get list of layers for map rendering The layers are stored in the reverse order of how they are rende...
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
QgsPoint layerToMapCoordinates(QgsMapLayer *layer, QgsPoint point) const
transform point coordinates from layer&#39;s CRS to output CRS
bool mValid
Whether the actual settings are valid (set in updateDerived())
void setOutputSize(QSize size)
Set the size of the resulting map image.
double magnificationFactor() const
Return the magnification factor.
QgsRectangle mExtent
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:207
Flag
Enumeration of flags that adjust the way the map is rendered.
QSize outputSize() const
Return the size of the resulting map image.
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:192
void setMagnificationFactor(double factor)
Set the magnification factor.
virtual QgsRectangle extent() const
Returns the extent of the layer.
static QgsUnitTypes::DistanceUnit readMapUnits(const QDomElement &element)
Decodes a distance unit from a DOM element.
Definition: qgsxmlutils.cpp:23
void setRotation(double degrees)
Set the rotation of the resulting map image Units are clockwise degrees.
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:186
QStringList layerIds() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
void setMapUnits(QgsUnitTypes::DistanceUnit mapUnits)
Set the map units.
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
Definition: qgis.h:300
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
static QDomElement writeMapUnits(QgsUnitTypes::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
Definition: qgsxmlutils.cpp:66
double mapUnitsPerPixel() const
Return the distance in geographical coordinates that equals to one pixel in the map.
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:51
void readXml(const QDomNode &parentNode)
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:452
Abstract base class for all geometries.
QgsScaleCalculator mScaleCalculator
A class to represent a point.
Definition: qgspoint.h:143
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:437
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:43
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
QgsPoint toMapCoordinatesF(double x, double y) const
Transform device coordinates to map (world) coordinates.
QgsPoint toMapCoordinates(int x, int y) const
Draw map such that there are no problems between adjacent tiles.
QString what() const
Definition: qgsexception.h:38
Transform from destination to source CRS.
double mMapUnitsPerPixel
QgsRectangle layerExtentToOutputExtent(QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer&#39;s CRS to output CRS
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
QgsPoint mapToLayerCoordinates(QgsMapLayer *layer, QgsPoint point) const
transform point coordinates from output CRS to layer&#39;s CRS
This class represents a coordinate reference system (CRS).
QgsRectangle extent() const
Return geographical coordinates of the rectangle that should be rendered.
QString authid() const
Returns the authority identifier for the CRS.
Class for doing transforms between two map coordinate systems.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
Transform from source to destination CRS.
QgsPoint transform(const QgsPoint &point, TransformDirection direction=ForwardTransform) const
Transform the point from the source CRS to the destination CRS.
QPolygonF visiblePolygon() const
Return the visible area as a polygon (may be rotated)
Custom exception class for Coordinate Reference System related exceptions.
void readXml(QDomNode &node)
double outputDpi() const
Return DPI used for conversion between real world units (e.g.
QgsRectangle outputExtentToLayerExtent(QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer&#39;s CRS
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:212
QgsDatumTransformStore mDatumTransformStore
void writeXml(QDomNode &node, QDomDocument &doc)
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:197
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:36
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:217
void setMapUnits(QgsUnitTypes::DistanceUnit u)
Set units of map&#39;s geographical coordinates - used for scale calculation.
void setCrsTransformEnabled(bool enabled)
sets whether to use projections for this layer set
void setLayers(const QList< QgsMapLayer * > &layers)
Set list of layers for map rendering.
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspoint.cpp:158
double x
Definition: qgspoint.h:147