Exemplo n.º 1
0
    def test_get_native_resolution(self):
        dataset = Dataset(inputfile=self.inputfile)

        # bluemarble.tif is a 1024×1024 image of the whole world
        self.assertEqual(dataset.GetNativeResolution(), 2)

        # Maximum
        self.assertEqual(dataset.GetNativeResolution(maximum=1), 1)
        self.assertEqual(dataset.GetNativeResolution(maximum=10), 2)

        # Transform into US survey feet
        sr = SpatialReference.FromEPSG(EPSG_WEB_MERCATOR)
        sr.ImportFromWkt(sr.ExportToWkt().replace(
            'UNIT["metre",1,AUTHORITY["EPSG","9001"]]',
            'UNIT["US survey foot",0.3048006096012192,AUTHORITY["EPSG","9003"]]'
        ))
        transform = dataset.GetCoordinateTransformation(dst_ref=sr)
        self.assertEqual(dataset.GetNativeResolution(transform=transform),
                         2 + int(round(log(3.28, 2))))  # 3.28 ft/m
Exemplo n.º 2
0
    def test_get_tiled_extents_partial_spanning(self):
        dataset = Dataset(inputfile=self.spanningfile)

        mercator = SpatialReference.FromEPSG(EPSG_WEB_MERCATOR)
        major_circumference = mercator.GetMajorCircumference()
        minor_circumference = mercator.GetMinorCircumference()

        # Native resolution, source projection which is Mercator, spanning
        # tiles.  This should be the south-western quadrant.
        ll, ur = dataset.GetTiledExtents()
        self.assertAlmostEqual(ll.x, -major_circumference / 2, places=0)
        self.assertAlmostEqual(ll.y, -minor_circumference / 2, places=0)
        self.assertAlmostEqual(ur.x, 0.0, places=0)
        self.assertAlmostEqual(ur.y, 0.0, places=0)

        # Resolution 1, source projection which is Mercator, spanning tiles.
        # This should be the south-western quadrant.
        ll, ur = dataset.GetTiledExtents(resolution=1)
        self.assertAlmostEqual(ll.x, -major_circumference / 2, places=0)
        self.assertAlmostEqual(ll.y, -minor_circumference / 2, places=0)
        self.assertAlmostEqual(ur.x, 0.0, places=0)
        self.assertAlmostEqual(ur.y, 0.0, places=0)

        # Resolution 5, source projection which is Mercator, spanning tiles.
        # This should be the south-western quadrant with a border of 32 pixels,
        # because the border of the dataset is 50 pixels.
        pixel_size = mercator.GetPixelDimensions(
            resolution=dataset.GetNativeResolution())
        border = 32 * pixel_size.x
        ll, ur = dataset.GetTiledExtents(resolution=5)
        self.assertAlmostEqual(ll.x,
                               -major_circumference / 2 + border,
                               places=0)
        self.assertAlmostEqual(ll.y,
                               -minor_circumference / 2 + border,
                               places=0)
        self.assertAlmostEqual(ur.x, 0.0 - border, places=0)
        self.assertAlmostEqual(ur.y, 0.0 - border, places=0)

        # Resolution 0, WGS 84 projection, spanning tiles. This should be
        # the western hemisphere.
        ll, ur = dataset.GetTiledExtents(
            transform=dataset.GetCoordinateTransformation(
                dst_ref=SpatialReference(osr.SRS_WKT_WGS84)),
            resolution=0)
        self.assertAlmostEqual(ll.x, -180.0, places=0)
        self.assertAlmostEqual(ll.y, -90.0, places=0)
        self.assertAlmostEqual(ur.x, 0.0, places=0)
        self.assertAlmostEqual(ur.y, 90.0, places=0)
