35 , mSize( QSize( 0, 0 ) )
37 , mProjectionsEnabled( false )
39 , mDatumTransformStore( mDestCRS )
40 , mBackgroundColor( Qt::white )
41 , mSelectionColor( Qt::yellow )
42 , mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling | DrawSelection )
43 , mImageFormat( QImage::Format_ARGB32_Premultiplied )
86 if ( extent.
width() > 0 &&
93 double xMean = ( qAbs( extent.
xMinimum() ) + qAbs( extent.
xMaximum() ) ) * 0.5;
94 double yMean = ( qAbs( extent.
yMinimum() ) + qAbs( extent.
yMaximum() ) ) * 0.5;
96 double xRange = extent.
width() / xMean;
97 double yRange = extent.
height() / yMean;
99 static const double minProportion = 1e-12;
100 if ( xRange < minProportion || yRange < minProportion )
107 double myHeight =
mSize.height();
108 double myWidth =
mSize.width();
110 if ( !myWidth || !myHeight )
119 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
125 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
244 return mFlags.testFlag( flag );
292 QgsDebugMsg( QString(
"sourceCrs = " + ct->sourceCrs().authid() ) );
293 QgsDebugMsg( QString(
"destCRS = " + ct->destCRS().authid() ) );
295 extent = ct->transformBoundingBox( extent );
318 QgsDebugMsg( QString(
"sourceCrs = " + ct->sourceCrs().authid() ) );
319 QgsDebugMsg( QString(
"destCRS = " + ct->destCRS().authid() ) );
433 QStringList::const_iterator it =
mLayers.begin();
440 QgsDebugMsg( QString(
"WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
464 if ( fullExtent.
width() == 0.0 || fullExtent.
height() == 0.0 )
473 fullExtent.
set( -1.0, -1.0, 1.0, 1.0 );
477 const double padFactor = 1e-8;
478 double widthPad = fullExtent.
xMinimum() * padFactor;
479 double heightPad = fullExtent.
yMinimum() * padFactor;
480 double xmin = fullExtent.
xMinimum() - widthPad;
481 double xmax = fullExtent.
xMaximum() + widthPad;
482 double ymin = fullExtent.
yMinimum() - heightPad;
483 double ymax = fullExtent.
yMaximum() + heightPad;
484 fullExtent.
set( xmin, ymin, xmax, ymax );
496 QDomNode mapUnitsNode = theNode.namedItem(
"units" );
501 QDomNode projNode = theNode.namedItem(
"projections" );
506 QDomNode srsNode = theNode.namedItem(
"destinationsrs" );
511 QDomNode extentNode = theNode.namedItem(
"extent" );
529 QDomElement projNode = theDoc.createElement(
"projections" );
531 theNode.appendChild( projNode );
534 QDomElement srsNode = theDoc.createElement(
"destinationsrs" );
535 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
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
QString qgsDoubleToString(const double &a)
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...
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
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
Flags flags() const
Return combination of flags used for rendering.
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)
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 geometry.
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...
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
bool writeXML(QDomNode &theNode, QDomDocument &theDoc) const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
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)
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
const QgsCoordinateTransform * layerTransfrom(QgsMapLayer *layer) const
Return coordinate transform from layer's CRS to destination CRS.
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
void writeXML(QDomNode &theNode, QDomDocument &theDoc)