예제 #1
0
 def __init__(self, **kwargs):
     """Process initialization"""
     # init process
     MapcheteProcess.__init__(self, **kwargs)
     self.identifier = "my_process_id",
     self.title = "My long process title",
     self.version = "0.1",
     self.abstract = "short description on what my process does"
예제 #2
0
 def __init__(self, **kwargs):
     """Process initialization"""
     # init process
     MapcheteProcess.__init__(self, **kwargs)
     self.identifier = "my_process_id",
     self.title="My long process title",
     self.version = "0.1",
     self.abstract="short description on what my process does"
예제 #3
0
def test_hillshade():
    """Render hillshade from array."""
    mp = mapchete.open(
        os.path.join(SCRIPTDIR, "testdata/cleantopo_tl.mapchete"))
    tile = mp.get_process_tiles(zoom=4).next()
    tile_process = MapcheteProcess(tile, params=mp.config.at_zoom(4))
    with tile_process.open("file1") as dem:
        shade = tile_process.hillshade(dem.read())
        assert isinstance(shade, np.ndarray)
예제 #4
0
def test_hillshade(cleantopo_tl):
    """Render hillshade from array."""
    with mapchete.open(cleantopo_tl.path) as mp:
        tile = next(mp.get_process_tiles(zoom=4))
        tile_process = MapcheteProcess(tile,
                                       params=mp.config.params_at_zoom(4))
        with tile_process.open("file1") as dem:
            shade = tile_process.hillshade(dem.read())
            assert isinstance(shade, np.ndarray)
예제 #5
0
def test_read_from_raster_file(cleantopo_br):
    """Read different bands from source raster."""
    with mapchete.open(cleantopo_br.path) as mp:
        process_tile = mp.config.process_pyramid.tile(5, 0, 0)
        process = MapcheteProcess(config=mp.config,
                                  tile=process_tile,
                                  params=mp.config.params_at_zoom(
                                      process_tile.zoom))
        with process.open("file1") as f:
            assert f.read().shape == f.read([1]).shape == f.read(1).shape
예제 #6
0
def test_clip(geojson):
    """Clip an array with a vector."""
    with mapchete.open(geojson.path) as mp:
        tile = next(mp.get_process_tiles(zoom=4))
        user_process = MapcheteProcess(
            tile=tile,
            params=mp.config.params_at_zoom(4),
            input=mp.config.get_inputs_for_tile(tile),
        )
        with user_process.open("file1") as vector_file:
            test_array = ma.masked_array(np.ones(user_process.tile.shape))
            clipped = user_process.clip(test_array, vector_file.read())
            # default params
            assert isinstance(clipped, ma.masked_array)
            assert clipped.mask.any()
            assert not clipped.mask.all()
            # inverted clip
            clipped_inverted = user_process.clip(test_array,
                                                 vector_file.read(),
                                                 inverted=True)
            assert isinstance(clipped_inverted, ma.masked_array)
            assert clipped_inverted.mask.any()
            assert not clipped_inverted.mask.all()
            # compare results
            assert (clipped + clipped_inverted).mask.all()
            # using empty Geometries
            geoms = [dict(geometry=Point())]
            clipped = user_process.clip(test_array, geoms)
            assert clipped.mask.all()
            # using empty Geometries inverted
            clipped = user_process.clip(test_array, geoms, inverted=True)
            assert not clipped.mask.any()
            # using Point Geometries
            geoms = [dict(geometry=tile.bbox.centroid)]
            clipped = user_process.clip(test_array, geoms)
            assert clipped.mask.all()
            # using Geometry Collections
            geoms = [
                dict(geometry=GeometryCollection(
                    [tile.bbox.centroid, tile.bbox]))
            ]
            clipped = user_process.clip(test_array, geoms)
            assert not clipped.mask.any()
            # using 3D array
            test_array = ma.masked_array(
                np.ones((1, ) + user_process.tile.shape))
            clipped = user_process.clip(test_array, vector_file.read())
            assert isinstance(clipped, ma.masked_array)
            assert clipped.mask.any()
            assert not clipped.mask.all()
예제 #7
0
def test_http_rasters(files_bounds, http_raster):
    """Raster file on remote server with http:// or https:// URLs."""
    zoom = 13
    config = files_bounds.dict
    config.update(input=dict(file1=http_raster), zoom_levels=zoom)
    # TODO make tests more performant
    with mapchete.open(config) as mp:
        assert mp.config.area_at_zoom(zoom).area > 0
        process_tile = next(mp.get_process_tiles(13))
        process = MapcheteProcess(config=mp.config,
                                  tile=process_tile,
                                  params=mp.config.params_at_zoom(
                                      process_tile.zoom))
        with process.open("file1") as f:
            assert f.read().any()
