Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix failing test
  • Loading branch information
nyalldawson committed Mar 14, 2017
1 parent 0afc88e commit 730d10a
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions tests/src/python/test_qgsvectorlayer.py
Expand Up @@ -1495,11 +1495,9 @@ def test_ExpressionFieldEllipsoidLengthCalculation(self):

# set project CRS and ellipsoid
srs = QgsCoordinateReferenceSystem(3111, QgsCoordinateReferenceSystem.EpsgCrsId)
QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCRSProj4String", srs.toProj4())
QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCRSID", srs.srsid())
QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCrs", srs.authid())
QgsProject.instance().writeEntry("Measure", "/Ellipsoid", "WGS84")
QgsProject.instance().writeEntry("Measurement", "/DistanceUnits", QgsUnitTypes.encodeUnit(QgsUnitTypes.DistanceMeters))
QgsProject.instance().setCrs(srs)
QgsProject.instance().setEllipsoid("WGS84")
QgsProject.instance().setDistanceUnits(QgsUnitTypes.DistanceMeters)

idx = temp_layer.addExpressionField('$length', QgsField('length', QVariant.Double)) # NOQA

Expand All @@ -1509,7 +1507,7 @@ def test_ExpressionFieldEllipsoidLengthCalculation(self):
self.assertAlmostEqual(f['length'], expected, 3)

# change project length unit, check calculation respects unit
QgsProject.instance().writeEntry("Measurement", "/DistanceUnits", QgsUnitTypes.encodeUnit(QgsUnitTypes.DistanceFeet))
QgsProject.instance().setDistanceUnits(QgsUnitTypes.DistanceFeet)
f = next(temp_layer.getFeatures())
expected = 88360.0918635
self.assertAlmostEqual(f['length'], expected, 3)
Expand All @@ -1525,11 +1523,9 @@ def test_ExpressionFieldEllipsoidAreaCalculation(self):

# set project CRS and ellipsoid
srs = QgsCoordinateReferenceSystem(3111, QgsCoordinateReferenceSystem.EpsgCrsId)
QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCRSProj4String", srs.toProj4())
QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCRSID", srs.srsid())
QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCrs", srs.authid())
QgsProject.instance().writeEntry("Measure", "/Ellipsoid", "WGS84")
QgsProject.instance().writeEntry("Measurement", "/AreaUnits", QgsUnitTypes.encodeUnit(QgsUnitTypes.AreaSquareMeters))
QgsProject.instance().setCrs(srs)
QgsProject.instance().setEllipsoid("WGS84")
QgsProject.instance().setAreaUnits(QgsUnitTypes.AreaSquareMeters)

idx = temp_layer.addExpressionField('$area', QgsField('area', QVariant.Double)) # NOQA

Expand All @@ -1539,7 +1535,7 @@ def test_ExpressionFieldEllipsoidAreaCalculation(self):
self.assertAlmostEqual(f['area'], expected, delta=1.0)

# change project area unit, check calculation respects unit
QgsProject.instance().writeEntry("Measurement", "/AreaUnits", QgsUnitTypes.encodeUnit(QgsUnitTypes.AreaSquareMiles))
QgsProject.instance().setAreaUnits(QgsUnitTypes.AreaSquareMiles)
f = next(temp_layer.getFeatures())
expected = 389.6117565069
self.assertAlmostEqual(f['area'], expected, 3)
Expand Down

0 comments on commit 730d10a

Please sign in to comment.