QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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#include "moc_qgsmaptoolcapturelayergeometry.cpp"
19#include "qgsproject.h"
20#include "qgscurvepolygon.h"
21#include "qgscurve.h"
22
23
24
25
26void QgsMapToolCaptureLayerGeometry::geometryCaptured( const QgsGeometry &geometry )
27{
28 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer() );
29 if ( !vlayer )
30 return;
31
32 QgsGeometry g( geometry );
33
34 switch ( mode() )
35 {
38 break;
41 //does provider support circular strings?
42 const bool datasetIsCurved = QgsWkbTypes::isCurvedType( vlayer->wkbType() );
43 const bool providerSupportsCurvedSegments = vlayer && ( vlayer->dataProvider()->capabilities() & Qgis::VectorProviderCapability::CircularGeometries );
44 if ( !datasetIsCurved || !providerSupportsCurvedSegments )
45 g = QgsGeometry( g.constGet()->segmentize() );
46
47 QList<QgsVectorLayer *> avoidIntersectionsLayers;
48 switch ( QgsProject::instance()->avoidIntersectionsMode() )
49 {
51 if ( vlayer )
52 avoidIntersectionsLayers.append( vlayer );
53 break;
55 avoidIntersectionsLayers = QgsProject::instance()->avoidIntersectionsLayers();
56 break;
58 break;
59 }
60 if ( avoidIntersectionsLayers.size() > 0 )
61 {
62 const Qgis::GeometryOperationResult avoidIntersectionsReturn = g.avoidIntersectionsV2( avoidIntersectionsLayers );
63 if ( avoidIntersectionsReturn == Qgis::GeometryOperationResult::InvalidBaseGeometry )
64 {
65 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 );
66 }
67 if ( g.isEmpty() ) //avoid intersection might have removed the whole geometry
68 {
69 emit messageEmitted( tr( "The feature cannot be added because its geometry collapsed due to intersection avoidance" ), Qgis::MessageLevel::Critical );
71 return;
72 }
73 }
74 break;
75 }
76
77 layerGeometryCaptured( g );
78
79 switch ( mode() )
80 {
82 break;
84 layerPointCaptured( *qgsgeometry_cast<const QgsPoint *>( g.constGet() ) );
85 break;
87 layerLineCaptured( qgsgeometry_cast<const QgsCurve *>( g.constGet() ) );
88 break;
90 layerPolygonCaptured( qgsgeometry_cast<const QgsCurvePolygon *>( g.constGet() ) );
91 break;
92 }
93}
@ CircularGeometries
Supports circular geometry types (circularstring, compoundcurve, curvepolygon)
GeometryOperationResult
Success or failure of a geometry operation.
Definition qgis.h:1889
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
@ Warning
Warning message.
Definition qgis.h:156
@ Critical
Critical/error message.
Definition qgis.h:157
@ AvoidIntersectionsLayers
Overlap with features from a specified list of layers when digitizing new features not allowed.
@ AllowIntersections
Overlap with any feature allowed when digitizing new features.
@ AvoidIntersectionsCurrentLayer
Overlap with features from the active layer when digitizing new features not allowed.
A geometry is the spatial representation of a feature.
virtual QgsMapLayer * layer() const
Returns the layer associated with the map tool.
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.
void messageEmitted(const QString &message, Qgis::MessageLevel=Qgis::MessageLevel::Info)
emit a message
static QgsProject * instance()
Returns the QgsProject singleton instance.
QList< QgsVectorLayer * > avoidIntersectionsLayers
Definition qgsproject.h:119
virtual Q_INVOKABLE Qgis::VectorProviderCapabilities capabilities() const
Returns flags containing the supported capabilities.
Represents a vector layer which manages a vector based data sets.
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 bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.