36 , mSize( QSize( 0, 0 ) )
37 , mBackgroundColor( Qt::white )
38 , mSelectionColor( Qt::yellow )
39 , mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling | DrawSelection )
40 , mSegmentationTolerance( M_PI_2 / 90 )
63 QgsDebugMsg( QString(
"Magnification factor: %1 dpi: %2 ratio: %3" ).arg( factor ).arg(
mDpi ).arg( ratio ) );
128 if ( extent.
width() > 0 &&
130 extent.
width() < 1 &&
135 double xMean = ( std::fabs( extent.
xMinimum() ) + std::fabs( extent.
xMaximum() ) ) * 0.5;
136 double yMean = ( std::fabs( extent.
yMinimum() ) + std::fabs( extent.
yMaximum() ) ) * 0.5;
138 double xRange = extent.
width() / xMean;
139 double yRange = extent.
height() / yMean;
141 static const double MIN_PROPORTION = 1e-12;
142 if ( xRange < MIN_PROPORTION || yRange < MIN_PROPORTION )
149 double myHeight =
mSize.height();
150 double myWidth =
mSize.width();
152 if ( !myWidth || !myHeight )
161 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
167 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
193 #if 1 // set visible extent taking rotation in consideration 200 dxmin = std::min( p1.
x(), std::min( p2.
x(), std::min( p3.
x(), p4.
x() ) ) );
201 dymin = std::min( p1.
y(), std::min( p2.
y(), std::min( p3.
y(), p4.
y() ) ) );
202 dxmax = std::max( p1.
x(), std::max( p2.
x(), std::max( p3.
x(), p4.
x() ) ) );
203 dymax = std::max( p1.
y(), std::max( p2.
y(), std::max( p3.
y(), p4.
y() ) ) );
248 return _qgis_listQPointerToIDs(
mLayers );
254 return _qgis_listQPointerToRaw(
mLayers );
260 auto filteredList =
layers;
261 filteredList.erase( std::remove_if( filteredList.begin(), filteredList.end(),
264 return !layer || !layer->isSpatial();
265 } ), filteredList.end() );
267 mLayers = _qgis_listRawToQPointer( filteredList );
327 return mFlags.testFlag( flag );
374 if ( !mHasTransformContext )
375 qWarning(
"No QgsCoordinateTransformContext context set for transform" );
385 mHasTransformContext =
true;
402 double distLayerUnits = std::sqrt( l1.sqrDist( l2 ) );
405 double distMapUnits = std::sqrt( m1.sqrDist( m2 ) );
406 return distMapUnits / distLayerUnits;
544 if ( lyr->extent().isNull() )
556 if ( fullExtent.
width() == 0.0 || fullExtent.
height() == 0.0 )
565 fullExtent.
set( -1.0, -1.0, 1.0, 1.0 );
569 const double padFactor = 1e-8;
570 double widthPad = fullExtent.
xMinimum() * padFactor;
571 double heightPad = fullExtent.
yMinimum() * padFactor;
572 double xmin = fullExtent.
xMinimum() - widthPad;
573 double xmax = fullExtent.
xMaximum() + widthPad;
574 double ymin = fullExtent.
yMinimum() - heightPad;
575 double ymax = fullExtent.
yMaximum() + heightPad;
576 fullExtent.
set( xmin, ymin, xmax, ymax );
589 QDomNode srsNode = node.namedItem( QStringLiteral(
"destinationsrs" ) );
590 if ( !srsNode.isNull() )
597 QDomNode extentNode = node.namedItem( QStringLiteral(
"extent" ) );
602 QDomNode rotationNode = node.namedItem( QStringLiteral(
"rotation" ) );
603 QString rotationVal = rotationNode.toElement().text();
604 if ( ! rotationVal.isEmpty() )
606 double rot = rotationVal.toDouble();
611 QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral(
"rendermaptile" ) );
612 if ( !renderMapTileElem.isNull() )
629 QDomElement rotNode = doc.createElement( QStringLiteral(
"rotation" ) );
633 node.appendChild( rotNode );
638 QDomElement srsNode = doc.createElement( QStringLiteral(
"destinationsrs" ) );
639 node.appendChild( srsNode );
644 QDomElement renderMapTileElem = doc.createElement( QStringLiteral(
"rendermaptile" ) );
646 renderMapTileElem.appendChild( renderMapTileText );
647 node.appendChild( renderMapTileElem );
double mMagnificationFactor
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
A rectangle specified with double values.
Base class for all map layer types.
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.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
QgsMapToPixel mMapToPixel
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
double magnificationFactor() const
Return the magnification factor.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QStringList layerIds() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
QgsCoordinateReferenceSystem mDestCRS
QgsCoordinateTransformContext mTransformContext
A class to represent a 2D point.
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
QMap< QString, QString > mLayerStyleOverrides
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer's CRS
void setOutputDpi(double dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
double layerToMapUnits(const QgsMapLayer *layer, const QgsRectangle &referenceExtent=QgsRectangle()) const
Computes an estimated conversion factor between layer and map units: layerUnits * layerToMapUnits = m...
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
void setFlags(QgsMapSettings::Flags flags)
Set combination of flags that will be used for rendering.
QgsUnitTypes::DistanceUnit mapUnits
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...
QList< QgsMapLayer * > layers() const
Get list of layers for map rendering The layers are stored in the reverse order of how they are rende...
Contains parameters for an ellipsoid.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
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)
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning)
add a message to the instance (and create it if necessary)
static EllipsoidParameters ellipsoidParameters(const QString &ellipsoid)
Returns the parameters for the specified ellipsoid.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
virtual QgsRectangle extent() const
Returns the extent of the layer.
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
QgsUnitTypes::DistanceUnit mapUnits() const
Get units of map's geographical coordinates - used for scale calculation.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Return coordinate transform from layer's CRS to destination CRS.
Perform transforms between map coordinates and device coordinates.
bool mValid
Whether the actual settings are valid (set in updateDerived())
QgsRectangle extent() const
Return geographical coordinates of the rectangle that should be rendered.
QPointF toQPointF() const
Converts a point to a QPointF.
void setOutputSize(QSize size)
Set the size of the resulting map image.
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
Flag
Enumeration of flags that adjust the way the map is rendered.
bool valid
Whether ellipsoid parameters are valid.
#define QgsDebugMsgLevel(str, level)
void setMagnificationFactor(double factor)
Set the magnification factor.
bool isEmpty() const
Returns true if the rectangle is empty.
double scale() const
Returns the calculated map scale.
double width() const
Returns the width of the rectangle.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
double mapUnitsPerPixel() const
Return the distance in geographical coordinates that equals to one pixel in the map.
void setMapUnits(QgsUnitTypes::DistanceUnit mapUnits)
Set the map units.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
static QDomElement writeMapUnits(QgsUnitTypes::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
Contains information about the context in which a coordinate transform is executed.
QgsScaleCalculator mScaleCalculator
const QgsMapToPixel & mapToPixel() const
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
DistanceUnit
Units of distance.
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
void combineExtentWith(const QgsRectangle &rect)
Expand the rectangle so that covers both the original rectangle and the given rectangle.
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.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
QMap< QString, QString > layerStyleOverrides() const
Get map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
QString ellipsoid() const
Returns ellipsoid's acronym.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
QgsRectangle fullExtent() const
returns current extent of layer set
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
This class represents a coordinate reference system (CRS).
Flags flags() const
Return combination of flags used for rendering.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setLayers(const QList< QgsMapLayer *> &layers)
Set list of layers for map rendering.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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)
void readXml(QDomNode &node)
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
void writeXml(QDomNode &node, QDomDocument &doc)
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
QgsPointXY toMapCoordinatesF(double x, double y) const
Transform device coordinates to map (world) coordinates.
static QgsRectangle readRectangle(const QDomElement &element)
QSize outputSize() const
Return the size of the resulting map image.
QgsPointXY toMapCoordinates(int x, int y) const
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
QString authid() const
Returns the authority identifier for the CRS.
double height() const
Returns the height of the rectangle.
QgsUnitTypes::DistanceUnit mapUnits() const
Returns current map units.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.