See demo of this configuration at https://gist.github.com/pelson/682c09838cb3f93cef77922b12fb0ed5. This repo has been deployed to Heroku to serve the WMS defined by the functions in this config. It is required that @pelson's cartopy_source branch is installed. The full diff of this branch can be found at https://github.com/mapproxy/mapproxy/compare/61bf3ada315591207fade42888a3e1060703ccbf...pelson:cartopy_source?expand=1.
Last active
November 2, 2020 17:23
-
-
Save pelson/80e8038fad80e1febdfb91f9a262aaa8 to your computer and use it in GitHub Desktop.
Example of cartopy source in mapproxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cartopy.examples.arrows import sample_data | |
def arrows(ax): | |
x, y, u, v, vector_crs = sample_data() | |
ax.quiver(x, y, u, v, transform=vector_crs) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -x | |
mkdir -p "$1" "$2" "$3" | |
build=$(cd "$1/" && pwd) | |
cache=$(cd "$2/" && pwd) | |
env_dir=$(cd "$3/" && pwd) | |
# ------- | |
wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh | |
bash miniconda.sh -b -p $HOME/.conda | |
export PATH=$HOME/.conda/bin:$PATH | |
# ------- | |
# Build the environment. | |
source create_env.sh $HOME/env | |
# Copy the environment to the Heroku build directory. | |
cp -rf $HOME/env $build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Makes the lightest weight environment possible to run mapproxy with cartopy. If there is no size constraint, | |
# we would just use conda directly, but as we want to run in Heroku, we must realise an environment <=300 Mb. | |
export ENV=$1 | |
conda create --yes -c conda-forge -p ${ENV} nomkl python pip pillow pyyaml cartopy | |
source activate $ENV | |
pip install git+https://github.com/pelson/mapproxy/@cartopy_source | |
python -c "import mapproxy; print(mapproxy);" | |
export PREFIX=$ENV | |
du -hs $PREFIX | |
rm -rf $PREFIX/share/doc $PREFIX/share/gtk-doc | |
rm -rf $PREFIX/lib/libicu* $PREFIX/lib/libxml* $PREFIX/lib/libQt* | |
rm -rf $PREFIX/bin/sqlite3 | |
export SP_DIR=$PREFIX/lib/python*/site-packages | |
rm -rf $SP_DIR/scipy/stats | |
du -hs $PREFIX | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cartopy.crs as ccrs | |
import matplotlib.textpath | |
import matplotlib.patches | |
from matplotlib.font_manager import FontProperties | |
import numpy as np | |
def main(ax): | |
# Comes from the cartopy gallery: http://scitools.org.uk/cartopy/docs/latest/examples/logo.html | |
# generate a matplotlib path representing the word "cartopy" | |
fp = FontProperties(family='Bitstream Vera Sans', weight='bold') | |
logo_path = matplotlib.textpath.TextPath((-175, -35), 'cartopy', | |
size=80, prop=fp) | |
# scale the letters up to sensible longitude and latitude sizes | |
logo_path._vertices *= np.array([1, 2]) | |
im = ax.stock_img() | |
def on_draw(event=None): | |
""" | |
Hooks into matplotlib's event mechanism to define the clip path of the | |
background image. | |
""" | |
plate_carree_transform = ccrs.PlateCarree()._as_mpl_transform(ax) | |
im.set_clip_path(logo_path, transform=plate_carree_transform) | |
# Register the on_draw method and call it once now. | |
ax.figure.canvas.mpl_connect('draw_event', on_draw) | |
on_draw() | |
# add the path as a patch, drawing black outlines around the text | |
patch = matplotlib.patches.PathPatch(logo_path, | |
antialiased=True, | |
facecolor='none', edgecolor='black', | |
transform=ccrs.PlateCarree()) | |
ax.add_patch(patch) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
# demo: | |
# tms: | |
# use_grid_names: true | |
# # origin for /tiles service | |
# origin: 'nw' | |
# kml: | |
# use_grid_names: true | |
# wmts: | |
wms: | |
md: | |
title: Cartopy WMS demo | |
abstract: Cartopy demonstration WMS. | |
layers: | |
- name: wind | |
title: Wind arrows | |
sources: [wind] | |
- name: logo | |
title: Cartopy logo | |
sources: [logo] | |
- name: coastlines | |
title: Cartopy coastlines | |
sources: [coastlines] | |
sources: | |
wind: | |
type: cartopy | |
module: arrows.py | |
function: arrows | |
logo: | |
type: cartopy | |
module: logo.py | |
function: main | |
coastlines: | |
type: cartopy | |
module: misc.py | |
function: coastlines | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def coastlines(ax): | |
ax.coastlines('10m') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: env/bin/mapproxy-util serve-develop mapproxy.yaml --bind 0.0.0.0:${PORT:=8080} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment