Skip to content
Permalink
Browse files

[bugfix] Do not add binding line in both side in reshape map tool

  • Loading branch information
pblottiere committed Dec 14, 2017
1 parent 2ef6a82 commit 49dfe3d0dda363b517bf6675ad287a1fc3ad317c
Showing with 110 additions and 53 deletions.
  1. +103 −51 src/app/qgsmaptoolreshape.cpp
  2. +5 −0 src/app/qgsmaptoolreshape.h
  3. +1 −1 src/gui/qgsmaptoolcapture.cpp
  4. +1 −1 src/gui/qgsmaptoolcapture.h
@@ -75,70 +75,122 @@ void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
stopCapturing();
return;
}
QgsPoint firstPoint = points().at( 0 );
QgsRectangle bbox( firstPoint.x(), firstPoint.y(), firstPoint.x(), firstPoint.y() );
for ( int i = 1; i < size(); ++i )
{
bbox.combineExtentWith( points().at( i ).x(), points().at( i ).y() );
}

//query all the features that intersect bounding box of capture line
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( bbox ).setSubsetOfAttributes( QgsAttributeList() ) );
QgsFeature f;
int reshapeReturn;
bool reshapeDone = false;
reshape( vlayer );

stopCapturing();
}
}

void QgsMapToolReshape::reshape( QgsVectorLayer *vlayer )
{
std::cout << "QgsMapToolReshape::reshape 0" << std::endl;
if ( !vlayer )
return;

QgsPoint firstPoint = points().at( 0 );
QgsRectangle bbox( firstPoint.x(), firstPoint.y(), firstPoint.x(), firstPoint.y() );
for ( int i = 1; i < size(); ++i )
{
bbox.combineExtentWith( points().at( i ).x(), points().at( i ).y() );
}

vlayer->beginEditCommand( tr( "Reshape" ) );
while ( fit.nextFeature( f ) )
//query all the features that intersect bounding box of capture line
std::cout << "QgsMapToolReshape::reshape 1" << std::endl;
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( bbox ).setSubsetOfAttributes( QgsAttributeList() ) );
QgsFeature f;
int reshapeReturn;
bool reshapeDone = false;
bool isBinding = isBindingLine( vlayer, bbox );

vlayer->beginEditCommand( tr( "Reshape" ) );
std::cout << "QgsMapToolReshape::reshape 2" << std::endl;
while ( fit.nextFeature( f ) )
{
std::cout << "QgsMapToolReshape::reshape 3" << std::endl;
//query geometry
//call geometry->reshape(mCaptureList)
//register changed geometry in vector layer
QgsGeometry* geom = f.geometry();
if ( geom )
{
//query geometry
//call geometry->reshape(mCaptureList)
//register changed geometry in vector layer
QgsGeometry* geom = f.geometry();
if ( geom )
std::cout << "QgsMapToolReshape::reshape 4" << std::endl;
// in case of a binding line, we just want to update the line from
// the starting point and not both side
if ( isBinding && !geom->asPolyline().contains( points().first() ) )
continue;

std::cout << "QgsMapToolReshape::reshape 5" << std::endl;
reshapeReturn = geom->reshapeGeometry( pointsV2() );
if ( reshapeReturn == 0 )
{
reshapeReturn = geom->reshapeGeometry( pointsV2() );
if ( reshapeReturn == 0 )
//avoid intersections on polygon layers
if ( vlayer->geometryType() == QGis::Polygon )
{
//avoid intersections on polygon layers
if ( vlayer->geometryType() == QGis::Polygon )
//ignore all current layer features as they should be reshaped too
QMap<QgsVectorLayer*, QSet<QgsFeatureId> > ignoreFeatures;
ignoreFeatures.insert( vlayer, vlayer->allFeatureIds() );

if ( geom->avoidIntersections( ignoreFeatures ) != 0 )
{
//ignore all current layer features as they should be reshaped too
QMap<QgsVectorLayer*, QSet<QgsFeatureId> > ignoreFeatures;
ignoreFeatures.insert( vlayer, vlayer->allFeatureIds() );

if ( geom->avoidIntersections( ignoreFeatures ) != 0 )
{
emit messageEmitted( tr( "An error was reported during intersection removal" ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
stopCapturing();
return;
}

if ( geom->isGeosEmpty() ) //intersection removal might have removed the whole geometry
{
emit messageEmitted( tr( "The feature cannot be reshaped because the resulting geometry is empty" ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
stopCapturing();
return;
}
emit messageEmitted( tr( "An error was reported during intersection removal" ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
stopCapturing();
return;
}

vlayer->changeGeometry( f.id(), geom );
reshapeDone = true;
if ( geom->isGeosEmpty() ) //intersection removal might have removed the whole geometry
{
emit messageEmitted( tr( "The feature cannot be reshaped because the resulting geometry is empty" ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
stopCapturing();
return;
}
}

vlayer->changeGeometry( f.id(), geom );
reshapeDone = true;
}
}
}

if ( reshapeDone )
{
vlayer->endEditCommand();
}
else
if ( reshapeDone )
{
vlayer->endEditCommand();
}
else
{
vlayer->destroyEditCommand();
}
}

bool QgsMapToolReshape::isBindingLine( QgsVectorLayer *vlayer, const QgsRectangle &bbox ) const
{
if ( vlayer->geometryType() != QGis::Line )
return false;

bool begin = false;
bool end = false;
const QgsPoint beginPoint = points().first();
const QgsPoint endPoint = points().last();

QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( bbox ).setSubsetOfAttributes( QgsAttributeList() ) );
QgsFeature f;

// check that extremities of the new line are contained by features
while ( fit.nextFeature( f ) )
{
const QgsGeometry *geom = f.geometry();
if ( geom )
{
vlayer->destroyEditCommand();
}
const QgsPolyline line = geom->asPolyline();

stopCapturing();
if ( line.contains( beginPoint ) )
begin = true;
else if ( line.contains( endPoint ) )
end = true;
}
}

return end && begin;
}
@@ -28,6 +28,11 @@ class APP_EXPORT QgsMapToolReshape: public QgsMapToolCapture
QgsMapToolReshape( QgsMapCanvas* canvas );
virtual ~QgsMapToolReshape();
void cadCanvasReleaseEvent( QgsMapMouseEvent * e ) override;

private:
void reshape( QgsVectorLayer *vlayer );

bool isBindingLine( QgsVectorLayer *vlayer, const QgsRectangle &bbox ) const;
};

#endif
@@ -713,7 +713,7 @@ int QgsMapToolCapture::size()
return mCaptureCurve.numPoints();
}

QList<QgsPoint> QgsMapToolCapture::points()
QList<QgsPoint> QgsMapToolCapture::points() const
{
QgsPointSequenceV2 pts;
QList<QgsPoint> points;
@@ -192,7 +192,7 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
* List of digitized points
* @return List of points
*/
QList<QgsPoint> points();
QList<QgsPoint> points() const;

/**
* List of digitized points with z support

0 comments on commit 49dfe3d

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