How to use geoviews - 10 common examples

To help you get started, we’ve selected a few geoviews examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github holoviz / geoviews / tests / testconversions.py View on Github external
def test_geographic_conversion(self):
        self.assertEqual(Dataset(self.cube, kdims=['longitude', 'latitude']).to.image(), Image(self.cube, kdims=['longitude', 'latitude']))
github holoviz / geoviews / tests / testplotting.py View on Github external
def test_auto_guess_bounds(self):
        # Check that the `get_data()` method automatically adds bounds
        # when they're missing.
        cube = lat_lon_cube()
        element = Image(cube.copy())
        plot = GeoImagePlot(element)
        ranges = {}
        style = {'interpolation': None}
        plot_args, style, axis_kwargs = plot.get_data(element, ranges, style)
        for name in ('latitude', 'longitude'):
            cube.coord(name).guess_bounds()
        self.assertEqual(plot_args, (cube,))
        self.assertEqual(style, {'vmax': 11, 'vmin': 0})
        self.assertEqual(axis_kwargs, {})
github holoviz / geoviews / tests / testplotting.py View on Github external
def test_auto_guess_bounds_not_needed(self):
        # Check that the `get_data()` method *doesn't* try to add or
        # modify the bounds when they're already present.
        cube = lat_lon_cube()
        for name in ('latitude', 'longitude'):
            coord = cube.coord(name)
            coord.guess_bounds()
            coord.bounds = coord.bounds + 0.1
        element = Image(cube.copy())
        plot = GeoImagePlot(element)
        ranges = {}
        style = {'interpolation': None}
        plot_args, style, axis_kwargs = plot.get_data(element, ranges, style)
        self.assertEqual(plot_args, (cube,))
        self.assertEqual(style, {'vmax': 11, 'vmin': 0})
        self.assertEqual(axis_kwargs, {})
github holoviz / geoviews / tests / testconversions.py View on Github external
def test_is_geographic_2d(self):
        self.assertTrue(is_geographic(Dataset(self.cube, kdims=['longitude', 'latitude']), ['longitude', 'latitude']))
github pyviz-topics / EarthSim / earthsim / annotators.py View on Github external
def _link_polys(self):
        style = dict(editable=True)
        plot = dict(width=self.table_width, height=self.table_height)

        # Add annotation columns to poly data
        for col in self.poly_columns:
            if col not in self.polys:
                self.polys = self.polys.add_dimension(col, 0, '', True)
        self.poly_stream.source = self.polys
        self.vertex_stream.source = self.polys
        self._poly_selection.source = self.polys

        if len(self.polys):
            poly_data = gv.project(self.polys).split()
            self.poly_stream.event(data={kd.name: [p.dimension_values(kd) for p in poly_data]
                                         for kd in self.polys.kdims})

        poly_data = {c: self.polys.dimension_values(c, expanded=False) for c in self.poly_columns}
        if len(set(len(v) for v in poly_data.values())) != 1:
            raise ValueError('poly_columns must refer to value dimensions '
                             'which vary per path while at least one of '
                             '%s varies by vertex.' % self.poly_columns)
        self.poly_table = Table(poly_data, self.poly_columns, []).opts(plot=plot, style=style)
        self.poly_link = DataLink(source=self.polys, target=self.poly_table)
        self.vertex_table = Table([], self.polys.kdims, self.vertex_columns).opts(plot=plot, style=style)
        self.vertex_link = VertexTableLink(self.polys, self.vertex_table)
github pyviz-topics / EarthSim / earthsim / grabcut.py View on Github external
def __init__(self, poly_data=[], **params):
        super(SelectRegionPanel, self).__init__(**params)
        self.boxes = gv.Polygons(poly_data).options(
            fill_alpha=0.5, color='grey', line_color='white',
            line_width=2, width=self.width, height=self.height
        )
        if not self.boxes:
            self.boxes = self.boxes.options(global_extent=True)
        self.box_stream = BoxEdit(source=self.boxes, num_objects=1)
github pyviz-topics / EarthSim / earthsim / io.py View on Github external
def save_shapefile(cdsdata, path, template):
    """
    Accepts bokeh ColumnDataSource data and saves it as a shapefile,
    using an existing template to determine the required schema.
    """
    collection = fiona.open(template)
    arrays = [np.column_stack([xs, ys]) for xs, ys in zip(cdsdata['xs'], cdsdata['ys'])]
    polys = gv.Polygons(arrays, crs=ccrs.GOOGLE_MERCATOR)
    projected = gv.operation.project_path(polys, projection=ccrs.PlateCarree())
    data = [list(map(tuple, arr)) for arr in projected.split(datatype='array')]
    shape_data = list(collection.items())[0][1]
    shape_data['geometry']['coordinates'] = data
    with fiona.open(path, 'w', collection.driver, collection.schema, collection.crs) as c:
        c.write(shape_data)
