[GRASS-SVN] r52172 - in grass/trunk: raster/r.buffer scripts scripts/r.buffer.lowmem

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 20 19:03:27 PDT 2012


Author: hamish
Date: 2012-06-20 19:03:27 -0700 (Wed, 20 Jun 2012)
New Revision: 52172

Added:
   grass/trunk/raster/r.buffer/r.buffer.html
   grass/trunk/scripts/r.buffer.lowmem/
   grass/trunk/scripts/r.buffer.lowmem/r.buffer.lowmem.html
   grass/trunk/scripts/r.buffer.lowmem/r.buffer.lowmem.py
Removed:
   grass/trunk/raster/r.buffer/r.buffer2.html
   grass/trunk/scripts/r.buffer.lowmem/r.buffer.html
   grass/trunk/scripts/r.buffer.lowmem/r.buffer.py
   grass/trunk/scripts/r.buffer/
Modified:
   grass/trunk/raster/r.buffer/
   grass/trunk/raster/r.buffer/Makefile
   grass/trunk/scripts/Makefile
   grass/trunk/scripts/r.buffer.lowmem/Makefile
Log:
Rename classic r.buffer back to its original name, rename the python
version to "lowmem". Describe the alternatives in the help pages.
The classic C version runs more than 40x faster and memory only becomes 
an issue when the map size is abnormally massive. (32000x32000 cells on
a machine with 1 GB RAM, 90000x90000 cells on a machine with 8 GB RAM).



Property changes on: grass/trunk/raster/r.buffer
___________________________________________________________________
Modified: svn:ignore
   - OBJ.*

   + OBJ.*
*.tmp.html


Modified: grass/trunk/raster/r.buffer/Makefile
===================================================================
--- grass/trunk/raster/r.buffer/Makefile	2012-06-21 01:26:08 UTC (rev 52171)
+++ grass/trunk/raster/r.buffer/Makefile	2012-06-21 02:03:27 UTC (rev 52172)
@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-PGM = r.buffer2
+PGM = r.buffer
 
 LIBES = $(RASTERLIB) $(GISLIB)
 DEPENDENCIES = $(RASTERDEP) $(GISDEP)

