Ejemplo n.º 1
0
    def test_get_attributes(self):
        self.ds.set_attribute('test', self.values2)
        self.assertEqual(self.ds.get_attributes(['test'], filt=('index', 0)), self.values2[0])
        self.assertEqual(self.ds.get_attributes(['test'], filt=('index', 1)), self.values2[1])

    def test_dump_vector(self):
        self.ds.dump_vector(tempfile.NamedTemporaryFile(mode='w+b').name)

    def test_dump_raster(self):
        proj = osr.SpatialReference()
        proj.ImportFromEPSG(31466)
        test = zonalstats.DataSource('examples/data/agger/agger_merge.shp', proj)
        self.assertRaises(AttributeError, test.dump_raster(tempfile.NamedTemporaryFile(mode='w+b').name, 'netCDF', pixel_size=100.))


@unittest.skipIf(not util.has_geos(), "GDAL without GEOS")
class ZonalDataTest(unittest.TestCase):
    def setUp(self):
        global skip
        # setup test grid and catchment
        lon = 7.071664
        lat = 50.730521
        r = np.array(range(50, 100 * 1000 + 50, 100))
        a = np.array(range(0, 360, 1))
        rays = a.shape[0]
        bins = r.shape[0]
        # create polar grid polygon vertices in lat,lon
        radar_ll = georef.polar2polyvert(r, a, (lon, lat))

        # create polar grid centroids in lat,lon
        rlon, rlat = georef.polar2centroids(r, a, (lon, lat))
Ejemplo n.º 2
0
    def test_dump_raster(self):
        proj = osr.SpatialReference()
        proj.ImportFromEPSG(31466)
        filename = util.get_wradlib_data_file('shapefiles/agger/'
                                              'agger_merge.shp')
        test = zonalstats.DataSource(filename, srs=proj)
        test.dump_raster(tempfile.NamedTemporaryFile(mode='w+b').name,
                         driver='netCDF',
                         pixel_size=100.)
        test.dump_raster(tempfile.NamedTemporaryFile(mode='w+b').name,
                         driver='netCDF',
                         pixel_size=100.,
                         attr='FID')


@unittest.skipIf(not util.has_geos(), "GDAL without GEOS")
class ZonalDataBaseTest(unittest.TestCase):
    def setUp(self):

        # GK3-Projection
        self.proj = osr.SpatialReference()
        self.proj.ImportFromEPSG(31466)

        # create synthetic box
        self.box0 = np.array([[2600000., 5630000.], [2600000., 5640000.],
                              [2610000., 5640000.], [2610000., 5630000.],
                              [2600000., 5630000.]])

        self.box1 = np.array([[2610000., 5630000.], [2610000., 5640000.],
                              [2620000., 5640000.], [2620000., 5630000.],
                              [2610000., 5630000.]])
Ejemplo n.º 3
0
                                              "agger_merge.shp")
        test = zonalstats.DataSource(filename, srs=proj)
        test.dump_raster(
            tempfile.NamedTemporaryFile(mode="w+b").name,
            driver="netCDF",
            pixel_size=100.0,
        )
        test.dump_raster(
            tempfile.NamedTemporaryFile(mode="w+b").name,
            driver="netCDF",
            pixel_size=100.0,
            attr="FID",
        )


@pytest.mark.skipif(not util.has_geos(), reason="GDAL without GEOS")
class TestZonalDataBase:
    # GK3-Projection
    proj = osr.SpatialReference()
    proj.ImportFromEPSG(31466)

    # create synthetic box
    box0 = np.array([
        [2600000.0, 5630000.0],
        [2600000.0, 5640000.0],
        [2610000.0, 5640000.0],
        [2610000.0, 5630000.0],
        [2600000.0, 5630000.0],
    ])

    box1 = np.array([