question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

geoviews.feature extents

See original GitHub issue

It would be nice if the extents given to the geoviews.feature determine the extent of data that is extracted/used, rather than just determing the viewable window size.

Below is an example that plots some fake data over a small region. Here the window extent is chosen by a) the dataset used and b) the extents given to the geoviews.feature.coastline

However, if you zoom out you can see that the coastline data is actually available for the entire globe rather than just the subdomain I have chosen.

This has implications for the size of files generated (HoloMaps) or data downloaded (DynamicMaps). This is especially noticiable when using high resolution data. If you turn on the use of 10m coastline resolution, you will see that the file size goes from ~approximately 150k to 8.8M. It is my suspiciion that the majority of the increased data comes from the highresolution data in regions on the world we don’t actually care about.

import numpy as np
import xarray as xr
import holoviews as hv
import geoviews as gv
import geoviews.feature as gf
from cartopy import crs as ccrs

def create_data():
    """
    create fake example data
    """
    times = [np.datetime64('2018-02-22 00:00:00')]
    lons = np.arange(144, 150, 1)
    lats = np.arange(-45, -39, 1)

    dims = ('time', 'latitude', 'longitude')
    shape = (len(times), len(lats), len(lons))
    coords = {'latitude':lats, 'longitude':lons, 'time':times}

    pres = np.zeros(shape)
    pres[0, :, :] = 10
    pres_xr = xr.DataArray(pres, dims=dims, coords=coords)
    xr_ds = xr.Dataset({'time': times, 'latitude': lats,
        'longitude': lons,  'pres': (dims, pres)})
    return xr_ds

hv.extension('bokeh')
renderer = hv.renderer('bokeh')
hv.output('size=200')
hv.opts("Image (cmap='Spectral_r')")

xr_ds = create_data()
vdims = ['pres']
kdims= ['time', 'latitude', 'longitude']
gv_ds = gv.Dataset(xr_ds, kdims=kdims, vdims=vdims, crs=ccrs.PlateCarree())

hv.Dimension.type_formatters[np.datetime64] = '%Y-%m-%d %H'

geo_dims = ['longitude', 'latitude']

extents = (144.0, -45.0, 149.0, -40.0)
# using extents on the geo feature sets the plot window extents,
# however, all the data is still extracted/used

#hv.opts("Feature [scale='10m']")
coast = gf.coastline.clone(extents=extents)
img = gv_ds.to(gv.Image, geo_dims) * coast
renderer.save(img, 'test_gf')

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ahuang11commented, Jul 9, 2019

http://geopandas.org/indexing.html I just discovered there’s a.cx method which might be useful here.

0reactions
ahuang11commented, Feb 2, 2020

I would like to help make a PR for this, but I don’t know where/how to start.

I was thinking of adding a subset or crop kwarg like this: gv.feature.coastline(subset=(x1, x2, y1, y2)) sort of similar to the scale kwarg gv.feature.coastline(scale='50m') so I tried searching for the scale kwarg in the code, but I only found it in https://github.com/holoviz/geoviews/blob/master/geoviews/element/geo.py#L152 which is only called when doing gv.feature.coastline(scale='50m').geoms

Any ideas appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting extents on Feature - GeoViews - HoloViz Discourse
Hi, I found this https://github.com/holoviz/geoviews/issues/141 talking about extents. It seems in this issue that this code should work : import ...
Read more >
geoviews.feature extents · Issue #141 - GitHub
It would be nice if the extents given to the geoviews.feature determine the extent of data that is extracted/used, rather than just determing ......
Read more >
How to use the geoviews.util.project_extents function in ... - Snyk
How to use the geoviews.util.project_extents function in geoviews ... set_extent method to project the extents to the Elements coordinate reference system.
Read more >
Geometries — GeoViews 1.9.5+g5eb9cd4-dirty documentation
The cartopy.feature module provides various ways of loading custom features, however geoviews provides a number of default features which we have imported ...
Read more >
GeoView viewpoint synchronization | ArcGIS Runtime API for ...
Analysis. Query feature count and extent · Line of sight (geoelement) · Data. Add features · Geometry. Buffer · Geoprocessing. Analyze hotspots ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found