Copied: grass/trunk/raster/r.buffer/r.buffer.html (from rev 52170, grass/trunk/raster/r.buffer/r.buffer2.html)
===================================================================
--- grass/trunk/raster/r.buffer/r.buffer.html	                        (rev 0)
+++ grass/trunk/raster/r.buffer/r.buffer.html	2012-06-21 02:03:27 UTC (rev 52172)
@@ -0,0 +1,122 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.buffer</em> creates a new raster map layer showing
+buffer (a.k.a. "distance" or "proximity") zones around all
+cells that contain non-NULL category values in an existing
+raster map layer.  The distances of buffer zones from cells
+with non-zero category values are user-chosen.  Suppose,
+for example, that you want to place buffer zones around
+roads.  This program could create the raster map layer
+shown below on the right based on road information
+contained in the raster map layer shown on the left.
+
+<div class="code"><pre>
+      000000000000000000000000 222233333333333333444444 
+      111000000000000000000000 111222222222223333333333 
+      000111111111100000000000 222111111111122223333333 
+      000000001000011100000000 332222221222211122222222 
+      000000001000000011111111 333333321233222211111111 
+      000000001000000000000000 433333321233333222222222 
+      000000001000000000000000 444443321233333333333333 
+      000000001000000000000000 444443321233443333333333 
+      000000001000000000000000 444443321233444444444444 
+
+      Category 0: No roads
+      Category 1: Road location 
+      Category 2: Buffer Zone 1 around roads 
+      Category 3: Buffer Zone 2 around roads 
+      Category 4: Buffer Zone 3 around roads 
+</pre></div>
+<br>
+
+
+<h2>NOTES</h2>
+
+The user has the option of identifying up to 250 continuous zones.
+The zones are identified by specifying the upper limit of each desired zone
+(<em>r.buffer</em> assumes that <tt>0</tt> is the starting point).
+("Continuous" is used in the sense that each category
+zone's lower value is the previous zone's upper value. The
+first buffer zone always has distance <tt>0</tt> as its lower
+bound.) Buffer distances can be specified using one of five units with the <em>
+units</em> parameter: <em>meters, kilometers, feet, miles</em>, and <em>nautmiles</em>
+(nautical miles).
+<p>
+<!-- ??? is this the real method used or some ancient option ??? -->
+Distances from cells containing the user-specified category values
+are calculated using the "fromcell" method. This method locates each
+cell that contains a category value from which distances are to be
+calculated, and draws the requested distance rings around
+them. This method works very fast when there are few cells
+containing the category values of interest, but works
+slowly when there are numerous cells containing the
+category values of interest spread throughout the area.
+<p>
+<em>r.buffer</em> measures distances from center of cell to
+center of cell using Euclidean distance measure for
+planimetric locations (like UTM) and using ellipsoidal
+geodesic distance measure for latitude/longitude locations.
+<p>
+<em>r.buffer</em> calculates distance zones from all cells having non-NULL 
+category values in the <em>input</em> map. If the user wishes to calculate
+distances from only selected <em>input</em> map layer 
+category values, the user should run (for example) 
+<em><a href="r.reclass.html">r.reclass</a></em> prior to 
+<em>r.buffer</em>, to reclass all categories from which distance zones 
+are not desired to be calculated into category NULL. 
+<p>
+The <b>-z</b> flag can be used to ignore raster values of zero instead of NULL
+values in the input raster map.
+<p>
+When working with massive raster regions consider the <em>r.buffer.lowmem</em>
+module if RAM use becomes a problem. The lowmem version can be > 40x slower,
+but will work with minimal memory requirements. The classic <em>r.buffer</em>
+should be able to deal with raster maps of 32000x32000 size on a system with
+1 GB RAM, and rasters of 90000x90000 on a system with 8 GB RAM without going
+into swap.
+
+
+<h2>EXAMPLE</h2>
+
+In the following example, the buffer zones would be (in the default units
+of meters):  0-100, 101-200, 201-300, 301-400 and 401-500.
+<br>
+<div class="code"><pre>
+<b>r.buffer input=</b>roads <b>output=</b>roads.buf <b>distances=</b>100,200,300,400,500
+</pre></div>
+
+Result:
+
+<div class="code"><pre>
+<b>r.category input=</b>roads.buf
+
+      1       distances calculated from these locations
+      2       0-100 meters
+      3       100-200 meters
+      4       200-300 meters
+      5       300-400 meters
+      6       400-500 meters
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="g.region.html">g.region</a><br>
+<a href="r.buffer.lowmem.html">r.buffer.lowmem</a><br>
+<a href="r.cost.html">r.cost</a><br>
+<a href="r.mapcalc.html">r.mapcalc</a><br>
+<a href="r.reclass.html">r.reclass</a><br>
+<a href="v.buffer.html">v.buffer</a>
+</em>
+
+
+<h2>AUTHORS</h2>
+
+Michael Shapiro, U.S. Army Construction Engineering 
+Research Laboratory
+<br>
+James Westervelt, U.S. Army Construction Engineering 
+Research Laboratory
+
+<p><i>Last changed: $Date$</i>

