Skip to content
Permalink
Browse files
[API][M] Fix capture M (#44782)
Fixes:
-  QgsMapSettings ignore m, so it wasn't returned.
- QgsMapToolCapture::mapPoint add also M as for the Z value
- QgsMapToolDigitizeFeature::cadCanvasReleaseEvent add M and simplify the logic of the method
- fix tests: isGeosEqual was used but it doesn't compare Z and M
  • Loading branch information
lbartoletti committed Aug 28, 2021
1 parent dab4e20 commit cab7e8cc0f5a070c21d7596b4d51d9b70024c1ba
@@ -546,6 +546,7 @@ QgsPoint QgsMapSettings::layerToMapCoordinates( const QgsMapLayer *layer, const
double x = point.x();
double y = point.y();
double z = point.z();
const double m = point.m();

try
{
@@ -558,7 +559,7 @@ QgsPoint QgsMapSettings::layerToMapCoordinates( const QgsMapLayer *layer, const
QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
}

return QgsPoint( x, y, z );
return QgsPoint( x, y, z, m );
}


@@ -600,6 +601,7 @@ QgsPoint QgsMapSettings::mapToLayerCoordinates( const QgsMapLayer *layer, const
double x = point.x();
double y = point.y();
double z = point.z();
const double m = point.m();

try
{
@@ -612,7 +614,7 @@ QgsPoint QgsMapSettings::mapToLayerCoordinates( const QgsMapLayer *layer, const
QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
}

return QgsPoint( x, y, z );
return QgsPoint( x, y, z, m );
}


@@ -1020,19 +1020,26 @@ QgsPoint QgsMapToolCapture::mapPoint( const QgsMapMouseEvent &e ) const
{
QgsPoint newPoint = mapPoint( e.mapPoint() );

// set z value from snapped point if necessary
if ( QgsWkbTypes::hasZ( newPoint.wkbType() ) )
// set z or m value from snapped point if necessary
if ( QgsWkbTypes::hasZ( newPoint.wkbType() ) || QgsWkbTypes::hasM( newPoint.wkbType() ) )
{
// if snapped, z dimension is taken from the corresponding snapped
// if snapped, z and m dimension are taken from the corresponding snapped
// point.
if ( e.isSnapped() )
{
const QgsPointLocator::Match match = e.mapPointMatch();

if ( match.layer() && QgsWkbTypes::hasZ( match.layer()->wkbType() ) )
if ( match.layer() )
{
const QgsFeature ft = match.layer()->getFeature( match.featureId() );
newPoint.setZ( ft.geometry().vertexAt( match.vertexIndex() ).z() );
if ( QgsWkbTypes::hasZ( match.layer()->wkbType() ) )
{
newPoint.setZ( ft.geometry().vertexAt( match.vertexIndex() ).z() );
}
if ( QgsWkbTypes::hasM( match.layer()->wkbType() ) )
{
newPoint.setM( ft.geometry().vertexAt( match.vertexIndex() ).m() );
}
}
}
}
@@ -155,28 +155,23 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

QgsPoint savePoint; //point in layer coordinates
bool isMatchPointZ = false;
bool isMatchPointM = false;
try
{
QgsPoint fetchPoint;
int res;
res = fetchLayerPoint( e->mapPointMatch(), fetchPoint );
if ( QgsWkbTypes::hasZ( fetchPoint.wkbType() ) )
isMatchPointZ = true;
isMatchPointZ = QgsWkbTypes::hasZ( fetchPoint.wkbType() );
isMatchPointM = QgsWkbTypes::hasM( fetchPoint.wkbType() );

if ( res == 0 )
{
if ( isMatchPointZ )
savePoint = fetchPoint;
else
savePoint = QgsPoint( fetchPoint.x(), fetchPoint.y() );
savePoint = QgsPoint( layerWKBType, fetchPoint.x(), fetchPoint.y(), fetchPoint.z(), fetchPoint.m() );
}
else
{
const QgsPointXY layerPoint = toLayerCoordinates( vlayer, e->mapPoint() );
if ( isMatchPointZ )
savePoint = QgsPoint( QgsWkbTypes::PointZ, layerPoint.x(), layerPoint.y(), fetchPoint.z() );
else
savePoint = QgsPoint( layerPoint.x(), layerPoint.y() );
savePoint = QgsPoint( layerWKBType, layerPoint.x(), layerPoint.y(), fetchPoint.z(), fetchPoint.m() );
}
}
catch ( QgsCsException &cse )
@@ -194,33 +189,24 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QgsFeature f( vlayer->fields() );

QgsGeometry g;
if ( layerWKBType == QgsWkbTypes::Point )
{
g = QgsGeometry( std::make_unique<QgsPoint>( savePoint ) );
}
else if ( !QgsWkbTypes::isMultiType( layerWKBType ) && QgsWkbTypes::hasZ( layerWKBType ) )
{
g = QgsGeometry( std::make_unique<QgsPoint>( savePoint.x(), savePoint.y(), isMatchPointZ ? savePoint.z() : defaultZValue() ) );
}
else if ( QgsWkbTypes::isMultiType( layerWKBType ) && !QgsWkbTypes::hasZ( layerWKBType ) )
{
g = QgsGeometry::fromMultiPointXY( QgsMultiPointXY() << savePoint );
}
else if ( QgsWkbTypes::isMultiType( layerWKBType ) && QgsWkbTypes::hasZ( layerWKBType ) )
{
QgsMultiPoint *mp = new QgsMultiPoint();
mp->addGeometry( new QgsPoint( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), isMatchPointZ ? savePoint.z() : defaultZValue() ) );
g.set( mp );
}
else
const QgsPoint result( layerWKBType, savePoint.x(), savePoint.y(), isMatchPointZ ? savePoint.z() : defaultZValue(), isMatchPointM ? savePoint.m() : defaultMValue() );
if ( mCheckGeometryType == false )
{
// if layer supports more types (mCheckGeometryType is false)
g = QgsGeometry( std::make_unique<QgsPoint>( savePoint ) );
}

if ( QgsWkbTypes::hasM( layerWKBType ) )
else
{
g.get()->addMValue( defaultMValue() );
if ( !QgsWkbTypes::isMultiType( layerWKBType ) )
{
g = QgsGeometry( std::make_unique<QgsPoint>( result ) );
}
else
{
QgsMultiPoint *mp = new QgsMultiPoint();
mp->addGeometry( new QgsPoint( result ) );
g.set( mp );
}
}

f.setGeometry( g );
@@ -35,7 +35,7 @@ bool operator==( const QgsGeometry &g1, const QgsGeometry &g2 )
if ( g1.isNull() && g2.isNull() )
return true;
else
return g1.isGeosEqual( g2 );
return g1.equals( g2 );
}

namespace QTest
@@ -627,7 +627,7 @@ void TestQgsMapToolAddFeatureLine::testLineString()

const QgsFeatureId newFid = utils.newFeatureId( oldFids );

const QString wkt = "LineStringZ (5 6.5 5, 6.25 6.5 333, 6.75 6.5 333, 7.25 6.5 333, 7.5 6.5 333)";
const QString wkt = "LineString (5 6.5, 6.25 6.5, 6.75 6.5, 7.25 6.5, 7.5 6.5)";
QCOMPARE( mLayerLine->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLine->undoStack()->undo();
@@ -663,7 +663,7 @@ void TestQgsMapToolAddFeatureLine::testCompoundCurve()

const QgsFeatureId newFid = utils.newFeatureId( oldFids );

const QString wkt = "CompoundCurve ((5 6.5, 6.25 6.5),CircularString (6.25 6.5, 6.75 6.5, 7.25 6.5),(7.25 6.5, 7.5 6.5),(7.5 6.5, 7.5 6),(7.5 6, 7.703125 6))";
const QString wkt = "CompoundCurve ((5 6.5, 6.25 6.5),CircularString (6.25 6.5, 6.75 6.5, 7.25 6.5),(7.25 6.5, 7.5 6.5, 7.5 6, 7.703125 6))";
QCOMPARE( mLayerLineCurved->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLineCurved->undoStack()->undo();
@@ -36,7 +36,7 @@ bool operator==( const QgsGeometry &g1, const QgsGeometry &g2 )
if ( g1.isNull() && g2.isNull() )
return true;
else
return g1.isGeosEqual( g2 );
return g1.equals( g2 );
}

namespace QTest
@@ -244,9 +244,9 @@ void TestQgsMapToolAddFeatureLineM::testTopologicalEditingM()
utils.mouseClick( 8, 6.5, Qt::RightButton );
const QgsFeatureId newFid = utils.newFeatureId( oldFids );

QString wkt = "LineStringM (6 6.5 5, 6.25 6.5 333, 6.75 6.5 333, 7.25 6.5 333, 7.5 6.5 333)";
QString wkt = "LineStringM (6 6.5 333, 6.25 6.5 333, 6.75 6.5 333, 7.25 6.5 333, 7.5 6.5 333)";
QCOMPARE( mLayerTopoM->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );
wkt = "MultiLineStringM ((7.25 6 0, 7.25 6.5 333, 7.25 7 0, 7.5 7 0, 7.5 6.5 333, 7.5 6 0, 7.25 6 0),(6 6 0, 6 6.5 5, 6 7 10, 7 7 0, 7 6 0, 6 6 0),(6.25 6.25 0, 6.75 6.25 0, 6.75 6.5 333, 6.75 6.75 0, 6.25 6.75 0, 6.25 6.5 333, 6.25 6.25 0))";
wkt = "MultiLineStringM ((7.25 6 0, 7.25 6.5 333, 7.25 7 0, 7.5 7 0, 7.5 6.5 333, 7.5 6 0, 7.25 6 0),(6 6 0, 6 6.5 333, 6 7 10, 7 7 0, 7 6 0, 6 6 0),(6.25 6.25 0, 6.75 6.25 0, 6.75 6.5 333, 6.75 6.75 0, 6.25 6.75 0, 6.25 6.5 333, 6.25 6.25 0))";
QCOMPARE( mLayerTopoM->getFeature( qgis::setToList( oldFids ).last() ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLine->undoStack()->undo();
@@ -36,7 +36,7 @@ bool operator==( const QgsGeometry &g1, const QgsGeometry &g2 )
if ( g1.isNull() && g2.isNull() )
return true;
else
return g1.isGeosEqual( g2 );
return g1.equals( g2 );
}

namespace QTest
@@ -245,9 +245,9 @@ void TestQgsMapToolAddFeatureLineZ::testTopologicalEditingZ()
utils.mouseClick( 8, 6.5, Qt::RightButton );
const QgsFeatureId newFid = utils.newFeatureId( oldFids );

QString wkt = "LineStringZ (6 6.5 5, 6.25 6.5 333, 6.75 6.5 333, 7.25 6.5 333, 7.5 6.5 333)";
QString wkt = "LineStringZ (6 6.5 333, 6.25 6.5 333, 6.75 6.5 333, 7.25 6.5 333, 7.5 6.5 333)";
QCOMPARE( mLayerTopoZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );
wkt = "MultiLineStringZ ((7.25 6 0, 7.25 6.5 333, 7.25 7 0, 7.5 7 0, 7.5 6.5 333, 7.5 6 0, 7.25 6 0),(6 6 0, 6 6.5 5, 6 7 10, 7 7 0, 7 6 0, 6 6 0),(6.25 6.25 0, 6.75 6.25 0, 6.75 6.5 333, 6.75 6.75 0, 6.25 6.75 0, 6.25 6.5 333, 6.25 6.25 0))";
wkt = "MultiLineStringZ ((7.25 6 0, 7.25 6.5 333, 7.25 7 0, 7.5 7 0, 7.5 6.5 333, 7.5 6 0, 7.25 6 0),(6 6 0, 6 6.5 333, 6 7 10, 7 7 0, 7 6 0, 6 6 0),(6.25 6.25 0, 6.75 6.25 0, 6.75 6.5 333, 6.75 6.75 0, 6.25 6.75 0, 6.25 6.5 333, 6.25 6.25 0))";
QCOMPARE( mLayerTopoZ->getFeature( qgis::setToList( oldFids ).last() ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLine->undoStack()->undo();
@@ -326,7 +326,7 @@ void TestQgsMapToolAddFeatureLineZ::testZSnapping()
newFid = utils.newFeatureId( oldFids );

QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry().get()->is3D(), true );
wkt = "LineStringZ (25 20 123, 25 25 321)";
wkt = "LineStringZ (25 20 321, 25 25 321)";
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLineZ->undoStack()->undo();
@@ -36,7 +36,7 @@ bool operator==( const QgsGeometry &g1, const QgsGeometry &g2 )
if ( g1.isNull() && g2.isNull() )
return true;
else
return g1.isGeosEqual( g2 );
return g1.equals( g2 );
}

namespace QTest

0 comments on commit cab7e8c

Please sign in to comment.