Exemplo n.º 3
0
    def test_get_extents_partial_spanning(self):
        dataset = Dataset(inputfile=self.spanningfile)
        mercator = dataset.GetSpatialReference()
        major_half_circumference = mercator.GetMajorCircumference() / 2
        minor_half_circumference = mercator.GetMinorCircumference() / 2

        # Spanning file is 50 pixels in from alignment
        pixel_size = mercator.GetPixelDimensions(
            resolution=dataset.GetNativeResolution())
        border = 50 * pixel_size.x

        ll, ur = dataset.GetExtents()
        self.assertAlmostEqual(ll.x,
                               -major_half_circumference + border,
                               places=0)
        self.assertAlmostEqual(ll.y,
                               -minor_half_circumference + border,
                               places=0)
        self.assertAlmostEqual(ur.x, 0.0 - border, places=0)
        self.assertAlmostEqual(ur.y, 0.0 - border, places=0)
Exemplo n.º 4
0
    def test_upsample_symlink(self):
        with NamedTemporaryDir() as outputdir:
            zoom = 3

            dataset = Dataset(self.upsamplingfile)
            image_pyramid(inputfile=self.upsamplingfile,
                          outputdir=outputdir,
                          max_resolution=dataset.GetNativeResolution() + zoom,
                          renderer=TouchRenderer(suffix='.png'))

            files = set(recursive_listdir(outputdir))
            self.assertEqual(
                files,
                set([
                    '0/',
                    '0/0/',
                    '0/0/0.png',
                    '1/',
                    '1/0/',
                    '1/0/0.png',
                    '1/0/1.png',
                    '1/1/',
                    '1/1/0.png',
                    '1/1/1.png',
                    '2/',
                    '2/0/',
                    '2/0/0.png',
                    '2/0/1.png',
                    '2/0/2.png',
                    '2/0/3.png',
                    '2/1/',
                    '2/1/0.png',
                    '2/1/1.png',
                    '2/1/2.png',
                    '2/1/3.png',
                    '2/2/',
                    '2/2/0.png',
                    '2/2/1.png',
                    '2/2/2.png',
                    '2/2/3.png',
                    '2/3/',
                    '2/3/0.png',
                    '2/3/1.png',
                    '2/3/2.png',
                    '2/3/3.png',
                    '3/',
                    '3/0/',
                    '3/0/0.png',
                    '3/0/1.png',
                    '3/0/2.png',
                    '3/0/3.png',
                    '3/0/4.png',
                    '3/0/5.png',
                    '3/0/6.png',
                    '3/0/7.png',
                    '3/1/',
                    '3/1/0.png',
                    '3/1/1.png',
                    '3/1/2.png',
                    '3/1/3.png',
                    '3/1/4.png',
                    '3/1/5.png',
                    '3/1/6.png',
                    '3/1/7.png',
                    '3/2/',
                    '3/2/0.png',
                    '3/2/1.png',
                    '3/2/2.png',
                    '3/2/3.png',
                    '3/2/4.png',
                    '3/2/5.png',
                    '3/2/6.png',
                    '3/2/7.png',
                    '3/3/',
                    '3/3/0.png',
                    '3/3/1.png',
                    '3/3/2.png',
                    '3/3/3.png',
                    '3/3/4.png',
                    '3/3/5.png',
                    '3/3/6.png',
                    '3/3/7.png',
                    '3/4/',
                    '3/4/0.png',
                    '3/4/1.png',
                    '3/4/2.png',
                    '3/4/3.png',
                    '3/4/4.png',
                    '3/4/5.png',
                    '3/4/6.png',
                    '3/4/7.png',
                    '3/5/',
                    '3/5/0.png',
                    '3/5/1.png',
                    '3/5/2.png',
                    '3/5/3.png',
                    '3/5/4.png',
                    '3/5/5.png',
                    '3/5/6.png',
                    '3/5/7.png',
                    '3/6/',
                    '3/6/0.png',
                    '3/6/1.png',
                    '3/6/2.png',
                    '3/6/3.png',
                    '3/6/4.png',
                    '3/6/5.png',
                    '3/6/6.png',
                    '3/6/7.png',
                    '3/7/',
                    '3/7/0.png',
                    '3/7/1.png',
                    '3/7/2.png',
                    '3/7/3.png',
                    '3/7/4.png',
                    '3/7/5.png',
                    '3/7/6.png',
                    '3/7/7.png',
                ]))