Ejemplo n.º 1
0
    def testStereographicProjection(self):
        from girder.plugins.large_image.tilesource import TileSourceException
        from girder.plugins.large_image.tilesource.mapniksource import MapnikTileSource

        filepath = os.path.join(os.path.dirname(__file__), 'test_files',
                                'rgb_geotiff.tiff')
        # We will fail if we ask for a stereographic projection and don't
        # specify unitsPerPixel
        with six.assertRaisesRegex(self, TileSourceException,
                                   'unitsPerPixel must be specified'):
            MapnikTileSource(filepath, projection='EPSG:3411')
        # But will pass if unitsPerPixel is specified
        MapnikTileSource(filepath,
                         projection='EPSG:3411',
                         unitsPerPixel=150000)

        # We can also upload and access this via a rest call
        file = self._uploadFile(filepath)
        itemId = str(file['itemId'])
        resp = self.request(path='/item/%s/tiles' % itemId,
                            user=self.admin,
                            params={
                                'projection': 'EPSG:3411',
                                'unitsPerPixel': 150000
                            })
        self.assertStatusOk(resp)
Ejemplo n.º 2
0
    def testProj4Proj(self):
        # Test obtaining pyproj.Proj projection values
        from girder.plugins.large_image.tilesource.mapniksource import MapnikTileSource

        proj = MapnikTileSource._proj4Proj(b'epsg:4326')
        self.assertEqual(MapnikTileSource._proj4Proj(u'epsg:4326').srs, proj.srs)
        self.assertEqual(MapnikTileSource._proj4Proj('proj4:EPSG:4326').srs, proj.srs)
        self.assertIsNone(MapnikTileSource._proj4Proj(4326))
Ejemplo n.º 3
0
    def testGuardAgainstBadLatLong(self):
        from girder.plugins.large_image.tilesource.mapniksource import MapnikTileSource
        filepath = os.path.join(
            os.path.dirname(__file__), 'test_files', 'global_dem.tif')
        source = MapnikTileSource(filepath)
        bounds = source.getBounds(srs='EPSG:4326')

        self.assertEqual(bounds['xmin'], -180.00416667)
        self.assertEqual(bounds['xmax'], 179.99583333)
        self.assertEqual(bounds['ymin'], -89.99583333)
        self.assertEqual(bounds['ymax'], 90)
Ejemplo n.º 4
0
 def testSourceErrors(self):
     from girder.plugins.large_image.tilesource import TileSourceException
     from girder.plugins.large_image.tilesource.mapniksource import MapnikTileSource
     filepath = os.path.join(
         os.path.dirname(__file__), 'test_files', 'rgb_geotiff.tiff')
     with six.assertRaisesRegex(self, TileSourceException, 'must not be geographic'):
         MapnikTileSource(filepath, 'EPSG:4326')
     filepath = os.path.join(
         os.path.dirname(__file__), 'test_files', 'zero_gi.tif')
     with six.assertRaisesRegex(self, TileSourceException, 'cannot be opened via Mapnik'):
         MapnikTileSource(filepath)
     filepath = os.path.join(
         os.path.dirname(__file__), 'test_files', 'yb10kx5k.png')
     with six.assertRaisesRegex(self, TileSourceException, 'does not have a projected scale'):
         MapnikTileSource(filepath)
Ejemplo n.º 5
0
    def testConvertProjectionUnits(self):
        from girder.plugins.large_image.tilesource import TileSourceException
        from girder.plugins.large_image.tilesource.mapniksource import MapnikTileSource
        filepath = os.path.join(
            os.path.dirname(__file__), 'test_files', 'rgb_geotiff.tiff')
        tsNoProj = MapnikTileSource(filepath)

        result = tsNoProj._convertProjectionUnits(
            -13024380, 3895303, None, None, None, None, 'EPSG:3857')
        self.assertAlmostEqual(result[0], 147, 0)
        self.assertAlmostEqual(result[1], 149, 0)
        self.assertEqual(result[2:], (None, None, 'base_pixels'))

        result = tsNoProj._convertProjectionUnits(
            None, None, -13080040, 3961860, None, None, 'EPSG:3857')
        self.assertAlmostEqual(result[2], 96, 0)
        self.assertAlmostEqual(result[3], 88, 0)
        self.assertEqual(result[:2], (None, None))
        result = tsNoProj._convertProjectionUnits(
            -117.5, 33, None, None, 0.5, 0.5, 'EPSG:4326')
        self.assertAlmostEqual(result[0], 96, 0)
        self.assertAlmostEqual(result[1], 149, 0)
        self.assertAlmostEqual(result[2], 147, 0)
        self.assertAlmostEqual(result[3], 89, 0)
        result = tsNoProj._convertProjectionUnits(
            None, None, -117, 33.5, 0.5, 0.5, 'EPSG:4326')
        self.assertAlmostEqual(result[0], 96, 0)
        self.assertAlmostEqual(result[1], 149, 0)
        self.assertAlmostEqual(result[2], 147, 0)
        self.assertAlmostEqual(result[3], 89, 0)
        result = tsNoProj._convertProjectionUnits(
            -117.5, 33, None, None, 0.5, 0.5, 'EPSG:4326', unitsWH='base_pixels')
        self.assertAlmostEqual(result[0], 96, 0)
        self.assertAlmostEqual(result[1], 149, 0)
        self.assertEqual(result[2:], (None, None, 'base_pixels'))

        with six.assertRaisesRegex(self, TileSourceException, 'Cannot convert'):
            tsNoProj._convertProjectionUnits(
                -117.5, None, -117, None, None, None, 'EPSG:4326')

        tsProj = MapnikTileSource(filepath, 'EPSG:3857')
        result = tsProj._convertProjectionUnits(
            -13024380, 3895303, None, None, None, None, 'EPSG:3857')
        self.assertAlmostEqual(result[0], -13024380, 0)
        self.assertAlmostEqual(result[1], 3895303, 0)
        self.assertEqual(result[2:], (None, None, 'projection'))