예제 #8
0
def test_clip():
    """Clip an array with a vector."""
    mp = mapchete.open(os.path.join(SCRIPTDIR, "testdata/geojson.mapchete"))
    tile = mp.get_process_tiles(zoom=4).next()
    tile_process = MapcheteProcess(tile, params=mp.config.at_zoom(4))
    with tile_process.open("file1") as vector_file:
        test_array = ma.masked_array(np.ones(tile_process.tile.shape))
        clipped = tile_process.clip(test_array, vector_file.read())
        # default params
        assert isinstance(clipped, ma.masked_array)
        assert clipped.mask.any()
        assert not clipped.mask.all()
        # inverted clip
        clipped_inverted = tile_process.clip(test_array,
                                             vector_file.read(),
                                             inverted=True)
        assert isinstance(clipped_inverted, ma.masked_array)
        assert clipped_inverted.mask.any()
        assert not clipped_inverted.mask.all()
        # compare results
        assert (clipped + clipped_inverted).mask.all()
        # using empty Geometries
        geoms = [dict(geometry=Point())]
        clipped = tile_process.clip(test_array, geoms)
        assert clipped.mask.all()
        # using empty Geometries inverted
        clipped = tile_process.clip(test_array, geoms, inverted=True)
        assert not clipped.mask.any()
        # using Point Geometries
        geoms = [dict(geometry=tile.bbox.centroid)]
        clipped = tile_process.clip(test_array, geoms)
        assert clipped.mask.all()
        # using Geometry Collections
        geoms = [
            dict(geometry=GeometryCollection([tile.bbox.centroid, tile.bbox]))
        ]
        clipped = tile_process.clip(test_array, geoms)
        assert not clipped.mask.any()
        # using 3D array
        test_array = ma.masked_array(np.ones((1, ) + tile_process.tile.shape))
        clipped = tile_process.clip(test_array, vector_file.read())
        assert isinstance(clipped, ma.masked_array)
        assert clipped.mask.any()
        assert not clipped.mask.all()
예제 #9
0
def test_contours():
    """Extract contours from array."""
    mp = mapchete.open(
        os.path.join(SCRIPTDIR, "testdata/cleantopo_tl.mapchete"))
    tile = mp.get_process_tiles(zoom=4).next()
    tile_process = MapcheteProcess(tile, params=mp.config.at_zoom(4))
    with tile_process.open("file1") as dem:
        contours = tile_process.contours(dem.read())
        assert contours
        assert isinstance(contours, list)
        # no contours
        contours = tile_process.contours(dem.read(), interval=10000)
        assert isinstance(contours, list)
        assert not contours
        # base bigger than values
        contours = tile_process.contours(dem.read(), base=10000)
        assert isinstance(contours, list)
        assert contours
예제 #10
0
def test_contours(cleantopo_tl):
    """Extract contours from array."""
    with mapchete.open(cleantopo_tl.path) as mp:
        tile = next(mp.get_process_tiles(zoom=4))
        tile_process = MapcheteProcess(tile,
                                       params=mp.config.params_at_zoom(4))
        with tile_process.open("file1") as dem:
            arr = dem.read()
            # valid contours
            contours = tile_process.contours(arr)
            assert contours
            assert isinstance(contours, list)
            # no contours
            contours = tile_process.contours(arr, interval=10000)
            assert isinstance(contours, list)
            assert not contours
            # base bigger than values
            contours = tile_process.contours(arr, base=10000)
            assert isinstance(contours, list)
            assert contours
예제 #11
0
 def __init__(self, config):
     MapcheteProcess.__init__(self, config)
     self.identifier = "example_process"
     self.title = "example process file",
     self.version = "dirty pre-alpha",
     self.abstract = "used for testing"
예제 #12
0
파일: tilify.py 프로젝트: ungarj/mapchete
 def __init__(self, **kwargs):
     MapcheteProcess.__init__(self, **kwargs)
     self.identifier = "tilify"
     self.title = "tilifies raster dataset into tile pyramid",
     self.version = "current",
     self.abstract = "used for raster2pyramid CLI"
예제 #13
0
파일: tilify.py 프로젝트: gijs/mapchete
 def __init__(self, **kwargs):
     MapcheteProcess.__init__(self, **kwargs)
     self.identifier = "tilify"
     self.title = "tilifies raster dataset into tile pyramid",
     self.version = "current",
     self.abstract = "used for raster2pyramid CLI"
예제 #14
0
 def __init__(self, config):
     MapcheteProcess.__init__(self, config)
     self.identifier = "example_process"
     self.title = "example process file",
     self.version = "dirty pre-alpha",
     self.abstract = "used for testing"