Ejemplo n.º 1
0
def test_create_map_source_with_existing_geodataframe():

    gdf = gpd.read_file(gpd.datasets.get_path('nybb'))

    # construct transforms
    reproject_transform = dict(name='reproject_vector', args=dict(epsg=3857))
    sp_transform = dict(name='to_spatialpandas',
                        args=dict(geometry_field='geometry'))
    transforms = [reproject_transform, sp_transform]

    # construct value obj
    source_obj = dict()
    source_obj['name'] = 'NYC Admin'
    source_obj['key'] = 'nyc-boroughs'
    source_obj['text'] = 'NYC Boroughs'
    source_obj['description'] = 'New York City Boroughs'
    source_obj['geometry_type'] = 'polygon'
    source_obj['agg_func'] = 'max'
    source_obj['shade_how'] = 'linear'
    source_obj['span'] = 'min/max'
    source_obj['dynspread'] = None
    source_obj['raster_interpolate'] = 'linear'
    source_obj['xfield'] = 'geometry'
    source_obj['yfield'] = 'geometry'
    source_obj['zfield'] = 'BoroCode'
    source_obj['data'] = gdf
    source_obj['transforms'] = transforms
    source_obj['service_types'] = ['tile', 'wms', 'image', 'geojson']

    source = MapSource.from_obj(source_obj).load()
    assert isinstance(source, VectorSource)

    arr = to_raster(source, width=100)
    assert isinstance(arr, xr.DataArray)
Ejemplo n.º 2
0
def test_default_to_image(source_func):
    source = MapSource.from_obj(source_func()).load()
    img = render_map(source,
                     xmin=-20e6,
                     ymin=-20e6,
                     xmax=20e6,
                     ymax=20e6,
                     width=500,
                     height=500)
    assert isinstance(img, Image)
Ejemplo n.º 3
0
def test_to_raster(source_func):
    source = MapSource.from_obj(source_func()).load()
    result = to_raster(source,
                       xmin=-20e6,
                       ymin=-20e6,
                       xmax=20e6,
                       ymax=20e6,
                       width=500,
                       height=500)
    assert isinstance(result, xr.DataArray)
    assert result.data.shape == (500, 500)
Ejemplo n.º 4
0
def test_default_to_geojson(source_func):
    source = MapSource.from_obj(source_func()).load()
    geojson = render_geojson(source)
    assert isinstance(geojson, str)
    data = json.loads(geojson)
    assert isinstance(data, dict)

    if not source.geometry_type in ('raster', 'line'):
        assert data.get('type') == 'FeatureCollection'
    else:
        assert data
Ejemplo n.º 5
0
def test_tile_render_edge_effects():
    source = MapSource.from_obj(elevation_source()).load()

    # this tile was bad...
    agg = create_agg(source, x=10, y=11, z=5)

    first_col = agg.data[:, 0]
    last_col = agg.data[:, -1]
    top_row = agg.data[0, :]  # TODO: do i have these flipped?
    bottom_row = agg.data[-1, :]

    assert np.all(~np.isnan(first_col))
    assert np.all(~np.isnan(last_col))
    assert np.all(~np.isnan(top_row))
    assert np.all(~np.isnan(bottom_row))

    img = render_map(source, x=10, y=11, z=5)
    assert isinstance(img, Image)
Ejemplo n.º 6
0
def test_load_default_dataset(source_func):
    source = MapSource.from_obj(source_func()).load()
    assert isinstance(source, MapSource)
Ejemplo n.º 7
0
def test_default_to_tile(source_func):
    source = MapSource.from_obj(source_func()).load()
    img = render_map(source, x=0, y=0, z=0, height=256, width=256)
    assert isinstance(img, Image)