github holoviz / geoviews / geoviews / data / geopandas.py View on Github external
def split(cls, dataset, start, end, datatype, **kwargs):
        objs = []
        xdim, ydim = dataset.kdims[:2]
        if not len(dataset.data):
            return []
        row = dataset.data.iloc[0]
        arr = geom_to_array(row['geometry'])
        d = {(xdim.name, ydim.name): arr}
        d.update({vd.name: row[vd.name] for vd in dataset.vdims})
        ds = dataset.clone(d, datatype=['dictionary'])
        for i, row in dataset.data.iterrows():
            if datatype == 'geom':
                objs.append(row['geometry'])
                continue
            arr = geom_to_array(row['geometry'])
            d = {xdim.name: arr[:, 0], ydim.name: arr[:, 1]}
            d.update({vd.name: row[vd.name] for vd in dataset.vdims})
            ds.data = d
            if datatype == 'array':
                obj = ds.array(**kwargs)
            elif datatype == 'dataframe':
                obj = ds.dframe(**kwargs)
            elif datatype == 'columns':
                obj = ds.columns(**kwargs)
            elif datatype is None:
                obj = ds.clone()
            else:
                raise ValueError("%s datatype not support" % datatype)
            objs.append(obj)
        return objs
github pyviz-topics / EarthSim / earthsim / analysis.py View on Github external
def __init__(self, obj, paths=None, **params):
        super(LineCrossSection, self).__init__(**params)
        self.obj = obj
        paths = [] if paths is None else paths
        self.path = Path(paths, crs=ccrs.GOOGLE_MERCATOR)
        self.path_stream = PolyDraw(source=self.path,
                                    num_objects=self._num_objects)
        PolyEdit(source=self.path)
        self.sections = Dynamic(self.obj, operation=self._sample,
                                streams=[self.path_stream])
        self.tiles = WMTS(self.tile_url)
github holoviz / geoviews / geoviews / tile_sources.py View on Github external
CartoMidnight = WMTS('http://3.api.cartocdn.com/base-midnight/{Z}/{X}/{Y}.png', name="CartoMidnight")

# Stamen basemaps
StamenTerrain = WMTS('http://tile.stamen.com/terrain/{Z}/{X}/{Y}.png', name="StamenTerrain")
StamenTerrainRetina = WMTS('http://tile.stamen.com/terrain/{Z}/{X}/{Y}@2x.png', name="StamenTerrainRetina")
StamenWatercolor = WMTS('http://tile.stamen.com/watercolor/{Z}/{X}/{Y}.jpg', name="StamenWatercolor")
StamenToner = WMTS('http://tile.stamen.com/toner/{Z}/{X}/{Y}.png', name="StamenToner")
StamenTonerBackground = WMTS('http://tile.stamen.com/toner-background/{Z}/{X}/{Y}.png', name="StamenTonerBackground")
StamenLabels = WMTS('http://tile.stamen.com/toner-labels/{Z}/{X}/{Y}.png', name="StamenLabels")

# Esri maps (see https://server.arcgisonline.com/arcgis/rest/services for the full list)
EsriImagery = WMTS('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}.jpg', name="EsriImagery")
EsriNatGeo = WMTS('https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{Z}/{Y}/{X}', name="EsriNatGeo")
EsriUSATopo = WMTS('https://server.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer/tile/{Z}/{Y}/{X}', name="EsriUSATopo")
EsriTerrain = WMTS('https://server.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer/tile/{Z}/{Y}/{X}', name="EsriTerrain")
EsriReference = WMTS('https://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Reference_Overlay/MapServer/tile/{Z}/{Y}/{X}', name="EsriReference")
EsriOceanBase = WMTS('https://server.arcgisonline.com/ArcGIS/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{Z}/{Y}/{X}', name="EsriOceanBase")
EsriOceanReference = WMTS('https://server.arcgisonline.com/ArcGIS/rest/services/Ocean/World_Ocean_Reference/MapServer/tile/{Z}/{Y}/{X}', name="EsriOceanReference")
ESRI = EsriImagery # For backwards compatibility with gv 1.5


# Miscellaneous
OSM = WMTS('https://c.tile.openstreetmap.org/{Z}/{X}/{Y}.png', name="OSM")
Wikipedia = WMTS('https://maps.wikimedia.org/osm-intl/{Z}/{X}/{Y}@2x.png', name="Wikipedia")


tile_sources = {k: v for k, v in locals().items() if isinstance(v, WMTS) and k != 'ESRI'}