[GRASS-SVN] r39534 - in grass-addons/raster: . r.out.kml
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Oct 16 23:26:16 EDT 2009
Author: hamish
Date: 2009-10-16 23:26:15 -0400 (Fri, 16 Oct 2009)
New Revision: 39534
Added:
grass-addons/raster/r.out.kml/
grass-addons/raster/r.out.kml/Makefile
grass-addons/raster/r.out.kml/r.out.kml
Log:
script to export raster to KML
Added: grass-addons/raster/r.out.kml/Makefile
===================================================================
--- grass-addons/raster/r.out.kml/Makefile (rev 0)
+++ grass-addons/raster/r.out.kml/Makefile 2009-10-17 03:26:15 UTC (rev 39534)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.out.kml
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Property changes on: grass-addons/raster/r.out.kml/Makefile
___________________________________________________________________
Added: svn:mime-type
+ text/x-makefile
Added: svn:eol-style
+ native
Added: grass-addons/raster/r.out.kml/r.out.kml
===================================================================
--- grass-addons/raster/r.out.kml/r.out.kml (rev 0)
+++ grass-addons/raster/r.out.kml/r.out.kml 2009-10-17 03:26:15 UTC (rev 39534)
@@ -0,0 +1,170 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE: r.out.kml
+# AUTHOR(S): Hamish Bowman, Dunedin, New Zealand
+# Ideas from Roger André and v.out.kml by Peter Loewe
+# PURPOSE: Export GRASS raster maps with a KML file.
+# Must be in geographic coordinates (lat/lon).
+# COPYRIGHT: (c) 2009 Hamish Bowman, and the GRASS Development Team
+#
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
+#
+# Restricted to LL WGS84 (epsg 4326) or convergence angle < 1px per 1280x1024
+# TODO: Ensure vertical datum is EGM96 (r.info -d; r.support vdatum=)
+# TODO: Add a -k flag to d.out.file to do KML output
+#############################################################################
+
+#%Module
+#% description: Creates KML and image files from a GRASS raster map.
+#%End
+#%option
+#% key: map
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: Raster input map
+#% required : yes
+#%end
+#%option
+#% key: output
+#% type: string
+##% gisprompt: new_file,file,file
+#% description: Base name of KML and image output files
+#% required : no
+#%end
+#%option
+#% key: format
+#% type: string
+#% options: png,jpeg,geotiff
+#% answer: png
+#% description: Graphics file format
+#%end
+
+if [ -z "$GISBASE" ] ; then
+ echo "You must be in GRASS GIS to run this program." 1>&2
+ exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+ exec g.parser "$0" "$@"
+fi
+
+
+MAP_NAME="$GIS_OPT_MAP"
+
+g.findfile element=cell file="$MAP_NAME" > /dev/null
+if [ $? -ne 0 ] ; then
+ g.message -e "Map <$MAP_NAME> not found"
+ exit 1
+fi
+
+MAP_TITLE=`r.info -m $MAP_NAME | cut -f2 -d=`
+
+if [ -n "$GIS_OPT_OUTPUT" ] ; then
+ OUT_NAME="$GIS_OPT_OUTPUT"
+else
+ OUT_NAME="$MAP_NAME"
+fi
+
+
+case "$GIS_OPT_FORMAT" in
+ png)
+ IMG_EXT=png
+ #GDAL_FMT=PNG
+ ;;
+ jpeg)
+ IMG_EXT=jpg
+ #GDAL_FMT=JPEG
+ if [ ! -x `which pnmtojpeg` ] ; then
+ g.message -e "NetPBM tools required for JPEG export. Please install."
+ exit 1
+ fi
+ ;;
+ geotiff)
+ IMG_EXT=tif
+ #GDAL_FMT=GTiff
+ ;;
+esac
+
+
+if [ -e "$OUT_NAME.kml" ] || [ -e "$OUT_NAME.$IMG_EXT" ] ; then
+ if [ -z "$GRASS_OVERWRITE" ] || [ "$GRASS_OVERWRITE" -ne 1 ] ; then
+ g.message -e "Output file already exists."
+ exit 1
+ fi
+fi
+
+
+IS_LL_WGS84=false
+if [ `g.proj -p | grep -w '^name' | grep -c 'Latitude-Longitude'` -eq 1 ] ; then
+ if [ `g.proj -p | grep -w '^datum' | grep -c 'wgs84'` -eq 1 ] ; then
+ IS_LL_WGS84=true
+ fi
+fi
+
+if [ "$IS_LL_WGS84" = "false" ] ; then
+ # check convergence angle is less than (arbitrary) 1px per 1280x1024 (~= 0.09 degrees)
+ eval `g.region -gn`
+ CONV_ANGLE_3INT=`echo $converge_angle | sed -e 's/\.//' | cut -b 1-3`
+ if [ "$CONV_ANGLE_3INT" -gt 009 ] ; then
+ g.message -e "Convergence angle too great for undistorted output, reproject first. ($converge_angle degrees)"
+ exit 1
+ fi
+fi
+
+
+if [ "$IS_LL_WGS84" = "true" ] ; then
+ eval `g.region -g`
+ NORTH=$n
+ SOUTH=$s
+ WEST=$w
+ EAST=$e
+else
+ eval `g.region -gb`
+ NORTH=$ll_n
+ SOUTH=$ll_s
+ WEST=$ll_w
+ EAST=$ll_e
+fi
+
+cat << EOF > "$OUT_NAME.kml"
+<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2">
+<GroundOverlay>
+ <name>$MAP_NAME</name>
+ <description>$MAP_TITLE</description>
+ <visibility>1</visibility>
+ <open>1</open>
+ <Icon>
+ <href>"$OUT_NAME.$IMG_EXT"</href>
+ </Icon>
+ <drawOrder>0</drawOrder>
+ <LatLonBox>
+ <north>$NORTH</north>
+ <south>$SOUTH</south>
+ <west>$WEST</west>
+ <east>$EAST</east>
+ </LatLonBox>
+</GroundOverlay>
+</kml>
+EOF
+
+
+case "$GIS_OPT_FORMAT" in
+ png)
+ r.out.png input="$MAP_NAME" output="$OUT_NAME.$IMG_EXT" --quiet
+ ;;
+ jpeg)
+ r.out.ppm input="$MAP_NAME" output="$OUT_NAME.ppm" --quiet
+ pnmtojpeg --quality=85 "$OUT_NAME.ppm" > "$OUT_NAME.$IMG_EXT"
+ \rm "$OUT_NAME.ppm"
+ ;;
+ geotiff)
+ r.out.gdal input="$MAP_NAME" output="$OUT_NAME.$IMG_EXT"
+ ;;
+esac
+
+#done
+
Property changes on: grass-addons/raster/r.out.kml/r.out.kml
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/x-sh
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list