Пример #1
0
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()

        self.filenames = [os.path.join(self.tempdir, x)
                          for x in ('ts1', 'ts2', 'ts3', 'ts4')]
        with open(self.filenames[0], 'w') as f:
            f.write("Location=19.557285 0.0473312 2100\n"  # GGRS87=5000 5000
                    "\n"
                    "2014-04-22 12:50,5.03,\n"
                    "2014-04-22 13:00,0.54,\n"
                    "2014-04-22 13:10,6.93,\n")
        with open(self.filenames[1], 'w') as f:
            f.write("Location=19.64689 0.04734 2100\n"  # GGRS87=15000 5000
                    "\n"
                    "2014-04-22 12:50,2.90,\n"
                    "2014-04-22 13:00,2.40,\n"
                    "2014-04-22 13:10,9.16,\n")
        with open(self.filenames[2], 'w') as f:
            f.write("Location=19.88886 0.12857 2100\n"  # GGRS87=42000 14000
                    "\n"
                    "2014-04-22 12:50,9.70,\n"
                    "2014-04-22 13:00,1.84,\n"
                    "2014-04-22 13:10,7.63,\n")
        with open(self.filenames[3], 'w') as f:
            # This station is missing the date required,
            # so it should not be taken into account
            f.write("Location=19.66480 0.15560 2100\n"  # GGRS87=17000 17000
                    "\n"
                    "2014-04-22 12:50,9.70,\n"
                    "2014-04-22 13:10,7.63,\n")

        self.create_mask()
        self.stations = ogr.GetDriverByName('memory').CreateDataSource('tmp')
        self.stations_layer = create_ogr_layer_from_timeseries(
            self.filenames, 2100, self.stations)
Пример #2
0
 def test_create_ogr_layer_from_timeseries(self):
     data_source = ogr.GetDriverByName('memory').CreateDataSource('tmp')
     filenames = [os.path.join(self.tempdir, x) for x in ('ts1', 'ts2')]
     layer = create_ogr_layer_from_timeseries(filenames, 2100, data_source)
     self.assertTrue(layer.GetFeatureCount(), 2)
     # The co-ordinates below are converted from WGS84 to Greek Grid/GGRS87
     ref = [{'x': 481180.63, 'y': 4202647.01,  # 23.78743, 37.97385
             'filename': filenames[0]},
            {'x': 549187.44, 'y': 4290612.25,  # 24.56789, 38.76543
             'filename': filenames[1]},
            ]
     for feature, r in zip(layer, ref):
         self.assertEqual(feature.GetField('filename'), r['filename'])
         self.assertAlmostEqual(feature.GetGeometryRef().GetX(), r['x'], 2)
         self.assertAlmostEqual(feature.GetGeometryRef().GetY(), r['y'], 2)