mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-27 00:07:16 -05:00
fix QgsLineString::sumUpArea accuracy
This commit is contained in:
parent
a07fac084e
commit
b7ea6c0ff0
@ -1945,8 +1945,11 @@ void QgsLineString::sumUpArea( double &sum ) const
|
||||
|
||||
mSummedUpArea = 0;
|
||||
const int maxIndex = mX.size();
|
||||
if ( maxIndex == 0 )
|
||||
if ( maxIndex < 2 )
|
||||
{
|
||||
mHasCachedSummedUpArea = true;
|
||||
return;
|
||||
}
|
||||
|
||||
const double *x = mX.constData();
|
||||
const double *y = mY.constData();
|
||||
@ -1954,7 +1957,7 @@ void QgsLineString::sumUpArea( double &sum ) const
|
||||
double prevY = *y++;
|
||||
for ( int i = 1; i < maxIndex; ++i )
|
||||
{
|
||||
mSummedUpArea += prevX * ( *y ) - prevY * ( *x );
|
||||
mSummedUpArea += prevX * ( *y - prevY ) - prevY * ( *x - prevX );
|
||||
prevX = *x++;
|
||||
prevY = *y++;
|
||||
}
|
||||
|
||||
@ -2245,6 +2245,29 @@ void TestQgsLineString::sumUpArea()
|
||||
<< QgsPoint( 2, 2 ) << QgsPoint( 0, 2 ) );
|
||||
ls.sumUpArea( area );
|
||||
QGSCOMPARENEAR( area, -18, 4 * std::numeric_limits<double>::epsilon() );
|
||||
|
||||
double shift = 10.0;
|
||||
ls.setPoints( QgsPointSequence() << QgsPoint( shift + 0, shift + 0 ) << QgsPoint( shift + 2, shift + 0 )
|
||||
<< QgsPoint( shift + 2, shift + 2 ) << QgsPoint( shift + 0, shift + 2 )
|
||||
<< QgsPoint( shift + 0, shift + 0 ) );
|
||||
ls.sumUpArea( area );
|
||||
QGSCOMPARENEAR( area, -14, 4 * std::numeric_limits<double>::epsilon() );
|
||||
|
||||
// the length of the equator ~ 40 075.014 172 304 363 km
|
||||
shift = 40075.014172304363;
|
||||
// expected area = 4, 1% error corresponds to 0.04
|
||||
double epsilonArea = 0.04;
|
||||
// accuracyMeterPow = 3 => kilometer; accuracyMeterPow = 0 => meter; accuracyMeterPow = -3 => millimeter;
|
||||
for ( int accuracyMeterPow = 3; accuracyMeterPow >= -3; accuracyMeterPow-- )
|
||||
{
|
||||
area = accuracyMeterPow - 4.0;
|
||||
ls.setPoints( QgsPointSequence() << QgsPoint( shift + 0, shift + 0 ) << QgsPoint( shift + 2, shift + 0 )
|
||||
<< QgsPoint( shift + 2, shift + 2 ) << QgsPoint( shift + 0, shift + 2 )
|
||||
<< QgsPoint( shift + 0, shift + 0 ) );
|
||||
ls.sumUpArea( area );
|
||||
QGSCOMPARENEAR( area, accuracyMeterPow, epsilonArea );
|
||||
shift = shift * 10.0;
|
||||
}
|
||||
}
|
||||
|
||||
void TestQgsLineString::boundingBox()
|
||||
|
||||
@ -268,12 +268,12 @@ void TestQgsOverlayExpression::testOverlayMeasure_data()
|
||||
QVariantMap expected3;
|
||||
expected3.insert( QStringLiteral( "id" ), 3LL );
|
||||
expected3.insert( QStringLiteral( "result" ), 3LL );
|
||||
expected3.insert( QStringLiteral( "overlap" ), 1.4033836999701634 );
|
||||
expected3.insert( QStringLiteral( "overlap" ), 1.4033836999702842 );
|
||||
expected3 .insert( QStringLiteral( "radius" ), 0.5344336346973622 );
|
||||
QVariantMap expected1;
|
||||
expected1.insert( QStringLiteral( "id" ), 1LL );
|
||||
expected1.insert( QStringLiteral( "result" ), 1LL );
|
||||
expected1.insert( QStringLiteral( "overlap" ), 1.2281139270096446 );
|
||||
expected1.insert( QStringLiteral( "overlap" ), 1.2281139270097938 );
|
||||
expected1.insert( QStringLiteral( "radius" ), 0.46454276882989376 );
|
||||
|
||||
QTest::newRow( "intersects min_overlap multi match return measure" ) << "overlay_intersects('polys', expression:=$id, min_overlap:=1.34, return_details:=true)" << "POLYGON((-107.37 33.75, -102.76 33.75, -102.76 36.97, -107.37 36.97, -107.37 33.75))" << ( QVariantList() << expected3 ) ;
|
||||
@ -299,11 +299,11 @@ void TestQgsOverlayExpression::testOverlayMeasure_data()
|
||||
QVariantMap expected3;
|
||||
expected3.insert( QStringLiteral( "id" ), 3LL );
|
||||
expected3.insert( QStringLiteral( "result" ), 3 );
|
||||
expected3.insert( QStringLiteral( "overlap" ), 19.049688572712284 );
|
||||
expected3.insert( QStringLiteral( "overlap" ), 19.0496885727123733 );
|
||||
QVariantMap expected1;
|
||||
expected1.insert( QStringLiteral( "id" ), 1LL );
|
||||
expected1.insert( QStringLiteral( "result" ), 1 );
|
||||
expected1.insert( QStringLiteral( "overlap" ), 18.569843123334977 );
|
||||
expected1.insert( QStringLiteral( "overlap" ), 18.5698431233350831 );
|
||||
|
||||
expected3.insert( QStringLiteral( "radius" ), 1.3414663642343596 );
|
||||
expected1.insert( QStringLiteral( "radius" ), 1.8924012738149243 );
|
||||
@ -393,7 +393,7 @@ void TestQgsOverlayExpression::testOverlayMeasure_data()
|
||||
// Test polygon intersection resulting in a line with min_inscribed_circle_radius and expression
|
||||
QVariantMap expectedPoly;
|
||||
expectedPoly.insert( QStringLiteral( "id" ), 2LL );
|
||||
expectedPoly.insert( QStringLiteral( "overlap" ), 667.992431640625 );
|
||||
expectedPoly.insert( QStringLiteral( "overlap" ), 667.9924154989421368 );
|
||||
expectedPoly.insert( QStringLiteral( "radius" ), 12.576424447201404 );
|
||||
expectedPoly.insert( QStringLiteral( "result" ), 1002 );
|
||||
QTest::newRow( "intersects line expression no match" ) << "overlay_intersects('polygons2', expression:=fid, return_details:=true, min_inscribed_circle_radius:=3, sort_by_intersection_size:='desc')" << "Polygon ((2604689.01899999985471368 1231313.05799999996088445, 2604695.41300000017508864 1231337.88999999989755452, 2604704.85499999998137355 1231335.10299999988637865, 2604713.89399999985471368 1231333.42900000000372529, 2604719.80599999986588955 1231332.34700000006705523, 2604713.325999999884516 1231305.375, 2604697.20899999979883432 1231310.25600000005215406, 2604689.01899999985471368 1231313.05799999996088445))" << ( QVariantList() << expectedPoly );
|
||||
|
||||
4
tests/testdata/geom_data.csv
vendored
4
tests/testdata/geom_data.csv
vendored
@ -114,6 +114,8 @@ Polygon,,,,,,,,,,,,,,Malformed WKT
|
||||
"Polygon ((60 180, 140 120, 100 180, 140 240, 140 240, 60 180))","POLYGON((60 180,140 120,100 180,140 240,140 240,60 180))",6,0,2400,344.2220510186,1,0,0,POINT(100 180),60,120,140,240,
|
||||
"Polygon ((60 180, 140 120, 100 180, 140 240, 60 180))","POLYGON((60 180,140 120,100 180,140 240,60 180))",5,0,2400,344.2220510186,1,0,0,POINT(100 180),60,120,140,240,
|
||||
"Polygon ((60 180, 140 240, 140 240, 140 240, 200 180, 120 120, 60 180))","POLYGON((60 180,140 240,140 240,140 240,200 180,120 120,60 180))",7,0,8400,369.7056274848,1,0,0,POINT(130 180),60,120,200,240,
|
||||
"Polygon ((0.1 0.1,0.2 0.1,0.2 0.2,0.1 0.2,0.1 0.1))","POLYGON((0.1 0.1,0.2 0.1,0.2 0.2,0.1 0.2,0.1 0.1))",5,0,0.01,0.4,1,0,0,POINT(0.15 0.15),0.1,0.1,0.2,0.2,"simple polygon measuring a square decimeter"
|
||||
"Polygon ((40075014.1 40075014.1,40075014.2 40075014.1,40075014.2 40075014.2,40075014.1 40075014.2,40075014.1 40075014.1))","POLYGON((40075014.1 40075014.1,40075014.2 40075014.1,40075014.2 40075014.2,40075014.1 40075014.2,40075014.1 40075014.1))",5,0,0.01,0.4,1,0,0,POINT(40075014.15 40075014.15),40075014.1,40075014.1,40075014.2,40075014.2,"simple polygon measuring a square decimeter somewhere far away"
|
||||
"Polygon(( 0 2 1, 3 2 2, 3 4 5, 0 4 6, 0 2 1),(0.5 2.5 8, 0.6 2.7 9, 0.5 2.7 10, 0.5 2.5 8))","PolygonZ(( 0 2 1, 3 2 2, 3 4 5, 0 4 6, 0 2 1),(0.5 2.5 8, 0.6 2.7 9, 0.5 2.7 10, 0.5 2.5 8))",9,0,5.99,10.5236067978,1,1,0,POINT(1.50161380077908 3.00061213132999),0,2,3,4,"z coordinate, but geometry not explicitly marked as such. Should be upgraded to have Z dimension"
|
||||
"Polygon(( 0 2 1, 3 2 2, 3 4 5, 0 4 6, 0 2 1))","PolygonZ(( 0 2 1, 3 2 2, 3 4 5, 0 4 6, 0 2 1))",5,0,6,10,1,0,0,Point (1.5 3),0,2,3,4,"z coordinate, but geometry not explicitly marked as such. Should be upgraded to have Z dimension"
|
||||
"Polygon((0 2 1 5, 3 2 2 6, 3 4 5 7, 0 4 6 8, 0 2 1 5),(0.5 2.5 8 10, 1.0 2.5 9 11, 0.5 2.5 10 12, 0.5 2.5 8 10))","PolygonZM((0 2 1 5, 3 2 2 6, 3 4 5 7, 0 4 6 8, 0 2 1 5),(0.5 2.5 8 10, 1.0 2.5 9 11, 0.5 2.5 10 12, 0.5 2.5 8 10))",9,0,6,11,1,1,0,Point (1.5 3),0,2,3,4,"z coordinate, but geometry not explicitly marked as such. Should be upgraded to have Z dimension"
|
||||
@ -121,4 +123,4 @@ Polygon,,,,,,,,,,,,,,Malformed WKT
|
||||
"PolygonM ((0 0 1, 10 0 1, 10 10 1, 0 10 1, 0 0 1),(5 5 1, 7 5 1, 7 7 1, 5 7 1, 5 5 1),(1 1 1,2 1 1, 2 2 1, 1 2 1, 1 1 1))","POLYGON M ((0 0 1,10 0 1,10 10 1,0 10 1,0 0 1),(5 5 1,7 5 1,7 7 1,5 7 1,5 5 1),(1 1 1,2 1 1,2 2 1,1 2 1,1 1 1))",15,0,95,52,1,2,0,POINT(4.99473684210526 4.99473684210526),0,0,10,10,
|
||||
"PolygonZ ((0 0 1 , 10 0 1, 10 10 1, 0 10 1, 0 0 1))","POLYGON Z ((0 0 1,10 0 1,10 10 1,0 10 1,0 0 1))",5,0,100,40,1,0,0,POINT(5 5),0,0,10,10,
|
||||
"PolygonZ ((0 0 1, 10 0 1, 10 10 1, 0 10 1, 0 0 1),(5 5 1, 7 5 1, 7 7 1 , 5 7 1, 5 5 1))","POLYGON Z ((0 0 1,10 0 1,10 10 1,0 10 1,0 0 1),(5 5 1,7 5 1,7 7 1,5 7 1,5 5 1))",10,0,96,48,1,1,0,POINT(4.95833333333333 4.95833333333333),0,0,10,10,
|
||||
"CurvePolygon (CompoundCurve ((2678124.57778842002153397 1225804.43286111624911427, 2678251.0684670670889318 1225964.66278979112394154, 2678201.75901959836483002 1226077.95337014575488865, 2678199.27904875669628382 1226083.94340024818666279, 2678198.13904719380661845 1226083.5034040967002511, 2678188.08903313148766756 1226079.56343783461488783, 2678164.688993189483881 1226068.85351158352568746, 2678152.65896565327420831 1226061.85354482522234321, 2678133.63892276119440794 1226050.92359781125560403),CircularString (2678133.63892276119440794 1226050.92359781125560403, 2678124.47892813989892602 1226045.71365369856357574, 2678115.92887723352760077 1226039.55364341707900167, 2678110.39902341179549694 1226025.70413719792850316, 2678113.52874504774808884 1226011.12356549175456166, 2678117.04747172351926565 1226004.70550769660621881, 2678121.17868330329656601 1225998.66349145700223744, 2678122.91810466628521681 1225991.71089569479227066, 2678120.73861891590058804 1225984.88345037144608796, 2678109.63862727722153068 1225981.37343537760898471, 2678097.99861149024218321 1225981.17354299034923315, 2678087.07146158767864108 1225984.57272616261616349, 2678076.13865283969789743 1225987.95366438734345138, 2678068.26173875294625759 1225987.17441278789192438, 2678060.82864314317703247 1225984.45372360944747925, 2678052.37183309439569712 1225977.24715672573074698, 2678045.5285750487819314 1225968.49374381266534328, 2678039.90821403311565518 1225957.94303491595201194, 2678035.46847799280658364 1225946.84372220188379288, 2678033.64745173417031765 1225940.12937669246457517, 2678032.40841578459367156 1225933.28369381325319409, 2678033.68931351415812969 1225925.84029478346928954, 2678036.55834634136408567 1225918.85362965753301978, 2678039.0693440935574472 1225913.78109931806102395, 2678040.70829536207020283 1225908.363577825948596),(2678040.70829536207020283 1225908.363577825948596, 2678124.57778842002153397 1225804.43286111624911427)))","CurvePolygon (CompoundCurve ((2678124.57778842002153397 1225804.43286111624911427, 2678251.0684670670889318 1225964.66278979112394154, 2678201.75901959836483002 1226077.95337014575488865, 2678199.27904875669628382 1226083.94340024818666279, 2678198.13904719380661845 1226083.5034040967002511, 2678188.08903313148766756 1226079.56343783461488783, 2678164.688993189483881 1226068.85351158352568746, 2678152.65896565327420831 1226061.85354482522234321, 2678133.63892276119440794 1226050.92359781125560403),CircularString (2678133.63892276119440794 1226050.92359781125560403, 2678124.47892813989892602 1226045.71365369856357574, 2678115.92887723352760077 1226039.55364341707900167, 2678110.39902341179549694 1226025.70413719792850316, 2678113.52874504774808884 1226011.12356549175456166, 2678117.04747172351926565 1226004.70550769660621881, 2678121.17868330329656601 1225998.66349145700223744, 2678122.91810466628521681 1225991.71089569479227066, 2678120.73861891590058804 1225984.88345037144608796, 2678109.63862727722153068 1225981.37343537760898471, 2678097.99861149024218321 1225981.17354299034923315, 2678087.07146158767864108 1225984.57272616261616349, 2678076.13865283969789743 1225987.95366438734345138, 2678068.26173875294625759 1225987.17441278789192438, 2678060.82864314317703247 1225984.45372360944747925, 2678052.37183309439569712 1225977.24715672573074698, 2678045.5285750487819314 1225968.49374381266534328, 2678039.90821403311565518 1225957.94303491595201194, 2678035.46847799280658364 1225946.84372220188379288, 2678033.64745173417031765 1225940.12937669246457517, 2678032.40841578459367156 1225933.28369381325319409, 2678033.68931351415812969 1225925.84029478346928954, 2678036.55834634136408567 1225918.85362965753301978, 2678039.0693440935574472 1225913.78109931806102395, 2678040.70829536207020283 1225908.363577825948596),(2678040.70829536207020283 1225908.363577825948596, 2678124.57778842002153397 1225804.43286111624911427)))",34,0,32087.8047511,770.542777805,1,1,0,Point (2678143.67776112211868167 1225948.36457449640147388),2678032.40842,1225804.43286112,2678251.06846707,1226083.94340025,
|
||||
"CurvePolygon (CompoundCurve ((2678124.57778842002153397 1225804.43286111624911427, 2678251.0684670670889318 1225964.66278979112394154, 2678201.75901959836483002 1226077.95337014575488865, 2678199.27904875669628382 1226083.94340024818666279, 2678198.13904719380661845 1226083.5034040967002511, 2678188.08903313148766756 1226079.56343783461488783, 2678164.688993189483881 1226068.85351158352568746, 2678152.65896565327420831 1226061.85354482522234321, 2678133.63892276119440794 1226050.92359781125560403),CircularString (2678133.63892276119440794 1226050.92359781125560403, 2678124.47892813989892602 1226045.71365369856357574, 2678115.92887723352760077 1226039.55364341707900167, 2678110.39902341179549694 1226025.70413719792850316, 2678113.52874504774808884 1226011.12356549175456166, 2678117.04747172351926565 1226004.70550769660621881, 2678121.17868330329656601 1225998.66349145700223744, 2678122.91810466628521681 1225991.71089569479227066, 2678120.73861891590058804 1225984.88345037144608796, 2678109.63862727722153068 1225981.37343537760898471, 2678097.99861149024218321 1225981.17354299034923315, 2678087.07146158767864108 1225984.57272616261616349, 2678076.13865283969789743 1225987.95366438734345138, 2678068.26173875294625759 1225987.17441278789192438, 2678060.82864314317703247 1225984.45372360944747925, 2678052.37183309439569712 1225977.24715672573074698, 2678045.5285750487819314 1225968.49374381266534328, 2678039.90821403311565518 1225957.94303491595201194, 2678035.46847799280658364 1225946.84372220188379288, 2678033.64745173417031765 1225940.12937669246457517, 2678032.40841578459367156 1225933.28369381325319409, 2678033.68931351415812969 1225925.84029478346928954, 2678036.55834634136408567 1225918.85362965753301978, 2678039.0693440935574472 1225913.78109931806102395, 2678040.70829536207020283 1225908.363577825948596),(2678040.70829536207020283 1225908.363577825948596, 2678124.57778842002153397 1225804.43286111624911427)))","CurvePolygon (CompoundCurve ((2678124.57778842002153397 1225804.43286111624911427, 2678251.0684670670889318 1225964.66278979112394154, 2678201.75901959836483002 1226077.95337014575488865, 2678199.27904875669628382 1226083.94340024818666279, 2678198.13904719380661845 1226083.5034040967002511, 2678188.08903313148766756 1226079.56343783461488783, 2678164.688993189483881 1226068.85351158352568746, 2678152.65896565327420831 1226061.85354482522234321, 2678133.63892276119440794 1226050.92359781125560403),CircularString (2678133.63892276119440794 1226050.92359781125560403, 2678124.47892813989892602 1226045.71365369856357574, 2678115.92887723352760077 1226039.55364341707900167, 2678110.39902341179549694 1226025.70413719792850316, 2678113.52874504774808884 1226011.12356549175456166, 2678117.04747172351926565 1226004.70550769660621881, 2678121.17868330329656601 1225998.66349145700223744, 2678122.91810466628521681 1225991.71089569479227066, 2678120.73861891590058804 1225984.88345037144608796, 2678109.63862727722153068 1225981.37343537760898471, 2678097.99861149024218321 1225981.17354299034923315, 2678087.07146158767864108 1225984.57272616261616349, 2678076.13865283969789743 1225987.95366438734345138, 2678068.26173875294625759 1225987.17441278789192438, 2678060.82864314317703247 1225984.45372360944747925, 2678052.37183309439569712 1225977.24715672573074698, 2678045.5285750487819314 1225968.49374381266534328, 2678039.90821403311565518 1225957.94303491595201194, 2678035.46847799280658364 1225946.84372220188379288, 2678033.64745173417031765 1225940.12937669246457517, 2678032.40841578459367156 1225933.28369381325319409, 2678033.68931351415812969 1225925.84029478346928954, 2678036.55834634136408567 1225918.85362965753301978, 2678039.0693440935574472 1225913.78109931806102395, 2678040.70829536207020283 1225908.363577825948596),(2678040.70829536207020283 1225908.363577825948596, 2678124.57778842002153397 1225804.43286111624911427)))",34,0,32087.80450719595,770.542777805,1,1,0,Point (2678143.67776112211868167 1225948.36457449640147388),2678032.40842,1225804.43286112,2678251.06846707,1226083.94340025,
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user