Deleted: grass/trunk/raster/r.buffer/r.buffer2.html
===================================================================
--- grass/trunk/raster/r.buffer/r.buffer2.html	2012-06-21 01:26:08 UTC (rev 52171)
+++ grass/trunk/raster/r.buffer/r.buffer2.html	2012-06-21 02:03:27 UTC (rev 52172)
@@ -1,111 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.buffer</em> creates a new raster map layer showing
-buffer (a.k.a. "distance" or "proximity") zones around all
-cells that contain non-NULL category values in an existing
-raster map layer.  The distances of buffer zones from cells
-with non-zero category values are user-chosen.  Suppose,
-for example, that you want to place buffer zones around
-roads.  This program could create the raster map layer
-shown below on the right based on road information
-contained in the raster map layer shown on the left.
-
-<div class="code"><pre>
-      000000000000000000000000 222233333333333333444444 
-      111000000000000000000000 111222222222223333333333 
-      000111111111100000000000 222111111111122223333333 
-      000000001000011100000000 332222221222211122222222 
-      000000001000000011111111 333333321233222211111111 
-      000000001000000000000000 433333321233333222222222 
-      000000001000000000000000 444443321233333333333333 
-      000000001000000000000000 444443321233443333333333 
-      000000001000000000000000 444443321233444444444444 
-
-      Category 0: No roads
-      Category 1: Road location 
-      Category 2: Buffer Zone 1 around roads 
-      Category 3: Buffer Zone 2 around roads 
-      Category 4: Buffer Zone 3 around roads 
-</pre></div>
-<br>
-
-<h2>NOTES</h2>
-
-The user has the option of identifying up to 250 continuous zones.
-The zones are identified by specifying the upper limit of each desired zone
-(<em>r.buffer</em> assumes that <tt>0</tt> is the starting point).
-("Continuous" is used in the sense that each category
-zone's lower value is the previous zone's upper value. The
-first buffer zone always has distance <tt>0</tt> as its lower
-bound.) Buffer distances can be specified using one of five units with the <em>
-units</em> parameter: <em>meters, kilometers, feet, miles</em>, and <em>nautmiles</em>
-(nautical miles).
-<p>
-<!-- ??? is this the real method used or some ancient option ??? -->
-Distances from cells containing the user-specified category values
-are calculated using the "fromcell" method. This method locates each
-cell that contains a category value from which distances are to be
-calculated, and draws the requested distance rings around
-them. This method works very fast when there are few cells
-containing the category values of interest, but works
-slowly when there are numerous cells containing the
-category values of interest spread throughout the area.
-<p>
-<em>r.buffer</em> measures distances from center of cell to
-center of cell using Euclidean distance measure for
-planimetric locations (like UTM) and using ellipsoidal
-geodesic distance measure for latitude/longitude locations.
-<p>
-<em>r.buffer</em> calculates distance zones from all cells having non-NULL 
-category values in the <em>input</em> map. If the user wishes to calculate
-distances from only selected <em>input</em> map layer 
-category values, the user should run (for example) 
-<em><a href="r.reclass.html">r.reclass</a></em> prior to 
-<em>r.buffer</em>, to reclass all categories from which distance zones 
-are not desired to be calculated into category NULL. 
-<p>
-The <b>-z</b> flag can be used to ignore raster values of zero instead of NULL
-values in the input raster map.
-<p>
-<h2>EXAMPLE</h2>
-
-In the following example, the buffer zones would be (in the default units
-of meters):  0-100, 101-200, 201-300, 301-400 and 401-500.
-<br>
-<div class="code"><pre>
-<b>r.buffer input=</b>roads <b>output=</b>roads.buf <b>distances=</b>100,200,300,400,500
-</pre></div>
-
-Result:
-
-<div class="code"><pre>
-<b>r.category input=</b>roads.buf
-
-      1       distances calculated from these locations
-      2       0-100 meters
-      3       100-200 meters
-      4       200-300 meters
-      5       300-400 meters
-      6       400-500 meters
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="g.region.html">g.region</a><br>
-<a href="r.cost.html">r.cost</a><br>
-<a href="r.mapcalc.html">r.mapcalc</a><br>
-<a href="r.reclass.html">r.reclass</a><br>
-<a href="v.buffer.html">v.buffer</a>
-</em>
-
-
-<h2>AUTHORS</h2>
-
-Michael Shapiro, U.S. Army Construction Engineering 
-Research Laboratory
-<br>
-James Westervelt, U.S. Army Construction Engineering 
-Research Laboratory
-
-<p><i>Last changed: $Date$</i>

Modified: grass/trunk/scripts/Makefile
===================================================================
--- grass/trunk/scripts/Makefile	2012-06-21 01:26:08 UTC (rev 52171)
+++ grass/trunk/scripts/Makefile	2012-06-21 02:03:27 UTC (rev 52172)
@@ -25,7 +25,7 @@
 	i.tasscap \
 	m.proj \
 	r.blend \
