[GRASS-SVN] r37200 - grass/branches/develbranch_6/scripts/m.proj

svn_grass at osgeo.org svn_grass at osgeo.org
Wed May 13 05:38:45 EDT 2009


Author: hamish
Date: 2009-05-13 05:38:44 -0400 (Wed, 13 May 2009)
New Revision: 37200

Modified:
   grass/branches/develbranch_6/scripts/m.proj/m.proj
Log:
add flag to include input coordinates in output file; obey --overwrite; todo note

Modified: grass/branches/develbranch_6/scripts/m.proj/m.proj
===================================================================
--- grass/branches/develbranch_6/scripts/m.proj/m.proj	2009-05-12 18:30:26 UTC (rev 37199)
+++ grass/branches/develbranch_6/scripts/m.proj/m.proj	2009-05-13 09:38:44 UTC (rev 37200)
@@ -17,6 +17,10 @@
 # notes:
 #  - cs2cs expects "x y" data so be sure to send it "lon lat" not "lat lon"
 #  - if you send cs2cs a third data column, beware it might be treated as "z"
+# todo:
+#  - `cut` away x,y columns into a temp file, feed to cs2cs, then `paste`
+#    back to input file. see method in v.in.garmin.sh. that way additional
+#    numeric and string columns would survive the trip.
 
 #%Module
 #%  description: Convert coordinates from one projection to another (cs2cs frontend).
@@ -71,6 +75,10 @@
 #% description: Output long/lat in decimal degrees or other projections with many decimal places
 #%end
 #%flag
+#% key: e
+#% description: Include input coordinates in output file
+#%end
+#%flag
 #% key: v
 #% description: Verbose mode (print projection parameters and filenames to stderr)
 #%end
@@ -112,8 +120,10 @@
    exit 1
 fi
 if [ -n "$GIS_OPT_OUTPUT" ] && [ -e "$GIS_OPT_OUTPUT" ] ; then
-   g.message -e "Output file already exists" 
-   exit 1
+   if [ -z "$GRASS_OVERWRITE" ] || [ "$GRASS_OVERWRITE" -ne 1 ] ; then
+      g.message -e "Output file already exists" 
+      exit 1
+   fi
 fi
 
 #### parse field separator
@@ -192,7 +202,7 @@
 
    # make sure we have at least one line of data
    if [ "`wc -l "$TMP" | cut -f1 -d' '`" -eq 0 ] ; then
-      g.message -e "ERROR reading data from stdin"
+      g.message -e "Problem reading data from stdin"
       exit 1
    fi
    infile="$TMP"
@@ -221,16 +231,23 @@
 else
    OUTFMT="-f %.8f"
 fi
+if [ $GIS_FLAG_E -eq 0 ] ; then
+   COPYINP=""
+else
+   COPYINP="-E"
+fi
 
+
 #### do the conversion
 # Convert cs2cs DMS format to GRASS DMS format:
 #   cs2cs | sed -e 's/d/:/g' -e "s/'/:/g"  -e 's/"//g'
 
 if [ -z "$outfile" ] ; then
-   cat "$infile" | tr "$fs" ' ' | cs2cs $OUTFMT $IN_PROJ +to $OUT_PROJ
+   cat "$infile" | tr "$fs" ' ' | cs2cs $COPYINP $OUTFMT $IN_PROJ +to $OUT_PROJ
    EXITCODE=$?
 else
-   cat "$infile" | tr "$fs" ' ' | cs2cs $OUTFMT $IN_PROJ +to $OUT_PROJ > "$outfile"
+   cat "$infile" | tr "$fs" ' ' | cs2cs $COPYINP $OUTFMT $IN_PROJ +to $OUT_PROJ \
+      > "$outfile"
    EXITCODE=$?
 
    #### check if transform REALLY worked (e.g. bogus output if grid file not found)



More information about the grass-commit mailing list