QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
24void QgsMapToolCaptureLayerGeometry::geometryCaptured( const QgsGeometry &geometry )
25{
26 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer() );
27 if ( !vlayer )
28 return;
29
30 QgsGeometry g( geometry );
31
32 switch ( mode() )
33 {
36 break;
39 //does provider support circular strings?
40 const bool datasetIsCurved = QgsWkbTypes::isCurvedType( vlayer->wkbType() );
41 const bool providerSupportsCurvedSegments = vlayer && ( vlayer->dataProvider()->capabilities() & Qgis::VectorProviderCapability::CircularGeometries );
42 if ( !datasetIsCurved || !providerSupportsCurvedSegments )
43 g = QgsGeometry( g.constGet()->segmentize() );
44
45 QList<QgsVectorLayer *> avoidIntersectionsLayers;
46 switch ( QgsProject::instance()->avoidIntersectionsMode() )
47 {
49 if ( vlayer )
50 avoidIntersectionsLayers.append( vlayer );
51 break;
53 avoidIntersectionsLayers = QgsProject::instance()->avoidIntersectionsLayers();
54 break;
56 break;
57 }
58 if ( avoidIntersectionsLayers.size() > 0 )
59 {
60 const Qgis::GeometryOperationResult avoidIntersectionsReturn = g.avoidIntersectionsV2( avoidIntersectionsLayers );
61 if ( avoidIntersectionsReturn == Qgis::GeometryOperationResult::InvalidBaseGeometry )
62 {
63 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 );
64 }
65 if ( g.isEmpty() ) //avoid intersection might have removed the whole geometry
66 {
67 emit messageEmitted( tr( "The feature cannot be added because its geometry collapsed due to intersection avoidance" ), Qgis::MessageLevel::Critical );
69 return;
70 }
71 }
72 break;
73 }
74
75 layerGeometryCaptured( g );
76
77 switch ( mode() )
78 {
80 break;
82 layerPointCaptured( *qgsgeometry_cast<const QgsPoint *>( g.constGet() ) );
83 break;
85 layerLineCaptured( qgsgeometry_cast<const QgsCurve *>( g.constGet() ) );
86 break;
88 layerPolygonCaptured( qgsgeometry_cast<const QgsCurvePolygon *>( g.constGet() ) );
89 break;
90 }
91}
@ CircularGeometries
Supports circular geometry types (circularstring, compoundcurve, curvepolygon)
GeometryOperationResult
Success or failure of a geometry operation.
Definition qgis.h:1952
@ 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.