Skip to content
Permalink
Browse files

Unit tests for QgsDistanceArea::latitudeGeodesicCrossesDateLine

  • Loading branch information
nyalldawson committed Jan 8, 2019
1 parent adc5c17 commit b0c3b9f7813ef1ba4a40db98e2012ed611454d19
Showing with 46 additions and 0 deletions.
  1. +46 −0 tests/src/python/test_qgsdistancearea.py
@@ -627,6 +627,52 @@ def testFormatDistance(self):
self.assertEqual(QgsDistanceArea.formatDistance(1.0, 1, QgsUnitTypes.DistanceUnknownUnit, False), '1.0')
QLocale.setDefault(QLocale.system())

def testGeodesicIntersectionAtDateLine(self):
da = QgsDistanceArea()
crs = QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
da.setSourceCrs(crs, QgsProject.instance().transformContext())
da.setEllipsoid("WGS84")

self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(0, 0), QgsPointXY(-170, 0)), 0, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(-170, 0), QgsPointXY(170, 0)), 0, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(179, 0), QgsPointXY(181, 0)), 0, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(-170, 0), QgsPointXY(170, 0)), 0, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(180, 0), QgsPointXY(180, 0)), 0, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(180, -10), QgsPointXY(180, -10)), -10, 5)

self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(138.26237, -20.314687), QgsPointXY(-151.6, -77.8)), -73.89148222666744914, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(138.26237, -20.314687), QgsPointXY(-151.6 + 360, -77.8)), -73.89148222666744914, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(-151.6, -77.8), QgsPointXY(138.26237, -20.314687)), -73.89148222666744914, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(170.60188754234980024, -70.81368329001529105),
QgsPointXY(-164.61259948055175073, -76.66761193248410677)), -73.89148222666744914, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(-164.61259948055175073, -76.66761193248410677),
QgsPointXY(170.60188754234980024,
-70.81368329001529105)), -73.89148222666744914, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(178.44469761238570982, -73.47820480021761114),
QgsPointXY(-179.21026002627399976, -74.08952948682963324)), -73.89148222666744914, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(-179.21026002627399976, -74.08952948682963324),
QgsPointXY(178.44469761238570982,
-73.47820480021761114)), -73.89148222666744914, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(179.83103440731269984, -73.8481044794813215),
QgsPointXY(-179.93191793815378787, -73.90885909527753483)), -73.89148222666744914, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(-179.93191793815378787, -73.90885909527753483),
QgsPointXY(179.83103440731269984, -73.8481044794813215)), -73.89148222666744914, 5)

self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(179.92498611649580198, 7.24703528617311754),
QgsPointXY(-178.20070563806575592, 16.09649962419504732)), 7.6112109902580265, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(-178.20070563806575592, 16.09649962419504732),
QgsPointXY(179.92498611649580198, 7.24703528617311754)), 7.6112109902580265, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(175.76717768974583578, 8.93749416467257873),
QgsPointXY(-175.15030911497356669, 8.59851183021221033)), 8.80683758146703966, 5)
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(-175.15030911497356669, 8.59851183021221033),
QgsPointXY(175.76717768974583578,
8.93749416467257873)), 8.80683758146703966, 5)

# calculation should be ellipsoid dependant!
da.setEllipsoid("Phobos2000")
self.assertAlmostEqual(da.latitudeGeodesicCrossesDateLine(QgsPointXY(-175.15030911497356669, 8.59851183021221033),
QgsPointXY(175.76717768974583578,
8.93749416467257873)), 8.836479503936307, 5)

if __name__ == '__main__':
unittest.main()

0 comments on commit b0c3b9f

Please sign in to comment.
You can’t perform that action at this time.