@@ -1205,35 +1205,29 @@ std::unique_ptr<QgsLineString> QgsGeos::sequenceToLinestring( const GEOSGeometry
1205
1205
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r ( geosinit.ctxt , geos );
1206
1206
unsigned int nPoints;
1207
1207
GEOSCoordSeq_getSize_r ( geosinit.ctxt , cs, &nPoints );
1208
- QVector< double > xOut;
1209
- xOut.reserve ( nPoints );
1210
- QVector< double > yOut;
1211
- yOut.reserve ( nPoints );
1208
+ QVector< double > xOut ( nPoints );
1209
+ QVector< double > yOut ( nPoints );
1212
1210
QVector< double > zOut;
1213
1211
if ( hasZ )
1214
- zOut.reserve ( nPoints );
1212
+ zOut.resize ( nPoints );
1215
1213
QVector< double > mOut ;
1216
1214
if ( hasM )
1217
- mOut .reserve ( nPoints );
1218
- double x = 0 ;
1219
- double y = 0 ;
1220
- double z = 0 ;
1221
- double m = 0 ;
1215
+ mOut .resize ( nPoints );
1216
+ double * x = xOut. data () ;
1217
+ double * y = yOut. data () ;
1218
+ double * z = zOut. data () ;
1219
+ double * m = mOut . data () ;
1222
1220
for ( unsigned int i = 0 ; i < nPoints; ++i )
1223
1221
{
1224
- GEOSCoordSeq_getX_r ( geosinit.ctxt , cs, i, &x );
1225
- xOut << x;
1226
- GEOSCoordSeq_getY_r ( geosinit.ctxt , cs, i, &y );
1227
- yOut << y;
1222
+ GEOSCoordSeq_getX_r ( geosinit.ctxt , cs, i, x++ );
1223
+ GEOSCoordSeq_getY_r ( geosinit.ctxt , cs, i, y++ );
1228
1224
if ( hasZ )
1229
1225
{
1230
- GEOSCoordSeq_getZ_r ( geosinit.ctxt , cs, i, &z );
1231
- zOut << z;
1226
+ GEOSCoordSeq_getZ_r ( geosinit.ctxt , cs, i, z++ );
1232
1227
}
1233
1228
if ( hasM )
1234
1229
{
1235
- GEOSCoordSeq_getOrdinate_r ( geosinit.ctxt , cs, i, 3 , &m );
1236
- mOut << m;
1230
+ GEOSCoordSeq_getOrdinate_r ( geosinit.ctxt , cs, i, 3 , m++ );
1237
1231
}
1238
1232
}
1239
1233
std::unique_ptr< QgsLineString > line ( new QgsLineString ( xOut, yOut, zOut, mOut ) );
@@ -1769,35 +1763,57 @@ GEOSCoordSequence *QgsGeos::createCoordinateSequence( const QgsCurve *curve, dou
1769
1763
QgsDebugMsg ( QStringLiteral ( " GEOS Exception: Could not create coordinate sequence for %1 points in %2 dimensions" ).arg ( numPoints ).arg ( coordDims ) );
1770
1764
return nullptr ;
1771
1765
}
1766
+
1767
+ const double *xData = line->xData ();
1768
+ const double *yData = line->yData ();
1769
+ const double *zData = hasZ ? line->zData () : nullptr ;
1770
+ const double *mData = hasM ? line->mData () : nullptr ;
1771
+
1772
1772
if ( precision > 0 . )
1773
1773
{
1774
1774
for ( int i = 0 ; i < numOutPoints; ++i )
1775
1775
{
1776
- GEOSCoordSeq_setX_r ( geosinit.ctxt , coordSeq, i, std::round ( line->xAt ( i % numPoints ) / precision ) * precision );
1777
- GEOSCoordSeq_setY_r ( geosinit.ctxt , coordSeq, i, std::round ( line->yAt ( i % numPoints ) / precision ) * precision );
1776
+ if ( i >= numPoints )
1777
+ {
1778
+ // start reading back from start of line
1779
+ xData = line->xData ();
1780
+ yData = line->yData ();
1781
+ zData = hasZ ? line->zData () : nullptr ;
1782
+ mData = hasM ? line->mData () : nullptr ;
1783
+ }
1784
+ GEOSCoordSeq_setX_r ( geosinit.ctxt , coordSeq, i, std::round ( *xData++ / precision ) * precision );
1785
+ GEOSCoordSeq_setY_r ( geosinit.ctxt , coordSeq, i, std::round ( *yData++ / precision ) * precision );
1778
1786
if ( hasZ )
1779
1787
{
1780
- GEOSCoordSeq_setOrdinate_r ( geosinit.ctxt , coordSeq, i, 2 , std::round ( line-> zAt ( i % numPoints ) / precision ) * precision );
1788
+ GEOSCoordSeq_setOrdinate_r ( geosinit.ctxt , coordSeq, i, 2 , std::round ( *zData++ / precision ) * precision );
1781
1789
}
1782
1790
if ( hasM )
1783
1791
{
1784
- GEOSCoordSeq_setOrdinate_r ( geosinit.ctxt , coordSeq, i, 3 , line->mAt ( i % numPoints ) );
1792
+ GEOSCoordSeq_setOrdinate_r ( geosinit.ctxt , coordSeq, i, 3 , line->mAt ( * mData ++ ) );
1785
1793
}
1786
1794
}
1787
1795
}
1788
1796
else
1789
1797
{
1790
1798
for ( int i = 0 ; i < numOutPoints; ++i )
1791
1799
{
1792
- GEOSCoordSeq_setX_r ( geosinit.ctxt , coordSeq, i, line->xAt ( i % numPoints ) );
1793
- GEOSCoordSeq_setY_r ( geosinit.ctxt , coordSeq, i, line->yAt ( i % numPoints ) );
1800
+ if ( i >= numPoints )
1801
+ {
1802
+ // start reading back from start of line
1803
+ xData = line->xData ();
1804
+ yData = line->yData ();
1805
+ zData = hasZ ? line->zData () : nullptr ;
1806
+ mData = hasM ? line->mData () : nullptr ;
1807
+ }
1808
+ GEOSCoordSeq_setX_r ( geosinit.ctxt , coordSeq, i, *xData++ );
1809
+ GEOSCoordSeq_setY_r ( geosinit.ctxt , coordSeq, i, *yData++ );
1794
1810
if ( hasZ )
1795
1811
{
1796
- GEOSCoordSeq_setOrdinate_r ( geosinit.ctxt , coordSeq, i, 2 , line-> zAt ( i % numPoints ) );
1812
+ GEOSCoordSeq_setOrdinate_r ( geosinit.ctxt , coordSeq, i, 2 , *zData++ );
1797
1813
}
1798
1814
if ( hasM )
1799
1815
{
1800
- GEOSCoordSeq_setOrdinate_r ( geosinit.ctxt , coordSeq, i, 3 , line-> mAt ( i % numPoints ) );
1816
+ GEOSCoordSeq_setOrdinate_r ( geosinit.ctxt , coordSeq, i, 3 , * mData ++ );
1801
1817
}
1802
1818
}
1803
1819
}
0 commit comments