[GRASS-SVN] r33706 - grass-addons/vector/v.what.rast.buffer
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Oct 7 00:52:15 EDT 2008
Author: hamish
Date: 2008-10-07 00:52:14 -0400 (Tue, 07 Oct 2008)
New Revision: 33706
Modified:
grass-addons/vector/v.what.rast.buffer/v.what.rast.buffer
Log:
fix buffering calc, better region zooming
Modified: grass-addons/vector/v.what.rast.buffer/v.what.rast.buffer
===================================================================
--- grass-addons/vector/v.what.rast.buffer/v.what.rast.buffer 2008-10-07 03:56:28 UTC (rev 33705)
+++ grass-addons/vector/v.what.rast.buffer/v.what.rast.buffer 2008-10-07 04:52:14 UTC (rev 33706)
@@ -127,7 +127,7 @@
#echo "Extractions of [$MAP] at [$SITES_FILE] `date`" > "$TMP"
echo "map_name${FS}cat_id${FS}easting${FS}northing${FS}value${FS}mean_${BUFFER}m_radius${FS}" \
"stdev_${BUFFER}m_radius${FS}max_${BUFFER}m_radius${FS}min_${BUFFER}m_radius${FS}" \
- "number of "$RES"m^2 cells within ${BUFFER}m_radius" > "$TMP"
+ "number of valid "$RES"m^2 cells within ${BUFFER}m_radius" > "$TMP"
#### per raster map
@@ -167,25 +167,39 @@
ID=`echo "$POS" | cut -f3 -d"|"`
g.message -v message="site e=$EASTING n=$NORTHING ID=$ID"
- int_EASTING=`echo $EASTING | cut -f1 -d.`
- int_NORTHING=`echo $NORTHING | cut -f1 -d.`
-
- # create region bounds so we only process local area
- R_NORTH=`echo $(((($int_NORTHING / $RES) * $RES) + ($RES * 10) ))`
- R_SOUTH=`echo $(((($int_NORTHING / $RES) * $RES) - ($RES * 10) ))`
- R_EAST=`echo $(((($int_EASTING / $RES) * $RES) + ($RES * 10) ))`
- R_WEST=`echo $(((($int_EASTING / $RES) * $RES) - ($RES * 10) ))`
-
# find site value
g.region rast="$MAP"
val=`r.what in="$MAP" null=nan east_north="$EASTING,$NORTHING" | cut -f4 -d"|"`
+ # create subregion bounds centered on mark so we quickly process
+
+if [ 0 ] ; then
+ # only the local area.
+ int_EASTING=`echo $EASTING | cut -f1 -d.`
+ int_NORTHING=`echo $NORTHING | cut -f1 -d.`
+# change this to measure from center of cell the point lies in, or ...?
+ # the following heavily relies on integer truncation.
+ R_NORTH=`echo $(((($int_NORTHING / $RES) * $RES) + ((($BUFFER/$RES)+2) * $RES) ))`
+ R_SOUTH=`echo $(((($int_NORTHING / $RES) * $RES) - ((($BUFFER/$RES)+2) * $RES) ))`
+ R_EAST=`echo $(((($int_EASTING / $RES) * $RES) + ((($BUFFER/$RES)+2) * $RES) ))`
+ R_WEST=`echo $(((($int_EASTING / $RES) * $RES) - ((($BUFFER/$RES)+2) * $RES) ))`
+
# zoom in on local region (for speed)
- g.region n=$R_NORTH s=$R_SOUTH e=$R_EAST w=$R_WEST res=$RES
+ g.region n=$R_NORTH s=$R_SOUTH e=$R_EAST w=$R_WEST res=$RES # -p
+else
+ # alternate method: rely on g.region -a expansion
+ R_NORTH=`echo $($NORTHING + $BUFFER)`
+ R_SOUTH=`echo $($NORTHING - $BUFFER)`
+ R_EAST=`echo $($EASTING + $BUFFER)`
+ R_WEST=`echo $($EASTING - $BUFFER)`
- # get stats about surrounding area, 100m radius
+ # zoom in on local region (for speed)
+ g.region n=$R_NORTH s=$R_SOUTH e=$R_EAST w=$R_WEST res=$RES -a # -p
+fi
+
+ # get stats about surrounding area, ${100}m radius
g.message -v " Building Buffer ..."
- r.circle -b output=MASK coord="$EASTING,$NORTHING" min=0 max="$RES" --quiet
+ r.circle -b output=MASK coord="$EASTING,$NORTHING" min=0 max="$BUFFER" --quiet
g.message " Calculating stats for cat $ID ..."
eval `r.univar -g map="$MAP"`
More information about the grass-commit
mailing list