QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
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 )
58 ext.
scale( ratio, center );
64 QgsDebugMsgLevel( QStringLiteral(
"Magnification factor: %1 dpi: %2 ratio: %3" ).arg( factor ).arg(
mDpi ).arg( ratio ), 3 );
152 static const double MIN_PROPORTION = 1e-12;
153 if ( xRange < MIN_PROPORTION || yRange < MIN_PROPORTION )
160 double myHeight =
mSize.height();
161 double myWidth =
mSize.width();
163 if ( !myWidth || !myHeight )
172 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
178 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
204 #if 1 // set visible extent taking rotation in consideration
211 dxmin = std::min( p1.
x(), std::min( p2.
x(), std::min( p3.
x(), p4.
x() ) ) );
212 dymin = std::min( p1.
y(), std::min( p2.
y(), std::min( p3.
y(), p4.
y() ) ) );
213 dxmax = std::max( p1.
x(), std::max( p2.
x(), std::max( p3.
x(), p4.
x() ) ) );
214 dymax = std::max( p1.
y(), std::max( p2.
y(), std::max( p3.
y(), p4.
y() ) ) );
278 return _qgis_listQPointerToIDs(
mLayers );
284 return _qgis_listQPointerToRaw(
mLayers );
290 auto filteredList =
layers;
291 filteredList.erase( std::remove_if( filteredList.begin(), filteredList.end(),
294 return !layer || !layer->isSpatial();
295 } ), filteredList.end() );
297 mLayers = _qgis_listRawToQPointer( filteredList );
357 return mFlags.testFlag( flag );
404 if ( !mHasTransformContext )
405 QgsDebugMsgLevel( QStringLiteral(
"No QgsCoordinateTransformContext context set for transform" ), 4 );
415 mHasTransformContext =
true;
501 double x = point.
x();
502 double y = point.
y();
503 double z = point.
z();
555 double x = point.
x();
556 double y = point.
y();
557 double z = point.
z();
602 const auto constMLayers =
mLayers;
610 if ( lyr->extent().isNull() )
635 const double padFactor = 1e-8;
655 QDomNode srsNode = node.namedItem( QStringLiteral(
"destinationsrs" ) );
656 if ( !srsNode.isNull() )
663 QDomNode extentNode = node.namedItem( QStringLiteral(
"extent" ) );
668 QDomNode rotationNode = node.namedItem( QStringLiteral(
"rotation" ) );
669 QString rotationVal = rotationNode.toElement().text();
670 if ( ! rotationVal.isEmpty() )
672 double rot = rotationVal.toDouble();
677 QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral(
"rendermaptile" ) );
678 if ( !renderMapTileElem.isNull() )
695 QDomElement rotNode = doc.createElement( QStringLiteral(
"rotation" ) );
699 node.appendChild( rotNode );
704 QDomElement srsNode = doc.createElement( QStringLiteral(
"destinationsrs" ) );
705 node.appendChild( srsNode );
710 QDomElement renderMapTileElem = doc.createElement( QStringLiteral(
"rendermaptile" ) );
712 renderMapTileElem.appendChild( renderMapTileText );
713 node.appendChild( renderMapTileElem );
728 mClippingRegions.append( region );
733 mClippingRegions = regions;
738 return mClippingRegions;
743 mRenderedFeatureHandlers.append( handler );
748 return mRenderedFeatureHandlers;
QgsCoordinateReferenceSystem crs
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
double mMagnificationFactor
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
bool isFinite() const
Returns true if the rectangle has finite boundaries.
@ NoSimplification
No simplification can be applied.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
void setLabelBoundaryGeometry(const QgsGeometry &boundary)
Sets the label boundary geometry, which restricts where in the rendered map labels are permitted to b...
Contains information about the context in which a coordinate transform is executed.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
A map clipping region (in map coordinates and CRS).
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setMapUnits(QgsUnitTypes::DistanceUnit mapUnits)
Set the map units.
void readXml(QDomNode &node)
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
bool mValid
Whether the actual settings are valid (set in updateDerived())
QSize outputSize() const
Returns the size of the resulting map image.
void setDpi(double dpi)
Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
double extentBuffer() const
Returns the buffer in map units to use around the visible extent for rendering symbols whose correspo...
Point geometry type, with support for z-dimension and m-values.
@ DistanceUnknownUnit
Unknown distance unit.
Q_GUI_EXPORT int qt_defaultDpiX()
#define QgsDebugMsgLevel(str, level)
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
double calculate(const QgsRectangle &mapExtent, double canvasWidth) const
Calculate the scale denominator.
Flags flags() const
Returns combination of flags used for rendering.
float devicePixelRatio() const
Returns device pixel ratio Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" di...
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
const QgsCoordinateReferenceSystem & crs
QgsVectorSimplifyMethod mSimplifyMethod
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer's CRS
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
void setClippingRegions(const QList< QgsMapClippingRegion > ®ions)
Sets the list of clipping regions to apply to the map.
QgsRectangle fullExtent() const
returns current extent of layer set
void writeXml(QDomNode &node, QDomDocument &doc)
QString ellipsoid() const
Returns ellipsoid's acronym.
double mapUnitsPerPixel() const
Returns the distance in geographical coordinates that equals to one pixel in the map.
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
QPointF toQPointF() const
Converts a point to a QPointF.
double magnificationFactor() const
Returns the magnification factor.
QMap< QString, QString > layerStyleOverrides() const
Gets map of map layer style overrides (key: layer ID, value: style name) where a different style shou...
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
QgsUnitTypes::DistanceUnit mapUnits() const
Returns current map units.
void setOutputDpi(double dpi)
Sets DPI used for conversion between real world units (e.g. mm) and pixels.
static EllipsoidParameters ellipsoidParameters(const QString &ellipsoid)
Returns the parameters for the specified ellipsoid.
DistanceUnit
Units of distance.
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
A rectangle specified with double values.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
An interface for classes which provider custom handlers for features rendered as part of a map render...
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
void addRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Adds a rendered feature handler to use while rendering the map settings.
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
Custom exception class for Coordinate Reference System related exceptions.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
static QDomElement writeMapUnits(QgsUnitTypes::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
QgsCoordinateTransformContext mTransformContext
void setDevicePixelRatio(float dpr)
Sets the device pixel ratio Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" d...
bool valid
Whether ellipsoid parameters are valid.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsUnitTypes::DistanceUnit mapUnits() const
Gets units of map's geographical coordinates - used for scale calculation.
void setMagnificationFactor(double factor, const QgsPointXY *center=nullptr)
Set the magnification factor.
Flag
Enumeration of flags that adjust the way the map is rendered.
QString authid() const
Returns the authority identifier for the CRS.
QPolygonF visiblePolygon() const
Returns the visible area as a polygon (may be rotated)
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
void setFlags(QgsMapSettings::Flags flags)
Sets combination of flags that will be used for rendering.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
double scale() const
Returns the calculated map scale.
QgsCoordinateReferenceSystem mDestCRS
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
QMap< QString, QString > mLayerStyleOverrides
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
This class represents a coordinate reference system (CRS).
void setLayers(const QList< QgsMapLayer * > &layers)
Set list of layers for map rendering.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
A class to represent a 2D point.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
Contains parameters for an ellipsoid.
QSize deviceOutputSize() const
Returns the device output size of the map canvas This is equivalent to the output size multiplicated ...
QgsGeometry mLabelBoundaryGeometry
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
void addClippingRegion(const QgsMapClippingRegion ®ion)
Adds a new clipping region to the map settings.
QgsScaleCalculator mScaleCalculator
A geometry is the spatial representation of a feature.
Perform transforms between map coordinates and device coordinates.
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 width() const SIP_HOLDGIL
Returns the width of the rectangle.
Base class for all map layer types.
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering the map settings.
QString asWktCoordinates() const
Returns a string representation of the rectangle in WKT format.
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
QgsMapToPixel mMapToPixel
QList< QgsMapClippingRegion > clippingRegions() const
Returns the list of clipping regions to apply to the map.
double layerToMapUnits(const QgsMapLayer *layer, const QgsRectangle &referenceExtent=QgsRectangle()) const
Computes an estimated conversion factor between layer and map units: layerUnits * layerToMapUnits = m...
void setOutputSize(QSize size)
Sets the size of the resulting map image.
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
QgsGeometry labelBoundaryGeometry() const
Returns the label boundary geometry, which restricts where in the rendered map labels are permitted t...
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
bool isEmpty() const
Returns true if the rectangle is empty.
const QgsMapToPixel & mapToPixel() const
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
QStringList layerIds() const
Gets list of layer IDs for map rendering The layers are stored in the reverse order of how they are r...
void setExtentBuffer(double buffer)
Sets the buffer in map units to use around the visible extent for rendering symbols whose correspondi...
static QgsRectangle readRectangle(const QDomElement &element)