Skip to content

Commit

Permalink
[FEATURE][tracing curves] Trace tools generates curved geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdalang committed May 12, 2020
1 parent ab423ca commit 350a495
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/gui/qgsmaptoolcapture.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
* * * *
***************************************************************************/ ***************************************************************************/


#include "qgsmaptoolcapture.h" #include <ogr_api.h>
#include <ogr_geometry.h>


#include "qgsmaptoolcapture.h"
#include "qgsexception.h" #include "qgsexception.h"
#include "qgsfeatureiterator.h" #include "qgsfeatureiterator.h"
#include "qgsgeometryvalidator.h" #include "qgsgeometryvalidator.h"
Expand Down Expand Up @@ -289,10 +291,40 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
mSnappingMatches.append( QgsPointLocator::Match() ); mSnappingMatches.append( QgsPointLocator::Match() );
} }


// If the layer supports curves, we de-approximate curves
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( vlayer->dataProvider()->capabilities().testFlag( QgsVectorDataProvider::Capability::CircularGeometries ) )
{
// We convert the capture curve to OGR geometry
OGRGeometry *ogrCaptureCurve;
OGRGeometryFactory::createFromWkt( mCaptureCurve.asWkt().toLocal8Bit().data(), nullptr, &ogrCaptureCurve );

// We de-approximate the curves using OGR (the geometry must be forced to linear first, as a mCaptureCurve is a CompoundCurve)
OGRGeometry *ogrLinestring = ogrCaptureCurve->getLinearGeometry(); // it must be forced to linear, as captuecurve is a compound curve
OGRGeometry *ogrRecurved = ogrLinestring->getCurveGeometry();

// We save back to mCaptureCurve
mCaptureCurve.clear();
mCaptureCurve.fromWkt( QString::fromStdString( ogrRecurved->exportToWkt() ) );
}

tracer->reportError( QgsTracer::ErrNone, true ); // clear messagebar if there was any error tracer->reportError( QgsTracer::ErrNone, true ); // clear messagebar if there was any error
return true; return true;
} }


// Required to avoid this (took values from https://github.com/OSGeo/gdal/blob/master/gdal/ogr/ogrgeometry.cpp):
// qgsmaptoolcapture.cpp.obj : error LNK2019: unresolved external symbol "private: static int __cdecl OGRWktOptions::getDefaultPrecision(void)" (?getDefaultPrecision@OGRWktOptions@@CAHXZ) referenced in function "public: __cdecl OGRWktOptions::OGRWktOptions(void)" (??0OGRWktOptions@@QEAA@XZ)
// qgsmaptoolcapture.cpp.obj : error LNK2019: unresolved external symbol "private: static bool __cdecl OGRWktOptions::getDefaultRound(void)" (?getDefaultRound@OGRWktOptions@@CA_NXZ) referenced in function "public: __cdecl OGRWktOptions::OGRWktOptions(void)" (??0OGRWktOptions@@QEAA@XZ)
// output\bin\qgis_gui.dll : fatal error LNK1120: 2 unresolved externals
int OGRWktOptions::getDefaultPrecision( void )
{
return 15;
}
bool OGRWktOptions::getDefaultRound( void )
{
return true;
}

QgsRubberBand *QgsMapToolCapture::takeRubberBand() QgsRubberBand *QgsMapToolCapture::takeRubberBand()
{ {
return mRubberBand.release(); return mRubberBand.release();
Expand Down

0 comments on commit 350a495

Please sign in to comment.