### Copy and run GeoViews examples with Jupyter Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst These commands copy the GeoViews example notebooks into the current directory, navigate into the examples directory, and then launch the Jupyter notebook environment to run them. This allows users to explore GeoViews functionalities interactively. ```bash geoviews examples cd geoviews-examples jupyter notebook ``` -------------------------------- ### Copy and Run GeoViews Examples Source: https://github.com/holoviz/geoviews/blob/main/README.md These commands allow users to copy GeoViews example notebooks to the current directory, navigate into the examples directory, and then launch a Jupyter notebook server to explore them. This provides a quick way to get started with GeoViews functionalities. ```bash geoviews examples cd geoviews-examples jupyter notebook ``` -------------------------------- ### Install GeoViews-core with conda for minimal dependencies Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst This command installs the geoviews-core package using conda, which includes only the minimal dependencies required to run GeoViews. Use this for a lighter installation. ```bash conda install -c pyviz geoviews-core ``` -------------------------------- ### Launching JupyterLab - Shell Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst Starts the JupyterLab server, providing a modern, integrated development environment for working with notebooks. Requires JupyterLab to be installed. This command is used after installation. ```Shell jupyter-lab ``` -------------------------------- ### Install GeoViews with pip Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst This command installs the GeoViews library and its core dependencies using the pip package manager. It is a straightforward method for setting up GeoViews in a Python environment. ```bash pip install geoviews ``` -------------------------------- ### Launch JupyterLab environment Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst This command launches the JupyterLab interface, providing an interactive development environment for working with GeoViews and other Python libraries. ```bash jupyter-lab ``` -------------------------------- ### Install JupyterLab extension for pyviz Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst For JupyterLab versions prior to 3.0, this command installs the necessary @pyviz/jupyterlab_pyviz extension. This extension ensures proper rendering and interaction with HoloViz libraries like GeoViews within JupyterLab. ```bash conda install -c conda-forge jupyterlab jupyter labextension install @pyviz/jupyterlab_pyviz ``` -------------------------------- ### Download GeoViews test and example data Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md Execute this command to download the data required for GeoViews tests and examples. This task runs within the `download-data` Pixi environment. ```bash pixi run -e download-data download-data ``` -------------------------------- ### Run GeoViews Example Notebook Tests Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md Executes all Jupyter Notebooks in the `examples/` folder using nbval. These tests ensure that the documentation examples run without errors, validating their correctness and functionality. ```bash pixi run test-example ``` -------------------------------- ### Install GeoViews project dependencies with Pixi Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md Run this command to install all necessary packages and create the `pixi.lock` file for the GeoViews development environment. This process may take a few minutes on the first run. ```bash pixi install ``` -------------------------------- ### Create conda environment with GeoViews and conda-forge dependencies Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst This command creates a new conda environment, installing GeoViews along with additional libraries like Iris and xesmf from the conda-forge channel. It's crucial to activate this environment afterward to use these packages. ```bash conda create -n env-name -c pyviz -c conda-forge geoviews iris xesmf ``` -------------------------------- ### Install GeoViews with conda from pyviz channel Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst This command installs the GeoViews library and its dependencies using the conda package manager from the pyviz channel. Conda is recommended for managing environments and complex dependencies. ```bash conda install -c pyviz geoviews ``` -------------------------------- ### Building NPM Package with Pixi Bash Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md Executes the Pixi task to build the project package in the Node Package Manager (NPM) format. This is relevant if the project includes JavaScript or front-end components distributed via NPM. ```Bash pixi run build-npm ``` -------------------------------- ### Building Conda Package with Pixi Bash Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md Runs the Pixi task responsible for building the project package in the Conda format. This generates files suitable for distribution via Conda channels. ```Bash pixi run build-conda ``` -------------------------------- ### Initialize Geoviews and Matplotlib Extension Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/world_population.ipynb Initializes the Geoviews library, imports necessary modules like pandas, and sets up the Matplotlib backend for rendering with SVG output. ```python import pandas as pd import geoviews as gv from geoviews import dim gv.extension('matplotlib') gv.output(fig='svg', size=200) ``` -------------------------------- ### Install GeoViews with All Dependencies Source: https://github.com/holoviz/geoviews/blob/main/README.md This command installs the full GeoViews package along with all its recommended dependencies from the pyviz channel. This is the standard installation method for a complete GeoViews environment. ```bash conda install -c pyviz geoviews ``` -------------------------------- ### Activate a conda environment Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst This command activates a specified conda environment, making its installed packages available for use. It's a necessary step after creating or before using a custom environment. ```bash conda activate env-name ``` -------------------------------- ### Install GeoViews in editable mode Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md Install the GeoViews project in editable mode, which allows changes to the source code to be reflected without requiring reinstallation. This is beneficial for active development. ```bash pixi run install ``` -------------------------------- ### Install GeoViews Core with Minimal Dependencies Source: https://github.com/holoviz/geoviews/blob/main/README.md This command installs only the minimal dependencies required to run GeoViews. Use this option if you need a lightweight installation or want to manage additional dependencies manually. ```bash conda install -c pyviz geoviews-core ``` -------------------------------- ### Install GeoViews in editable mode for a specific environment Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md Install GeoViews in editable mode for a particular Pixi environment, such as `test-ui`. This command demonstrates how to specify the target environment using the `-e` or `--environment` flag. ```bash pixi run -e test-ui install ``` -------------------------------- ### Creating Conda Environment with Multiple Channels - Shell Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst Creates a new isolated conda environment ('env-name') and installs specified packages (GeoViews, Iris, xesmf) from multiple designated channels (pyviz and conda-forge) to ensure compatibility and proper dependency resolution. Requires Anaconda or Miniconda. ```Shell conda create -n env-name -c pyviz -c conda-forge geoviews iris xesmf ``` -------------------------------- ### Install GeoViews Pre-Commit Linting Hooks Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md This command sets up pre-commit hooks to automatically run linting checks before each commit. This is the recommended approach to prevent Continuous Integration (CI) failures due to linting issues. ```bash pixi run lint-install ``` -------------------------------- ### Initialize GeoViews Environment Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/trimesh_uk.ipynb This snippet imports necessary libraries like NumPy, GeoViews, and Cartopy, then initializes the GeoViews extension for Matplotlib and configures the output format for figures. ```python import numpy as np import geoviews as gv import geoviews.feature as gf import cartopy.crs as ccrs gv.extension('matplotlib') gv.output(fig='svg', size=200) ``` -------------------------------- ### Launch JupyterLab Environment Source: https://github.com/holoviz/geoviews/blob/main/README.md This command launches the JupyterLab interface in your web browser. It is the primary way to interact with Jupyter notebooks and GeoViews visualizations after installation. ```bash jupyter-lab ``` -------------------------------- ### Initialize GeoViews and Bokeh Extension Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Imports necessary libraries like `geoviews` and `cartopy.crs`, and initializes the Bokeh extension for GeoViews to enable interactive plotting and annotation tools. ```python import geoviews as gv import cartopy.crs as ccrs from geoviews import annotate gv.extension('bokeh') ``` -------------------------------- ### Activating Conda Environment - Shell Source: https://github.com/holoviz/geoviews/blob/main/doc/index.rst Activates the specified conda environment ('env-name'), making the packages installed within it available for use in your current terminal session. This isolates project dependencies. Requires the environment to be created. ```Shell conda activate env-name ``` -------------------------------- ### Initialize GeoViews and Import Libraries Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/vectorfield_example.ipynb Imports necessary libraries like NumPy for numerical operations, GeoViews for geospatial data visualization, and Cartopy for coordinate reference system handling. It then initializes the GeoViews Bokeh extension, enabling interactive plotting capabilities. ```python import numpy as np import geoviews as gv import cartopy.crs as ccrs gv.extension('bokeh') ``` -------------------------------- ### Initialize GeoViews with Matplotlib Backend Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/tile_sources.ipynb This snippet imports the `geoviews` library and its `opts` and `tile_sources` modules, aliasing them for convenience. It then initializes GeoViews to use the `matplotlib` backend for plotting, which is a necessary setup step before creating any visualizations. ```python import geoviews as gv from geoviews import opts, tile_sources as gvts gv.extension('matplotlib') ``` -------------------------------- ### Import Libraries and Initialize GeoViews Extension Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/new_york_boroughs.ipynb Imports essential libraries for geospatial data handling and visualization, including geodatasets, geopandas, geoviews, and cartopy. It also initializes the 'bokeh' extension for GeoViews to enable interactive plotting capabilities. ```python import geodatasets as gds import geopandas as gpd import geoviews as gv import cartopy.crs as ccrs gv.extension('bokeh') ``` -------------------------------- ### Initialize GeoViews for Matplotlib Backend Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/wind_barbs_example.ipynb Imports necessary libraries (NumPy, GeoViews) and sets up GeoViews to use the Matplotlib backend. It also configures the output figure format to SVG and sets a default size for visualizations. ```python import numpy as np import geoviews as gv gv.extension('matplotlib') gv.output(fig='svg', size=200) ``` -------------------------------- ### Install JupyterLab PyViz Extension (JupyterLab < 3.0) Source: https://github.com/holoviz/geoviews/blob/main/README.md For JupyterLab versions prior to 3.0, this command manually installs the necessary @pyviz/jupyterlab_pyviz extension. This extension is crucial for GeoViews objects to render correctly within the JupyterLab environment. ```bash jupyter labextension install @pyviz/jupyterlab_pyviz ``` -------------------------------- ### Initialize GeoViews Environment Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/orthographic_vectorfield.ipynb This snippet imports necessary libraries like NumPy, GeoViews, GeoViews features, and Cartopy for geographical projections. It also initializes the GeoViews extension to use the Bokeh backend for interactive visualizations. ```python import numpy as np import geoviews as gv import geoviews.feature as gf import cartopy.crs as ccrs gv.extension('bokeh') ``` -------------------------------- ### Initialize Geoviews and Import Libraries Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/new_york_boroughs.ipynb This snippet imports necessary libraries such as geodatasets, geopandas, geoviews, and cartopy. It also configures geoviews to use the 'matplotlib' backend and sets the output resolution and format for generated plots. ```python import geodatasets as gds import geopandas as gpd import geoviews as gv import cartopy.crs as ccrs gv.extension('matplotlib') gv.output(dpi=120, fig='svg') ``` -------------------------------- ### GeoViews: Initial Setup and Imports Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/airport_graph.ipynb This snippet initializes the GeoViews library and imports necessary modules like pandas, geoviews, and sample data for airport routes. It also sets the GeoViews extension to 'bokeh' for interactive plotting. ```python import pandas as pd import geoviews as gv from geoviews import opts from bokeh.sampledata.airport_routes import airports, routes gv.extension('bokeh') ``` -------------------------------- ### Initialize GeoViews with Bokeh Extension Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/tile_sources.ipynb Imports the GeoViews library, its options and tile sources, and initializes the Bokeh extension for interactive plotting. This setup is crucial for using GeoViews functionalities. ```python import geoviews as gv from geoviews import opts, tile_sources as gvts gv.extension('bokeh') ``` -------------------------------- ### Create Conda environment for Cartopy Source: https://github.com/holoviz/geoviews/blob/main/doc/user_guide/Using_Features_Offline.md Initializes a new Conda environment named `cartopy_env` with Python 3.10, suitable for installing Cartopy and GeoViews. ```bash conda create -n cartopy_env python=3.10 ``` -------------------------------- ### Initialize GeoViews with Bokeh and Matplotlib Backends Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Projections.ipynb Imports GeoViews and Cartopy, then initializes GeoViews to use Bokeh and Matplotlib plotting backends. This setup enables both interactive web-based plots and static high-quality figures. ```python import geoviews as gv import geoviews.feature as gf from geoviews import opts from cartopy import crs gv.extension('bokeh', 'matplotlib') ``` -------------------------------- ### GeoViews Module Structure and Subpackages Overview Source: https://github.com/holoviz/geoviews/blob/main/doc/reference_manual/index.rst This section outlines the primary subpackages within the GeoViews library, providing a high-level overview of their purpose and the functionalities they encapsulate. It serves as a guide to the organization of the GeoViews API. ```APIDOC GeoViews Subpackages: annotators: Helper functions and classes to annotate visual elements. data: Data interface classes enabling GeoViews to work with various data types. element: Core elements that form the basis of geographic visualizations. links: Tools for linking different elements and streams. models: Custom models extending GeoViews' capabilities. operation: Operations applied to transform existing elements or data structures. plotting: Base plotting classes and utilities. plotting.bokeh: Bokeh-specific plotting classes and utilities. plotting.matplotlib: Matplotlib-specific plotting classes and utilities. streams: Stream classes providing interactivity for dynamic maps. util: High-level utilities supporting GeoViews functionality. ``` -------------------------------- ### Annotate GeoViews Paths on a Map Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Demonstrates annotating `gv.Path` objects, highlighting the distinction between feature nodes (start/end) and regular nodes. It sets up a sample path and enables interactive drawing and editing, with support for splitting paths. ```python sample_poly=dict( Longitude = [-10114986, -10123906, -10130333, -10121522, -10129889, -10122959], Latitude = [ 3806790, 3812413, 3807530, 3805407, 3798394, 3796693]) path = gv.Path([sample_poly], crs=ccrs.GOOGLE_MERCATOR).opts( line_width=2, color='black', responsive=True ) path_annotate = annotate.instance() annotated = path_annotate(path, vertex_annotations=['Height']) annotate.compose(tiles, annotated) ``` -------------------------------- ### Load and Prepare City Population Data with Geoviews Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/world_population.ipynb Loads city population data from a CSV file into a Pandas DataFrame, converts it into a Geoviews Dataset, and then transforms it into Geoviews Points for geographical plotting. It also initializes OpenStreetMap tiles. ```python cities = pd.read_csv('../../assets/cities.csv', encoding="ISO-8859-1") population = gv.Dataset(cities, kdims=['City', 'Country', 'Year']) points = population.to(gv.Points, ['Longitude', 'Latitude'], ['Population', 'City', 'Country']) tiles = gv.tile_sources.OSM ``` -------------------------------- ### Initialize Geoviews and Import Libraries Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/filled_contours.ipynb This snippet imports necessary libraries like numpy for data manipulation, geoviews for plotting, and cartopy for coordinate reference systems. It also initializes the geoviews extension for Bokeh, enabling interactive visualizations. ```python import numpy as np import geoviews as gv import geoviews.feature as gf from cartopy import crs from geoviews import opts gv.extension('bokeh') ``` -------------------------------- ### Annotate GeoViews Polygons for visualization Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Initializes a GeoViews Polygons element with a sample polygon and applies annotations using the `annotate` instance. It adds 'Value' and 'Height' annotations to the polygon and its vertices, then composes the result with map tiles. ```python poly = gv.Polygons([sample_poly], crs=ccrs.GOOGLE_MERCATOR) poly_annotate = annotate.instance() annotated = poly_annotate(poly, annotations=['Value'], vertex_annotations=['Height']) annotate.compose(tiles, annotated) ``` -------------------------------- ### Annotate GeoViews Rectangles on a Map Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Illustrates the process of annotating rectangle data using the `annotate` coordinator. It sets up an initial rectangle and enables interactive drawing and editing, with table coordinates projected for human readability. ```python rectangles = gv.Rectangles([(0, 0, 10, 10)]) box_annotate = annotate.instance() annotated = box_annotate(rectangles, annotations=['Label'], name='Rectangles') annotate.compose(tiles, annotated) ``` -------------------------------- ### Annotate GeoViews Points on a Map Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Demonstrates how to set up and use the `annotate` coordinator to draw and edit point data on an OpenStreetMap tile source. It initializes sample points in Web Mercator and applies annotation tools, displaying coordinates as latitude/longitude in the editable table. ```python tiles = gv.tile_sources.OSM() sample_points = dict( Longitude = [-10131185, -10131943, -10131766, -10131032, -10129766], Latitude = [ 3805587, 3803182, 3801073, 3799778, 3798878]) points = gv.Points(sample_points, crs=ccrs.GOOGLE_MERCATOR).opts( size=10, line_color='black', responsive=True, min_height=600 ) point_annotate = annotate.instance() annotated = point_annotate(points, annotations=['Size']) annotate.compose(tiles, annotated) ``` -------------------------------- ### Plot City Population Data on a Map Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/world_population.ipynb Generates a geographical plot by overlaying city population points on OpenStreetMap tiles. The size and color of the points are mapped to the 'Population' dimension, providing a visual representation of population density. ```python tiles.opts(zoom=0) * points.opts( s=dim('Population')*0.00001, color='Population', cmap='viridis', global_extent=True) ``` -------------------------------- ### Visualize Geographic Features with Custom Projection Source: https://github.com/holoviz/geoviews/blob/main/examples/Homepage.ipynb This example demonstrates combining various geographic features (ocean, land, coastline, borders) from `geoviews.feature` and applying a custom `Geostationary` projection. It sets the global extent and height for the plot, showcasing basic feature composition in GeoViews. ```python (gf.ocean + gf.land + gf.ocean * gf.land * gf.coastline * gf.borders).opts( 'Feature', projection=crs.Geostationary(), global_extent=True, height=325) ``` -------------------------------- ### Visualize GeoViews Triangulation with Coastline Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/trimesh_uk.ipynb This snippet visualizes the defined triangulation (trimesh) overlaid with a coastline feature from geoviews.feature. The coastline is styled with a red edge color and a '50m' scale, while the triangulation plot includes a padding of 0.1 for better visualization. ```python gf.coastline().opts(edgecolor='red', scale='50m') * trimesh.opts(padding=0.1) ``` -------------------------------- ### Clone GeoViews repository Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md Instructions to fork and clone the GeoViews GitHub repository to your local machine, replacing the placeholder with your GitHub username. ```bash git clone https://github.com//geoviews ``` -------------------------------- ### GeoViews Initial Setup and Imports Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Geometries.ipynb This snippet imports necessary libraries like pandas, holoviews, geoviews, and cartopy. It also configures GeoViews to use 'matplotlib' and 'bokeh' extensions and sets the default output format for plots. ```python import pandas as pd import holoviews as hv import geoviews as gv import geoviews.feature as gf import cartopy import cartopy.feature as cf from geoviews import opts from cartopy import crs as ccrs gv.extension('matplotlib', 'bokeh') gv.output(dpi=120, fig='svg') ``` -------------------------------- ### Load and Project Geographical Data with Geoviews Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/new_york_boroughs.ipynb This snippet defines the base map tiles using OpenStreetMap and loads the New York City borough boundaries dataset using geodatasets and geopandas. It then projects the geographical data to the Web Mercator coordinate system, which is suitable for web mapping, and creates a Geoviews Polygons element. ```python tiles = gv.tile_sources.OSM # Project data to Web Mercator nybb = gpd.read_file(gds.get_path('nybb')) poly_data = nybb.to_crs(ccrs.GOOGLE_MERCATOR.proj4_init) polys = gv.Polygons(poly_data, vdims='BoroName', crs=ccrs.GOOGLE_MERCATOR) ``` -------------------------------- ### Build GeoViews Documentation Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md This command compiles the GeoViews documentation, which primarily consists of Jupyter Notebooks. Due to the nature of the documentation, this process is time-consuming, taking approximately an hour to complete. ```bash pixi run docs-build ``` -------------------------------- ### Visualize Geographical Data on a Map Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/new_york_boroughs.ipynb This snippet combines the base map tiles with the projected polygon data to create a final visualization. It applies styling options to both the tiles (zoom level) and the polygons (color by borough name, colormap, figure size, and padding) to produce an interactive map. ```python tiles.opts(zoom=10) * polys.opts(color='BoroName', cmap='tab20', fig_size=200, padding=0.1) ``` -------------------------------- ### Example: Caching OpenStreetMaps Tiles Source: https://github.com/holoviz/geoviews/blob/main/doc/user_guide/Using_WMTS_Offline.md This snippet demonstrates how to use the `cache_tiles` function to download and cache OpenStreetMaps (OSM) tiles. It specifies 'OSM' as the tile source and sets a maximum zoom level of 6. The function returns the path to the directory where the tiles are cached. ```python cache_dir = cache_tiles("OSM", max_target_z=6) ``` -------------------------------- ### Example: Converting Cached Tiles to PNG Format Source: https://github.com/holoviz/geoviews/blob/main/doc/user_guide/Using_WMTS_Offline.md This snippet illustrates how to invoke the `convert_tiles_cache` function to transform the previously cached NumPy tiles into PNG format. It takes the directory containing the NumPy tiles as input and returns a format string that is suitable for use with mapping libraries like GeoViews. ```python tiles_fmt = convert_tiles_cache(cache_dir) ``` -------------------------------- ### Generate Sample Vector Data for GeoViews Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/vectorfield_example.ipynb Defines a `sample_data` function to create synthetic vector field data (x, y, u, v) with a Rotated Pole CRS, which results in unevenly spaced vectors in regular PlateCarree space. It then calls this function to obtain the data, calculates the magnitude and angle from the vector components, and constructs a `gv.VectorField` object, preparing the data for visualization on a map. ```python def sample_data(shape=(20, 30)): """ Return ``(x, y, u, v, crs)`` of some vector data computed mathematically. The returned crs will be a rotated pole CRS, meaning that the vectors will be unevenly spaced in regular PlateCarree space. """ crs = ccrs.RotatedPole(pole_longitude=177.5, pole_latitude=37.5) x = np.linspace(311.9, 391.1, shape[1]) y = np.linspace(-23.6, 24.8, shape[0]) x2d, y2d = np.meshgrid(x, y) u = 10 * (2 * np.cos(2 * np.deg2rad(x2d) + 3 * np.deg2rad(y2d + 30)) ** 2) v = 20 * np.cos(6 * np.deg2rad(x2d)) return x, y, u, v, crs xs, ys, U, V, crs = sample_data() mag = np.sqrt(U**2 + V**2) angle = np.pi / 2 - np.arctan2(-V, -U) tiles = gv.tile_sources.OSM vectorfield = gv.VectorField((xs, ys, angle, mag), crs=crs) ``` -------------------------------- ### Visualize Vector Field on a Map with GeoViews Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/vectorfield_example.ipynb Combines OpenStreetMap (OSM) tiles with the previously generated vector field using GeoViews' overlay operator. Options are applied to the vector field for visualization, including setting the magnitude display, defining the plot width and height, and adjusting padding around the plot. ```python tiles * vectorfield.opts(magnitude='Magnitude', width=600, height=500, padding=0.1) ``` -------------------------------- ### Define Triangulation Data for GeoViews Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/trimesh_uk.ipynb This snippet defines a set of 2D points and a corresponding triangulation array using NumPy. These raw coordinates are then converted to latitude and longitude. Finally, a gv.TriMesh object is created, representing the triangulation with a Plate Carree coordinate reference system, ready for plotting. ```python # Some points defining a triangulation over (roughly) Britain. xy = np.asarray([ [-0.101, 0.872], [-0.080, 0.883], [-0.069, 0.888], [-0.054, 0.890], [-0.045, 0.897], [-0.057, 0.895], [-0.073, 0.900], [-0.087, 0.898], [-0.090, 0.904], [-0.069, 0.907], [-0.069, 0.921], [-0.080, 0.919], [-0.073, 0.928], [-0.052, 0.930], [-0.048, 0.942], [-0.062, 0.949], [-0.054, 0.958], [-0.069, 0.954], [-0.087, 0.952], [-0.087, 0.959], [-0.080, 0.966], [-0.085, 0.973], [-0.087, 0.965], [-0.097, 0.965], [-0.097, 0.975], [-0.092, 0.984], [-0.101, 0.980], [-0.108, 0.980], [-0.104, 0.987], [-0.102, 0.993], [-0.115, 1.001], [-0.099, 0.996], [-0.101, 1.007], [-0.090, 1.010], [-0.087, 1.021], [-0.069, 1.021], [-0.052, 1.022], [-0.052, 1.017], [-0.069, 1.010], [-0.064, 1.005], [-0.048, 1.005], [-0.031, 1.005], [-0.031, 0.996], [-0.040, 0.987], [-0.045, 0.980], [-0.052, 0.975], [-0.040, 0.973], [-0.026, 0.968], [-0.020, 0.954], [-0.006, 0.947], [ 0.003, 0.935], [ 0.006, 0.926], [ 0.005, 0.921], [ 0.022, 0.923], [ 0.033, 0.912], [ 0.029, 0.905], [ 0.017, 0.900], [ 0.012, 0.895], [ 0.027, 0.893], [ 0.019, 0.886], [ 0.001, 0.883], [-0.012, 0.884], [-0.029, 0.883], [-0.038, 0.879], [-0.057, 0.881], [-0.062, 0.876], [-0.078, 0.876], [-0.087, 0.872], [-0.030, 0.907], [-0.007, 0.905], [-0.057, 0.916], [-0.025, 0.933], [-0.077, 0.990], [-0.059, 0.993]]) # Make lats + lons x = xy[:, 0]*180/3.14159 y = xy[:, 1]*180/3.14159 # A selected triangulation of the points. triangles = np.asarray([ [67, 66, 1], [65, 2, 66], [ 1, 66, 2], [64, 2, 65], [63, 3, 64], [60, 59, 57], [ 2, 64, 3], [ 3, 63, 4], [ 0, 67, 1], [62, 4, 63], [57, 59, 56], [59, 58, 56], [61, 60, 69], [57, 69, 60], [ 4, 62, 68], [ 6, 5, 9], [61, 68, 62], [69, 68, 61], [ 9, 5, 70], [ 6, 8, 7], [ 4, 70, 5], [ 8, 6, 9], [56, 69, 57], [69, 56, 52], [70, 10, 9], [54, 53, 55], [56, 55, 53], [68, 70, 4], [52, 56, 53], [11, 10, 12], [69, 71, 68], [68, 13, 70], [10, 70, 13], [51, 50, 52], [13, 68, 71], [52, 71, 69], [12, 10, 13], [71, 52, 50], [71, 14, 13], [50, 49, 71], [49, 48, 71], [14, 16, 15], [14, 71, 48], [17, 19, 18], [17, 20, 19], [48, 16, 14], [48, 47, 16], [47, 46, 16], [16, 46, 45], [23, 22, 24], [21, 24, 22], [17, 16, 45], [20, 17, 45], [21, 25, 24], [27, 26, 28], [20, 72, 21], [25, 21, 72], [45, 72, 20], [25, 28, 26], [44, 73, 45], [72, 45, 73], [28, 25, 29], [29, 25, 31], [43, 73, 44], [73, 43, 40], [72, 73, 39], [72, 31, 25], [42, 40, 43], [31, 30, 29], [39, 73, 40], [42, 41, 40], [72, 33, 31], [32, 31, 33], [39, 38, 72], [33, 72, 38], [33, 38, 34], [37, 35, 38], [34, 38, 35], [35, 37, 36]]) trimesh = gv.TriMesh((triangles, (x, y)), crs=ccrs.PlateCarree()) ``` -------------------------------- ### Define and Project Geospatial Data to Web Mercator Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/new_york_boroughs.ipynb Loads OpenStreetMap (OSM) tiles as a base layer and retrieves New York City borough boundary data using geodatasets and geopandas. The borough data is then reprojected from its original coordinate system to Web Mercator (EPSG:3857) for compatibility with web mapping services, and converted into a GeoViews Polygons element. ```python tiles = gv.tile_sources.OSM # Project data to Web Mercator nybb = gpd.read_file(gds.get_path('nybb')) poly_data = nybb.to_crs(ccrs.GOOGLE_MERCATOR.proj4_init) polys = gv.Polygons(poly_data, vdims=['BoroName'], crs=ccrs.GOOGLE_MERCATOR) ``` -------------------------------- ### Build GeoViews Packages Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md These commands build the GeoViews packages for different distribution channels: Pip, Conda, and NPM. Each command targets a specific package manager for distribution. ```bash pixi run build-pip ``` ```bash pixi run build-conda ``` ```bash pixi run build-npm ``` -------------------------------- ### Plot GeoPandas Shapefiles and Choropleths Source: https://github.com/holoviz/geoviews/blob/main/examples/Homepage.ipynb This example demonstrates how GeoViews integrates with `geopandas` to plot shapefiles. It loads a shapefile using `geopandas` and `geodatasets`, reprojects it to Google Mercator, and then overlays it on an OpenStreetMap tile source. The polygons are visualized with 'BoroName' as a value dimension, enabling hover tools for interactivity. ```python import geopandas as gpd import geodatasets as gds nybb = gpd.read_file(gds.get_path('nybb')) poly_data = nybb.to_crs(crs.GOOGLE_MERCATOR.proj4_init) gv.tile_sources.OSM * gv.Polygons(poly_data, vdims='BoroName', crs=crs.GOOGLE_MERCATOR).opts(height=500, width=500, tools=["hover"]) ``` -------------------------------- ### Plot Geospatial Data with Interactive Options Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/new_york_boroughs.ipynb Combines the base OSM tile layer with the projected polygon data to create a composite plot. Styling options are applied to the polygons, including coloring by 'BoroName' using a 'Category20' colormap, setting plot dimensions, and enabling interactive tools like 'hover' and 'tap' for data exploration. ```python tiles * polys.opts(color='BoroName', cmap='Category20', width=800, height=600, tools=['hover', 'tap']) ``` -------------------------------- ### Update All Conda Packages Source: https://github.com/holoviz/geoviews/blob/main/README.md This command updates all packages in the current conda environment. It is recommended before installing new packages to ensure a consistent and up-to-date environment, though it carries a small risk of breaking existing setups. ```bash conda update --all ``` -------------------------------- ### Run GeoViews Code Linting Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md This command executes the pre-commit linting checks on all GeoViews files. It helps ensure code quality and adherence to style guidelines before committing changes. ```bash pixi run lint ``` -------------------------------- ### Install GeoViews and Cartopy offline data packages Source: https://github.com/holoviz/geoviews/blob/main/doc/user_guide/Using_Features_Offline.md Installs `geoviews`, `cartopy`, and `cartopy_offlinedata` into the current Conda environment from the `conda-forge` channel. `cartopy_offlinedata` is required for offline feature usage. An alternative command is provided for environments that only need the offline data package. ```bash conda install -c conda-forge geoviews cartopy cartopy_offlinedata ``` ```bash conda install -c conda-forge cartopy_offlinedata ``` -------------------------------- ### Initialize GeoViews with Bokeh and Matplotlib Backends Source: https://github.com/holoviz/geoviews/blob/main/examples/Homepage.ipynb This snippet imports necessary GeoViews modules and sets up the Bokeh and Matplotlib backends for visualization. It includes imports for `geoviews`, `geoviews.feature`, `xarray`, and `cartopy.crs`. ```python import geoviews as gv import geoviews.feature as gf import xarray as xr from cartopy import crs gv.extension('bokeh', 'matplotlib') ``` -------------------------------- ### Convert Annotated Rectangles to Shapely Geometry Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Converts the annotated rectangle data into a Shapely geometry object, facilitating spatial analysis and manipulation. ```python box_annotate.annotated.geom() ``` -------------------------------- ### Access Annotated Rectangle Data as DataFrame Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Retrieves the annotated rectangle data from the `box_annotate` instance as a Pandas DataFrame, providing access to the coordinates in their original coordinate system. ```python box_annotate.annotated.dframe() ``` -------------------------------- ### Access Annotated Point Data as DataFrame Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Retrieves the annotated point data from the `point_annotate` instance as a Pandas DataFrame, allowing access to the coordinates in their original coordinate system. ```python point_annotate.annotated.dframe() ``` -------------------------------- ### Initialize GeoViews and Import Libraries Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/great_circle.ipynb Imports necessary libraries including `pyproj` for geographic calculations, `numpy` for numerical operations, `geoviews` for geospatial visualization, and `bokeh.sampledata` for airport and route data. It also initializes the GeoViews Bokeh extension for interactive plotting. ```python import pyproj import numpy as np import geoviews as gv from bokeh.sampledata.airport_routes import airports, routes gv.extension('bokeh') ``` -------------------------------- ### Convert Annotated Points to Shapely Geometry Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Converts the annotated point data into a Shapely geometry object, optionally reprojecting it to a specified coordinate system (e.g., `PlateCarree` for lat/lon). ```python point_annotate.annotated.geom(projection=ccrs.PlateCarree()) ``` -------------------------------- ### Access annotated GeoViews Polygon data as DataFrame Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Demonstrates how to retrieve the underlying data of an annotated GeoViews Polygon element as a Pandas DataFrame. This allows for inspection and manipulation of the polygon's attributes. ```python poly_annotate.annotated.iloc[0].dframe() ``` -------------------------------- ### Sync Git tags with upstream GeoViews repository Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md This command syncs local Git tags with the upstream GeoViews repository. This step is crucial for ensuring correct version numbering, as GeoViews' version depends on Git tags. ```bash pixi run sync-git-tags ``` -------------------------------- ### Convert Annotated Paths to Shapely Geometry Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Converts the annotated path data into a Shapely geometry object, optionally reprojecting it to a specified coordinate system (e.g., `PlateCarree` for lat/lon) for spatial operations. ```python path_annotate.annotated.geom(projection=ccrs.PlateCarree()) ``` -------------------------------- ### Initialize GeoViews and Import Libraries Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/vectorfield_example.ipynb Initializes the GeoViews library for the Matplotlib backend, sets the output format to SVG with a specified size, and imports necessary libraries like NumPy for numerical operations and Cartopy for coordinate reference system handling. ```python import numpy as np import geoviews as gv import cartopy.crs as ccrs gv.extension('matplotlib') gv.output(fig='svg', size=200) ``` -------------------------------- ### Access Annotated Path Segment Data as DataFrame Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Annotators.ipynb Retrieves the data for a specific path segment (e.g., the first segment using `iloc[0]`) from the `path_annotate` instance as a Pandas DataFrame, providing access to its coordinates. ```python path_annotate.annotated.iloc[0].dframe() ``` -------------------------------- ### Initialize GeoViews and Set Output Options Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/city_population.ipynb This snippet imports necessary libraries like pandas and geoviews. It then initializes the GeoViews extension for Matplotlib and sets the output DPI for higher resolution plots. ```python import pandas as pd import geoviews as gv from geoviews import dim, tile_sources as gvts gv.extension('matplotlib') gv.output(dpi=120) ``` -------------------------------- ### Initialize GeoViews and HoloViews Environment Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Gridded_Datasets_II.ipynb Imports necessary libraries like NumPy, XArray, HoloViews, GeoViews, and Cartopy. It also sets up GeoViews extensions for Matplotlib and Bokeh, and configures the output size. ```python import numpy as np import xarray as xr import holoviews as hv import geoviews as gv import geoviews.feature as gf from geoviews import opts from cartopy import crs as ccrs gv.extension('matplotlib', 'bokeh') gv.output(size=200) ``` -------------------------------- ### Load GeoPandas DataFrame Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Geometries.ipynb This snippet demonstrates how to load a GeoPandas DataFrame using geodatasets. It reads an example dataset of Airbnb rentals in Chicago and displays the head of relevant columns, preparing the data for spatial operations and visualization. ```python import geodatasets as gds import geopandas as gpd data = gpd.read_file(gds.get_path('geoda airbnb')) data[["community", "population", "num_spots", "geometry"]].head() ``` -------------------------------- ### Run GeoViews Unit Tests Source: https://github.com/holoviz/geoviews/blob/main/doc/developer_guide/index.md Executes the small, pytest-based unit tests located in `geoviews/tests/`. These tests can be run in various Python environments (e.g., test-310, test-311, test-312, test-core) to ensure compatibility across different Python versions and dependency sets. ```bash pixi run test-unit ``` -------------------------------- ### Rendering Shapely Geometries with gv.Shape Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Geometries.ipynb Illustrates how to wrap a shapely geometry in a `gv.Shape` object for rendering with GeoViews. This example combines the Australian continent shape with a point and text annotation, demonstrating how `gv.Shape` integrates with other GeoViews elements. ```python australia = gv.Shape(land_geoms[21]) alice_springs = gv.Text(133.870,-21.5, 'Alice Springs') australia * gv.Points([(133.870,-23.700)]).opts(color='black', width=400) * alice_springs ``` -------------------------------- ### Importing Libraries and Initializing GeoViews Extension Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/brexit_choropleth.ipynb This snippet imports essential Python libraries: pandas for data manipulation, geopandas for geospatial data, and geoviews for interactive visualizations. It then initializes the geoviews extension with 'bokeh' as the backend, enabling interactive plotting capabilities. ```python import pandas as pd import geopandas as gpd import geoviews as gv gv.extension('bokeh') ``` -------------------------------- ### Initialize GeoViews with Bokeh Backend Source: https://github.com/holoviz/geoviews/blob/main/examples/user_guide/Working_with_Bokeh.ipynb Imports necessary libraries for GeoViews, NumPy, Xarray, and Pandas, then sets the Bokeh backend for interactive plotting, enabling advanced tools for data exploration. ```python import numpy as np import xarray as xr import pandas as pd import geoviews as gv import geoviews.feature as gf from geoviews import dim, opts gv.extension('bokeh') ``` -------------------------------- ### Import GeoViews and Cartopy Libraries Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/katrina_track.ipynb Imports necessary libraries for geospatial data visualization and processing, including GeoViews for plotting, Cartopy for map projections and shapefile reading, and Shapely for geometric operations. It also initializes the Bokeh extension for GeoViews. ```python import geoviews as gv import cartopy.crs as ccrs import cartopy.io.shapereader as shpreader import shapely.geometry as sgeom gv.extension('bokeh') ``` -------------------------------- ### Initialize Geoviews with Bokeh Extension Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/xarray_image.ipynb Imports necessary libraries like geoviews, geoviews.feature, xarray, and cartopy.crs, then initializes the Geoviews extension for Bokeh backend. ```python import geoviews as gv import geoviews.feature as gf import xarray as xr from cartopy import crs gv.extension('bokeh') ``` -------------------------------- ### Initialize GeoViews and Matplotlib Backend Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/orthographic_vectorfield.ipynb Imports necessary libraries for geospatial data visualization with GeoViews, including NumPy for numerical operations, Cartopy for coordinate reference systems, and sets up the Matplotlib backend for rendering. It also configures the output format and size for the plot. ```python import numpy as np import geoviews as gv import geoviews.feature as gf import cartopy.crs as ccrs gv.extension('matplotlib') gv.output(fig='svg', size=200) ``` -------------------------------- ### Import Geoviews and Initialize Bokeh Extension Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/trimesh_uk.ipynb This snippet imports necessary libraries like NumPy for numerical operations, Geoviews for geographical data visualization, and Cartopy for coordinate reference systems. It also initializes the Geoviews extension with 'bokeh' for interactive plotting. ```python import numpy as np import geoviews as gv import geoviews.feature as gf import cartopy.crs as ccrs gv.extension('bokeh') ``` -------------------------------- ### Importing Libraries and Initializing GeoViews Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/matplotlib/brexit_choropleth.ipynb This snippet imports necessary libraries like pandas, geopandas, and geoviews, and then initializes the geoviews extension for matplotlib output, setting the figure size and format. ```python import pandas as pd import geopandas as gpd import geoviews as gv gv.extension('matplotlib') gv.output(fig='svg', size=200) ``` -------------------------------- ### Initialize GeoViews Extension Source: https://github.com/holoviz/geoviews/blob/main/examples/gallery/bokeh/xarray_quadmesh.ipynb Initializes the GeoViews extension, specifying 'bokeh' as the plotting backend. This step is essential for rendering GeoViews plots in a web browser environment. ```python import xarray as xr import geoviews as gv gv.extension('bokeh') ```