Skip to content

Commit

Permalink
Merge pull request #3905 from nextgis/25d_enhancement
Browse files Browse the repository at this point in the history
[FEATURE] QGIS setting to choose default Z value
  • Loading branch information
vmora authored Feb 13, 2017
2 parents 92091c5 + 332961f commit 77bf999
Show file tree
Hide file tree
Showing 26 changed files with 322 additions and 61 deletions.
13 changes: 13 additions & 0 deletions python/core/geometry/qgsgeometry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ class QgsGeometry
*/
bool insertVertex( double x, double y, int beforeVertex );

/** Insert a new vertex before the given vertex index,
* ring and item (first number is index 0)
* If the requested vertex number (beforeVertex.back()) is greater
* than the last actual vertex on the requested ring and item,
* it is assumed that the vertex is to be appended instead of inserted.
* Returns false if atVertex does not correspond to a valid vertex
* on this geometry (including if this geometry is a Point).
* It is up to the caller to distinguish between
* these error conditions. (Or maybe we add another method to this
* object to help make the distinction?)
*/
bool insertVertex( const QgsPointV2& point, int beforeVertex );

/** Moves the vertex at the given position number
* and item (first number is index 0)
* to the given coordinates.
Expand Down
6 changes: 6 additions & 0 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,12 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator
*/
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );

/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature
* Not meaningful for Point geometries
*/
bool insertVertex( const QgsPointV2& point, QgsFeatureId atFeatureId, int beforeVertex );

/** Moves the vertex at the given position number,
* ring and item (first number is index 0), and feature
* to the given coordinates
Expand Down
6 changes: 6 additions & 0 deletions python/core/qgsvectorlayereditutils.sip
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class QgsVectorLayerEditUtils
*/
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );

/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature
* Not meaningful for Point geometries
*/
bool insertVertex( const QgsPointV2& point, QgsFeatureId atFeatureId, int beforeVertex );

/** Moves the vertex at the given position number,
* ring and item (first number is index 0), and feature
* to the given coordinates
Expand Down
1 change: 1 addition & 0 deletions python/gui/qgsmaptooledit.sip
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class QgsMapToolEdit: QgsMapTool

virtual Flags flags() const;

double defaultZValue() const;
protected:

/** Creates a rubber band with the color/line width from
Expand Down
4 changes: 3 additions & 1 deletion src/app/nodetool/qgsmaptoolnodetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QgsMapMouseEvent* e )
vlayer->beginEditCommand( tr( "Inserted vertex" ) );

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

if ( topologicalEditing )
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptooladdfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
}
else if ( layerWKBType == QgsWkbTypes::Point25D )
{
g = QgsGeometry( new QgsPointV2( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), 0.0 ) );
g = QgsGeometry( new QgsPointV2( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), defaultZValue() ) );
}
else if ( layerWKBType == QgsWkbTypes::MultiPoint )
{
Expand All @@ -155,7 +155,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
else if ( layerWKBType == QgsWkbTypes::MultiPoint25D )
{
QgsMultiPointV2* mp = new QgsMultiPointV2();
mp->addGeometry( new QgsPointV2( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), 0.0 ) );
mp->addGeometry( new QgsPointV2( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), defaultZValue() ) );
g = QgsGeometry( mp );
}
else
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )

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

mDefaultZValueSpinBox->setValue(
mSettings->value( QStringLiteral( "/qgis/digitizing/default_z_value" ), Qgis::DEFAULT_Z_COORDINATE ).toDouble()
);

//default snap mode
mSnappingEnabledDefault->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), false ).toBool() );
mDefaultSnapModeComboBox->addItem( tr( "Vertex" ), QgsSnappingConfig::Vertex );
Expand Down Expand Up @@ -1362,6 +1366,8 @@ void QgsOptions::saveOptions()

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

mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), mDefaultZValueSpinBox->value() );

//default snap mode
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), mSnappingEnabledDefault->isChecked() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snap_type" ), mDefaultSnapModeComboBox->currentData().toInt() );
Expand Down
26 changes: 26 additions & 0 deletions src/core/geometry/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,32 @@ bool QgsGeometry::insertVertex( double x, double y, int beforeVertex )
return d->geometry->insertVertex( id, QgsPointV2( x, y ) );
}

bool QgsGeometry::insertVertex( const QgsPointV2& point, int beforeVertex )
{
if ( !d->geometry )
{
return false;
}

//maintain compatibility with < 2.10 API
if ( QgsWkbTypes::flatType( d->geometry->wkbType() ) == QgsWkbTypes::MultiPoint )
{
detach( true );
//insert geometry instead of point
return static_cast< QgsGeometryCollection* >( d->geometry )->insertGeometry( new QgsPointV2( point ), beforeVertex );
}

QgsVertexId id;
if ( !vertexIdFromVertexNr( beforeVertex, id ) )
{
return false;
}

detach( true );

return d->geometry->insertVertex( id, point );
}

QgsPoint QgsGeometry::vertexAt( int atVertex ) const
{
if ( !d->geometry )
Expand Down
13 changes: 13 additions & 0 deletions src/core/geometry/qgsgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,19 @@ class CORE_EXPORT QgsGeometry
*/
bool insertVertex( double x, double y, int beforeVertex );

