How to Add Data Layers on Custom Projections
See original GitHub issuehttps://github.com/jupyter-widgets/ipyleaflet/pull/598 added the ability to display maps with custom projections, which is highly useful for the polar regions!
It’s a bit unclear currently what is supported for adding data layers onto maps with custom projections. According to the Proj4Leaflet readme it seems straightforward to support GeoJSON and Image Overlays, but as far as I can tell this isn’t yet supported (ipyleaflet 0.13.0).
Here is a full gist (https://gist.github.com/scottyhq/39b39917e851a2fc691fa6e6d9716794) with a few self-contained examples for adding a coastline layer or simple bounding box for the south pole (projections.EPSG3031)
Default projection
SPS projection And for the north polar projection (projections.EPSG3413) here is an example from @betolink with screenshot showing offset polygons
from ipyleaflet import Map, GeoJSON, projections
import json
import os
import requests
if not os.path.exists('europe_110.geo.json'):
url = 'https://github.com/jupyter-widgets/ipyleaflet/raw/master/examples/europe_110.geo.json'
r = requests.get(url)
with open('europe_110.geo.json', 'w') as f:
f.write(r.content.decode("utf-8"))
with open('europe_110.geo.json', 'r') as f:
data = json.load(f)
m = Map(center=(60, 0), zoom=2, crs=projections.EPSG3413)
geo_json = GeoJSON(data=data, style = {'color': 'green', 'opacity':1, 'weight':1.9, 'dashArray':'9', 'fillOpacity':0.1})
m.add_layer(geo_json)
m
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top GitHub Comments
FYI xarray-leaflet just got initial support for custom projections, see this example.
Thanks so much for looking into this and providing a workaround @betolink !