QGIS API Documentation  2.99.0-Master (314842d)
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  , mDestCRS( QgsCoordinateReferenceSystem::fromSrsId( GEOCRS_ID ) ) // WGS 84
41  , mDatumTransformStore( mDestCRS )
42  , mBackgroundColor( Qt::white )
43  , mSelectionColor( Qt::yellow )
44  , mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling | DrawSelection )
45  , mImageFormat( QImage::Format_ARGB32_Premultiplied )
46  , mSegmentationTolerance( M_PI_2 / 90 )
47  , mSegmentationToleranceType( QgsAbstractGeometry::MaximumAngle )
48  , mValid( false )
49  , mVisibleExtent()
50  , mMapUnitsPerPixel( 1 )
51  , mScale( 1 )
52 {
53  // set default map units - we use WGS 84 thus use degrees
55 
56  updateDerived();
57 }
58 
60 {
61  double ratio = mMagnificationFactor / factor;
62 
63  mMagnificationFactor = factor;
64 
65  double rot = rotation();
66  setRotation( 0.0 );
67 
69  ext.scale( ratio );
70 
71  mRotation = rot;
72  mExtent = ext;
73  mDpi = mDpi / ratio;
74 
75  QgsDebugMsg( QString( "Magnification factor: %1 dpi: %2 ratio: %3" ).arg( factor ).arg( mDpi ).arg( ratio ) );
76 
77  updateDerived();
78 }
79 
81 {
82  return mMagnificationFactor;
83 }
84 
86 {
87  return mExtent;
88 }
89 
90 void QgsMapSettings::setExtent( const QgsRectangle &extent, bool magnified )
91 {
92  QgsRectangle magnifiedExtent = extent;
93 
94  if ( !magnified )
95  magnifiedExtent.scale( 1 / mMagnificationFactor );
96 
97  mExtent = magnifiedExtent;
98 
99  updateDerived();
100 }
101 
103 {
104  return mRotation;
105 }
106 
107 void QgsMapSettings::setRotation( double degrees )
108 {
109  if ( qgsDoubleNear( mRotation, degrees ) ) 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 = ( qAbs( extent.xMinimum() ) + qAbs( extent.xMaximum() ) ) * 0.5;
147  double yMean = ( qAbs( extent.yMinimum() ) + qAbs( 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  QgsPoint p1 = mMapToPixel.toMapCoordinates( QPoint( 0, 0 ) );
208  QgsPoint p2 = mMapToPixel.toMapCoordinates( QPoint( 0, myHeight ) );
209  QgsPoint p3 = mMapToPixel.toMapCoordinates( QPoint( myWidth, 0 ) );
210  QgsPoint 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  QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ), qgsDoubleToString( mapUnitsPerPixelY ) ) );
220  QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mSize.width() ), qgsDoubleToString( mSize.height() ) ) );
221  QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ), qgsDoubleToString( mExtent.height() ) ) );
223  QgsDebugMsg( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / myWidth ), qgsDoubleToString( mVisibleExtent.height() / myHeight ) ) );
224  QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / mMapUnitsPerPixel ), qgsDoubleToString( mVisibleExtent.height() / mMapUnitsPerPixel ) ) );
225  QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ) );
226  QgsDebugMsg( QString( "Rotation: %1 degrees" ).arg( mRotation ) );
227 
228  mValid = true;
229 }
230 
231 
233 {
234  return mSize;
235 }
236 
238 {
239  mSize = size;
240 
241  updateDerived();
242 }
243 
245 {
246  return mDpi;
247 }
248 
250 {
251  mDpi = dpi;
252 
253  updateDerived();
254 }
255 
256 
257 QStringList QgsMapSettings::layerIds() const
258 {
259  return _qgis_listQPointerToIDs( mLayers );
260 }
261 
262 
263 QList<QgsMapLayer *> QgsMapSettings::layers() const
264 {
265  return _qgis_listQPointerToRaw( mLayers );
266 }
267 
268 void QgsMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
269 {
270  mLayers = _qgis_listRawToQPointer( layers );
271 }
272 
273 QMap<QString, QString> QgsMapSettings::layerStyleOverrides() const
274 {
275  return mLayerStyleOverrides;
276 }
277 
278 void QgsMapSettings::setLayerStyleOverrides( const QMap<QString, QString> &overrides )
279 {
280  mLayerStyleOverrides = overrides;
281 }
282 
284 {
285  mDestCRS = crs;
287 
289  // Since the map units have changed, force a recalculation of the scale.
290  updateDerived();
291 }
292 
294 {
295  return mDestCRS;
296 }
297 
298 void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
299 {
300  mFlags = flags;
301 }
302 
304 {
305  if ( on )
306  mFlags |= flag;
307  else
308  mFlags &= ~flag;
309 }
310 
311 QgsMapSettings::Flags QgsMapSettings::flags() const
312 {
313  return mFlags;
314 }
315 
317 {
318  return mFlags.testFlag( flag );
319 }
320 
322 {
323  return mScaleCalculator.mapUnits();
324 }
325 
326 
328 {
329  return mValid;
330 }
331 
333 {
334  return mVisibleExtent;
335 }
336 
338 {
339  QPolygonF poly;
340 
341  const QSize &sz = outputSize();
342  const QgsMapToPixel &m2p = mapToPixel();
343 
344  poly << m2p.toMapCoordinatesF( 0, 0 ).toQPointF();
345  poly << m2p.toMapCoordinatesF( sz.width(), 0 ).toQPointF();
346  poly << m2p.toMapCoordinatesF( sz.width(), sz.height() ).toQPointF();
347  poly << m2p.toMapCoordinatesF( 0, sz.height() ).toQPointF();
348 
349  return poly;
350 }
351 
353 {
354  return mMapUnitsPerPixel;
355 }
356 
357 double QgsMapSettings::scale() const
358 {
359  return mScale;
360 }
361 
362 
364 {
365  return mDatumTransformStore.transformation( layer );
366 }
367 
368 
369 double QgsMapSettings::layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle &referenceExtent ) const
370 {
371  QgsRectangle extent = referenceExtent.isEmpty() ? layer->extent() : referenceExtent;
372  QgsPoint l1( extent.xMinimum(), extent.yMinimum() );
373  QgsPoint l2( extent.xMaximum(), extent.yMaximum() );
374  double distLayerUnits = std::sqrt( l1.sqrDist( l2 ) );
375  QgsPoint m1 = layerToMapCoordinates( layer, l1 );
376  QgsPoint m2 = layerToMapCoordinates( layer, l2 );
377  double distMapUnits = std::sqrt( m1.sqrDist( m2 ) );
378  return distMapUnits / distLayerUnits;
379 }
380 
381 
383 {
384  try
385  {
387  if ( ct.isValid() )
388  {
389  QgsDebugMsg( QString( "sourceCrs = " + ct.sourceCrs().authid() ) );
390  QgsDebugMsg( QString( "destCRS = " + ct.destinationCrs().authid() ) );
391  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
392  extent = ct.transformBoundingBox( extent );
393  }
394  }
395  catch ( QgsCsException &cse )
396  {
397  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
398  }
399 
400  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
401 
402  return extent;
403 }
404 
405 
407 {
408  try
409  {
411  if ( ct.isValid() )
412  {
413  QgsDebugMsg( QString( "sourceCrs = " + ct.sourceCrs().authid() ) );
414  QgsDebugMsg( QString( "destCRS = " + ct.destinationCrs().authid() ) );
415  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
417  }
418  }
419  catch ( QgsCsException &cse )
420  {
421  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
422  }
423 
424  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
425 
426  return extent;
427 }
428 
429 
431 {
432  try
433  {
435  if ( ct.isValid() )
437  }
438  catch ( QgsCsException &cse )
439  {
440  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
441  }
442 
443  return point;
444 }
445 
446 
448 {
449  try
450  {
452  if ( ct.isValid() )
454  }
455  catch ( QgsCsException &cse )
456  {
457  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
458  }
459 
460  return rect;
461 }
462 
463 
465 {
466  try
467  {
469  if ( ct.isValid() )
471  }
472  catch ( QgsCsException &cse )
473  {
474  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
475  }
476 
477  return point;
478 }
479 
480 
482 {
483  try
484  {
486  if ( ct.isValid() )
488  }
489  catch ( QgsCsException &cse )
490  {
491  QgsMessageLog::logMessage( QStringLiteral( "Transform error caught: %1" ).arg( cse.what() ), QStringLiteral( "CRS" ) );
492  }
493 
494  return rect;
495 }
496 
497 
498 
500 {
501  QgsDebugMsg( "called." );
502 
503  // reset the map canvas extent since the extent may now be smaller
504  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
506  fullExtent.setMinimal();
507 
508  // iterate through the map layers and test each layers extent
509  // against the current min and max values
510  QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayers.count() ) );
511  Q_FOREACH ( const QgsWeakMapLayerPointer &layerPtr, mLayers )
512  {
513  if ( QgsMapLayer *lyr = layerPtr.data() )
514  {
515  QgsDebugMsg( "Updating extent using " + lyr->name() );
516  QgsDebugMsg( "Input extent: " + lyr->extent().toString() );
517 
518  if ( lyr->extent().isNull() )
519  continue;
520 
521  // Layer extents are stored in the coordinate system (CS) of the
522  // layer. The extent must be projected to the canvas CS
523  QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() );
524 
525  QgsDebugMsg( "Output extent: " + extent.toString() );
526  fullExtent.unionRect( extent );
527  }
528  }
529 
530  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
531  {
532  // If all of the features are at the one point, buffer the
533  // rectangle a bit. If they are all at zero, do something a bit
534  // more crude.
535 
536  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
537  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
538  {
539  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
540  }
541  else
542  {
543  const double padFactor = 1e-8;
544  double widthPad = fullExtent.xMinimum() * padFactor;
545  double heightPad = fullExtent.yMinimum() * padFactor;
546  double xmin = fullExtent.xMinimum() - widthPad;
547  double xmax = fullExtent.xMaximum() + widthPad;
548  double ymin = fullExtent.yMinimum() - heightPad;
549  double ymax = fullExtent.yMaximum() + heightPad;
550  fullExtent.set( xmin, ymin, xmax, ymax );
551  }
552  }
553 
554  QgsDebugMsg( "Full extent: " + fullExtent.toString() );
555  return fullExtent;
556 }
557 
558 
559 void QgsMapSettings::readXml( QDomNode &node )
560 {
561  // set destination CRS
563  QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );
564  if ( !srsNode.isNull() )
565  {
566  srs.readXml( srsNode );
567  }
568  setDestinationCrs( srs );
569 
570  // set extent
571  QDomNode extentNode = node.namedItem( QStringLiteral( "extent" ) );
572  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
573  setExtent( aoi );
574 
575  // set rotation
576  QDomNode rotationNode = node.namedItem( QStringLiteral( "rotation" ) );
577  QString rotationVal = rotationNode.toElement().text();
578  if ( ! rotationVal.isEmpty() )
579  {
580  double rot = rotationVal.toDouble();
581  setRotation( rot );
582  }
583 
584  //render map tile
585  QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral( "rendermaptile" ) );
586  if ( !renderMapTileElem.isNull() )
587  {
588  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == QLatin1String( "1" ) );
589  }
590 
592 }
593 
594 
595 
596 void QgsMapSettings::writeXml( QDomNode &node, QDomDocument &doc )
597 {
598  // units
599  node.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), doc ) );
600 
601  // Write current view extents
602  node.appendChild( QgsXmlUtils::writeRectangle( extent(), doc ) );
603 
604  // Write current view rotation
605  QDomElement rotNode = doc.createElement( QStringLiteral( "rotation" ) );
606  rotNode.appendChild(
607  doc.createTextNode( qgsDoubleToString( rotation() ) )
608  );
609  node.appendChild( rotNode );
610 
611  // destination CRS
612  if ( mDestCRS.isValid() )
613  {
614  QDomElement srsNode = doc.createElement( QStringLiteral( "destinationsrs" ) );
615  node.appendChild( srsNode );
616  mDestCRS.writeXml( srsNode, doc );
617  }
618 
619  //render map tile
620  QDomElement renderMapTileElem = doc.createElement( QStringLiteral( "rendermaptile" ) );
621  QDomText renderMapTileText = doc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
622  renderMapTileElem.appendChild( renderMapTileText );
623  node.appendChild( renderMapTileElem );
624 
625  mDatumTransformStore.writeXml( node, doc );
626 }
void unionRect(const QgsRectangle &rect)
Updates rectangle to include passed argument.
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:42
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 magnificationFactor() const
Return the magnification factor.
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspoint.cpp:40
double rotation() const
Return the rotation of the resulting map image Units are clockwise degrees.
QStringList layerIds() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
QgsCoordinateReferenceSystem mDestCRS
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
QMap< QString, QString > mLayerStyleOverrides
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer&#39;s CRS
void scale(double scaleFactor, const QgsPoint *c=nullptr)
Scale the rectangle around its center point.
void setOutputDpi(double dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
QgsPoint mapToLayerCoordinates(const QgsMapLayer *layer, QgsPoint point) const
transform point coordinates from output CRS to layer&#39;s CRS
QgsCoordinateTransform transformation(const QgsMapLayer *layer) const
Will return transform from layer&#39;s CRS to current destination CRS.
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 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)
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
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system, which the transform will transform coordinates t...
void setFlags(QgsMapSettings::Flags flags)
Set combination of flags that will be used for rendering.
QgsPoint toMapCoordinates(int x, int y) const
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
Get list of layers for map rendering The layers are stored in the reverse order of how they are rende...
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:976
Q_GUI_EXPORT int qt_defaultDpiX()
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:198
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
virtual QgsRectangle extent() const
Returns the extent of the layer.
#define M_PI_2
Definition: util.cpp:45
QString what() const
Definition: qgsexception.h:38
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
QgsUnitTypes::DistanceUnit mapUnits() const
Get units of map&#39;s geographical coordinates - used for scale calculation.
void set(const QgsPoint &p1, const QgsPoint &p2)
Set the rectangle from two QgsPoints.
QgsPoint layerToMapCoordinates(const QgsMapLayer *layer, QgsPoint point) const
transform point coordinates from layer&#39;s CRS to output CRS
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Return coordinate transform from layer&#39;s CRS to destination CRS.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
bool mValid
Whether the actual settings are valid (set in updateDerived())
QgsRectangle extent() const
Return geographical coordinates of the rectangle that should be rendered.
void setOutputSize(QSize size)
Set 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
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
QgsPoint transform(const QgsPoint &point, TransformDirection direction=ForwardTransform) const
Transform the point from the source CRS to the destination CRS.
Flag
Enumeration of flags that adjust the way the map is rendered.
void setMagnificationFactor(double factor)
Set the magnification factor.
bool isEmpty() const
test if rectangle is empty.
void setRotation(double degrees)
Set the rotation of the resulting map image Units are clockwise degrees.
double scale() const
Return the calculated scale of the map.
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:215
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:186
double mapUnitsPerPixel() const
Return the distance in geographical coordinates that equals to one pixel in the map.
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...
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
Definition: qgis.h:311
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
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:50
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer&#39;s CRS to output CRS
void readXml(const QDomNode &parentNode)
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
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:37
const QgsMapToPixel & mapToPixel() const
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
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:210
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:195
Draw map such that there are no problems between adjacent tiles.
double outputDpi() const
Return DPI used for conversion between real world units (e.g.
QMap< QString, QString > layerStyleOverrides() const
Get map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
Transform from destination to source CRS.
double mMapUnitsPerPixel
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).
Class for doing transforms between two map coordinate systems.
Flags flags() const
Return combination of flags used for rendering.
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:200
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
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:205
Transform from source to destination CRS.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
Custom exception class for Coordinate Reference System related exceptions.
QPolygonF visiblePolygon() const
Return the visible area as a polygon (may be rotated)
void readXml(QDomNode &node)
QgsPoint toMapCoordinatesF(double x, double y) const
Transform device coordinates to map (world) coordinates.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
QgsDatumTransformStore mDatumTransformStore
void writeXml(QDomNode &node, QDomDocument &doc)
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:36
QSize outputSize() const
Return the size of the resulting map image.
QString authid() const
Returns the authority identifier for the CRS.
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:220
QgsUnitTypes::DistanceUnit mapUnits() const
Returns current map units.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
double x
Definition: qgspoint.h:41