QGIS API Documentation  2.15.0-Master (af20121)
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( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId ) // 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  mMagnificationFactor = factor;
63 
64  double rot = rotation();
65  setRotation( 0.0 );
66 
68  ext.scale( ratio );
69 
70  mRotation = rot;
71  mExtent = ext;
72  mDpi = outputDpi() / ratio;
73 
74  updateDerived();
75 }
76 
78 {
79  return mMagnificationFactor;
80 }
81 
83 {
84  return mExtent;
85 }
86 
87 void QgsMapSettings::setExtent( const QgsRectangle& extent, bool magnified )
88 {
89  QgsRectangle magnifiedExtent = extent;
90 
91  if ( !magnified )
92  magnifiedExtent.scale( 1 / mMagnificationFactor );
93 
94  mExtent = magnifiedExtent;
95 
96  updateDerived();
97 }
98 
100 {
101  return mRotation;
102 }
103 
104 void QgsMapSettings::setRotation( double degrees )
105 {
106  if ( qgsDoubleNear( mRotation, degrees ) ) return;
107 
108  mRotation = degrees;
109 
110  // TODO: update extent while keeping scale ?
111  updateDerived();
112 }
113 
114 
116 {
118 
119  if ( extent.isEmpty() || !extent.isFinite() )
120  {
121  mValid = false;
122  return;
123  }
124 
125  // Don't allow zooms where the current extent is so small that it
126  // can't be accurately represented using a double (which is what
127  // currentExtent uses). Excluding 0 avoids a divide by zero and an
128  // infinite loop when rendering to a new canvas. Excluding extents
129  // greater than 1 avoids doing unnecessary calculations.
130 
131  // The scheme is to compare the width against the mean x coordinate
132  // (and height against mean y coordinate) and only allow zooms where
133  // the ratio indicates that there is more than about 12 significant
134  // figures (there are about 16 significant figures in a double).
135 
136  if ( extent.width() > 0 &&
137  extent.height() > 0 &&
138  extent.width() < 1 &&
139  extent.height() < 1 )
140  {
141  // Use abs() on the extent to avoid the case where the extent is
142  // symmetrical about 0.
143  double xMean = ( qAbs( extent.xMinimum() ) + qAbs( extent.xMaximum() ) ) * 0.5;
144  double yMean = ( qAbs( extent.yMinimum() ) + qAbs( extent.yMaximum() ) ) * 0.5;
145 
146  double xRange = extent.width() / xMean;
147  double yRange = extent.height() / yMean;
148 
149  static const double minProportion = 1e-12;
150  if ( xRange < minProportion || yRange < minProportion )
151  {
152  mValid = false;
153  return;
154  }
155  }
156 
157  double myHeight = mSize.height();
158  double myWidth = mSize.width();
159 
160  if ( !myWidth || !myHeight )
161  {
162  mValid = false;
163  return;
164  }
165 
166  // calculate the translation and scaling parameters
167  double mapUnitsPerPixelY = mExtent.height() / myHeight;
168  double mapUnitsPerPixelX = mExtent.width() / myWidth;
169  mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
170 
171  // calculate the actual extent of the mapCanvas
172  double dxmin = mExtent.xMinimum(), dxmax = mExtent.xMaximum(),
173  dymin = mExtent.yMinimum(), dymax = mExtent.yMaximum(), whitespace;
174 
175  if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
176  {
177  whitespace = (( myWidth * mMapUnitsPerPixel ) - mExtent.width() ) * 0.5;
178  dxmin -= whitespace;
179  dxmax += whitespace;
180  }
181  else
182  {
183  whitespace = (( myHeight * mMapUnitsPerPixel ) - mExtent.height() ) * 0.5;
184  dymin -= whitespace;
185  dymax += whitespace;
186  }
187 
188  mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
189 
190  // update the scale
193 
195  visibleExtent().center().x(),
196  visibleExtent().center().y(),
197  outputSize().width(),
198  outputSize().height(),
199  mRotation );
200 
201 #if 1 // set visible extent taking rotation in consideration
202  if ( mRotation )
203  {
205  QgsPoint p2 = mMapToPixel.toMapCoordinates( QPoint( 0, myHeight ) );
206  QgsPoint p3 = mMapToPixel.toMapCoordinates( QPoint( myWidth, 0 ) );
207  QgsPoint p4 = mMapToPixel.toMapCoordinates( QPoint( myWidth, myHeight ) );
208  dxmin = std::min( p1.x(), std::min( p2.x(), std::min( p3.x(), p4.x() ) ) );
209  dymin = std::min( p1.y(), std::min( p2.y(), std::min( p3.y(), p4.y() ) ) );
210  dxmax = std::max( p1.x(), std::max( p2.x(), std::max( p3.x(), p4.x() ) ) );
211  dymax = std::max( p1.y(), std::max( p2.y(), std::max( p3.y(), p4.y() ) ) );
212  mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
213  }
214 #endif
215 
216  QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ), qgsDoubleToString( mapUnitsPerPixelY ) ) );
217  QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mSize.width() ), qgsDoubleToString( mSize.height() ) ) );
218  QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ), qgsDoubleToString( mExtent.height() ) ) );
220  QgsDebugMsg( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / myWidth ), qgsDoubleToString( mVisibleExtent.height() / myHeight ) ) );
221  QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / mMapUnitsPerPixel ), qgsDoubleToString( mVisibleExtent.height() / mMapUnitsPerPixel ) ) );
222  QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ) );
223  QgsDebugMsg( QString( "Rotation: %1 degrees" ).arg( mRotation ) );
224 
225  mValid = true;
226 }
227 
228 
230 {
231  return mSize;
232 }
233 
235 {
236  mSize = size;
237 
238  updateDerived();
239 }
240 
242 {
243  return mDpi;
244 }
245 
247 {
248  mDpi = dpi;
249 
250  updateDerived();
251 }
252 
253 
255 {
256  return mLayers;
257 }
258 
260 {
261  mLayers = layers;
262 }
263 
265 {
266  return mLayerStyleOverrides;
267 }
268 
270 {
271  mLayerStyleOverrides = overrides;
272 }
273 
275 {
276  mProjectionsEnabled = enabled;
277 }
278 
280 {
281  return mProjectionsEnabled;
282 }
283 
284 
286 {
287  mDestCRS = crs;
289 }
290 
292 {
293  return mDestCRS;
294 }
295 
296 
298 {
300 
301  // Since the map units have changed, force a recalculation of the scale.
302  updateDerived();
303 }
304 
305 void QgsMapSettings::setFlags( const QgsMapSettings::Flags& flags )
306 {
307  mFlags = flags;
308 }
309 
311 {
312  if ( on )
313  mFlags |= flag;
314  else
315  mFlags &= ~flag;
316 }
317 
318 QgsMapSettings::Flags QgsMapSettings::flags() const
319 {
320  return mFlags;
321 }
322 
324 {
325  return mFlags.testFlag( flag );
326 }
327 
329 {
330  return mScaleCalculator.mapUnits();
331 }
332 
333 
335 {
336  return mValid;
337 }
338 
340 {
341  return mVisibleExtent;
342 }
343 
345 {
346  QPolygonF poly;
347 
348  const QSize& sz = outputSize();
349  const QgsMapToPixel& m2p = mapToPixel();
350 
351  poly << m2p.toMapCoordinatesF( 0, 0 ).toQPointF();
352  poly << m2p.toMapCoordinatesF( sz.width(), 0 ).toQPointF();
353  poly << m2p.toMapCoordinatesF( sz.width(), sz.height() ).toQPointF();
354  poly << m2p.toMapCoordinatesF( 0, sz.height() ).toQPointF();
355 
356  return poly;
357 }
358 
360 {
361  return mMapUnitsPerPixel;
362 }
363 
364 double QgsMapSettings::scale() const
365 {
366  return mScale;
367 }
368 
369 
371 {
372  return mDatumTransformStore.transformation( layer );
373 }
374 
375 
376 double QgsMapSettings::layerToMapUnits( QgsMapLayer *theLayer, const QgsRectangle& referenceExtent ) const
377 {
378  QgsRectangle extent = referenceExtent.isEmpty() ? theLayer->extent() : referenceExtent;
379  QgsPoint l1( extent.xMinimum(), extent.yMinimum() );
380  QgsPoint l2( extent.xMaximum(), extent.yMaximum() );
381  double distLayerUnits = std::sqrt( l1.sqrDist( l2 ) );
382  QgsPoint m1 = layerToMapCoordinates( theLayer, l1 );
383  QgsPoint m2 = layerToMapCoordinates( theLayer, l2 );
384  double distMapUnits = std::sqrt( m1.sqrDist( m2 ) );
385  return distMapUnits / distLayerUnits;
386 }
387 
388 
390 {
391  if ( hasCrsTransformEnabled() )
392  {
393  try
394  {
395  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
396  {
397  QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
398  QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
399  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
400  extent = ct->transformBoundingBox( extent );
401  }
402  }
403  catch ( QgsCsException &cse )
404  {
405  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
406  }
407  }
408 
409  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
410 
411  return extent;
412 }
413 
414 
416 {
417  if ( hasCrsTransformEnabled() )
418  {
419  try
420  {
421  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
422  {
423  QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
424  QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
425  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
426  extent = ct->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
427  }
428  }
429  catch ( QgsCsException &cse )
430  {
431  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
432  }
433  }
434 
435  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
436 
437  return extent;
438 }
439 
440 
442 {
443  if ( hasCrsTransformEnabled() )
444  {
445  try
446  {
447  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
448  point = ct->transform( point, QgsCoordinateTransform::ForwardTransform );
449  }
450  catch ( QgsCsException &cse )
451  {
452  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
453  }
454  }
455  else
456  {
457  // leave point without transformation
458  }
459  return point;
460 }
461 
462 
464 {
465  if ( hasCrsTransformEnabled() )
466  {
467  try
468  {
469  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
470  rect = ct->transform( rect, QgsCoordinateTransform::ForwardTransform );
471  }
472  catch ( QgsCsException &cse )
473  {
474  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
475  }
476  }
477  else
478  {
479  // leave point without transformation
480  }
481  return rect;
482 }
483 
484 
486 {
487  if ( hasCrsTransformEnabled() )
488  {
489  try
490  {
491  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
492  point = ct->transform( point, QgsCoordinateTransform::ReverseTransform );
493  }
494  catch ( QgsCsException &cse )
495  {
496  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
497  }
498  }
499  else
500  {
501  // leave point without transformation
502  }
503  return point;
504 }
505 
506 
508 {
509  if ( hasCrsTransformEnabled() )
510  {
511  try
512  {
513  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
514  rect = ct->transform( rect, QgsCoordinateTransform::ReverseTransform );
515  }
516  catch ( QgsCsException &cse )
517  {
518  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
519  }
520  }
521  return rect;
522 }
523 
524 
525 
527 {
528  QgsDebugMsg( "called." );
530 
531  // reset the map canvas extent since the extent may now be smaller
532  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
534  fullExtent.setMinimal();
535 
536  // iterate through the map layers and test each layers extent
537  // against the current min and max values
539  QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayers.count() ) );
540  while ( it != mLayers.end() )
541  {
542  QgsMapLayer * lyr = registry->mapLayer( *it );
543  if ( !lyr )
544  {
545  QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
546  }
547  else
548  {
549  QgsDebugMsg( "Updating extent using " + lyr->name() );
550  QgsDebugMsg( "Input extent: " + lyr->extent().toString() );
551 
552  if ( lyr->extent().isNull() )
553  {
554  ++it;
555  continue;
556  }
557 
558  // Layer extents are stored in the coordinate system (CS) of the
559  // layer. The extent must be projected to the canvas CS
561 
562  QgsDebugMsg( "Output extent: " + extent.toString() );
563  fullExtent.unionRect( extent );
564 
565  }
566  ++it;
567  }
568 
569  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
570  {
571  // If all of the features are at the one point, buffer the
572  // rectangle a bit. If they are all at zero, do something a bit
573  // more crude.
574 
575  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
576  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
577  {
578  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
579  }
580  else
581  {
582  const double padFactor = 1e-8;
583  double widthPad = fullExtent.xMinimum() * padFactor;
584  double heightPad = fullExtent.yMinimum() * padFactor;
585  double xmin = fullExtent.xMinimum() - widthPad;
586  double xmax = fullExtent.xMaximum() + widthPad;
587  double ymin = fullExtent.yMinimum() - heightPad;
588  double ymax = fullExtent.yMaximum() + heightPad;
589  fullExtent.set( xmin, ymin, xmax, ymax );
590  }
591  }
592 
593  QgsDebugMsg( "Full extent: " + fullExtent.toString() );
594  return fullExtent;
595 }
596 
597 
599 {
600  // set units
601  QDomNode mapUnitsNode = theNode.namedItem( "units" );
602  QGis::UnitType units = QgsXmlUtils::readMapUnits( mapUnitsNode.toElement() );
603  setMapUnits( units );
604 
605  // set projections flag
606  QDomNode projNode = theNode.namedItem( "projections" );
607  setCrsTransformEnabled( projNode.toElement().text().toInt() );
608 
609  // set destination CRS
611  QDomNode srsNode = theNode.namedItem( "destinationsrs" );
612  srs.readXML( srsNode );
613  setDestinationCrs( srs );
614 
615  // set extent
616  QDomNode extentNode = theNode.namedItem( "extent" );
617  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
618  setExtent( aoi );
619 
620  // set rotation
621  QDomNode rotationNode = theNode.namedItem( "rotation" );
622  QString rotationVal = rotationNode.toElement().text();
623  if ( ! rotationVal.isEmpty() )
624  {
625  double rot = rotationVal.toDouble();
626  setRotation( rot );
627  }
628 
629  //render map tile
630  QDomElement renderMapTileElem = theNode.firstChildElement( "rendermaptile" );
631  if ( !renderMapTileElem.isNull() )
632  {
633  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == "1" ? true : false );
634  }
635 
636  mDatumTransformStore.readXML( theNode );
637 }
638 
639 
640 
642 {
643  // units
644  theNode.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), theDoc ) );
645 
646  // Write current view extents
647  theNode.appendChild( QgsXmlUtils::writeRectangle( extent(), theDoc ) );
648 
649  // Write current view rotation
650  QDomElement rotNode = theDoc.createElement( "rotation" );
651  rotNode.appendChild(
653  );
654  theNode.appendChild( rotNode );
655 
656  // projections enabled
657  QDomElement projNode = theDoc.createElement( "projections" );
659  theNode.appendChild( projNode );
660 
661  // destination CRS
662  QDomElement srsNode = theDoc.createElement( "destinationsrs" );
663  theNode.appendChild( srsNode );
664  destinationCrs().writeXML( srsNode, theDoc );
665 
666  //render map tile
667  QDomElement renderMapTileElem = theDoc.createElement( "rendermaptile" );
668  QDomText renderMapTileText = theDoc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
669  renderMapTileElem.appendChild( renderMapTileText );
670  theNode.appendChild( renderMapTileElem );
671 
672  mDatumTransformStore.writeXML( theNode, theDoc );
673 }
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.
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from layer&#39;s CRS to output CRS
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.
int width() const
QgsMapToPixel mMapToPixel
double scale() const
Return the calculated scale of the map.
QString name() const
Get the display name of the layer.
QDomNode appendChild(const QDomNode &newChild)
void readXML(QDomNode &theNode)
QgsRectangle fullExtent() const
returns current extent of layer set
const QgsCoordinateTransform * layerTransform(QgsMapLayer *layer) const
Return coordinate transform from layer&#39;s CRS to destination CRS.
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:197
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
QgsCoordinateReferenceSystem mDestCRS
QMap< QString, QString > mLayerStyleOverrides
void scale(double scaleFactor, const QgsPoint *c=nullptr)
Scale the rectangle around its center point.
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
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)
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
Returns current map units.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
QgsRectangle layerExtentToOutputExtent(QgsMapLayer *theLayer, QgsRectangle extent) const
transform bounding box from layer&#39;s CRS to output CRS
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.
QgsPoint mapToLayerCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from output CRS to layer&#39;s CRS
void setLayers(const QStringList &layers)
Set list of layer IDs for map rendering.
double toDouble(bool *ok) const
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:352
double x() const
Get the x value of the point.
Definition: qgspoint.h:185
#define M_PI_2
Definition: util.cpp:43
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
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.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
bool mValid
whether the actual settings are valid (set in updateDerived())
int outputDpi() const
Return DPI used for conversion between real world units (e.g.
QString number(int n, int base)
int count(const T &value) const
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.
QString text() const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:202
Flag
Enumeration of flags that adjust the way how 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:187
void setMagnificationFactor(double factor)
Set the magnification factor.
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.
void setMapUnits(QGis::UnitType u)
Set units of map&#39;s geographical coordinates - used for scale calculation.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
int toInt(bool *ok, int base) const
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:340
void writeXML(QDomNode &parentNode, QDomDocument &theDoc) const
bool isEmpty() const
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
Definition: qgis.h:450
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)
double mapUnitsPerPixel() const
Return the distance in geographical coordinates that equals to one pixel in the map.
QGis::UnitType mapUnits() const
Get units of map&#39;s geographical coordinates - used for scale calculation.
const QgsCoordinateTransform * transformation(QgsMapLayer *layer) const
Will return transform from layer&#39;s CRS to current destination CRS.
QgsScaleCalculator mScaleCalculator
A class to represent a point.
Definition: qgspoint.h:117
static QGis::UnitType readMapUnits(const QDomElement &element)
Definition: qgsxmlutils.cpp:23
This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a m...
QDomText createTextNode(const QString &value)
iterator end()
QDomNode namedItem(const QString &name) const
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.
bool isNull() const
QgsPoint toMapCoordinates(int x, int y) const
Draw map such that there are no problems between adjacent tiles.
double layerToMapUnits(QgsMapLayer *theLayer, const QgsRectangle &referenceExtent=QgsRectangle()) const
Computes an estimated conversion factor between layer and map units: layerUnits * layerToMapUnits = m...
QString what() const
Definition: qgsexception.h:36
bool writeXML(QDomNode &theNode, QDomDocument &theDoc) const
Stores state to the given Dom node in the given document.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
double mMapUnitsPerPixel
void setFlags(const QgsMapSettings::Flags &flags)
Set combination of flags that will be used for rendering.
void readXML(const QDomNode &parentNode)
QDomElement firstChildElement(const QString &tagName) const
Class for storing a coordinate reference system (CRS)
int height() const
QgsRectangle extent() const
Return geographical coordinates of the rectangle that should be rendered.
Class for doing transforms between two map coordinate systems.
UnitType
Map units that qgis supports.
Definition: qgis.h:159
double y() const
Get the y value of the point.
Definition: qgspoint.h:193
QStringList layers() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
QPolygonF visiblePolygon() const
Return the visible area as a polygon (may be rotated)
Custom exception class for Coordinate Reference System related exceptions.
QStringList mLayers
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
QDomElement createElement(const QString &tagName)
QgsRectangle outputExtentToLayerExtent(QgsMapLayer *theLayer, QgsRectangle extent) const
transform bounding box from output CRS to layer&#39;s CRS
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:207
QgsDatumTransformStore mDatumTransformStore
virtual QgsRectangle extent()
Return the extent of the layer.
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:192
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:52
iterator begin()
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
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspoint.cpp:129
void writeXML(QDomNode &theNode, QDomDocument &theDoc)