#!/bin/bash
# This file is part of the PyOWS-WMS-Server package (= program).
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# author(s): Sebastian Holler
#
# Copyright (c)2008 by Sebastian Holler
# for document references, used in this source code: see
# use: listing metadata of all vector and raster layers in the mapset
# run this script in GRASS environment!!
# input format (stdin): layer1_name layer2_name layerX_name
# output format: (list)
# layer@mapset;;format;;title;;organization;;\
# creator;;date;;bb-Northing|LatMax;;bb-Easting|LonMax;;bb-Southing|LatMin;;
# bb-Westing|LonMin##
for PYWMS_LAYER in $(cat /dev/stdin)
do
#echo "processing $PYWMS_LAYER" >/dev/stderr
PYWMS_VALID="yes"
PYWMS_TYPE=${PYWMS_LAYER:0:1}
PYWMS_LAYER=${PYWMS_LAYER:2}
PYWMS_PRINT="${PYWMS_LAYER};;"
# [v,r].info
PYWMS_LINFO=$(${PYWMS_TYPE}.info $PYWMS_LAYER -gt 2>/dev/null || echo "invalid")
if [ "$PYWMS_LINFO" == "invalid" ]; then
PYWMS_VALID="no"
continue
fi
#NOTE: echo ${PYWMS_LINFO} --> line continues get lost
# echo "${PYWMS_LINFO}" --> line continues preserved
if [ "$PYWMS_TYPE" == "v" ]; then
# get the vector type and boundaries of the layer:
# v-a:areas, v-l:lines, v-p:points, v-u:unknown
if [ ! "$(echo "$PYWMS_LINFO" | grep "areas=" | sed 's/areas=//')" == "0" ]; then
PYWMS_PRINT="${PYWMS_PRINT}v-a"
elif [ ! "$(echo "$PYWMS_LINFO" | grep "lines=" | sed 's/lines=//')" == "0" ]; then
PYWMS_PRINT="${PYWMS_PRINT}v-l"
elif [ ! "$(echo "$PYWMS_LINFO" | grep "points=" | sed 's/points=//')" == "0" ]; then
PYWMS_PRINT="${PYWMS_PRINT}v-p"
else
# if unknown vector type:
PYWMS_VALID="no"
continue
fi
else
#raster (integer/floatingpoint/doubleprecision/3d)
PYWMS_RTYPE=$(echo "$PYWMS_LINFO" | grep "datatype=" | sed 's/datatype=//')
if [ "$PYWMS_RTYPE" == "CELL" ]; then
PYWMS_PRINT="${PYWMS_PRINT}r-i"
elif [ "$PYWMS_RTYPE" == "FCELL" ]; then
PYWMS_PRINT="${PYWMS_PRINT}r-f"
elif [ "$PYWMS_RTYPE" == "DCELL" ]; then
PYWMS_PRINT="${PYWMS_PRINT}r-d"
else
# if unknown raster type:
PYWMS_VALID="no"
continue
fi
fi
PYWMS_PRINT="${PYWMS_PRINT};;"
#TODO: title;;organization;;creator;;date;;
PYWMS_PRINT="${PYWMS_PRINT};;;;;;;;"
PYWMS_COORD="$(echo "${PYWMS_LINFO}" | grep "north=" | sed 's/north=//')"
PYWMS_PRINT="${PYWMS_PRINT}${PYWMS_COORD};;"
PYWMS_COORD="$(echo "${PYWMS_LINFO}" | grep "east=" | sed 's/east=//')"
PYWMS_PRINT="${PYWMS_PRINT}${PYWMS_COORD};;"
PYWMS_COORD="$(echo "${PYWMS_LINFO}" | grep "south=" | sed 's/south=//')"
PYWMS_PRINT="${PYWMS_PRINT}${PYWMS_COORD};;"
PYWMS_COORD="$(echo "${PYWMS_LINFO}" | grep "west=" | sed 's/west=//')"
PYWMS_PRINT="${PYWMS_PRINT}${PYWMS_COORD}"
# if layer seems to be valid, return metadata:
[ "${PYWMS_VALID}" == "yes" ] && echo -n "${PYWMS_PRINT}##"
done