示例#1
0
def get_geojson(request, source: MapSource):

    if not source.is_loaded:
        source.load()

    response = render_geojson(source)
    return JsonResponse(response, safe=False)
示例#2
0
def flask_to_geojson(source: MapSource):

    if not source.is_loaded:
        source.load()

    resp = render_geojson(source)
    return resp
示例#3
0
def get_tile(request, source: MapSource, z=0, x=0, y=0):
    if not source.is_loaded:
        print(f'Dynamically Loading Data {source.name}', file=sys.stdout)
        source.load()

    img = render_map(source, x=int(x), y=int(y), z=int(z))
    return StreamingHttpResponse(img.to_bytesio(), content_type='image/png')
示例#4
0
def flask_to_tile(source: MapSource, z=0, x=0, y=0):

    if not source.is_loaded:
        print(f'Dynamically Loading Data {source.name}', file=sys.stdout)
        source.load()

    img = render_map(source, x=int(x), y=int(y), z=int(z))
    return send_file(img.to_bytesio(), mimetype='image/png')
示例#5
0
def get_image(request, source: MapSource,
              xmin=-20e6, ymin=-20e6,
              xmax=20e6, ymax=20e6,
              height=500, width=500):
    if not source.is_loaded:
        source.load()

    img = render_map(source, xmin=float(xmin), ymin=float(ymin),
                     xmax=float(xmax), ymax=float(ymax),
                     height=int(height), width=int(width))
    return StreamingHttpResponse(img.to_bytesio(), content_type='image/png')
示例#6
0
def flask_to_image(source: MapSource,
                   xmin=-20e6, ymin=-20e6,
                   xmax=20e6, ymax=20e6,
                   height=500, width=500):

    if not source.is_loaded:
        source.load()

    img = render_map(source, xmin=float(xmin), ymin=float(ymin),
                     xmax=float(xmax), ymax=float(ymax),
                     height=int(height), width=int(width))
    return send_file(img.to_bytesio(), mimetype='image/png')
示例#7
0
def flask_to_wms(source: MapSource):

    if not source.is_loaded:
        source.load()

    height = request.args.get('height')
    width = request.args.get('width')
    bbox = request.args.get('bbox')
    xmin, ymin, xmax, ymax = bbox.split(',')
    img = render_map(source, xmin=float(xmin), ymin=float(ymin),
                     xmax=float(xmax), ymax=float(ymax),
                     height=int(height), width=int(width))
    return send_file(img.to_bytesio(), mimetype='image/png')
示例#8
0
def get_wms(request, source: MapSource):

    if not source.is_loaded:
        source.load()

    height = request.GET.get('height')
    width = request.GET.get('width')
    bbox = request.GET.get('bbox', '')
    xmin, ymin, xmax, ymax = bbox.split(',')
    img = render_map(source, xmin=float(xmin), ymin=float(ymin),
                     xmax=float(xmax), ymax=float(ymax),
                     height=int(height), width=int(width))
    return StreamingHttpResponse(img.to_bytesio(), content_type='image/png')
示例#9
0
def flask_to_geojson(source: MapSource):

    if not source.is_loaded:
        source.load()

    q = request.args.get('q')
    limit = request.args.get('limit')
    offset = request.args.get('offset')
    simplify = request.args.get('simplify')
    bbox = request.args.get('bbox')


    resp = render_geojson(source)
    return resp
示例#10
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)
示例#11
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)
示例#12
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)
示例#13
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
示例#14
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)
示例#15
0
def test_load_default_dataset(source_func):
    source = MapSource.from_obj(source_func()).load()
    assert isinstance(source, MapSource)
示例#16
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)