Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use geodatasets for geodatasources #635

Merged
merged 7 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: doit develop_install
run: |
conda activate test-environment
doit develop_install -o doc -o examples
doit develop_install -o doc -o examples_extra
- name: doit env_capture
run: |
conda activate test-environment
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
python-version: ${{ matrix.python-version }}
channel-priority: strict
channels: pyviz/label/dev,bokeh,conda-forge,nodefaults
envs: "-o tests -o examples -o recommended"
envs: "-o tests -o examples_extra -o recommended"
cache: true
conda-update: true
conda-mamba: mamba
Expand Down
10 changes: 6 additions & 4 deletions examples/Homepage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@
"outputs": [],
"source": [
"import geopandas as gpd\n",
"gv.Polygons(gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')), vdims=['pop_est', ('name', 'Country')]).opts(\n",
" tools=['hover'], width=600, projection=crs.Robinson()\n",
")"
"import geodatasets as gds\n",
"\n",
"nybb = gpd.read_file(gds.get_path('nybb'))\n",
"poly_data = nybb.to_crs(crs.GOOGLE_MERCATOR.proj4_init)\n",
"gv.tile_sources.OSM * gv.Polygons(poly_data, vdims='BoroName', crs=crs.GOOGLE_MERCATOR).opts(height=500, width=500, tools=[\"hover\"])"
]
}
],
Expand All @@ -83,5 +85,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
3 changes: 2 additions & 1 deletion examples/gallery/bokeh/new_york_boroughs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"import geodatasets as gds\n",
"import geopandas as gpd\n",
"import geoviews as gv\n",
"import cartopy.crs as ccrs\n",
Expand All @@ -29,7 +30,7 @@
"tiles = gv.tile_sources.OSM\n",
"\n",
"# Project data to Web Mercator\n",
"nybb = gpd.read_file(gpd.datasets.get_path('nybb'))\n",
"nybb = gpd.read_file(gds.get_path('nybb'))\n",
"poly_data = nybb.to_crs(ccrs.GOOGLE_MERCATOR.proj4_init)\n",
"polys = gv.Polygons(poly_data, vdims=['BoroName'], crs=ccrs.GOOGLE_MERCATOR)"
]
Expand Down
3 changes: 2 additions & 1 deletion examples/gallery/matplotlib/new_york_boroughs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"import geodatasets as gds\n",
"import geopandas as gpd\n",
"import geoviews as gv\n",
"import cartopy.crs as ccrs\n",
Expand All @@ -30,7 +31,7 @@
"tiles = gv.tile_sources.OSM \n",
"\n",
"# Project data to Web Mercator\n",
"nybb = gpd.read_file(gpd.datasets.get_path('nybb'))\n",
"nybb = gpd.read_file(gds.get_path('nybb'))\n",
"poly_data = nybb.to_crs(ccrs.GOOGLE_MERCATOR.proj4_init)\n",
"polys = gv.Polygons(poly_data, vdims='BoroName', crs=ccrs.GOOGLE_MERCATOR)"
]
Expand Down
20 changes: 11 additions & 9 deletions examples/user_guide/Geometries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
"metadata": {},
"source": [
"GeoPandas extends the datatypes used by pandas to allow spatial operations on geometric types, which makes it a very convenient way of working with geometries with associated variables. GeoViews ``Path``, ``Contours`` and ``Polygons`` Elements natively support projecting and plotting of\n",
"geopandas DataFrames using both ``matplotlib`` and ``bokeh`` plotting extensions. We will load the example dataset of the world which also includes some additional data about each country:"
"geopandas DataFrames using both ``matplotlib`` and ``bokeh`` plotting extensions. We will load an example dataset of Airbnb rentals in Chicago, which also includes some additional data about the city's communities:"
]
},
{
Expand All @@ -273,16 +273,18 @@
"metadata": {},
"outputs": [],
"source": [
"import geodatasets as gds\n",
"import geopandas as gpd\n",
"world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))\n",
"world.head()"
"\n",
"data = gpd.read_file(gds.get_path('geoda airbnb'))\n",
"data[[\"community\", \"population\", \"num_spots\", \"geometry\"]].head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can simply pass the GeoPandas DataFrame to a Polygons, Path or Contours element and it will plot the data for us. The ``Contours`` and ``Polygons`` will automatically color the data by the first specified value dimension defined by the ``vdims`` keyword (the geometries may be colored by any dimension using the ``color_index`` plot option):"
"We can simply pass the GeoPandas DataFrame to a Polygons, Path or Contours element and it will plot the data for us. The ``Contours`` and ``Polygons`` will automatically color the data by the first specified value dimension defined by the ``vdims`` keyword (the geometries may be colored by any dimension using the ``color`` plot option):"
]
},
{
Expand All @@ -291,14 +293,15 @@
"metadata": {},
"outputs": [],
"source": [
"gv.Polygons(world, vdims='pop_est').opts(projection=ccrs.Robinson(), width=600, tools=['hover'])"
"poly_plot = gv.Polygons(data, vdims=[\"population\", \"community\", \"num_spots\"]).opts(width=600, height=600)\n",
"gv.tile_sources.OSM * poly_plot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Geometries can be displayed using both matplotlib and bokeh, here we will switch to bokeh allowing us to color by a categorical variable (``continent``) and activating the hover tool to reveal information about the plot."
"Here we will switch the color by number of spots (``num_spots``) and activating the hover tool to reveal information about the plot. The switch will work in both Matplotlib and Nokeh, but the bokeh version will be more interactive:"
]
},
{
Expand All @@ -307,8 +310,7 @@
"metadata": {},
"outputs": [],
"source": [
"gv.Polygons(world, vdims=['continent', 'name', 'pop_est']).opts(\n",
" cmap='tab20', width=600, height=400, tools=['hover'], infer_projection=True)"
"gv.tile_sources.OSM * poly_plot.opts(color=\"num_spots\", cmap='tab20', tools=['hover'])"
]
},
{
Expand All @@ -326,5 +328,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def run(self):
'iris',
'xesmf',
'mock',
'fiona'
'fiona',
'geodatasets',
]

extras_require={
Expand Down