[GRASS-SVN] r58279 - in grass-addons/grass7/general: . g.proj.all

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 21 21:37:02 PST 2013


Author: annakrat
Date: 2013-11-21 21:37:02 -0800 (Thu, 21 Nov 2013)
New Revision: 58279

Added:
   grass-addons/grass7/general/g.proj.all/
   grass-addons/grass7/general/g.proj.all/Makefile
   grass-addons/grass7/general/g.proj.all/g.proj.all.html
   grass-addons/grass7/general/g.proj.all/g.proj.all.py
Log:
g.proj.all: reproject entire mapset

Added: grass-addons/grass7/general/g.proj.all/Makefile
===================================================================
--- grass-addons/grass7/general/g.proj.all/Makefile	                        (rev 0)
+++ grass-addons/grass7/general/g.proj.all/Makefile	2013-11-22 05:37:02 UTC (rev 58279)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = g.proj.all
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


Property changes on: grass-addons/grass7/general/g.proj.all/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass-addons/grass7/general/g.proj.all/g.proj.all.html
===================================================================
--- grass-addons/grass7/general/g.proj.all/g.proj.all.html	                        (rev 0)
+++ grass-addons/grass7/general/g.proj.all/g.proj.all.html	2013-11-22 05:37:02 UTC (rev 58279)
@@ -0,0 +1,30 @@
+<h2>DESCRIPTION</h2>
+
+<em>g.proj.all</em> reprojects all raster and vector maps from given location and mapset to the current mapset.
+If flag <tt>r</tt> is set, current computational region is used for raster maps reprojection.
+Otherwise, each raster map is reprojected to its bounds, ignoring computational region in the current mapset.
+
+Modules <a href="r.proj.html">r.proj</a> and <a href="v.proj.html">v.proj</a> are used for reprojecting.
+
+<h2>EXAMPLE</h2>
+
+This example reprojects raster maps (with resolution 50 map units) and vector maps from mapset 'landsat'
+of 'nc_spm_08' location to the current mapset.
+
+<div class="code"><pre>
+g.proj.all resolution=50 location=nc_spm_08 mapset=landsat
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+  <a href="r.proj.html">r.proj</a>,
+  <a href="v.proj.html">v.proj</a>
+</em>
+
+<h2>AUTHORS</h2>
+
+Anna Petrasova, <a href="http://gis.ncsu.edu/osgeorel/">NCSU OSGeoREL</a>,<br>
+Vaclav Petras, <a href="http://gis.ncsu.edu/osgeorel/">NCSU OSGeoREL</a>
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass-addons/grass7/general/g.proj.all/g.proj.all.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/grass7/general/g.proj.all/g.proj.all.py
===================================================================
--- grass-addons/grass7/general/g.proj.all/g.proj.all.py	                        (rev 0)
+++ grass-addons/grass7/general/g.proj.all/g.proj.all.py	2013-11-22 05:37:02 UTC (rev 58279)
@@ -0,0 +1,170 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:       g.proj.all
+# AUTHOR(S):    Anna Petrasova (kratochanna gmail.com)
+#               Vaclav Petras (wenzeslaus gmail.com)
+#
+# PURPOSE:      Reproject the entire mapset
+# COPYRIGHT:    (C) 2013 by 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.
+#
+#############################################################################
+
+#%module
+#% description: Reprojects raster and vector maps from given location and mapset to current mapset.
+#% keywords: general, projection, transformation
+#%end
+#%option
+#% key: location
+#% key_desc: name
+#% type: string
+#% required: yes
+#% description: Location containing input raster map
+#% gisprompt: old,location,location
+#% guisection: Source
+#%end
+#% option G_OPT_M_MAPSET
+#% description: Mapset containing input raster map
+#% required: yes
+#% guisection: Source
+#%end
+#%option
+#% key: dbase
+#% key_desc: path
+#% type: string
+#% required: no
+#% description: Path to GRASS database of input location
+#% gisprompt: old,dbase,dbase
+#%end
+#%option
+#% key: method
+#% type: string
+#% required: no
+#% description: Interpolation method to use
+#% guisection: Raster
+#% answer: nearest
+#% options: nearest,linear,cubic,lanczos,linear_f,cubic_f,lanczos_f
+#% descriptions: nearest;nearest neighbor;linear;linear interpolation;cubic;cubic convolution;lanczos;lanczos filter;linear_f;linear interpolation with fallback;cubic_f;cubic convolution with fallback;lanczos_f;lanczos filter with fallback
+#%end
+#%option
+#% key: resolution
+#% type: double
+#% required: no
+#% description: Resolution of output raster map
+#% guisection: Raster
+#%end
+#%flag
+#% key: r
+#% description: Use current region instead of maps bounds
+#% guisection: Raster
+#%end
+#%flag
+#% key: z
+#% label: Assume z coordinate is ellipsoidal height and transform if possible
+#% description: 3D vector maps only
+#% guisection: Vector
+#%end
+#%flag
+#% key: o
+#% description: Allow output files to overwrite existing files
+#%end
+
+
+## location, mapset, dbase should be moved to one tab (Source)
+## if we override Required (which is not possible now)
+
+
+import sys
+import atexit
+
+from grass.script import core as gcore
+
+
+def main():
+    options, flags = gcore.parser()
+
+    location = options['location']
+    mapset = options['mapset']
+    dbase = options['dbase']
+
+    resolution = options['resolution']
+    if resolution:
+        resolution = float(resolution)
+    method = options['method']
+    curr_region = flags['r']
+
+    transform_z = flags['z']
+    overwrite = flags['o']
+
+    if not curr_region:
+        gcore.use_temp_region()
+        atexit.register(gcore.del_temp_region)
+    if overwrite or gcore.overwrite():
+        overwrite = True
+    else:
+        overwrite = False
+    #
+    # r.proj
+    #
+    parameters = dict(location=location, mapset=mapset, flags='l',
+                      overwrite=overwrite)
+    if dbase:
+        parameters.update(dict(dbase=dbase))
+    # first run r.proj to see if it works
+    returncode = gcore.run_command('r.proj', quiet=True, **parameters)
+    if returncode != 0:
+        gcore.fatal(_("Module r.proj failed. Please check the error messages above."))
+    # run again to get the raster maps
+    rasters = gcore.read_command('r.proj', **parameters)
+    rasters = rasters.strip().split()
+    gcore.info(_("{num} raster maps will be reprojected from mapset <{mapsetS}> "
+                 "to mapset <{mapsetT}>.").format(num=len(rasters), mapsetS=mapset,
+                                               mapsetT=gcore.gisenv()['MAPSET']))
+
+    parameters = dict(location=location, mapset=mapset, method=method,
+                      overwrite=overwrite)
+    if resolution:
+        parameters.update(dict(resolution=resolution))
+    if dbase:
+        parameters.update(dict(dbase=dbase))
+    for raster in rasters:
+        if not curr_region:
+            bounds = gcore.read_command('r.proj', input=raster, flags='g',
+                                        **parameters)
+            bounds = gcore.parse_key_val(bounds, vsep=' ')
+            gcore.run_command('g.region', **bounds)
+
+        gcore.run_command('r.proj', input=raster, **parameters)
+
+    #
+    # v.proj
+    #
+    parameters = dict(location=location, mapset=mapset, flags='l',
+                       overwrite=overwrite)
+    if dbase:
+        parameters.update(dict(dbase=dbase))
+    # first run v.proj to see if it works
+    returncode = gcore.run_command('v.proj', quiet=True, **parameters)
+    if returncode != 0:
+        gcore.fatal(_("Module v.proj failed. Please check the error messages above."))
+    # run again to get the vector maps
+    vectors = gcore.read_command('v.proj', **parameters)
+    vectors = vectors.strip().split()
+    gcore.info(_("{num} vectors maps will be reprojected from mapset <{mapsetS}> "
+                 "to mapset <{mapsetT}>.").format(num=len(vectors), mapsetS=mapset,
+                                               mapsetT=gcore.gisenv()['MAPSET']))
+
+    parameters = dict(location=location, mapset=mapset,
+                      overwrite=overwrite)
+    if transform_z:
+        parameters.update(dict(flags='z'))
+    for vector in vectors:
+        gcore.run_command('v.proj', input=vector, **parameters)
+
+if __name__ == "__main__":
+    sys.exit(main())


Property changes on: grass-addons/grass7/general/g.proj.all/g.proj.all.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native



More information about the grass-commit mailing list