35 , mSize( QSize( 0, 0 ) )
38 , mProjectionsEnabled( false )
40 , mDatumTransformStore( mDestCRS )
41 , mBackgroundColor( Qt::white )
42 , mSelectionColor( Qt::yellow )
43 , mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling | DrawSelection )
44 , mImageFormat( QImage::Format_ARGB32_Premultiplied )
47 , mMapUnitsPerPixel( 1 )
106 if ( extent.
width() > 0 &&
108 extent.
width() < 1 &&
113 double xMean = ( qAbs( extent.
xMinimum() ) + qAbs( extent.
xMaximum() ) ) * 0.5;
114 double yMean = ( qAbs( extent.
yMinimum() ) + qAbs( extent.
yMaximum() ) ) * 0.5;
116 double xRange = extent.
width() / xMean;
117 double yRange = extent.
height() / yMean;
119 static const double minProportion = 1e-12;
120 if ( xRange < minProportion || yRange < minProportion )
127 double myHeight =
mSize.height();
128 double myWidth =
mSize.width();
130 if ( !myWidth || !myHeight )
139 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
145 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
171 #if 1 // set visible extent taking rotation in consideration 295 return mFlags.testFlag( flag );
354 QgsDebugMsg( QString(
"sourceCrs = " + ct->sourceCrs().authid() ) );
355 QgsDebugMsg( QString(
"destCRS = " + ct->destCRS().authid() ) );
357 extent = ct->transformBoundingBox( extent );
380 QgsDebugMsg( QString(
"sourceCrs = " + ct->sourceCrs().authid() ) );
381 QgsDebugMsg( QString(
"destCRS = " + ct->destCRS().authid() ) );
495 QStringList::const_iterator it =
mLayers.begin();
502 QgsDebugMsg( QString(
"WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
526 if ( fullExtent.
width() == 0.0 || fullExtent.
height() == 0.0 )
535 fullExtent.
set( -1.0, -1.0, 1.0, 1.0 );
539 const double padFactor = 1e-8;
540 double widthPad = fullExtent.
xMinimum() * padFactor;
541 double heightPad = fullExtent.
yMinimum() * padFactor;
542 double xmin = fullExtent.
xMinimum() - widthPad;
543 double xmax = fullExtent.
xMaximum() + widthPad;
544 double ymin = fullExtent.
yMinimum() - heightPad;
545 double ymax = fullExtent.
yMaximum() + heightPad;
546 fullExtent.
set( xmin, ymin, xmax, ymax );
558 QDomNode mapUnitsNode = theNode.namedItem(
"units" );
563 QDomNode projNode = theNode.namedItem(
"projections" );
568 QDomNode srsNode = theNode.namedItem(
"destinationsrs" );
573 QDomNode extentNode = theNode.namedItem(
"extent" );
578 QDomNode rotationNode = theNode.namedItem(
"rotation" );
579 QString rotationVal = rotationNode.toElement().text();
580 if ( ! rotationVal.isEmpty() )
582 double rot = rotationVal.toDouble();
600 QDomElement rotNode = theDoc.createElement(
"rotation" );
604 theNode.appendChild( rotNode );
607 QDomElement projNode = theDoc.createElement(
"projections" );
609 theNode.appendChild( projNode );
612 QDomElement srsNode = theDoc.createElement(
"destinationsrs" );
613 theNode.appendChild( srsNode );
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.
Base class for all map layer types.
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from layer'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.
QgsMapToPixel mMapToPixel
double scale() const
Return the calculated scale of the map.
void readXML(QDomNode &theNode)
QgsRectangle fullExtent() const
returns current extent of layer set
const QgsCoordinateTransform * layerTransform(QgsMapLayer *layer) const
Return coordinate transform from layer'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)
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
QgsCoordinateReferenceSystem mDestCRS
QMap< QString, QString > mLayerStyleOverrides
static QgsMapLayerRegistry * instance()
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.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
Q_DECL_DEPRECATED void setParameters(double mapUnitsPerPixel, double xmin, double ymin, double height)
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'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's CRS
void setLayers(const QStringList &layers)
Set list of layer IDs for map rendering.
Q_GUI_EXPORT int qt_defaultDpiX()
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
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.
const QString & name() const
Get the display name of the layer.
Perform transforms between map coordinates and device coordinates.
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.
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
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)
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's geographical coordinates - used for scale calculation.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
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's geographical coordinates - used for scale calculation.
QgsScaleCalculator mScaleCalculator
A class to represent a point.
static QGis::UnitType readMapUnits(const QDomElement &element)
This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a m...
QString qgsDoubleToString(const double &a, const int &precision=17)
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
QgsPoint toMapCoordinatesF(double x, double y) const
QgsPoint toMapCoordinates(int x, int y) const
bool writeXML(QDomNode &theNode, QDomDocument &theDoc) const
void setOutputSize(const QSize &size)
Set the size of the resulting map image.
Class for storing a coordinate reference system (CRS)
void setExtent(const QgsRectangle &rect)
Set coordinates of the rectangle which should be rendered.
QgsRectangle extent() const
Return geographical coordinates of the rectangle that should be rendered.
UnitType
Map units that qgis supports.
QStringList layers() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
bool readXML(QDomNode &theNode)
QPolygonF visiblePolygon() const
Return the visible area as a polygon (may be rotated)
Custom exception class for Coordinate Reference System related exceptions.
QgsRectangle outputExtentToLayerExtent(QgsMapLayer *theLayer, QgsRectangle extent) const
transform bounding box from output CRS to layer's CRS
double width() const
Width of the rectangle.
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
void setFlags(Flags flags)
Set combination of flags that will be used for rendering.
double xMinimum() const
Get the x minimum value (left side of rectangle)
static QgsRectangle readRectangle(const QDomElement &element)
double height() const
Height of the rectangle.
static QDomElement writeMapUnits(QGis::UnitType units, QDomDocument &doc)
void setCrsTransformEnabled(bool enabled)
sets whether to use projections for this layer set
QPointF toQPointF() const
Converts a point to a QPointF.
void writeXML(QDomNode &theNode, QDomDocument &theDoc)