QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgscrscache.h"
24 #include "qgsmessagelog.h"
25 #include "qgsmaplayer.h"
26 #include "qgsmaplayerregistry.h"
27 #include "qgsxmlutils.h"
28 
29 
30 Q_GUI_EXPORT extern int qt_defaultDpiX();
31 
32 
34  : mDpi( qt_defaultDpiX() ) // DPI that will be used by default for QImage instances
35  , mSize( QSize( 0, 0 ) )
36  , mExtent()
37  , mRotation( 0.0 )
38  , mMagnificationFactor( 1.0 )
39  , mProjectionsEnabled( false )
40  , mDestCRS( QgsCRSCache::instance()->crsBySrsId( 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( QgsAbstractGeometryV2::MaximumAngle )
48  , mValid( false )
49  , mVisibleExtent()
50  , mMapUnitsPerPixel( 1 )
51  , mScale( 1 )
52 {
53  updateDerived();
54 
55  // set default map units - we use WGS 84 thus use degrees
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 minProportion = 1e-12;
153  if ( xRange < minProportion || yRange < minProportion )
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  {
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 
258 {
259  return mLayers;
260 }
261 
263 {
264  mLayers = layers;
265 }
266 
268 {
269  return mLayerStyleOverrides;
270 }
271 
273 {
274  mLayerStyleOverrides = overrides;
275 }
276 
278 {
279  mProjectionsEnabled = enabled;
280 }
281 
283 {
284  return mProjectionsEnabled;
285 }
286 
287 
289 {
290  mDestCRS = crs;
292 }
293 
295 {
296  return mDestCRS;
297 }
298 
299 
301 {
303 
304  // Since the map units have changed, force a recalculation of the scale.
305  updateDerived();
306 }
307 
308 void QgsMapSettings::setFlags( const QgsMapSettings::Flags& flags )
309 {
310  mFlags = flags;
311 }
312 
314 {
315  if ( on )
316  mFlags |= flag;
317  else
318  mFlags &= ~flag;
319 }
320 
321 QgsMapSettings::Flags QgsMapSettings::flags() const
322 {
323  return mFlags;
324 }
325 
327 {
328  return mFlags.testFlag( flag );
329 }
330 
332 {
333  return mScaleCalculator.mapUnits();
334 }
335 
336 
338 {
339  return mValid;
340 }
341 
343 {
344  return mVisibleExtent;
345 }
346 
348 {
349  QPolygonF poly;
350 
351  const QSize& sz = outputSize();
352  const QgsMapToPixel& m2p = mapToPixel();
353 
354  poly << m2p.toMapCoordinatesF( 0, 0 ).toQPointF();
355  poly << m2p.toMapCoordinatesF( sz.width(), 0 ).toQPointF();
356  poly << m2p.toMapCoordinatesF( sz.width(), sz.height() ).toQPointF();
357  poly << m2p.toMapCoordinatesF( 0, sz.height() ).toQPointF();
358 
359  return poly;
360 }
361 
363 {
364  return mMapUnitsPerPixel;
365 }
366 
367 double QgsMapSettings::scale() const
368 {
369  return mScale;
370 }
371 
372 
374 {
375  return mDatumTransformStore.transformation( layer );
376 }
377 
378 
379 double QgsMapSettings::layerToMapUnits( QgsMapLayer *theLayer, const QgsRectangle& referenceExtent ) const
380 {
381  QgsRectangle extent = referenceExtent.isEmpty() ? theLayer->extent() : referenceExtent;
382  QgsPoint l1( extent.xMinimum(), extent.yMinimum() );
383  QgsPoint l2( extent.xMaximum(), extent.yMaximum() );
384  double distLayerUnits = std::sqrt( l1.sqrDist( l2 ) );
385  QgsPoint m1 = layerToMapCoordinates( theLayer, l1 );
386  QgsPoint m2 = layerToMapCoordinates( theLayer, l2 );
387  double distMapUnits = std::sqrt( m1.sqrDist( m2 ) );
388  return distMapUnits / distLayerUnits;
389 }
390 
391 
393 {
394  if ( hasCrsTransformEnabled() )
395  {
396  try
397  {
398  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
399  {
400  QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
401  QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
402  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
403  extent = ct->transformBoundingBox( extent );
404  }
405  }
406  catch ( QgsCsException &cse )
407  {
408  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
409  }
410  }
411 
412  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
413 
414  return extent;
415 }
416 
417 
419 {
420  if ( hasCrsTransformEnabled() )
421  {
422  try
423  {
424  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
425  {
426  QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
427  QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
428  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
429  extent = ct->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
430  }
431  }
432  catch ( QgsCsException &cse )
433  {
434  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
435  }
436  }
437 
438  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
439 
440  return extent;
441 }
442 
443 
445 {
446  if ( hasCrsTransformEnabled() )
447  {
448  try
449  {
450  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
451  point = ct->transform( point, QgsCoordinateTransform::ForwardTransform );
452  }
453  catch ( QgsCsException &cse )
454  {
455  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
456  }
457  }
458  else
459  {
460  // leave point without transformation
461  }
462  return point;
463 }
464 
465 
467 {
468  if ( hasCrsTransformEnabled() )
469  {
470  try
471  {
472  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
473  rect = ct->transform( rect, QgsCoordinateTransform::ForwardTransform );
474  }
475  catch ( QgsCsException &cse )
476  {
477  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
478  }
479  }
480  else
481  {
482  // leave point without transformation
483  }
484  return rect;
485 }
486 
487 
489 {
490  if ( hasCrsTransformEnabled() )
491  {
492  try
493  {
494  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
495  point = ct->transform( point, QgsCoordinateTransform::ReverseTransform );
496  }
497  catch ( QgsCsException &cse )
498  {
499  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
500  }
501  }
502  else
503  {
504  // leave point without transformation
505  }
506  return point;
507 }
508 
509 
511 {
512  if ( hasCrsTransformEnabled() )
513  {
514  try
515  {
516  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
517  rect = ct->transform( rect, QgsCoordinateTransform::ReverseTransform );
518  }
519  catch ( QgsCsException &cse )
520  {
521  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
522  }
523  }
524  return rect;
525 }
526 
527 
528 
530 {
531  QgsDebugMsg( "called." );
533 
534  // reset the map canvas extent since the extent may now be smaller
535  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
537  fullExtent.setMinimal();
538 
539  // iterate through the map layers and test each layers extent
540  // against the current min and max values
542  QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayers.count() ) );
543  while ( it != mLayers.end() )
544  {
545  QgsMapLayer * lyr = registry->mapLayer( *it );
546  if ( !lyr )
547  {
548  QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
549  }
550  else
551  {
552  QgsDebugMsg( "Updating extent using " + lyr->name() );
553  QgsDebugMsg( "Input extent: " + lyr->extent().toString() );
554 
555  if ( lyr->extent().isNull() )
556  {
557  ++it;
558  continue;
559  }
560 
561  // Layer extents are stored in the coordinate system (CS) of the
562  // layer. The extent must be projected to the canvas CS
564 
565  QgsDebugMsg( "Output extent: " + extent.toString() );
566  fullExtent.unionRect( extent );
567 
568  }
569  ++it;
570  }
571 
572  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
573  {
574  // If all of the features are at the one point, buffer the
575  // rectangle a bit. If they are all at zero, do something a bit
576  // more crude.
577 
578  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
579  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
580  {
581  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
582  }
583  else
584  {
585  const double padFactor = 1e-8;
586  double widthPad = fullExtent.xMinimum() * padFactor;
587  double heightPad = fullExtent.yMinimum() * padFactor;
588  double xmin = fullExtent.xMinimum() - widthPad;
589  double xmax = fullExtent.xMaximum() + widthPad;
590  double ymin = fullExtent.yMinimum() - heightPad;
591  double ymax = fullExtent.yMaximum() + heightPad;
592  fullExtent.set( xmin, ymin, xmax, ymax );
593  }
594  }
595 
596  QgsDebugMsg( "Full extent: " + fullExtent.toString() );
597  return fullExtent;
598 }
599 
600 
602 {
603  // set units
604  QDomNode mapUnitsNode = theNode.namedItem( "units" );
605  QGis::UnitType units = QgsXmlUtils::readMapUnits( mapUnitsNode.toElement() );
606  setMapUnits( units );
607 
608  // set projections flag
609  QDomNode projNode = theNode.namedItem( "projections" );
610  setCrsTransformEnabled( projNode.toElement().text().toInt() );
611 
612  // set destination CRS
614  QDomNode srsNode = theNode.namedItem( "destinationsrs" );
615  srs.readXML( srsNode );
616  setDestinationCrs( srs );
617 
618  // set extent
619  QDomNode extentNode = theNode.namedItem( "extent" );
620  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
621  setExtent( aoi );
622 
623  // set rotation
624  QDomNode rotationNode = theNode.namedItem( "rotation" );
625  QString rotationVal = rotationNode.toElement().text();
626  if ( ! rotationVal.isEmpty() )
627  {
628  double rot = rotationVal.toDouble();
629  setRotation( rot );
630  }
631 
632  //render map tile
633  QDomElement renderMapTileElem = theNode.firstChildElement( "rendermaptile" );
634  if ( !renderMapTileElem.isNull() )
635  {
636  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == "1" ? true : false );
637  }
638 
639  mDatumTransformStore.readXML( theNode );
640 }
641 
642 
643 
645 {
646  // units
647  theNode.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), theDoc ) );
648 
649  // Write current view extents
650  theNode.appendChild( QgsXmlUtils::writeRectangle( extent(), theDoc ) );
651 
652  // Write current view rotation
653  QDomElement rotNode = theDoc.createElement( "rotation" );
654  rotNode.appendChild(
656  );
657  theNode.appendChild( rotNode );
658 
659  // projections enabled
660  QDomElement projNode = theDoc.createElement( "projections" );
662  theNode.appendChild( projNode );
663 
664  // destination CRS
665  QDomElement srsNode = theDoc.createElement( "destinationsrs" );
666  theNode.appendChild( srsNode );
667  destinationCrs().writeXML( srsNode, theDoc );
668 
669  //render map tile
670  QDomElement renderMapTileElem = theDoc.createElement( "rendermaptile" );
671  QDomText renderMapTileText = theDoc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
672  renderMapTileElem.appendChild( renderMapTileText );
673  theNode.appendChild( renderMapTileElem );
674 
675  mDatumTransformStore.writeXML( theNode, theDoc );
676 }
void setMapUnits(QGis::UnitType mapUnits)
Set the map units.
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:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
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.
int width() const
QgsMapToPixel mMapToPixel
double magnificationFactor() const
Return the magnification factor.
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspoint.cpp:129
QDomNode appendChild(const QDomNode &newChild)
double rotation() const
Return the rotation of the resulting map image Units are clockwise degrees.
void readXML(QDomNode &theNode)
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
QgsCoordinateReferenceSystem mDestCRS
const QgsCoordinateTransform * transformation(QgsMapLayer *layer) const
Will return transform from layer&#39;s CRS to current destination CRS.
QgsMapLayer * mapLayer(const QString &theLayerId) const
Retrieve a pointer to a registered layer by layer ID.
QgsRectangle layerExtentToOutputExtent(QgsMapLayer *theLayer, QgsRectangle extent) const
transform bounding box from layer&#39;s CRS to output CRS
QMap< QString, QString > mLayerStyleOverrides
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.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
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)
Q_DECL_DEPRECATED void setParameters(double mapUnitsPerPixel, double xmin, double ymin, double height)
Set parameters for use in transforming coordinates.
Abstract base class for all geometries.
QGis::UnitType mapUnits() const
Get units of map&#39;s geographical coordinates - used for scale calculation.
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...
void setLayers(const QStringList &layers)
Set list of layer IDs for map rendering.
double toDouble(bool *ok) const
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:353
#define M_PI_2
Definition: util.cpp:45
double y() const
Get the y value of the point.
Definition: qgspoint.h:193
QString what() const
Definition: qgsexception.h:36
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.
QDomElement toElement() const
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
bool mValid
whether the actual settings are valid (set in updateDerived())
QString number(int n, int base)
int count(const T &value) const
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.
QgsRectangle mExtent
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
double layerToMapUnits(QgsMapLayer *theLayer, const QgsRectangle &referenceExtent=QgsRectangle()) const
Computes an estimated conversion factor between layer and map units: layerUnits * layerToMapUnits = m...
QString text() const
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.
void setMapUnits(QGis::UnitType u)
Set units of map&#39;s geographical coordinates - used for scale calculation.
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:207
int toInt(bool *ok, int base) const
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:341
bool isEmpty() const
double mapUnitsPerPixel() const
Return the distance in geographical coordinates that equals to one pixel in the map.
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
Definition: qgis.h:461
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)
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
const QgsCoordinateTransform * layerTransform(QgsMapLayer *layer) const
Return coordinate transform from layer&#39;s CRS to destination CRS.
QgsScaleCalculator mScaleCalculator
A class to represent a point.
Definition: qgspoint.h:117
const QgsMapToPixel & mapToPixel() const
Caches QgsCoordinateReferenceSystem construction, which may be expensive.
Definition: qgscrscache.h:67
static QGis::UnitType readMapUnits(const QDomElement &element)
Definition: qgsxmlutils.cpp:23
This class tracks map layers that are currently loaded and provides various methods to retrieve match...
QDomText createTextNode(const QString &value)
bool isFinite() const
Returns true if the rectangle has finite boundaries.
iterator end()
QGis::UnitType mapUnits() const
Returns current map units.
QDomNode namedItem(const QString &name) const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:202
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:187
bool isNull() const
void writeXML(QDomNode &parentNode, QDomDocument &theDoc) const
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...
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from layer&#39;s CRS to output CRS
double mMapUnitsPerPixel
void setFlags(const QgsMapSettings::Flags &flags)
Set combination of flags that will be used for rendering.
QgsPoint mapToLayerCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from output CRS to layer&#39;s CRS
void readXML(const QDomNode &parentNode)
QgsRectangle fullExtent() const
returns current extent of layer set
QDomElement firstChildElement(const QString &tagName) const
Class for storing a coordinate reference system (CRS)
int height() const
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Class for doing transforms between two map coordinate systems.
Flags flags() const
Return combination of flags used for rendering.
UnitType
Map units that qgis supports.
Definition: qgis.h:159
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:192
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:197
QString name
Read property of QString layerName.
Definition: qgsmaplayer.h:53
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)
QStringList mLayers
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
bool writeXML(QDomNode &theNode, QDomDocument &theDoc) const
Stores state to the given Dom node in the given document.
QDomElement createElement(const QString &tagName)
QStringList layers() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
QgsPoint toMapCoordinatesF(double x, double y) const
Transform device coordinates to map (world) coordinates.
QgsDatumTransformStore mDatumTransformStore
virtual QgsRectangle extent()
Return the extent of the layer.
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:52
iterator begin()
QSize outputSize() const
Return the size of the resulting map image.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
QgsRectangle outputExtentToLayerExtent(QgsMapLayer *theLayer, QgsRectangle extent) const
transform bounding box from output CRS to layer&#39;s CRS
double x() const
Get the x value of the point.
Definition: qgspoint.h:185
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:212
static QDomElement writeMapUnits(QGis::UnitType units, QDomDocument &doc)
Definition: qgsxmlutils.cpp:82
void setCrsTransformEnabled(bool enabled)
sets whether to use projections for this layer set
void writeXML(QDomNode &theNode, QDomDocument &theDoc)