/** Insert a new vertex before the given vertex index,
* ring and item (first number is index 0)
* If the requested vertex number (beforeVertex.back()) is greater
* than the last actual vertex on the requested ring and item,
* it is assumed that the vertex is to be appended instead of inserted.
* Returns false if atVertex does not correspond to a valid vertex
* on this geometry (including if this geometry is a Point).
* It is up to the caller to distinguish between
* these error conditions. (Or maybe we add another method to this
* object to help make the distinction?)
*/
bool insertVertex( const QgsPointV2& point, int beforeVertex );

/** Moves the vertex at the given position number
* and item (first number is index 0)
* to the given coordinates.
Expand Down
1 change: 1 addition & 0 deletions src/core/qgis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const double Qgis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM = 1.0;

const double Qgis::SCALE_PRECISION = 0.9999999999;

const double Qgis::DEFAULT_Z_COORDINATE = 0.0;

double qgsPermissiveToDouble( QString string, bool &ok )
{
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgis.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ class CORE_EXPORT Qgis
* @note added in 2.15*/
static const double SCALE_PRECISION;

/** Default Z coordinate value for 2.5d geometry
* This value have to be assigned to the Z coordinate for the new 2.5d geometry vertex.
* @note added in 3.0 */
static const double DEFAULT_Z_COORDINATE;

};

// hack to workaround warnings when casting void pointers
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,19 @@ bool QgsVectorLayer::insertVertex( double x, double y, QgsFeatureId atFeatureId,
}


bool QgsVectorLayer::insertVertex( const QgsPointV2& point, QgsFeatureId atFeatureId, int beforeVertex )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
return false;

QgsVectorLayerEditUtils utils( this );
bool result = utils.insertVertex( point, atFeatureId, beforeVertex );
if ( result )
updateExtents();
return result;
}


bool QgsVectorLayer::moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );

/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature
* Not meaningful for Point geometries
*/
bool insertVertex( const QgsPointV2& point, QgsFeatureId atFeatureId, int beforeVertex );

/** Moves the vertex at the given position number,
* ring and item (first number is index 0), and feature
* to the given coordinates
Expand Down
21 changes: 21 additions & 0 deletions src/core/qgsvectorlayereditutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ bool QgsVectorLayerEditUtils::insertVertex( double x, double y, QgsFeatureId atF
return true;
}

bool QgsVectorLayerEditUtils::insertVertex( const QgsPointV2& point, QgsFeatureId atFeatureId, int beforeVertex )
{
if ( !L->hasGeometryType() )
return false;

QgsGeometry geometry;
if ( !cache()->geometry( atFeatureId, geometry ) )
{
// it's not in cache: let's fetch it from layer
QgsFeature f;
if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( atFeatureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.hasGeometry() )
return false; // geometry not found

geometry = f.geometry();
}

geometry.insertVertex( point, beforeVertex );

L->editBuffer()->changeGeometry( atFeatureId, geometry );
return true;
}

bool QgsVectorLayerEditUtils::moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex )
{
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayereditutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class CORE_EXPORT QgsVectorLayerEditUtils
*/
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );

/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature
* Not meaningful for Point geometries
*/
bool insertVertex( const QgsPointV2& point, QgsFeatureId atFeatureId, int beforeVertex );

/** Moves the vertex at the given position number,
* ring and item (first number is index 0), and feature
* to the given coordinates
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ int QgsMapToolCapture::nextPoint( const QgsPointV2& mapPoint, QgsPointV2& layerP
QgsPoint mapP( mapPoint.x(), mapPoint.y() ); //#spellok
layerPoint = QgsPointV2( toLayerCoordinates( vlayer, mapP ) ); //transform snapped point back to layer crs //#spellok
if ( QgsWkbTypes::hasZ( vlayer->wkbType() ) )
layerPoint.addZValue( 0.0 );
layerPoint.addZValue( defaultZValue() );
if ( QgsWkbTypes::hasM( vlayer->wkbType() ) )
layerPoint.addMValue( 0.0 );
}
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmaptooledit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ QgsMapToolEdit::QgsMapToolEdit( QgsMapCanvas* canvas )
{
}

double QgsMapToolEdit::defaultZValue() const
{
return QSettings().value( QStringLiteral( "/qgis/digitizing/default_z_value" ), Qgis::DEFAULT_Z_COORDINATE ).toDouble();
}

QgsRubberBand* QgsMapToolEdit::createRubberBand( QgsWkbTypes::GeometryType geometryType, bool alternativeBand )
{
QSettings settings;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmaptooledit.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class GUI_EXPORT QgsMapToolEdit: public QgsMapTool

virtual Flags flags() const override { return QgsMapTool::EditTool; }

/**
* Return default Z value
* Use for set Z coordinate to new vertex for 2.5d geometries
*/
double defaultZValue() const;