-	r.buffer \
+	r.buffer.lowmem \
 	r.colors.stddev \
 	r.fillnulls \
 	r.grow \

Modified: grass/trunk/scripts/r.buffer.lowmem/Makefile
===================================================================
--- grass/trunk/scripts/r.buffer/Makefile	2012-06-20 21:52:11 UTC (rev 52170)
+++ grass/trunk/scripts/r.buffer.lowmem/Makefile	2012-06-21 02:03:27 UTC (rev 52172)
@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-PGM = r.buffer
+PGM = r.buffer.lowmem
 
 include $(MODULE_TOPDIR)/include/Make/Script.make
 


Property changes on: grass/trunk/scripts/r.buffer.lowmem/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Deleted: grass/trunk/scripts/r.buffer.lowmem/r.buffer.html
===================================================================
--- grass/trunk/scripts/r.buffer/r.buffer.html	2012-06-20 21:52:11 UTC (rev 52170)
+++ grass/trunk/scripts/r.buffer.lowmem/r.buffer.html	2012-06-21 02:03:27 UTC (rev 52172)
@@ -1,111 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.buffer</em> creates a new raster map layer showing
-buffer (a.k.a. "distance" or "proximity") zones around all
-cells that contain non-NULL category values in an existing
-raster map layer.  The distances of buffer zones from cells
-with non-zero category values are user-chosen.  Suppose,
-for example, that you want to place buffer zones around
-roads.  This program could create the raster map layer
-shown below on the right based on road information
-contained in the raster map layer shown on the left.
-
-<div class="code"><pre>
-      000000000000000000000000 222233333333333333444444 
-      111000000000000000000000 111222222222223333333333 
-      000111111111100000000000 222111111111122223333333 
-      000000001000011100000000 332222221222211122222222 
-      000000001000000011111111 333333321233222211111111 
-      000000001000000000000000 433333321233333222222222 
-      000000001000000000000000 444443321233333333333333 
-      000000001000000000000000 444443321233443333333333 
-      000000001000000000000000 444443321233444444444444 
-
-      Category 0: No roads
-      Category 1: Road location 
-      Category 2: Buffer Zone 1 around roads 
-      Category 3: Buffer Zone 2 around roads 
-      Category 4: Buffer Zone 3 around roads 
-</pre></div>
-<br>
-
-<h2>NOTES</h2>
-
-The user has the option of identifying up to 250 continuous zones.
-The zones are identified by specifying the upper limit of each desired zone
-(<em>r.buffer</em> assumes that <tt>0</tt> is the starting point).
-("Continuous" is used in the sense that each category
-zone's lower value is the previous zone's upper value. The
-first buffer zone always has distance <tt>0</tt> as its lower
-bound.) Buffer distances can be specified using one of five units with the <em>
-units</em> parameter: <em>meters, kilometers, feet, miles</em>, and <em>nautmiles</em>
-(nautical miles).
-<p>
-<!-- ??? is this the real method used or some ancient option ??? -->
-Distances from cells containing the user-specified category values
-are calculated using the "fromcell" method. This method locates each
-cell that contains a category value from which distances are to be
-calculated, and draws the requested distance rings around
-them. This method works very fast when there are few cells
-containing the category values of interest, but works
-slowly when there are numerous cells containing the
-category values of interest spread throughout the area.
-<p>
-<em>r.buffer</em> measures distances from center of cell to
-center of cell using Euclidean distance measure for
-planimetric locations (like UTM) and using ellipsoidal
-geodesic distance measure for latitude/longitude locations.
-<p>
-<em>r.buffer</em> calculates distance zones from all cells having non-NULL 
-category values in the <em>input</em> map. If the user wishes to calculate
-distances from only selected <em>input</em> map layer 
-category values, the user should run (for example) 
-<em><a href="r.reclass.html">r.reclass</a></em> prior to 
-<em>r.buffer</em>, to reclass all categories from which distance zones 
-are not desired to be calculated into category NULL. 
-<p>
-The <b>-z</b> flag can be used to ignore raster values of zero instead of NULL
-values in the input raster map.
-<p>
-<h2>EXAMPLE</h2>
-
-In the following example, the buffer zones would be (in the default units
-of meters):  0-100, 101-200, 201-300, 301-400 and 401-500.
-<br>
-<div class="code"><pre>
-<b>r.buffer input=</b>roads <b>output=</b>roads.buf <b>distances=</b>100,200,300,400,500
-</pre></div>
-
-Result:
-
-<div class="code"><pre>
-<b>r.category input=</b>roads.buf
-
-      1       distances calculated from these locations
-      2       0-100 meters
-      3       100-200 meters
-      4       200-300 meters
-      5       300-400 meters
-      6       400-500 meters
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="g.region.html">g.region</a><br>
-<a href="r.cost.html">r.cost</a><br>
-<a href="r.mapcalc.html">r.mapcalc</a><br>
-<a href="r.reclass.html">r.reclass</a><br>
-<a href="v.buffer.html">v.buffer</a>
-</em>
-
-
-<h2>AUTHORS</h2>
-
-Michael Shapiro, U.S. Army Construction Engineering 
-Research Laboratory
-<br>
-James Westervelt, U.S. Army Construction Engineering 
-Research Laboratory
-
-<p><i>Last changed: $Date$</i>

