-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] A reshape tool to apply to line/polygon geometries. The par…
…t of a geometry between the first and last intersection of the reshape line will be replaced git-svn-id: http://svn.osgeo.org/qgis/trunk@11500 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
mhugent
committed
Aug 25, 2009
1 parent
61604a3
commit 20591ba
Showing
9 changed files
with
719 additions
and
24 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/*************************************************************************** | ||
qgsmaptoolreshape.cpp | ||
--------------------------- | ||
begin : Juli 2009 | ||
copyright : (C) 2009 by Marco Hugentobler | ||
email : marco dot hugentobler at karto dot baug dot ethz dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
/* $Id$ */ | ||
|
||
#include "qgsmaptoolreshape.h" | ||
#include "qgsgeometry.h" | ||
#include "qgsmapcanvas.h" | ||
#include "qgsrubberband.h" | ||
#include "qgsvectorlayer.h" | ||
#include <QMessageBox> | ||
#include <QMouseEvent> | ||
|
||
QgsMapToolReshape::QgsMapToolReshape( QgsMapCanvas* canvas ): QgsMapToolCapture( canvas, QgsMapToolCapture::CaptureLine ) | ||
{ | ||
|
||
} | ||
|
||
QgsMapToolReshape::~QgsMapToolReshape() | ||
{ | ||
|
||
} | ||
|
||
void QgsMapToolReshape::canvasReleaseEvent( QMouseEvent * e ) | ||
{ | ||
//check if we operate on a vector layer //todo: move this to a function in parent class to avoid duplication | ||
QgsVectorLayer *vlayer = dynamic_cast <QgsVectorLayer*>( mCanvas->currentLayer() ); | ||
|
||
if ( !vlayer ) | ||
{ | ||
QMessageBox::information( 0, tr( "Not a vector layer" ), | ||
tr( "The current layer is not a vector layer" ) ); | ||
return; | ||
} | ||
|
||
if ( !vlayer->isEditable() ) | ||
{ | ||
QMessageBox::information( 0, tr( "Layer not editable" ), | ||
tr( "Cannot edit the vector layer. To make it editable, go to the file item " | ||
"of the layer, right click and check 'Allow Editing'." ) ); | ||
return; | ||
} | ||
|
||
//add point to list and to rubber band | ||
int error = addVertex( e->pos() ); | ||
if ( error == 1 ) | ||
{ | ||
//current layer is not a vector layer | ||
return; | ||
} | ||
else if ( error == 2 ) | ||
{ | ||
//problem with coordinate transformation | ||
QMessageBox::information( 0, tr( "Coordinate transform error" ), | ||
tr( "Cannot transform the point to the layers coordinate system" ) ); | ||
return; | ||
} | ||
|
||
if ( e->button() == Qt::LeftButton ) | ||
{ | ||
mCapturing = TRUE; | ||
} | ||
else if ( e->button() == Qt::RightButton ) | ||
{ | ||
mCapturing = FALSE; | ||
delete mRubberBand; | ||
mRubberBand = 0; | ||
|
||
//find out bounding box of mCaptureList | ||
if(mCaptureList.size() < 1) | ||
{ | ||
return; | ||
} | ||
QgsPoint firstPoint = mCaptureList.at(0); | ||
QgsRectangle bbox(firstPoint.x(), firstPoint.y(), firstPoint.x(), firstPoint.y()); | ||
for(int i = 1; i < mCaptureList.size(); ++i) | ||
{ | ||
bbox.combineExtentWith(mCaptureList.at(i).x(), mCaptureList.at(i).y()); | ||
} | ||
|
||
//query all the features that intersect bounding box of capture line | ||
vlayer->select(QgsAttributeList(), bbox, true, false); | ||
QgsFeature f; | ||
int reshapeReturn; | ||
bool reshapeDone = false; | ||
|
||
vlayer->beginEditCommand( tr( "Reshape" ) ); | ||
while(vlayer->nextFeature(f)) | ||
{ | ||
//query geometry | ||
//call geometry->reshape(mCaptureList) | ||
//register changed geometry in vector layer | ||
QgsGeometry* geom = f.geometry(); | ||
if(geom) | ||
{ | ||
reshapeReturn = geom->reshapeGeometry(mCaptureList); | ||
if(reshapeReturn == 0) | ||
{ | ||
vlayer->changeGeometry(f.id(), geom); | ||
reshapeDone = true; | ||
} | ||
} | ||
} | ||
|
||
if(reshapeDone) | ||
{ | ||
vlayer->endEditCommand(); | ||
} | ||
else | ||
{ | ||
vlayer->destroyEditCommand(); | ||
} | ||
|
||
mCaptureList.clear(); | ||
mCanvas->refresh(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*************************************************************************** | ||
qgsmaptoolreshape.h | ||
--------------------- | ||
begin : Juli 2009 | ||
copyright : (C) 2009 by Marco Hugentobler | ||
email : marco.hugentobler at karto dot baug dot ethz dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
/* $Id$ */ | ||
|
||
#ifndef QGSMAPTOOLRESHAPE_H | ||
#define QGSMAPTOOLRESHAPE_H | ||
|
||
#include "qgsmaptoolcapture.h" | ||
|
||
/**A map tool that draws a line and splits the features cut by the line*/ | ||
class QgsMapToolReshape: public QgsMapToolCapture | ||
{ | ||
public: | ||
QgsMapToolReshape( QgsMapCanvas* canvas ); | ||
virtual ~QgsMapToolReshape(); | ||
void canvasReleaseEvent( QMouseEvent * e ); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.