protected:

/** Creates a rubber band with the color/line width from
Expand Down
51 changes: 16 additions & 35 deletions src/gui/qgsnewmemorylayerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,9 @@ QgsVectorLayer *QgsNewMemoryLayerDialog::runAndCreateLayer( QWidget *parent )

QgsWkbTypes::Type geometrytype = dialog.selectedType();

QString geomType;
switch ( geometrytype )
{
case QgsWkbTypes::Point:
geomType = QStringLiteral( "point" );
break;
case QgsWkbTypes::LineString:
geomType = QStringLiteral( "linestring" );
break;
case QgsWkbTypes::Polygon:
geomType = QStringLiteral( "polygon" );
break;
case QgsWkbTypes::MultiPoint:
geomType = QStringLiteral( "multipoint" );
break;
case QgsWkbTypes::MultiLineString:
geomType = QStringLiteral( "multilinestring" );
break;
case QgsWkbTypes::MultiPolygon:
geomType = QStringLiteral( "multipolygon" );
break;
case QgsWkbTypes::NoGeometry:
geomType = QStringLiteral( "none" );
break;
default:
geomType = QStringLiteral( "point" );
}
QString geomType = QgsWkbTypes::displayString( geometrytype );
if ( geomType.isNull() )
geomType = "none";

QString layerProperties = QStringLiteral( "%1?" ).arg( geomType );
if ( QgsWkbTypes::NoGeometry != geometrytype )
Expand Down Expand Up @@ -103,35 +79,40 @@ QgsNewMemoryLayerDialog::~QgsNewMemoryLayerDialog()

QgsWkbTypes::Type QgsNewMemoryLayerDialog::selectedType() const
{
QgsWkbTypes::Type wkbType = QgsWkbTypes::Unknown;
if ( !buttonGroupGeometry->isChecked() )
{
return QgsWkbTypes::NoGeometry;
wkbType = QgsWkbTypes::NoGeometry;
}
else if ( mPointRadioButton->isChecked() )
{
return QgsWkbTypes::Point;
wkbType = QgsWkbTypes::Point;
}
else if ( mLineRadioButton->isChecked() )
{
return QgsWkbTypes::LineString;
wkbType = QgsWkbTypes::LineString;
}
else if ( mPolygonRadioButton->isChecked() )
{
return QgsWkbTypes::Polygon;
wkbType = QgsWkbTypes::Polygon;
}
else if ( mMultiPointRadioButton->isChecked() )
{
return QgsWkbTypes::MultiPoint;
wkbType = QgsWkbTypes::MultiPoint;
}
else if ( mMultiLineRadioButton->isChecked() )
{
return QgsWkbTypes::MultiLineString;
wkbType = QgsWkbTypes::MultiLineString;
}
else if ( mMultiPolygonRadioButton->isChecked() )
{
return QgsWkbTypes::MultiPolygon;
wkbType = QgsWkbTypes::MultiPolygon;
}
return QgsWkbTypes::Unknown;

if ( mGeometryWithZCheckBox->isChecked() && wkbType != QgsWkbTypes::Unknown && wkbType != QgsWkbTypes::NoGeometry )
wkbType = QgsWkbTypes::zmType( wkbType, true, true );

return wkbType;
}

QgsCoordinateReferenceSystem QgsNewMemoryLayerDialog::crs() const
Expand Down
13 changes: 9 additions & 4 deletions src/gui/qgsnewvectorlayerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,24 @@ void QgsNewVectorLayerDialog::on_mTypeBox_currentIndexChanged( int index )

QgsWkbTypes::Type QgsNewVectorLayerDialog::selectedType() const
{
QgsWkbTypes::Type wkbType = QgsWkbTypes::Unknown;
if ( mPointRadioButton->isChecked() )
{
return QgsWkbTypes::Point;
wkbType = QgsWkbTypes::Point;
}
else if ( mLineRadioButton->isChecked() )
{
return QgsWkbTypes::LineString;
wkbType = QgsWkbTypes::LineString;
}
else if ( mPolygonRadioButton->isChecked() )
{
return QgsWkbTypes::Polygon;
wkbType = QgsWkbTypes::Polygon;
}
return QgsWkbTypes::Unknown;

if ( mGeometryWithZCheckBox->isChecked() && wkbType != QgsWkbTypes::Unknown )
wkbType = QgsWkbTypes::to25D( wkbType );

return wkbType;
}

int QgsNewVectorLayerDialog::selectedCrsId() const
Expand Down
Loading

0 comments on commit 77bf999

Please sign in to comment.