Copied: grass/trunk/scripts/r.buffer.lowmem/r.buffer.lowmem.html (from rev 52170, grass/trunk/scripts/r.buffer/r.buffer.html)
===================================================================
--- grass/trunk/scripts/r.buffer.lowmem/r.buffer.lowmem.html	                        (rev 0)
+++ grass/trunk/scripts/r.buffer.lowmem/r.buffer.lowmem.html	2012-06-21 02:03:27 UTC (rev 52172)
@@ -0,0 +1,127 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.buffer.lowmem</em> creates a new raster map layer showing
+buffer (a.k.a. "distance" or "proximity") zones around all
+cells that contain non-NULL category values in an existing
+raster map layer.  The distances of buffer zones from cells
+with non-zero category values are user-chosen.
+
+<p>
+This is the low-memory alternative to the classic <em>r.buffer</em>
+module. It is much slower than the classic version, but will
+run on massive raster maps without using a lot of RAM. If your
+raster map is larger than 32000x32000 cells on a system with
+1 GB of RAM, or larger than 90000x90000 cells on a system with
+8 GB of RAM, consider using this module.
+
+<p>
+Suppose,
+for example, that you want to place buffer zones around
+roads.  This program could create the raster map layer
+shown below on the right based on road information
+contained in the raster map layer shown on the left.
+
+<div class="code"><pre>
+      000000000000000000000000 222233333333333333444444 
+      111000000000000000000000 111222222222223333333333 
+      000111111111100000000000 222111111111122223333333 
+      000000001000011100000000 332222221222211122222222 
+      000000001000000011111111 333333321233222211111111 
+      000000001000000000000000 433333321233333222222222 
+      000000001000000000000000 444443321233333333333333 
+      000000001000000000000000 444443321233443333333333 
+      000000001000000000000000 444443321233444444444444 
+
+      Category 0: No roads
+      Category 1: Road location 
+      Category 2: Buffer Zone 1 around roads 
+      Category 3: Buffer Zone 2 around roads 
+      Category 4: Buffer Zone 3 around roads 
+</pre></div>
+<br>
+
+<h2>NOTES</h2>
+
+The user has the option of identifying up to 250 continuous zones.
+The zones are identified by specifying the upper limit of each desired zone
+(<em>r.buffer</em> assumes that <tt>0</tt> is the starting point).
+("Continuous" is used in the sense that each category
+zone's lower value is the previous zone's upper value. The
+first buffer zone always has distance <tt>0</tt> as its lower
+bound.) Buffer distances can be specified using one of five units with the <em>
+units</em> parameter: <em>meters, kilometers, feet, miles</em>, and <em>nautmiles</em>
+(nautical miles).
+<p>
+<!-- ??? is this the real method used or some ancient option ??? -->
+Distances from cells containing the user-specified category values
+are calculated using the "fromcell" method. This method locates each
+cell that contains a category value from which distances are to be
+calculated, and draws the requested distance rings around
+them. This method works very fast when there are few cells
+containing the category values of interest, but works
+slowly when there are numerous cells containing the
+category values of interest spread throughout the area.
+<p>
+<em>r.buffer</em> measures distances from center of cell to
+center of cell using Euclidean distance measure for
+planimetric locations (like UTM) and using ellipsoidal
+geodesic distance measure for latitude/longitude locations.
+<p>
+<em>r.buffer</em> calculates distance zones from all cells having non-NULL 
+category values in the <em>input</em> map. If the user wishes to calculate
+distances from only selected <em>input</em> map layer 
+category values, the user should run (for example) 
+<em><a href="r.reclass.html">r.reclass</a></em> prior to 
+<em>r.buffer</em>, to reclass all categories from which distance zones 
+are not desired to be calculated into category NULL. 
+<p>
+The <b>-z</b> flag can be used to ignore raster values of zero instead of NULL
+values in the input raster map.
+<p>
+<h2>EXAMPLE</h2>
+
+In the following example, the buffer zones would be (in the default units
+of meters):  0-100, 101-200, 201-300, 301-400 and 401-500.
+<br>
+<div class="code"><pre>
+<b>r.buffer input=</b>roads <b>output=</b>roads.buf <b>distances=</b>100,200,300,400,500
+</pre></div>
+
+Result:
+
+<div class="code"><pre>
+<b>r.category input=</b>roads.buf
+
+      1       distances calculated from these locations
+      2       0-100 meters
+      3       100-200 meters
+      4       200-300 meters
+      5       300-400 meters
+      6       400-500 meters
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="g.region.html">g.region</a><br>
+<a href="r.buffer.html">r.buffer</a><br>
+<a href="r.cost.html">r.cost</a><br>
+<a href="r.grow.distance.html">r.grow.distance</a><br>
+<a href="r.mapcalc.html">r.mapcalc</a><br>
+<a href="r.reclass.html">r.reclass</a><br>
+<a href="v.buffer.html">v.buffer</a>
+</em>
+
+
+<h2>AUTHORS</h2>
+
+Michael Shapiro, U.S. Army Construction Engineering 
+Research Laboratory
+<br>
+James Westervelt, U.S. Army Construction Engineering 
+Research Laboratory
+<br>
+Low-memory Python version by Glynn Clements
+
+<p>
+<i>Last changed: $Date$</i>

