Skip to content

Commit

Permalink
changes for mapscript API updates in MapServer 8 (ECCC-CCCS#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dukestep authored and Geomet user for nightly docker builds committed Dec 6, 2024
1 parent 02f047b commit 42925e1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 52 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ ENV BASEDIR=/data/web/geomet-climate-nightly \
GEOMET_CLIMATE_ES_URL=https://${GEOMET_CLIMATE_ES_USERNAME}:${GEOMET_CLIMATE_ES_PASSWORD}@localhost:9200 \
GEOMET_CLIMATE_OWS_DEBUG=5
# GEOMET_CLIMATE_OWS_LOG=/tmp/geomet-climate-ows.log
ENV DEBIAN_FRONTEND=noninteractive
ENV MAPSERVER_CONFIG_FILE=${BASEDIR}/build/mapserver.config
ENV MS_MAP_PATTERN=${BASEDIR}/build/mapfile/.*

WORKDIR $BASEDIR

# Install system dependencies
RUN apt update && apt install -y software-properties-common && \
## Add this WMO PPA
## Add this UbuntuGIS PPA (mappyfile)
add-apt-repository ppa:ubuntugis/ppa && apt update && \
## Add this WMO PPA (mapserver)
add-apt-repository ppa:gcpp-kalxas/wmo-staging && apt update && \
## Install dependencies from debian/control
apt install -y mapserver-bin python3-all python3-pip python3-click python3-gdal python3-mappyfile python3-mapscript python3-matplotlib python3-numpy python3-pyproj python3-yaml proj-bin proj-data python3-certifi && \
Expand Down
1 change: 0 additions & 1 deletion docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ services:
build:
args:
GEOMET_CLIMATE_URL: https://geomet-dev-31-nightly.edc-mtl.ec.gc.ca/geomet-climate
# GEOMET_CLIMATE_URL: http://geomet-dev-31.edc-mtl.ec.gc.ca:8099
environment:
GEOMET_CLIMATE_OWS_DEBUG: 5
GEOMET_CLIMATE_ES_URL: http://${GEOMET_CLIMATE_ES_USERNAME}:${GEOMET_CLIMATE_ES_PASSWORD}@localhost:9200
Expand Down
1 change: 0 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ services:
# for SSL-enabled connections to internal hosts (geomet-dev-xx.edc-mtl.ec.gc.ca)
- "/etc/ssl/certs:/etc/ssl/certs:ro" # mount host ssl certs
- "/usr/local/share/ca-certificates/:/usr/local/share/ca-certificates/:ro" # mount host ca-certificates

networks:
default:
name: geomet_default
Expand Down
19 changes: 19 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
BASEDIR=/data/web/geomet-climate-nightly
GEOMET_CLIMATE_BASEDIR=$BASEDIR/build
GEOMET_CLIMATE_ES_URL=${GEOMET_CLIMATE_ES_URL}
MAPSERVER_CONFIG_FILE=${MAPSERVER_CONFIG_FILE}

# replace localhost ES URL with docker-host URL to ES
if [ $GEOMET_CLIMATE_ES_URL != "" ]
Expand All @@ -13,6 +14,21 @@ fi

cd $BASEDIR

# Ensure the directory for MAPSERVER_CONFIG_FILE exists
mkdir -p "$(dirname "$MAPSERVER_CONFIG_FILE")"

# Ensure MAPSERVER_CONFIG_FILE exists; create it if it doesn't
if [ ! -f "$MAPSERVER_CONFIG_FILE" ]; then
echo "CONFIG" > "$MAPSERVER_CONFIG_FILE"
echo "END" >> "$MAPSERVER_CONFIG_FILE"
echo "MapServer config file created: $MAPSERVER_CONFIG_FILE"
else
echo "MapServer config file already exists: $MAPSERVER_CONFIG_FILE"
fi

# Set appropriate permissions for the config file
chmod 644 "$MAPSERVER_CONFIG_FILE"

echo "Generating geomet-climate VRTs for all layers..."
geomet-climate vrt generate
echo "Generating geomet-climate tileindex for all layers..."
Expand All @@ -36,6 +52,9 @@ mapserv -nh QUERY_STRING="map=$GEOMET_CLIMATE_BASEDIR/mapfile/geomet-climate-WCS
echo "Caching WCS (French)..."
mapserv -nh QUERY_STRING="map=$GEOMET_CLIMATE_BASEDIR/mapfile/geomet-climate-WCS-fr.map&lang=fr&service=WCS&version=2.1.0&request=GetCapabilities" > $GEOMET_CLIMATE_BASEDIR/geomet-climate-WCS-2.0.1-capabilities-fr.xml && mv -f $GEOMET_CLIMATE_BASEDIR/geomet-climate-WCS-2.0.1-capabilities-fr.xml $GEOMET_CLIMATE_BASEDIR/mapfile




echo "Done."

# server runs
Expand Down
1 change: 0 additions & 1 deletion geomet_climate/mapfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ def gen_layer(layer_name, layer_info, template_path, service='WMS'):
'classes': []
}
layer['type'] = 'RASTER'
layer['dump'] = True
layer['template'] = template_path
layer['name'] = layer_name
layer['tolerance'] = 150
Expand Down
1 change: 0 additions & 1 deletion geomet_climate/resources/mapfile-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"name": "geomet-climate",
"imagetype": "PNG",
"status": "ON",
"transparent": "ON",
"debug": "OFF",
"maxsize": 4096,
"size": [500, 300],
Expand Down
76 changes: 29 additions & 47 deletions geomet_climate/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,46 +60,28 @@ def metadata_lang(m, lg):
function to update the mapfile MAP metadata
keys in function of the lang of the request
:param m: mapfile object to update language
:param m: mapfile.web object to update language
:param lg: lang of the request
"""

m.setMetaData('ows_address',
m.getMetaData('ows_address_{}'.format(lg)))
m.setMetaData('ows_contactperson',
m.getMetaData('ows_contactperson_{}'.format(lg)))
m.setMetaData('ows_city',
m.getMetaData('ows_city_{}'.format(lg)))
m.setMetaData('ows_country',
m.getMetaData('ows_country_{}'.format(lg)))
m.setMetaData('ows_keywordlist_http://purl.org/dc/terms/_items',
m.getMetaData('ows_keywordlist_http://purl.org/dc/terms/_items_{}'.format(lg))) # noqa
m.setMetaData('wms_attribution_title',
m.getMetaData('wms_attribution_title_{}'.format(lg)))
m.setMetaData('ows_contactinstructions',
m.getMetaData('ows_contactinstructions_{}'.format(lg)))
m.setMetaData('ows_contactposition',
m.getMetaData('ows_contactposition_{}'.format(lg)))
m.setMetaData('ows_contactorganization',
m.getMetaData('ows_contactorganization_{}'.format(lg)))
m.setMetaData('wms_attribution_onlineresource',
m.getMetaData('wms_attribution_onlineresource_{}'.format(lg))) # noqa
m.setMetaData('ows_onlineresource',
m.getMetaData('ows_onlineresource_{}'.format(lg)))
m.setMetaData('ows_abstract',
m.getMetaData('ows_abstract_{}'.format(lg)))
m.setMetaData('ows_service_onlineresource',
m.getMetaData('ows_service_onlineresource_{}'.format(lg)))
m.setMetaData('ows_title',
m.getMetaData('ows_title_{}'.format(lg)))
m.setMetaData('ows_hoursofservice',
m.getMetaData('ows_hoursofservice_{}'.format(lg)))
m.setMetaData('ows_stateorprovince',
m.getMetaData('ows_stateorprovince_{}'.format(lg)))
m.setMetaData('ows_keywordlist',
m.getMetaData('ows_keywordlist_{}'.format(lg)))
m.setMetaData('wcs_description',
m.getMetaData('wcs_description_{}'.format(lg)))
m.metadata['ows_address'] = m.metadata[f'ows_address_{lg}']
m.metadata['ows_contactperson'] = m.metadata[f'ows_contactperson_{lg}']
m.metadata['ows_city'] = m.metadata[f'ows_city_{lg}']
m.metadata['ows_country'] = m.metadata[f'ows_country_{lg}']
m.metadata['ows_keywordlist_http://purl.org/dc/terms/_items'] = m.metadata[f'ows_keywordlist_http://purl.org/dc/terms/_items_{lg}'] # noqa
m.metadata['wms_attribution_title'] = m.metadata[f'wms_attribution_title_{lg}'] # noqa
m.metadata['ows_contactinstructions'] = m.metadata[f'ows_contactinstructions_{lg}'] # noqa
m.metadata['ows_contactposition'] = m.metadata[f'ows_contactposition_{lg}'] # noqa
m.metadata['ows_contactorganization'] = m.metadata[f'ows_contactorganization_{lg}'] # noqa
m.metadata['wms_attribution_onlineresource'] = m.metadata[f'wms_attribution_onlineresource_{lg}'] # noqa
m.metadata['ows_onlineresource'] = m.metadata[f'ows_onlineresource_{lg}']
m.metadata['ows_abstract'] = m.metadata[f'ows_abstract_{lg}']
m.metadata['ows_service_onlineresource'] = m.metadata[f'ows_service_onlineresource_{lg}'] # noqa
m.metadata['ows_title'] = m.metadata[f'ows_title_{lg}']
m.metadata['ows_hoursofservice'] = m.metadata[f'ows_hoursofservice_{lg}']
m.metadata['ows_stateorprovince'] = m.metadata[f'ows_stateorprovince_{lg}'] # noqa
m.metadata['ows_keywordlist'] = m.metadata[f'ows_keywordlist_{lg}']
m.metadata['wcs_description'] = m.metadata[f'wcs_description_{lg}']


def get_custom_service_exception(code, locator, text):
Expand Down Expand Up @@ -192,12 +174,14 @@ def application(env, start_response):
LOGGER.debug('Loading mapfile: {}'.format(mapfile_))
mapfile = mapscript.mapObj(mapfile_)
if request_ == 'GetCapabilities' and lang == 'fr':
metadata_lang(mapfile, lang)
metadata_lang(mapfile.web, lang)
layerobj = mapfile.getLayerByName(layer)
layerobj.setMetaData('ows_title',
layerobj.getMetaData('ows_title_{}'.format(lang))) # noqa
layerobj.setMetaData('ows_layer_group',
layerobj.getMetaData('ows_layer_group_{}'.format(lang))) # noqa
layerobj.metadata['ows_title'] = layerobj.metadata[
f'ows_title_{lang}'
]
layerobj.metadata['ows_layer_group'] = layerobj.metadata[
f'ows_layer_group_{lang}'
]

elif request_ == 'GetLegendGraphic' and layer is not None:
mapfile = mapscript.mapObj(mapfile_)
Expand All @@ -218,15 +202,13 @@ def application(env, start_response):
layerobj = mapfile.getLayerByName(layer)
if request_ == 'GetCapabilities' and lang == 'fr':
metadata_lang(mapfile, lang)
layerobj.setMetaData('ows_title',
layerobj.getMetaData('ows_title_{}'.format(lang))) # noqa
layerobj.setMetaData('ows_layer_group',
layerobj.getMetaData('ows_layer_group_{}'.format(lang))) # noqa
layerobj.metadata['ows_title'] = layerobj.metadata[f'ows_title_{lang}'] # noqa
layerobj.metadata['ows_layer_group'] = layerobj.metadata[f'ows_layer_group_{lang}'] # noqa

if time_ and 'ows_timeextent' in layerobj.metadata.keys():
try:
dates = []
timeextent = layerobj.getMetaData('ows_timeextent')
timeextent = layerobj.metadata['ows_timeextent']

start_date, end_date, duration = timeextent.split('/')
start_date = isoparse(start_date)
Expand Down

0 comments on commit 42925e1

Please sign in to comment.