コード例 #1
0
 def testEpsgCodes(self):
     '''
     Test if the correct EPSG code of points within Switzerland are returned.
     '''
     
     self.assertEqual(21780, GlacierReader.getEpsgCode(600000, 200000), "LV03")
     self.assertEqual(2056, GlacierReader.getEpsgCode(2600000, 1200000), "LV95")
     self.assertEqual(4326, GlacierReader.getEpsgCode(8.64870, 46.88999), "WGS-84")
     self.assertEqual(32632, GlacierReader.getEpsgCode(410968.286, 5163967.012), "UTM-32")
コード例 #2
0
    def testInvalidCoordinates(self):
        '''
        Test if the correct error is raised in case of wrong coordinates.
        '''
        
        # FIXME: Testing a raised exception could be done more nicely with AssertRaises.
        
        # Inverted coordinates LV03.
        try:
            GlacierReader.getEpsgCode(200000, 600000)
        
        except Exception as e:
            if type(e) is InvalidCoordinatesError:
                self.assertTrue(True, "Correct exception raised")
            else:
                self.assertTrue(False, "Wrong exception raised")

        # Inverted coordinates LV95.
        try:
            GlacierReader.getEpsgCode(1200000, 2600000)
        
        except Exception as e:
            if type(e) is InvalidCoordinatesError:
                self.assertTrue(True, "Correct exception raised")
            else:
                self.assertTrue(False, "Wrong exception raised")
                
        # Inverted coordinates WGS-84.
        try:
            GlacierReader.getEpsgCode(46.88999, 8.64870)
        
        except Exception as e:
            if type(e) is InvalidCoordinatesError:
                self.assertTrue(True, "Correct exception raised")
            else:
                self.assertTrue(False, "Wrong exception raised")
                
        # Inverted coordinates UTM-32.
        try:
            GlacierReader.getEpsgCode(5163967.012, 410968.286)
        
        except Exception as e:
            if type(e) is InvalidCoordinatesError:
                self.assertTrue(True, "Correct exception raised")
            else:
                self.assertTrue(False, "Wrong exception raised")
                
        # Nonsense.
        try:
            GlacierReader.getEpsgCode(42.2, 1973.7)
        
        except Exception as e:
            if type(e) is InvalidCoordinatesError:
                self.assertTrue(True, "Correct exception raised")
            else:
                self.assertTrue(False, "Wrong exception raised")