Copied: grass/trunk/scripts/r.buffer.lowmem/r.buffer.lowmem.py (from rev 52170, grass/trunk/scripts/r.buffer/r.buffer.py)
===================================================================
--- grass/trunk/scripts/r.buffer.lowmem/r.buffer.lowmem.py	                        (rev 0)
+++ grass/trunk/scripts/r.buffer.lowmem/r.buffer.lowmem.py	2012-06-21 02:03:27 UTC (rev 52172)
@@ -0,0 +1,134 @@
+#!/usr/bin/env python
+#
+############################################################################
+#
+# MODULE:	r.buffer.lowmem
+# AUTHOR(S):	Glynn Clements
+# PURPOSE:	Low-memory replacement for r.buffer using r.grow.distance
+#
+# COPYRIGHT:	(C) 2008, 2010 by Glynn Clements
+#
+#		This program is free software under the GNU General Public
+#		License (>=v2). Read the file COPYING that comes with GRASS
+#		for details.
+#
+#############################################################################
+
+#%module
+#% description: Creates a raster map showing buffer zones surrounding cells that contain non-NULL category values.
+#% keywords: raster
+#% keywords: buffer
+#%end
+#%flag
+#% key: z
+#% description: Ignore zero (0) data cells instead of NULL cells
+#%end
+#%option G_OPT_R_INPUT
+#%end
+#%option G_OPT_R_OUTPUT
+#%end
+#%option
+#% key: distances
+#% type: double
+#% required: yes
+#% multiple: yes
+#% description: Distance zone(s)
+#%end
+#%option G_OPT_M_UNITS
+#% options: meters,kilometers,feet,miles,nautmiles
+#% description: Units of distance
+#% answer: meters
+#%end
+
+import sys
+import os
+import atexit
+import math
+import grass.script as grass
+
+scales = {
+    'meters': 1.0,
+    'kilometers': 1000.0,
+    'feet': 0.3048,
+    'miles': 1609.344,
+    'nautmiles': 1852.0
+    }
+
+# what to do in case of user break:
+def cleanup():
+    if grass.find_file(temp_src)['file']:
+        grass.run_command('g.remove', quiet = True, flags = 'f', rast = temp_src)
+    if grass.find_file(temp_dist)['file']:
+        grass.run_command('g.remove', quiet = True, flags = 'f', rast = temp_dist)
+
+def main():
+    global temp_dist, temp_src
+
+    input = options['input']
+    output = options['output']
+    distances = options['distances']
+    units = options['units']
+    zero = flags['z']
+
+    tmp = str(os.getpid())
+    temp_dist = "r.buffer.tmp.%s.dist" % tmp
+    temp_src = "r.buffer.tmp.%s.src" % tmp
+
+    #check if input file exists
+    if not grass.find_file(input)['file']:
+	grass.fatal(_("<%s> does not exist.") % input)
+
+    scale = scales[units]
+
+    distances  = distances.split(',')
+    distances1 = [scale * float(d) for d in distances]
+    distances2 = [d * d for d in distances1]
+
+    s = grass.read_command("g.proj", flags='j')
+    kv = grass.parse_key_val(s)
+    if kv['+proj'] == 'longlat':
+	metric = 'geodesic'
+    else:
+	metric = 'squared'
+
+    grass.run_command('r.grow.distance',  input = input, metric = metric,
+		      distance = temp_dist, flags = 'm')
+
+    if zero:
+	exp = "$temp_src = if($input == 0,null(),1)"
+    else:
+	exp = "$temp_src = if(isnull($input),null(),1)"
+
+    grass.message(_("Extracting buffers (1/2)..."))
+    grass.mapcalc(exp, temp_src = temp_src, input = input)
+
+    exp = "$output = if(!isnull($input),$input,%s)"
+    if metric == 'squared':
+	for n, dist2 in enumerate(distances2):
+	    exp %= "if($dist <= %f,%d,%%s)" % (dist2,n + 2)
+    else:
+	for n, dist2 in enumerate(distances1):
+	    exp %= "if($dist <= %f,%d,%%s)" % (dist2,n + 2)
+    exp %= "null()"
+
+    grass.message(_("Extracting buffers (2/2)..."))
+    grass.mapcalc(exp, output = output, input = temp_src, dist = temp_dist)
+
+    p = grass.feed_command('r.category', map = output, rules = '-')
+    p.stdin.write("1:distances calculated from these locations\n")
+    d0 = "0"
+    for n, d in enumerate(distances):
+	p.stdin.write("%d:%s-%s %s\n" % (n + 2, d0, d, units))
+	d0 = d
+    p.stdin.close()
+    p.wait()
+
+    grass.run_command('r.colors', map = output, color = 'rainbow')
+
+    # write cmd history:
+    grass.raster_history(output)
+    
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    atexit.register(cleanup)
+    main()

