Skip to content

Commit 77bf999

Browse files
authored
Merge pull request #3905 from nextgis/25d_enhancement
[FEATURE] QGIS setting to choose default Z value
2 parents 92091c5 + 332961f commit 77bf999

26 files changed

+322
-61
lines changed

python/core/geometry/qgsgeometry.sip

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ class QgsGeometry
207207
*/
208208
bool insertVertex( double x, double y, int beforeVertex );
209209

210+
/** Insert a new vertex before the given vertex index,
211+
* ring and item (first number is index 0)
212+
* If the requested vertex number (beforeVertex.back()) is greater
213+
* than the last actual vertex on the requested ring and item,
214+
* it is assumed that the vertex is to be appended instead of inserted.
215+
* Returns false if atVertex does not correspond to a valid vertex
216+
* on this geometry (including if this geometry is a Point).
217+
* It is up to the caller to distinguish between
218+
* these error conditions. (Or maybe we add another method to this
219+
* object to help make the distinction?)
220+
*/
221+
bool insertVertex( const QgsPointV2& point, int beforeVertex );
222+
210223
/** Moves the vertex at the given position number
211224
* and item (first number is index 0)
212225
* to the given coordinates.

python/core/qgsvectorlayer.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,12 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator
795795
*/
796796
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );
797797

798+
/** Insert a new vertex before the given vertex number,
799+
* in the given ring, item (first number is index 0), and feature
800+
* Not meaningful for Point geometries
801+
*/
802+
bool insertVertex( const QgsPointV2& point, QgsFeatureId atFeatureId, int beforeVertex );
803+
798804
/** Moves the vertex at the given position number,
799805
* ring and item (first number is index 0), and feature
800806
* to the given coordinates

python/core/qgsvectorlayereditutils.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class QgsVectorLayerEditUtils
1515
*/
1616
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );
1717

18+
/** Insert a new vertex before the given vertex number,
19+
* in the given ring, item (first number is index 0), and feature
20+
* Not meaningful for Point geometries
21+
*/
22+
bool insertVertex( const QgsPointV2& point, QgsFeatureId atFeatureId, int beforeVertex );
23+
1824
/** Moves the vertex at the given position number,
1925
* ring and item (first number is index 0), and feature
2026
* to the given coordinates

python/gui/qgsmaptooledit.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class QgsMapToolEdit: QgsMapTool
2727

2828
virtual Flags flags() const;
2929

30+
double defaultZValue() const;
3031
protected:
3132

3233
/** Creates a rubber band with the color/line width from

src/app/nodetool/qgsmaptoolnodetool.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,9 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QgsMapMouseEvent* e )
630630
vlayer->beginEditCommand( tr( "Inserted vertex" ) );
631631

632632
// add vertex
633-
vlayer->insertVertex( layerCoords.x(), layerCoords.y(), mSelectedFeature->featureId(), snapResults.first().afterVertexNr );
633+
QgsPointV2 p( layerCoords.x(), layerCoords.y() );
634+
p.addZValue( defaultZValue() );
635+
vlayer->insertVertex( p, mSelectedFeature->featureId(), snapResults.first().afterVertexNr );
634636

635637
if ( topologicalEditing )
636638
{

src/app/qgsmaptooladdfeature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
146146
}
147147
else if ( layerWKBType == QgsWkbTypes::Point25D )
148148
{
149-
g = QgsGeometry( new QgsPointV2( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), 0.0 ) );
149+
g = QgsGeometry( new QgsPointV2( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), defaultZValue() ) );
150150
}
151151
else if ( layerWKBType == QgsWkbTypes::MultiPoint )
152152
{
@@ -155,7 +155,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
155155
else if ( layerWKBType == QgsWkbTypes::MultiPoint25D )
156156
{
157157
QgsMultiPointV2* mp = new QgsMultiPointV2();
158-
mp->addGeometry( new QgsPointV2( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), 0.0 ) );
158+
mp->addGeometry( new QgsPointV2( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), defaultZValue() ) );
159159
g = QgsGeometry( mp );
160160
}
161161
else

src/app/qgsoptions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
856856

857857
mLineGhostCheckBox->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/line_ghost" ), false ).toBool() );
858858

859+
mDefaultZValueSpinBox->setValue(
860+
mSettings->value( QStringLiteral( "/qgis/digitizing/default_z_value" ), Qgis::DEFAULT_Z_COORDINATE ).toDouble()
861+
);
862+
859863
//default snap mode
860864
mSnappingEnabledDefault->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), false ).toBool() );
861865
mDefaultSnapModeComboBox->addItem( tr( "Vertex" ), QgsSnappingConfig::Vertex );
@@ -1362,6 +1366,8 @@ void QgsOptions::saveOptions()
13621366

13631367
settings.setValue( QStringLiteral( "/qgis/digitizing/line_ghost" ), mLineGhostCheckBox->isChecked() );
13641368

1369+
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), mDefaultZValueSpinBox->value() );
1370+
13651371
//default snap mode
13661372
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), mSnappingEnabledDefault->isChecked() );
13671373
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snap_type" ), mDefaultSnapModeComboBox->currentData().toInt() );

src/core/geometry/qgsgeometry.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,32 @@ bool QgsGeometry::insertVertex( double x, double y, int beforeVertex )
519519
return d->geometry->insertVertex( id, QgsPointV2( x, y ) );
520520
}
521521

522+
bool QgsGeometry::insertVertex( const QgsPointV2& point, int beforeVertex )
523+
{
524+
if ( !d->geometry )
525+
{
526+
return false;
527+
}
528+
529+
//maintain compatibility with < 2.10 API
530+
if ( QgsWkbTypes::flatType( d->geometry->wkbType() ) == QgsWkbTypes::MultiPoint )
531+
{
532+
detach( true );
533+
//insert geometry instead of point
534+
return static_cast< QgsGeometryCollection* >( d->geometry )->insertGeometry( new QgsPointV2( point ), beforeVertex );
535+
}
536+
537+
QgsVertexId id;
538+
if ( !vertexIdFromVertexNr( beforeVertex, id ) )
539+
{
540+
return false;
541+
}
542+
543+
detach( true );
544+
545+
return d->geometry->insertVertex( id, point );
546+
}
547+
522548
QgsPoint QgsGeometry::vertexAt( int atVertex ) const
523549
{
524550
if ( !d->geometry )

src/core/geometry/qgsgeometry.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,19 @@ class CORE_EXPORT QgsGeometry
273273
*/
274274
bool insertVertex( double x, double y, int beforeVertex );
275275

276+
/** Insert a new vertex before the given vertex index,
277+
* ring and item (first number is index 0)
278+
* If the requested vertex number (beforeVertex.back()) is greater
279+
* than the last actual vertex on the requested ring and item,
280+
* it is assumed that the vertex is to be appended instead of inserted.
281+
* Returns false if atVertex does not correspond to a valid vertex
282+
* on this geometry (including if this geometry is a Point).
283+
* It is up to the caller to distinguish between
284+
* these error conditions. (Or maybe we add another method to this
285+
* object to help make the distinction?)
286+
*/
287+
bool insertVertex( const QgsPointV2& point, int beforeVertex );
288+
276289
/** Moves the vertex at the given position number
277290
* and item (first number is index 0)
278291
* to the given coordinates.

src/core/qgis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const double Qgis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM = 1.0;
8383

8484
const double Qgis::SCALE_PRECISION = 0.9999999999;
8585

86+
const double Qgis::DEFAULT_Z_COORDINATE = 0.0;
8687

8788
double qgsPermissiveToDouble( QString string, bool &ok )
8889
{

0 commit comments

Comments
 (0)