Skip to content
Permalink
Browse files

Merge pull request #3905 from nextgis/25d_enhancement

[FEATURE] QGIS setting to choose default Z value
  • Loading branch information
vmora committed Feb 13, 2017
2 parents 92091c5 + 332961f commit 77bf999094b188c0e4d81e5829808284438c2f33
@@ -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.
@@ -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
@@ -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
@@ -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
@@ -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 )
{
@@ -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 )
{
@@ -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
@@ -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 );
@@ -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() );
@@ -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 )
@@ -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.
@@ -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 )
{
@@ -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
@@ -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 )
@@ -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
@@ -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 )
{
@@ -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
@@ -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 );
}
@@ -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;
@@ -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
@@ -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 )
@@ -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
@@ -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

0 comments on commit 77bf999

Please sign in to comment.
You can’t perform that action at this time.