Deleted: grass/trunk/scripts/r.buffer.lowmem/r.buffer.py
===================================================================
--- grass/trunk/scripts/r.buffer/r.buffer.py	2012-06-20 21:52:11 UTC (rev 52170)
+++ grass/trunk/scripts/r.buffer.lowmem/r.buffer.py	2012-06-21 02:03:27 UTC (rev 52172)
@@ -1,134 +0,0 @@
-#!/usr/bin/env python
-#
-############################################################################
-#
-# MODULE:	r.buffer
-# AUTHOR(S):	Glynn Clements
-# PURPOSE:	Replacement for r.buffer using r.grow.distance
-#
-# COPYRIGHT:	(C) 2008, 2010 by Glynn Clements
-#
-#		This program is free software under the GNU General Public
-#		License (>=v2). Read the file COPYING that comes with GRASS
-#		for details.
-#
-#############################################################################
-
-#%module
-#% description: Creates a raster map showing buffer zones surrounding cells that contain non-NULL category values.
-#% keywords: raster
-#% keywords: buffer
-#%end
-#%flag
-#% key: z
-#% description: Ignore zero (0) data cells instead of NULL cells
-#%end
-#%option G_OPT_R_INPUT
-#%end
-#%option G_OPT_R_OUTPUT
-#%end
-#%option
-#% key: distances
-#% type: double
-#% required: yes
-#% multiple: yes
-#% description: Distance zone(s)
-#%end
-#%option G_OPT_M_UNITS
-#% options: meters,kilometers,feet,miles,nautmiles
-#% description: Units of distance
-#% answer: meters
-#%end
-
-import sys
-import os
-import atexit
-import math
-import grass.script as grass
-
-scales = {
-    'meters': 1.0,
-    'kilometers': 1000.0,
-    'feet': 0.3048,
-    'miles': 1609.344,
-    'nautmiles': 1852.0
-    }
-
-# what to do in case of user break:
-def cleanup():
-    if grass.find_file(temp_src)['file']:
-        grass.run_command('g.remove', quiet = True, flags = 'f', rast = temp_src)
-    if grass.find_file(temp_dist)['file']:
-        grass.run_command('g.remove', quiet = True, flags = 'f', rast = temp_dist)
-
-def main():
-    global temp_dist, temp_src
-
-    input = options['input']
-    output = options['output']
-    distances = options['distances']
-    units = options['units']
-    zero = flags['z']
-
-    tmp = str(os.getpid())
-    temp_dist = "r.buffer.tmp.%s.dist" % tmp
-    temp_src = "r.buffer.tmp.%s.src" % tmp
-
-    #check if input file exists
-    if not grass.find_file(input)['file']:
-	grass.fatal(_("<%s> does not exist.") % input)
-
-    scale = scales[units]
-
-    distances  = distances.split(',')
-    distances1 = [scale * float(d) for d in distances]
-    distances2 = [d * d for d in distances1]
-
-    s = grass.read_command("g.proj", flags='j')
-    kv = grass.parse_key_val(s)
-    if kv['+proj'] == 'longlat':
-	metric = 'geodesic'
-    else:
-	metric = 'squared'
-
-    grass.run_command('r.grow.distance',  input = input, metric = metric,
-		      distance = temp_dist, flags = 'm')
-
-    if zero:
-	exp = "$temp_src = if($input == 0,null(),1)"
-    else:
-	exp = "$temp_src = if(isnull($input),null(),1)"
-
-    grass.message(_("Extracting buffers (1/2)..."))
-    grass.mapcalc(exp, temp_src = temp_src, input = input)
-
-    exp = "$output = if(!isnull($input),$input,%s)"
-    if metric == 'squared':
-	for n, dist2 in enumerate(distances2):
-	    exp %= "if($dist <= %f,%d,%%s)" % (dist2,n + 2)
-    else:
-	for n, dist2 in enumerate(distances1):
-	    exp %= "if($dist <= %f,%d,%%s)" % (dist2,n + 2)
-    exp %= "null()"
-
-    grass.message(_("Extracting buffers (2/2)..."))
-    grass.mapcalc(exp, output = output, input = temp_src, dist = temp_dist)
-
-    p = grass.feed_command('r.category', map = output, rules = '-')
-    p.stdin.write("1:distances calculated from these locations\n")
-    d0 = "0"
-    for n, d in enumerate(distances):
-	p.stdin.write("%d:%s-%s %s\n" % (n + 2, d0, d, units))
-	d0 = d
-    p.stdin.close()
-    p.wait()
-
-    grass.run_command('r.colors', map = output, color = 'rainbow')
-
-    # write cmd history:
-    grass.raster_history(output)
-    
-if __name__ == "__main__":
-    options, flags = grass.parser()
-    atexit.register(cleanup)
-    main()



More information about the grass-commit mailing list