QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
37 , mSize( QSize( 0, 0 ) )
38 , mBackgroundColor( Qt::white )
39 , mSelectionColor( Qt::yellow )
40 , mFlags(
Qgis::MapSettingsFlag::Antialiasing |
Qgis::MapSettingsFlag::UseAdvancedEffects |
Qgis::MapSettingsFlag::DrawLabeling |
Qgis::MapSettingsFlag::DrawSelection )
41 , mSegmentationTolerance( M_PI_2 / 90 )
59 ext.
scale( ratio, center );
65 QgsDebugMsgLevel( QStringLiteral(
"Magnification factor: %1 dpi: %2 ratio: %3" ).arg( factor ).arg(
mDpi ).arg( ratio ), 3 );
153 static const double MIN_PROPORTION = 1e-12;
154 if ( xRange < MIN_PROPORTION || yRange < MIN_PROPORTION )
161 const double myHeight =
mSize.height();
162 const double myWidth =
mSize.width();
164 if ( !myWidth || !myHeight )
171 const double mapUnitsPerPixelY =
mExtent.
height() / myHeight;
172 const double mapUnitsPerPixelX =
mExtent.
width() / myWidth;
173 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
179 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
209 #if 1 // set visible extent taking rotation in consideration
216 dxmin = std::min( p1.
x(), std::min( p2.
x(), std::min( p3.
x(), p4.
x() ) ) );
217 dymin = std::min( p1.
y(), std::min( p2.
y(), std::min( p3.
y(), p4.
y() ) ) );
218 dxmax = std::max( p1.
x(), std::max( p2.
x(), std::max( p3.
x(), p4.
x() ) ) );
219 dymax = std::max( p1.
y(), std::max( p2.
y(), std::max( p3.
y(), p4.
y() ) ) );
291 const QList<QgsMapLayer * > mapLayers =
layers( expandGroupLayers );
293 res.reserve( mapLayers.size() );
301 const QList<QgsMapLayer *> actualLayers = _qgis_listQPointerToRaw(
mLayers );
302 if ( !expandGroupLayers )
305 QList< QgsMapLayer * > result;
307 std::function< void(
const QList< QgsMapLayer * >&
layers ) > expandLayers;
308 expandLayers = [&result, &expandLayers](
const QList< QgsMapLayer * > &
layers )
312 if (
QgsGroupLayer *groupLayer = qobject_cast< QgsGroupLayer * >( layer ) )
314 expandLayers( groupLayer->childLayers() );
323 expandLayers( actualLayers );
330 auto filteredList =
layers;
331 filteredList.erase( std::remove_if( filteredList.begin(), filteredList.end(),
334 return !layer || !layer->isSpatial();
335 } ), filteredList.end() );
337 mLayers = _qgis_listRawToQPointer( filteredList );
387 mFlags &= ~(
static_cast< int >( flag ) );
397 return mFlags.testFlag( flag );
447 poly << m2p.
toMapCoordinates(
static_cast<double>( sz.width() + buffer ),
static_cast<double>( sz.height() + buffer ) ).
toQPointF();
466 if ( !mHasTransformContext )
467 QgsDebugMsgLevel( QStringLiteral(
"No QgsCoordinateTransformContext context set for transform" ), 4 );
477 mHasTransformContext =
true;
495 const double scaledWidthInInches = outputWidthInInches *
scale;
501 QgsRectangle ext( center.
x() - delta, center.
y() - delta, center.
x() + delta, center.
y() + delta );
512 const double delta = 0.5 * scaledWidthInInches * conversionFactor;
513 return QgsRectangle( center.
x() - delta, center.
y() - delta, center.
x() + delta, center.
y() + delta );
584 point = ct.
transform( point, Qgis::TransformDirection::Forward );
596 double x = point.
x();
597 double y = point.
y();
598 double z = point.
z();
599 const double m = point.
m();
622 rect = ct.
transform( rect, Qgis::TransformDirection::Forward );
639 point = ct.
transform( point, Qgis::TransformDirection::Reverse );
651 double x = point.
x();
652 double y = point.
y();
653 double z = point.
z();
654 const double m = point.
m();
677 rect = ct.
transform( rect, Qgis::TransformDirection::Reverse );
699 const auto constMLayers =
mLayers;
707 if ( lyr->extent().isNull() )
732 const double padFactor = 1e-8;
752 const QDomNode srsNode = node.namedItem( QStringLiteral(
"destinationsrs" ) );
753 if ( !srsNode.isNull() )
760 const QDomNode extentNode = node.namedItem( QStringLiteral(
"extent" ) );
765 const QDomNode rotationNode = node.namedItem( QStringLiteral(
"rotation" ) );
766 const QString rotationVal = rotationNode.toElement().text();
767 if ( ! rotationVal.isEmpty() )
769 const double rot = rotationVal.toDouble();
774 const QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral(
"rendermaptile" ) );
775 if ( !renderMapTileElem.isNull() )
792 QDomElement rotNode = doc.createElement( QStringLiteral(
"rotation" ) );
796 node.appendChild( rotNode );
801 QDomElement srsNode = doc.createElement( QStringLiteral(
"destinationsrs" ) );
802 node.appendChild( srsNode );
807 QDomElement renderMapTileElem = doc.createElement( QStringLiteral(
"rendermaptile" ) );
809 renderMapTileElem.appendChild( renderMapTileText );
810 node.appendChild( renderMapTileElem );
825 mClippingRegions.append( region );
830 mClippingRegions = regions;
835 return mClippingRegions;
840 mRenderedFeatureHandlers.append( handler );
845 return mRenderedFeatureHandlers;
QgsCoordinateReferenceSystem crs
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
double mMagnificationFactor
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Sets the destination crs (coordinate reference system) for the map render.
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.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
A map clipping region (in map coordinates and CRS).
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.
void set(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true)
Sets the rectangle from two QgsPoints.
bool mValid
Whether the actual settings are valid (set in updateDerived())
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
void setDpi(double dpi)
Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations.
void setFlag(Qgis::MapSettingsFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
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)
Sets parameters for use in transforming coordinates.
double calculate(const QgsRectangle &mapExtent, double canvasWidth) const
Calculate the scale denominator.
double dpiTarget() const
Returns the target DPI (dots per inch) to be taken into consideration when rendering.
float devicePixelRatio() const
Returns the device pixel ratio.
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
MapSettingsFlag
Coordinate transformation flags.
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.
void setFrameRate(double rate)
Sets the frame rate of the map (in frames per second), for maps which are part of an animation.
double magnificationFactor() const
Returns the magnification factor.
A map layer which consists of a set of child layers, where all component layers are rendered as a sin...
QMap< QString, QString > layerStyleOverrides() const
Returns the map of map layer style overrides (key: layer ID, value: style name) where a different sty...
void setZRange(const QgsDoubleRange &range)
Sets the range of z-values which will be visible in the map.
Qgis::MapSettingsFlags flags() const
Returns combination of flags used for rendering.
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
QgsUnitTypes::DistanceUnit mapUnits() const
Returns current map units.
void setCurrentFrame(long long frame)
Sets the current frame of the map, for maps which are part of an animation.
void setOutputDpi(double dpi)
Sets the dpi (dots per inch) used for conversion between real world units (e.g.
static EllipsoidParameters ellipsoidParameters(const QString &ellipsoid)
Returns the parameters for the specified ellipsoid.
DistanceUnit
Units of distance.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
double frameRate() const
Returns the frame rate of the map (in frames per second), for maps which are part of an animation.
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).
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
Qgis::RendererUsage rendererUsage() const
Returns the rendering usage.
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.
QPolygonF visiblePolygonWithBuffer() const
Returns the visible area as a polygon (may be rotated) with extent buffer included.
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.
QStringList layerIds(bool expandGroupLayers=false) const
Returns the list of layer IDs which will be rendered in the map.
bool testFlag(Qgis::MapSettingsFlag flag) const
Check whether a particular flag is enabled.
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
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.
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
Returns the units of the map's geographical coordinates - used for scale calculation.
void setMagnificationFactor(double factor, const QgsPointXY *center=nullptr)
Set the magnification factor.
QPolygonF visiblePolygon() const
Returns the visible area as a polygon (may be rotated)
QgsDoubleRange zRange() const
Returns the range of z-values which will be visible in the map.
@ DistanceFeet
Imperial feet.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
double computeScaleForExtent(const QgsRectangle &extent) const
Compute the scale that corresponds to the specified extent.
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...
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)
Sets the list of layers to render in the map.
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 the destination coordinate reference system for the map render.
void setDpiTarget(double dpi)
Sets the target dpi (dots per inch) to be taken into consideration when rendering.
Contains parameters for an ellipsoid.
QSize deviceOutputSize() const
Returns the device output size of the map render.
QgsGeometry mLabelBoundaryGeometry
QgsRange which stores a range of double values.
QgsUnitTypes::DistanceUnit mapUnits
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
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)
Sets the map of map layer style overrides (key: layer ID, value: style name) where a different style ...
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Base class for all map layer types. This is the base class for all map layer types (vector,...
Qgis::MapSettingsFlags mFlags
void setFlags(Qgis::MapSettingsFlags flags)
Sets combination of flags that will be used for rendering.
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.
RendererUsage
Usage of the renderer.
QgsMapToPixel mMapToPixel
The Qgis class provides global constants for use throughout the application.
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, in pixels.
double outputDpi() const
Returns the DPI (dots per inch) 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 output image size into account.
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)
Sets the coordinates of the rectangle which should be rendered.
long long currentFrame() const
Returns the current frame number of the map, for maps which are part of an animation.
void setRendererUsage(Qgis::RendererUsage rendererUsage)
Sets the rendering usage.
bool isEmpty() const
Returns true if the rectangle is empty.
Qgis::RendererUsage mRendererUsage
QgsRectangle computeExtentForScale(const QgsPointXY ¢er, double scale) const
Compute the extent such that its center is at the specified position (mapped to the destinatonCrs) an...
const QgsMapToPixel & mapToPixel() const
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
QList< QgsMapLayer * > layers(bool expandGroupLayers=false) const
Returns the list of layers which will be rendered in the map.
void setExtentBuffer(double buffer)
Sets the buffer in map units to use around the visible extent for rendering symbols whose correspondi...
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc, const QString &elementName=QStringLiteral("extent"))
Encodes a rectangle to a DOM element.
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
static QgsRectangle readRectangle(const QDomElement &element)