Data used: Pilgrim Paths in Ireland (https://data.gov.ie/dataset/pilgrim-paths)
# import libraries
import os
from zipfile import ZipFile
import geopandas as gpd
import pooch
import xyzservices.providers as xyz
from bokeh.io import output_notebook
from bokeh.models import CategoricalColorMapper, GeoJSONDataSource
from bokeh.palettes import Category20b
from bokeh.plotting import figure, show
# pilgrims paths dataset
URL = (
"http://www.heritagecouncil.ie/content/files/Pilgrim-Paths-Shapefiles.zip"
)
KNOWN_HASH = None
FILE_NAME = "Pilgrim-Paths-Shapefiles.zip"
SUB_DIR = os.path.join("data", "Pilgrim-Paths")
DATA_FILE = os.path.join(SUB_DIR, FILE_NAME)
# download data if necessary
if not os.path.isfile(os.path.join(SUB_DIR, FILE_NAME)):
os.makedirs(SUB_DIR, exist_ok=True)
pooch.retrieve(
url=URL, known_hash=KNOWN_HASH, fname=FILE_NAME, path=SUB_DIR
)
# list of files in the ZIP archive
ZipFile(DATA_FILE).namelist()
['Pilgrim Paths Shapefiles/PilgrimPaths.cpg', 'Pilgrim Paths Shapefiles/PilgrimPaths.dbf', 'Pilgrim Paths Shapefiles/PilgrimPaths.prj', 'Pilgrim Paths Shapefiles/PilgrimPaths.sbn', 'Pilgrim Paths Shapefiles/PilgrimPaths.sbx', 'Pilgrim Paths Shapefiles/PilgrimPaths.shp', 'Pilgrim Paths Shapefiles/PilgrimPaths.shp.xml', 'Pilgrim Paths Shapefiles/PilgrimPaths.shx']
# read shapefile data
pilgrim_paths = gpd.read_file(
f"zip://{DATA_FILE}!"
+ [x for x in ZipFile(DATA_FILE).namelist() if x.endswith(".shp")][0]
)
# view data
pilgrim_paths.head()
Feature_Id | Feature_Ty | HCVector_H | Length | Projection | X_Co_ord | Y_Co_ord | Z_Co_ord | Country | County | ... | Data_Sourc | Commission | Survey_Con | Data_Data | Resource_P | URL_2 | URL_3 | URL_1 | geometry | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1.0 | Pilgrim Walk | None | None | ITM | 553160.0 | 884600.0 | None | IE | Donegal | ... | Data gathered from publicly available websites... | The Heritage Council | P. Reid | 21/08/2014 | To promote and aid in the preservation of the ... | http://www.colmcille.org/glencolmcille | http://www.heritagecouncil.ie/landscape/initia... | http://www.pilgrimpath.ie/pilgrim-paths-day/tu... | liam@fiontrai.ie or oideasgael@eircom.net | POINT (553160.033 884600.238) |
1 | 2.0 | Pilgrim Walk | None | None | ITM | 555550.0 | 878100.0 | None | IE | Donegal | ... | Data gathered from publicly available websites... | The Heritage Council | P. Reid | 22/08/2014 | To promote and aid in the preservation of the ... | http://www.irishtrails.ie/Trail/Sliabh-Liag-Pi... | http://www.heritagecouncil.ie/landscape/initia... | http://www.pilgrimpath.ie/pilgrim-paths-day/sl... | info@slieveleaguecliffs.ie | POINT (555550.005 878100.224) |
2 | 3.0 | Pilgrim Walk | None | None | ITM | 609000.0 | 873200.0 | None | IE | Donegal | ... | Data gathered from publicly available websites... | The Heritage Council | P. Reid | 23/08/2014 | To promote and aid in the preservation of the ... | http://www.irishtrails.ie/Trail/Lough-Derg-Pil... | http://www.heritagecouncil.ie/fileadmin/user_u... | http://www.pilgrimpath.ie/pilgrim-paths-day/lo... | info@loughderg.org | POINT (609000.015 873200.115) |
3 | 4.0 | Pilgrim Walk | None | None | ITM | 515400.0 | 779340.0 | None | IE | Mayo | ... | Data gathered from publicly available websites... | The Heritage Council | P. Reid | 24/08/2014 | To promote and aid in the preservation of the ... | http://www.mayo-ireland.ie/en/towns-villages/b... | http://www.heritagecouncil.ie/landscape/initia... | http://www.pilgrimpath.ie/pilgrim-paths-day/to... | info@ballintubberabbey.ie | POINT (515399.821 779340.039) |
4 | 5.0 | Pilgrim Walk | None | None | ITM | 621000.0 | 730700.0 | None | IE | Offaly | ... | Data gathered from publicly available websites... | The Heritage Council | P. Reid | 25/08/2014 | To promote and aid in the preservation of the ... | http://www.offaly.ie/eng/Services/Heritage/Doc... | None | http://www.pilgrimpath.ie/pilgrim-paths-day/sl... | info@offalytourism.com | POINT (620999.767 730699.983) |
5 rows × 34 columns
pilgrim_paths.shape
(13, 34)
list(pilgrim_paths)
['Feature_Id', 'Feature_Ty', 'HCVector_H', 'Length', 'Projection', 'X_Co_ord', 'Y_Co_ord', 'Z_Co_ord', 'Country', 'County', 'Local_Auth', 'Electoral', 'Townland', 'Dataset_Na', 'Object_Typ', 'Start_Poin', 'Length_1', 'Duration', 'Level_of_D', 'Map', 'Contact_Ph', 'Photo_ID', 'Object_Own', 'Landowner', 'Data_Sourc', 'Commission', 'Survey_Con', 'Data_Data', 'Resource_P', 'URL_2', 'URL_3', 'URL_1', 'Email', 'geometry']
pilgrim_paths.crs
<Projected CRS: EPSG:2157> Name: IRENET95 / Irish Transverse Mercator Axis Info [cartesian]: - E[east]: Easting (metre) - N[north]: Northing (metre) Area of Use: - name: Ireland - onshore. United Kingdom (UK) - Northern Ireland (Ulster) - onshore. - bounds: (-10.56, 51.39, -5.34, 55.43) Coordinate Operation: - name: Irish Transverse Mercator - method: Transverse Mercator Datum: IRENET95 - Ellipsoid: GRS 1980 - Prime Meridian: Greenwich
# reproject to web mercator
data = pilgrim_paths.to_crs(3857)
# convert data source to GeoJSON
geo_source = GeoJSONDataSource(geojson=data.to_json())
# generate unique colours for each point
const = list(set(data["Object_Typ"]))
palette = Category20b[len(const)]
color_map = CategoricalColorMapper(factors=const, palette=palette)
# define title and tooltips
TITLE = "Pilgrim Paths in Ireland. © Heritage Council."
TOOLTIPS = [
("Name", "@Object_Typ"),
("County", "@County"),
("Townland", "@Townland"),
("Start point", "@Start_Poin"),
("Length", "@Length_1"),
("Difficulty", "@Level_of_D"),
]
# configure plot
p = figure(
title=TITLE,
tools="wheel_zoom, pan, reset, hover, save",
tooltips=TOOLTIPS,
x_axis_type="mercator",
y_axis_type="mercator",
)
p.grid.grid_line_color = "lightgrey"
p.hover.point_policy = "follow_mouse"
# add data points
p.scatter(
"x",
"y",
source=geo_source,
size=15,
marker="square_pin",
line_width=0.5,
line_color="darkslategrey",
fill_color={"field": "Object_Typ", "transform": color_map},
fill_alpha=0.7,
)
# add basemap
p.add_tile(xyz.CartoDB.Voyager)
show(p)