QGIS API Documentation  2.14.0-Essen
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  , mProjectionsEnabled( false )
39  , mDestCRS( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId ) // WGS 84
40  , mDatumTransformStore( mDestCRS )
41  , mBackgroundColor( Qt::white )
42  , mSelectionColor( Qt::yellow )
43  , mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling | DrawSelection )
44  , mImageFormat( QImage::Format_ARGB32_Premultiplied )
45  , mValid( false )
46  , mVisibleExtent()
47  , mMapUnitsPerPixel( 1 )
48  , mScale( 1 )
49 {
50  updateDerived();
51 
52  // set default map units - we use WGS 84 thus use degrees
54 }
55 
56 
58 {
59  return mExtent;
60 }
61 
63 {
64  mExtent = extent;
65 
66  updateDerived();
67 }
68 
70 {
71  return mRotation;
72 }
73 
74 void QgsMapSettings::setRotation( double degrees )
75 {
76  if ( qgsDoubleNear( mRotation, degrees ) ) return;
77 
78  mRotation = degrees;
79 
80  // TODO: update extent while keeping scale ?
81  updateDerived();
82 }
83 
84 
86 {
88 
89  if ( extent.isEmpty() || !extent.isFinite() )
90  {
91  mValid = false;
92  return;
93  }
94 
95  // Don't allow zooms where the current extent is so small that it
96  // can't be accurately represented using a double (which is what
97  // currentExtent uses). Excluding 0 avoids a divide by zero and an
98  // infinite loop when rendering to a new canvas. Excluding extents
99  // greater than 1 avoids doing unnecessary calculations.
100 
101  // The scheme is to compare the width against the mean x coordinate
102  // (and height against mean y coordinate) and only allow zooms where
103  // the ratio indicates that there is more than about 12 significant
104  // figures (there are about 16 significant figures in a double).
105 
106  if ( extent.width() > 0 &&
107  extent.height() > 0 &&
108  extent.width() < 1 &&
109  extent.height() < 1 )
110  {
111  // Use abs() on the extent to avoid the case where the extent is
112  // symmetrical about 0.
113  double xMean = ( qAbs( extent.xMinimum() ) + qAbs( extent.xMaximum() ) ) * 0.5;
114  double yMean = ( qAbs( extent.yMinimum() ) + qAbs( extent.yMaximum() ) ) * 0.5;
115 
116  double xRange = extent.width() / xMean;
117  double yRange = extent.height() / yMean;
118 
119  static const double minProportion = 1e-12;
120  if ( xRange < minProportion || yRange < minProportion )
121  {
122  mValid = false;
123  return;
124  }
125  }
126 
127  double myHeight = mSize.height();
128  double myWidth = mSize.width();
129 
130  if ( !myWidth || !myHeight )
131  {
132  mValid = false;
133  return;
134  }
135 
136  // calculate the translation and scaling parameters
137  double mapUnitsPerPixelY = mExtent.height() / myHeight;
138  double mapUnitsPerPixelX = mExtent.width() / myWidth;
139  mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
140 
141  // calculate the actual extent of the mapCanvas
142  double dxmin = mExtent.xMinimum(), dxmax = mExtent.xMaximum(),
143  dymin = mExtent.yMinimum(), dymax = mExtent.yMaximum(), whitespace;
144 
145  if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
146  {
147  whitespace = (( myWidth * mMapUnitsPerPixel ) - mExtent.width() ) * 0.5;
148  dxmin -= whitespace;
149  dxmax += whitespace;
150  }
151  else
152  {
153  whitespace = (( myHeight * mMapUnitsPerPixel ) - mExtent.height() ) * 0.5;
154  dymin -= whitespace;
155  dymax += whitespace;
156  }
157 
158  mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
159 
160  // update the scale
163 
165  visibleExtent().center().x(),
166  visibleExtent().center().y(),
167  outputSize().width(),
168  outputSize().height(),
169  mRotation );
170 
171 #if 1 // set visible extent taking rotation in consideration
172  if ( mRotation )
173  {
175  QgsPoint p2 = mMapToPixel.toMapCoordinates( QPoint( 0, myHeight ) );
176  QgsPoint p3 = mMapToPixel.toMapCoordinates( QPoint( myWidth, 0 ) );
177  QgsPoint p4 = mMapToPixel.toMapCoordinates( QPoint( myWidth, myHeight ) );
178  dxmin = std::min( p1.x(), std::min( p2.x(), std::min( p3.x(), p4.x() ) ) );
179  dymin = std::min( p1.y(), std::min( p2.y(), std::min( p3.y(), p4.y() ) ) );
180  dxmax = std::max( p1.x(), std::max( p2.x(), std::max( p3.x(), p4.x() ) ) );
181  dymax = std::max( p1.y(), std::max( p2.y(), std::max( p3.y(), p4.y() ) ) );
182  mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
183  }
184 #endif
185 
186  QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ), qgsDoubleToString( mapUnitsPerPixelY ) ) );
187  QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mSize.width() ), qgsDoubleToString( mSize.height() ) ) );
188  QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ), qgsDoubleToString( mExtent.height() ) ) );
190  QgsDebugMsg( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / myWidth ), qgsDoubleToString( mVisibleExtent.height() / myHeight ) ) );
191  QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / mMapUnitsPerPixel ), qgsDoubleToString( mVisibleExtent.height() / mMapUnitsPerPixel ) ) );
192  QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ) );
193  QgsDebugMsg( QString( "Rotation: %1 degrees" ).arg( mRotation ) );
194 
195  mValid = true;
196 }
197 
198 
200 {
201  return mSize;
202 }
203 
205 {
206  mSize = size;
207 
208  updateDerived();
209 }
210 
212 {
213  return mDpi;
214 }
215 
217 {
218  mDpi = dpi;
219 
220  updateDerived();
221 }
222 
223 
225 {
226  return mLayers;
227 }
228 
230 {
231  mLayers = layers;
232 }
233 
235 {
236  return mLayerStyleOverrides;
237 }
238 
240 {
241  mLayerStyleOverrides = overrides;
242 }
243 
245 {
246  mProjectionsEnabled = enabled;
247 }
248 
250 {
251  return mProjectionsEnabled;
252 }
253 
254 
256 {
257  mDestCRS = crs;
259 }
260 
262 {
263  return mDestCRS;
264 }
265 
266 
268 {
270 
271  // Since the map units have changed, force a recalculation of the scale.
272  updateDerived();
273 }
274 
275 void QgsMapSettings::setFlags( const QgsMapSettings::Flags& flags )
276 {
277  mFlags = flags;
278 }
279 
281 {
282  if ( on )
283  mFlags |= flag;
284  else
285  mFlags &= ~flag;
286 }
287 
288 QgsMapSettings::Flags QgsMapSettings::flags() const
289 {
290  return mFlags;
291 }
292 
294 {
295  return mFlags.testFlag( flag );
296 }
297 
299 {
300  return mScaleCalculator.mapUnits();
301 }
302 
303 
305 {
306  return mValid;
307 }
308 
310 {
311  return mVisibleExtent;
312 }
313 
315 {
316  QPolygonF poly;
317 
318  const QSize& sz = outputSize();
319  const QgsMapToPixel& m2p = mapToPixel();
320 
321  poly << m2p.toMapCoordinatesF( 0, 0 ).toQPointF();
322  poly << m2p.toMapCoordinatesF( sz.width(), 0 ).toQPointF();
323  poly << m2p.toMapCoordinatesF( sz.width(), sz.height() ).toQPointF();
324  poly << m2p.toMapCoordinatesF( 0, sz.height() ).toQPointF();
325 
326  return poly;
327 }
328 
330 {
331  return mMapUnitsPerPixel;
332 }
333 
334 double QgsMapSettings::scale() const
335 {
336  return mScale;
337 }
338 
339 
341 {
342  return mDatumTransformStore.transformation( layer );
343 }
344 
345 
346 double QgsMapSettings::layerToMapUnits( QgsMapLayer *theLayer, const QgsRectangle& referenceExtent ) const
347 {
348  QgsRectangle extent = referenceExtent.isEmpty() ? theLayer->extent() : referenceExtent;
349  QgsPoint l1( extent.xMinimum(), extent.yMinimum() );
350  QgsPoint l2( extent.xMaximum(), extent.yMaximum() );
351  double distLayerUnits = std::sqrt( l1.sqrDist( l2 ) );
352  QgsPoint m1 = layerToMapCoordinates( theLayer, l1 );
353  QgsPoint m2 = layerToMapCoordinates( theLayer, l2 );
354  double distMapUnits = std::sqrt( m1.sqrDist( m2 ) );
355  return distMapUnits / distLayerUnits;
356 }
357 
358 
360 {
361  if ( hasCrsTransformEnabled() )
362  {
363  try
364  {
365  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
366  {
367  QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
368  QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
369  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
370  extent = ct->transformBoundingBox( extent );
371  }
372  }
373  catch ( QgsCsException &cse )
374  {
375  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
376  }
377  }
378 
379  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
380 
381  return extent;
382 }
383 
384 
386 {
387  if ( hasCrsTransformEnabled() )
388  {
389  try
390  {
391  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
392  {
393  QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
394  QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
395  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
396  extent = ct->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
397  }
398  }
399  catch ( QgsCsException &cse )
400  {
401  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
402  }
403  }
404 
405  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
406 
407  return extent;
408 }
409 
410 
412 {
413  if ( hasCrsTransformEnabled() )
414  {
415  try
416  {
417  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
418  point = ct->transform( point, QgsCoordinateTransform::ForwardTransform );
419  }
420  catch ( QgsCsException &cse )
421  {
422  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
423  }
424  }
425  else
426  {
427  // leave point without transformation
428  }
429  return point;
430 }
431 
432 
434 {
435  if ( hasCrsTransformEnabled() )
436  {
437  try
438  {
439  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
440  rect = ct->transform( rect, QgsCoordinateTransform::ForwardTransform );
441  }
442  catch ( QgsCsException &cse )
443  {
444  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
445  }
446  }
447  else
448  {
449  // leave point without transformation
450  }
451  return rect;
452 }
453 
454 
456 {
457  if ( hasCrsTransformEnabled() )
458  {
459  try
460  {
461  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
462  point = ct->transform( point, QgsCoordinateTransform::ReverseTransform );
463  }
464  catch ( QgsCsException &cse )
465  {
466  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
467  }
468  }
469  else
470  {
471  // leave point without transformation
472  }
473  return point;
474 }
475 
476 
478 {
479  if ( hasCrsTransformEnabled() )
480  {
481  try
482  {
483  if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
484  rect = ct->transform( rect, QgsCoordinateTransform::ReverseTransform );
485  }
486  catch ( QgsCsException &cse )
487  {
488  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
489  }
490  }
491  return rect;
492 }
493 
494 
495 
497 {
498  QgsDebugMsg( "called." );
500 
501  // reset the map canvas extent since the extent may now be smaller
502  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
504  fullExtent.setMinimal();
505 
506  // iterate through the map layers and test each layers extent
507  // against the current min and max values
509  QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayers.count() ) );
510  while ( it != mLayers.end() )
511  {
512  QgsMapLayer * lyr = registry->mapLayer( *it );
513  if ( !lyr )
514  {
515  QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
516  }
517  else
518  {
519  QgsDebugMsg( "Updating extent using " + lyr->name() );
520  QgsDebugMsg( "Input extent: " + lyr->extent().toString() );
521 
522  if ( lyr->extent().isNull() )
523  {
524  ++it;
525  continue;
526  }
527 
528  // Layer extents are stored in the coordinate system (CS) of the
529  // layer. The extent must be projected to the canvas CS
531 
532  QgsDebugMsg( "Output extent: " + extent.toString() );
533  fullExtent.unionRect( extent );
534 
535  }
536  ++it;
537  }
538 
539  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
540  {
541  // If all of the features are at the one point, buffer the
542  // rectangle a bit. If they are all at zero, do something a bit
543  // more crude.
544 
545  if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
546  fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
547  {
548  fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
549  }
550  else
551  {
552  const double padFactor = 1e-8;
553  double widthPad = fullExtent.xMinimum() * padFactor;
554  double heightPad = fullExtent.yMinimum() * padFactor;
555  double xmin = fullExtent.xMinimum() - widthPad;
556  double xmax = fullExtent.xMaximum() + widthPad;
557  double ymin = fullExtent.yMinimum() - heightPad;
558  double ymax = fullExtent.yMaximum() + heightPad;
559  fullExtent.set( xmin, ymin, xmax, ymax );
560  }
561  }
562 
563  QgsDebugMsg( "Full extent: " + fullExtent.toString() );
564  return fullExtent;
565 }
566 
567 
569 {
570  // set units
571  QDomNode mapUnitsNode = theNode.namedItem( "units" );
572  QGis::UnitType units = QgsXmlUtils::readMapUnits( mapUnitsNode.toElement() );
573  setMapUnits( units );
574 
575  // set projections flag
576  QDomNode projNode = theNode.namedItem( "projections" );
577  setCrsTransformEnabled( projNode.toElement().text().toInt() );
578 
579  // set destination CRS
581  QDomNode srsNode = theNode.namedItem( "destinationsrs" );
582  srs.readXML( srsNode );
583  setDestinationCrs( srs );
584 
585  // set extent
586  QDomNode extentNode = theNode.namedItem( "extent" );
587  QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
588  setExtent( aoi );
589 
590  // set rotation
591  QDomNode rotationNode = theNode.namedItem( "rotation" );
592  QString rotationVal = rotationNode.toElement().text();
593  if ( ! rotationVal.isEmpty() )
594  {
595  double rot = rotationVal.toDouble();
596  setRotation( rot );
597  }
598 
599  //render map tile
600  QDomElement renderMapTileElem = theNode.firstChildElement( "rendermaptile" );
601  if ( !renderMapTileElem.isNull() )
602  {
603  setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == "1" ? true : false );
604  }
605 
606  mDatumTransformStore.readXML( theNode );
607 }
608 
609 
610 
612 {
613  // units
614  theNode.appendChild( QgsXmlUtils::writeMapUnits( mapUnits(), theDoc ) );
615 
616  // Write current view extents
617  theNode.appendChild( QgsXmlUtils::writeRectangle( extent(), theDoc ) );
618 
619  // Write current view rotation
620  QDomElement rotNode = theDoc.createElement( "rotation" );
621  rotNode.appendChild(
623  );
624  theNode.appendChild( rotNode );
625 
626  // projections enabled
627  QDomElement projNode = theDoc.createElement( "projections" );
629  theNode.appendChild( projNode );
630 
631  // destination CRS
632  QDomElement srsNode = theDoc.createElement( "destinationsrs" );
633  theNode.appendChild( srsNode );
634  destinationCrs().writeXML( srsNode, theDoc );
635 
636  //render map tile
637  QDomElement renderMapTileElem = theDoc.createElement( "rendermaptile" );
638  QDomText renderMapTileText = theDoc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
639  renderMapTileElem.appendChild( renderMapTileText );
640  theNode.appendChild( renderMapTileElem );
641 
642  mDatumTransformStore.writeXML( theNode, theDoc );
643 }
void setMapUnits(QGis::UnitType mapUnits)
Set the map units.
void unionRect(const QgsRectangle &rect)
Updates rectangle to include passed argument.
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
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
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.
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)
Definition: qgis.h:285
double x() const
Get the x value of the point.
Definition: qgspoint.h:128
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.
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 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)
Definition: qgis.h:274
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:353
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:65
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)
void setExtent(const QgsRectangle &rect)
Set coordinates of the rectangle which should be rendered.
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:155
double y() const
Get the y value of the point.
Definition: qgspoint.h:136
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:121
void writeXML(QDomNode &theNode, QDomDocument &theDoc)