QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsmaptoolcapturelayergeometry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaptoolcapturelayergeometry.cpp - base class for map tools digitizing layer geometries
3 ---------------------
4 begin : January 2022
5 copyright : (C) Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16
18
19#include "qgscurve.h"
20#include "qgscurvepolygon.h"
21#include "qgsproject.h"
22
23#include "moc_qgsmaptoolcapturelayergeometry.cpp"
24
26{
27 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer() );
28 if ( !vlayer )
29 return;
30
31 QgsGeometry g( geometry );
32
33 switch ( mode() )
34 {
37 break;
40 //does provider support circular strings?
41 const bool datasetIsCurved = QgsWkbTypes::isCurvedType( vlayer->wkbType() );
42 const bool providerSupportsCurvedSegments = vlayer && ( vlayer->dataProvider()->capabilities() & Qgis::VectorProviderCapability::CircularGeometries );
43 if ( !datasetIsCurved || !providerSupportsCurvedSegments )
44 g = QgsGeometry( g.constGet()->segmentize() );
45
46 QList<QgsVectorLayer *> avoidIntersectionsLayers;
47 switch ( QgsProject::instance()->avoidIntersectionsMode() )
48 {
50 if ( vlayer )
51 avoidIntersectionsLayers.append( vlayer );
52 break;
54 avoidIntersectionsLayers = QgsProject::instance()->avoidIntersectionsLayers();
55 break;
57 break;
58 }
59 if ( avoidIntersectionsLayers.size() > 0 )
60 {
61 const Qgis::GeometryOperationResult avoidIntersectionsReturn = g.avoidIntersectionsV2( avoidIntersectionsLayers );
62 if ( avoidIntersectionsReturn == Qgis::GeometryOperationResult::InvalidBaseGeometry )
63 {
64 emit messageEmitted( tr( "The feature has been added, but at least one geometry intersected is invalid. These geometries must be manually repaired." ), Qgis::MessageLevel::Warning );
65 }
66 if ( g.isEmpty() ) //avoid intersection might have removed the whole geometry
67 {
68 emit messageEmitted( tr( "The feature cannot be added because its geometry collapsed due to intersection avoidance" ), Qgis::MessageLevel::Critical );
70 return;
71 }
72 }
73 break;
74 }
75
77
78 switch ( mode() )
79 {
81 break;
84 break;
87 break;
90 break;
91 }
92}
@ CircularGeometries
Supports circular geometry types (circularstring, compoundcurve, curvepolygon).
Definition qgis.h:514
GeometryOperationResult
Success or failure of a geometry operation.
Definition qgis.h:2042
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
Definition qgis.h:2045
@ Warning
Warning message.
Definition qgis.h:158
@ Critical
Critical/error message.
Definition qgis.h:159
@ AvoidIntersectionsLayers
Overlap with features from a specified list of layers when digitizing new features not allowed.
Definition qgis.h:4276
@ AllowIntersections
Overlap with any feature allowed when digitizing new features.
Definition qgis.h:4274
@ AvoidIntersectionsCurrentLayer
Overlap with features from the active layer when digitizing new features not allowed.
Definition qgis.h:4275
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Qgis::GeometryOperationResult avoidIntersectionsV2(const QList< QgsVectorLayer * > &avoidIntersectionsLayers, const QHash< QgsVectorLayer *, QSet< QgsFeatureId > > &ignoreFeatures=(QHash< QgsVectorLayer *, QSet< QgsFeatureId > >()))
Modifies geometry to avoid intersections with the layers specified in project properties.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
virtual QgsMapLayer * layer() const
Returns the layer associated with the map tool.
virtual void layerGeometryCaptured(const QgsGeometry &geometry)
Called when the geometry is captured.
virtual void layerPolygonCaptured(const QgsCurvePolygon *polygon)
Called when a polygon is captured.
virtual void layerLineCaptured(const QgsCurve *line)
Called when a line is captured.
void geometryCaptured(const QgsGeometry &geometry) override
Called when the geometry is captured.
virtual void layerPointCaptured(const QgsPoint &point)
Called when a point is captured.
void stopCapturing()
Stop capturing.
CaptureMode mode() const
The capture mode.
@ CapturePolygon
Capture polygons.
@ CaptureNone
Do not capture / determine mode from layer geometry type.
@ CapturePoint
Capture points.
@ CaptureLine
Capture lines.
virtual QgsMapToolCapture::Capabilities capabilities() const
Returns flags containing the supported capabilities.
void messageEmitted(const QString &message, Qgis::MessageLevel level=Qgis::MessageLevel::Info)
Emitted when a message should be shown to the user in the application message bar.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QList< QgsVectorLayer * > avoidIntersectionsLayers
Definition qgsproject.h:122
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE Qgis::WkbType wkbType() const final
Returns the WKBType or WKBUnknown in case of error.
QgsVectorDataProvider * dataProvider() final
Returns the layer's data provider, it may be nullptr.
static Q_INVOKABLE bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.
T qgsgeometry_cast(QgsAbstractGeometry *geom)