-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE]: maptool for parallel line displacement
- Loading branch information
Showing
7 changed files
with
178 additions
and
2 deletions.
There are no files selected for viewing
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,105 @@ | ||
/*************************************************************************** | ||
qgsmaptooloffsetcurve.cpp | ||
------------------------------------------------------------ | ||
begin : February 2012 | ||
copyright : (C) 2012 by Marco Hugentobler | ||
email : marco dot hugentobler at sourcepole 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsmaptooloffsetcurve.h" | ||
#include "qgsrubberband.h" | ||
#include "qgsvectorlayer.h" | ||
#include <QMouseEvent> | ||
|
||
QgsMapToolOffsetCurve::QgsMapToolOffsetCurve( QgsMapCanvas* canvas ): QgsMapToolEdit( canvas ), mRubberBand( 0 ), mGeometry( 0 ) | ||
{ | ||
} | ||
|
||
QgsMapToolOffsetCurve::~QgsMapToolOffsetCurve() | ||
{ | ||
deleteRubberBandAndGeometry(); | ||
} | ||
|
||
void QgsMapToolOffsetCurve::canvasPressEvent( QMouseEvent * e ) | ||
{ | ||
deleteRubberBandAndGeometry(); | ||
|
||
//get selected features or snap to nearest feature if no selection | ||
QgsVectorLayer* layer = currentVectorLayer(); | ||
if ( !layer ) | ||
{ | ||
return; | ||
} | ||
|
||
//selection or take closest feature | ||
//QgsPoint layerCoords = toLayerCoordinates( layer, e->pos() ); | ||
|
||
//optionally merge the features together | ||
|
||
//create rubberband from feature(s) | ||
|
||
//for now, just take the first selected feature | ||
QgsFeatureList selectedFeatures = layer->selectedFeatures(); | ||
if ( selectedFeatures.size() > 0 ) | ||
{ | ||
mGeometry = selectedFeatures[0].geometryAndOwnership(); | ||
mRubberBand = createRubberBand(); | ||
mRubberBand->setToGeometry( mGeometry, layer ); | ||
} | ||
} | ||
|
||
void QgsMapToolOffsetCurve::canvasReleaseEvent( QMouseEvent * e ) | ||
{ | ||
deleteRubberBandAndGeometry(); | ||
} | ||
|
||
void QgsMapToolOffsetCurve::canvasMoveEvent( QMouseEvent * e ) | ||
{ | ||
if ( !mGeometry || !mRubberBand ) | ||
{ | ||
return; | ||
} | ||
|
||
QgsVectorLayer* layer = currentVectorLayer(); | ||
if ( !layer ) | ||
{ | ||
return; | ||
} | ||
|
||
//get offset from current position rectangular to feature | ||
QgsPoint layerCoords = toLayerCoordinates( layer, e->pos() ); | ||
QgsPoint minDistPoint; | ||
int beforeVertex; | ||
double offset = sqrt( mGeometry->closestSegmentWithContext( layerCoords, minDistPoint, beforeVertex ) ); | ||
qWarning( QString::number( offset ).toLocal8Bit().data() ); | ||
|
||
//create offset geometry using geos | ||
QgsGeometry geomCopy( *mGeometry ); | ||
GEOSGeometry* geosGeom = geomCopy.asGeos(); | ||
if ( geosGeom ) | ||
{ | ||
//GEOSGeometry* offsetGeom = GEOSOffsetCurve( geosGeom, offset, 8, 1, 1 ); | ||
GEOSGeometry* offsetGeom = GEOSSingleSidedBuffer( geosGeom, offset, 8, 1, 1, 0 ); | ||
if ( offsetGeom ) | ||
{ | ||
QgsGeometry rubberBandGeometry; | ||
rubberBandGeometry.fromGeos( offsetGeom ); | ||
mRubberBand->setToGeometry( &rubberBandGeometry, layer ); | ||
} | ||
} | ||
} | ||
|
||
void QgsMapToolOffsetCurve::deleteRubberBandAndGeometry() | ||
{ | ||
delete mRubberBand; | ||
mRubberBand = 0; | ||
delete mGeometry; | ||
mGeometry = 0; | ||
} |
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,42 @@ | ||
/*************************************************************************** | ||
qgsmaptooloffsetcurve.h | ||
------------------------------------------------------------ | ||
begin : February 2012 | ||
copyright : (C) 2012 by Marco Hugentobler | ||
email : marco dot hugentobler at sourcepole 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSMAPTOOLOFFSETCURVE_H | ||
#define QGSMAPTOOLOFFSETCURVE_H | ||
|
||
#include "qgsmaptooledit.h" | ||
class QgsGeometry; | ||
|
||
class QgsMapToolOffsetCurve: public QgsMapToolEdit | ||
{ | ||
public: | ||
QgsMapToolOffsetCurve( QgsMapCanvas* canvas ); | ||
~QgsMapToolOffsetCurve(); | ||
|
||
void canvasPressEvent( QMouseEvent * e ); | ||
void canvasReleaseEvent( QMouseEvent * e ); | ||
void canvasMoveEvent( QMouseEvent * e ); | ||
|
||
private: | ||
|
||
/**Rubberband that shows the position of the offset curve*/ | ||
QgsRubberBand* mRubberBand; | ||
/**Geometry to manipulate*/ | ||
QgsGeometry* mGeometry; | ||
|
||
void deleteRubberBandAndGeometry(); | ||
}; | ||
|
||
#endif // QGSMAPTOOLOFFSETCURVE_H |
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