mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Support also curved geometries for tracing (fixes #15109)
This commit is contained in:
parent
5f6627624e
commit
bf07d2bf58
@ -408,6 +408,20 @@ void resetGraph( QgsTracerGraph& g )
|
||||
|
||||
void extractLinework( const QgsGeometry* g, QgsMultiPolyline& mpl )
|
||||
{
|
||||
// segmentize curved geometries - we will use noding algorithm from GEOS
|
||||
// to find all intersections a bit later (so we need them segmentized anyway)
|
||||
QScopedPointer<QgsGeometry> segmentizedGeom;
|
||||
if ( QgsWKBTypes::isCurvedType( g->geometry()->wkbType() ) )
|
||||
{
|
||||
QgsAbstractGeometryV2* segmentizedGeomV2 = g->geometry()->segmentize();
|
||||
if ( !segmentizedGeomV2 )
|
||||
return;
|
||||
|
||||
// temporarily replace the original geometry by our segmentized one
|
||||
segmentizedGeom.reset( new QgsGeometry( segmentizedGeomV2 ) );
|
||||
g = segmentizedGeom.data();
|
||||
}
|
||||
|
||||
switch ( QgsWKBTypes::flatType( g->geometry()->wkbType() ) )
|
||||
{
|
||||
case QgsWKBTypes::LineString:
|
||||
|
@ -34,6 +34,7 @@ class TestQgsTracer : public QObject
|
||||
void testLayerUpdates();
|
||||
void testExtent();
|
||||
void testReprojection();
|
||||
void testCurved();
|
||||
|
||||
private:
|
||||
|
||||
@ -319,6 +320,40 @@ void TestQgsTracer::testReprojection()
|
||||
QCOMPARE( points1.count(), 2 );
|
||||
}
|
||||
|
||||
void TestQgsTracer::testCurved()
|
||||
{
|
||||
QStringList wkts;
|
||||
wkts << "CIRCULARSTRING(0 0, 10 10, 20 0)";
|
||||
|
||||
/* This shape - half of a circle (r = 10)
|
||||
* 10,10 _
|
||||
* / \
|
||||
* 0,0 | | 20,0
|
||||
*/
|
||||
|
||||
QgsVectorLayer* vl = make_layer( wkts );
|
||||
|
||||
QgsTracer tracer;
|
||||
tracer.setLayers( QList<QgsVectorLayer*>() << vl );
|
||||
|
||||
QgsPolyline points1 = tracer.findShortestPath( QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) );
|
||||
|
||||
QVERIFY( points1.count() != 0 );
|
||||
|
||||
QgsGeometry* tmpG1 = QgsGeometry::fromPolyline( points1 );
|
||||
double l = tmpG1->length();
|
||||
delete tmpG1;
|
||||
|
||||
// fuzzy comparison of QCOMPARE is too strict for this case
|
||||
double full_circle_length = 2 * M_PI * 10;
|
||||
QVERIFY( qAbs( l - full_circle_length / 4 ) < 0.01 );
|
||||
|
||||
QCOMPARE( points1[0], QgsPoint( 0, 0 ) );
|
||||
QCOMPARE( points1[points1.count()-1], QgsPoint( 10, 10 ) );
|
||||
|
||||
delete vl;
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN( TestQgsTracer )
|
||||
#include "testqgstracer.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user