[GRASS-SVN] r58856 - in grass/trunk/raster/r.li: r.li.daemon r.li.edgedensity r.li.patchdensity r.li.setup

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Feb 3 09:28:13 PST 2014


Author: neteler
Date: 2014-02-03 09:28:13 -0800 (Mon, 03 Feb 2014)
New Revision: 58856

Modified:
   grass/trunk/raster/r.li/r.li.daemon/daemon.c
   grass/trunk/raster/r.li/r.li.daemon/daemon.h
   grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c
   grass/trunk/raster/r.li/r.li.patchdensity/main.c
   grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh
Log:
r.li.*: revert r58850 (fixes from G6, still to be done here)

Modified: grass/trunk/raster/r.li/r.li.daemon/daemon.c
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/daemon.c	2014-02-03 17:03:56 UTC (rev 58855)
+++ grass/trunk/raster/r.li/r.li.daemon/daemon.c	2014-02-03 17:28:13 UTC (rev 58856)
@@ -56,6 +56,8 @@
     struct list *l;
     msg m, doneJob;
 
+    /* int perc=0; */
+
     g = (struct g_area *) G_malloc(sizeof(struct g_area));
     g->maskname = NULL;
     l = (struct list*) G_malloc(sizeof(struct list));
@@ -206,7 +208,7 @@
 
     token = strtok(buf, " ");
     if (strcmp("SAMPLINGFRAME", token) != 0)
-	G_fatal_error(_("Unable to parse configuration file (sampling frame)"));
+	G_fatal_error(_("Unable to parse configuration file"));
 
     rel_x = atof(strtok(NULL, "|"));
     rel_y = atof(strtok(NULL, "|"));
@@ -286,7 +288,7 @@
     else if (strcmp("MASKEDSAMPLEAREA", token) == 0) {
 	double rel_sa_x, rel_sa_y, rel_sa_rl, rel_sa_cl;
 	int aid = 1;
-	char maskname[GNAME_MAX] = {'\0'};
+	char maskname[GNAME_MAX];
 
 	do {
 	    rel_sa_x = atof(strtok(NULL, "|"));
@@ -294,6 +296,7 @@
 	    rel_sa_rl = atof(strtok(NULL, "|"));
 	    rel_sa_cl = atof(strtok(NULL, "|"));
 	    strcpy(maskname, strtok(NULL, "\n"));
+
 	    if (rel_sa_x == -1 && rel_sa_y == -1) {
 		/* runtime disposition */
 		int sa_rl, sa_cl;
@@ -333,7 +336,7 @@
     else if (strcmp("MASKEDOVERLAYAREA", token) == 0) {
 	double sa_n, sa_s, sa_w, sa_e;
 	int aid = 1;
-	char maskname[GNAME_MAX] = { '\0' };
+	char maskname[GNAME_MAX];
 	msg m;
 
 	do {
@@ -344,24 +347,10 @@
 	    sa_w = atof(strtok(NULL, "\n"));
 
 	    m.type = MASKEDAREA;
-
-	    struct Cell_head window;
-	    /* Get the window setting. g.region rast=<input raster> */
-	    G_get_window(&window);
-	    /* Each input overlay area from input vector are converted to raster
-	    via v.to.rast. See r.li.setup/sample_area_vector.sh. This is to used 
-	    only for reading the region (NS, EW). */
-
-	    /* Get start x and y position of masked overlay raster with respect 
-	    to input raster region from window. 
-	    sa_n, sa_e are read from configuration file. */
-	    m.f.f_ma.x = (int)G_easting_to_col(sa_e, &window);
-	    m.f.f_ma.y = (int)G_northing_to_row(sa_n, &window);
-
-	    /* Get row count and column count of overlay raster */
-	    m.f.f_ma.rl = (int)rint((sa_n - sa_s) / cellhd.ns_res);
-	    m.f.f_ma.cl = (int)rint((sa_e - sa_w) / cellhd.ew_res);
-
+	    m.f.f_ma.x = (int)rint((cellhd.north - sa_n) * cellhd.ns_res);
+	    m.f.f_ma.y = (int)rint((cellhd.west + sa_w) * cellhd.ew_res);
+	    m.f.f_ma.rl = (int)rint((sa_n - sa_s) * cellhd.ns_res);
+	    m.f.f_ma.cl = (int)rint((sa_e - sa_w) * cellhd.ew_res);
 	    m.f.f_ma.aid = aid;
 	    strcpy(m.f.f_ma.mask, maskname);
 	    aid++;
@@ -369,20 +358,18 @@
 	}
 	while ((token = strtok(NULL, " ")) != NULL &&
 	       (strcmp(token, "MASKEDOVERLAYAREA") == 0));
-
 	if (strcmp(token, "RASTERMAP") != 0)
 	    G_fatal_error(_("Irregular maskedoverlay areas definition"));
-
 	token = strtok(NULL, "\n");
-	if (strcmp(token, raster_) != 0)
+	if (strcmp(token, raster) != 0)
 	    G_fatal_error(_("The configuration file can be used only with \
-			%s rasterfile and not with %s "), token, raster_);
+			%s rasterfile"), token);
 	close(setup);
 	return NORMAL;
+
     }
     else
-	G_fatal_error(_("Unable to parse configuration file (sample area)"));
-
+	G_fatal_error(_("Illegal configuration file (sample area)"));
     close(setup);
     return ERROR;
 }
@@ -485,7 +472,7 @@
 	r_strat_len = (int)rint(g->rows / r_strat);
 	c_strat_len = (int)rint(g->cols / c_strat);
 	if (r_strat_len < g->rl || c_strat_len < g->cl)
-	    G_fatal_error(_("Too many stratified random sample for raster map"));
+	    G_fatal_error(_("Too many strats for raster map"));
 	loop = r_strat * c_strat;
 	srandom(0);
 	for (i = 0; i < loop; i++) {

Modified: grass/trunk/raster/r.li/r.li.daemon/daemon.h
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/daemon.h	2014-02-03 17:03:56 UTC (rev 58855)
+++ grass/trunk/raster/r.li/r.li.daemon/daemon.h	2014-02-03 17:28:13 UTC (rev 58856)
@@ -20,7 +20,6 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include "list.h"
-#include "defs.h"
 
 
 /**

Modified: grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c
===================================================================
--- grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c	2014-02-03 17:03:56 UTC (rev 58855)
+++ grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c	2014-02-03 17:28:13 UTC (rev 58856)
@@ -17,6 +17,7 @@
 #include <fcntl.h>		/* for O_RDONLY usage */
 #include <math.h>
 
+#include "../r.li.daemon/defs.h"
 #include "../r.li.daemon/avlDefs.h"
 #include "../r.li.daemon/avl.h"
 #include "../r.li.daemon/daemon.h"
@@ -127,8 +128,6 @@
 
     AVL_table *array;
 
-    buf_sup = NULL;
-
     long tot = 0;
     long zero = 0;
     long m = 0;
@@ -147,7 +146,7 @@
     /* open mask if needed */
     if (ad->mask == 1) {
 	if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
-	    G_fatal_error("can't  open mask %s", ad->mask_name);
+	    G_fatal_error("can't  open mask");
 	    return RLI_ERRORE;
 	}
 
@@ -174,6 +173,7 @@
 
     Rast_set_c_null_value(buf_sup + ad->x, ad->cl);	/*the first time buf_sup is all null */
 
+
     for (j = 0; j < ad->rl; j++) {	/* for each raster row */
 
 	buf_corr = RLI_get_cell_raster_row(fd, j + ad->y, ad);	/* read row of raster */
@@ -309,15 +309,23 @@
 		}
 
 		bordoCorr = 0;
+
 	    }
 
+
 	    prevCell = buf_corr[i + ad->x];
 	}
 
+
+
 	if (masked)
 	    mask_sup = mask_corr;
+
+
+
     }
 
+
     /* calculate index */
     if (area == 0)
 	indice = -1;
@@ -339,6 +347,7 @@
 	}
 	else {			/* all classes */
 
+
 	    array = G_malloc(m * sizeof(AVL_tableRow));
 	    if (array == NULL) {
 		G_fatal_error("malloc array failed");
@@ -491,6 +500,8 @@
 
 	    if (!(Rast_is_null_value(&corrCell, DCELL_TYPE))) {
 
+
+
 		if ((i + 1) == ad->cl)	/*last cell of the row */
 		    Rast_set_d_null_value(&nextCell, 1);
 		else if (masked && mask_corr[i + 1 + ad->x] == 0)
@@ -571,18 +582,25 @@
 
 	    }
 
+
 	    prevCell = buf_corr[i + ad->x];
 	}
 
+
+
 	if (masked)
 	    mask_sup = mask_corr;
 
+
+
     }
 
+
     /* calculate index */
     if (area == 0)
 	indice = -1;
     else {
+
 	if (valore != NULL) {	/* only 1 class */
 	    char *sval;
 	    double val;
@@ -595,8 +613,10 @@
 	    c1.t = DCELL_TYPE;
 	    e = (double)howManyCell(albero, c1);
 	    somma = e;
+
 	}
 	else {			/* all classes */
+
 	    array = G_malloc(m * sizeof(AVL_tableRow));
 	    if (array == NULL) {
 		G_fatal_error("malloc array failed");
@@ -681,6 +701,7 @@
 
     Rast_set_f_null_value(buf_sup + ad->x, ad->cl);	/*the first time buf_sup is all null */
 
+
     for (j = 0; j < ad->rl; j++) {	/* for each raster row */
 
 	buf_corr = RLI_get_fcell_raster_row(fd, j + ad->y, ad);	/* read row of raster */
@@ -688,6 +709,7 @@
 	if (j > 0)		/* not first row */
 	    buf_sup = RLI_get_fcell_raster_row(fd, j - 1 + ad->y, ad);
 
+
 	if ((j + 1) < ad->rl) {	/*not last row */
 
 	    buf_inf = RLI_get_fcell_raster_row(fd, 1 + j + ad->y, ad);
@@ -710,6 +732,7 @@
 		return RLI_ERRORE;
 	    }
 
+
 	    if ((j + 1) < ad->rl) {	/*not last row */
 		if (read(mask_fd, mask_inf, (ad->cl * sizeof(int))) < 0) {
 		    G_fatal_error("reading mask_inf");
@@ -821,18 +844,25 @@
 
 	    }
 
+
 	    prevCell = buf_corr[i + ad->x];
 	}
 
+
+
 	if (masked)
 	    mask_sup = mask_corr;
 
+
+
     }
 
+
     /* calculate index */
     if (area == 0)
 	indice = -1;
     else {
+
 	if (valore != NULL) {	/* only 1 class */
 	    char *sval;
 	    float val;
@@ -848,6 +878,8 @@
 
 	}
 	else {			/* all classes */
+
+
 	    array = G_malloc(m * sizeof(AVL_tableRow));
 	    if (array == NULL) {
 		G_fatal_error("malloc array failederror");

Modified: grass/trunk/raster/r.li/r.li.patchdensity/main.c
===================================================================
--- grass/trunk/raster/r.li/r.li.patchdensity/main.c	2014-02-03 17:03:56 UTC (rev 58855)
+++ grass/trunk/raster/r.li/r.li.patchdensity/main.c	2014-02-03 17:28:13 UTC (rev 58856)
@@ -21,6 +21,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 #include "../r.li.daemon/daemon.h"
+#include "../r.li.daemon/defs.h"
 
 int main(int argc, char *argv[])
 {

Modified: grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh
===================================================================
--- grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh	2014-02-03 17:03:56 UTC (rev 58855)
+++ grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh	2014-02-03 17:28:13 UTC (rev 58856)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh -x
 #
 # This program is free software under the GPL (>=v2)
 # Read the COPYING file that comes with GRASS for details.
@@ -50,46 +50,26 @@
 
 f_path="$GISBASE/etc/r.li.setup"
 
-##############################################################
-#read categories from input vector, extract,
-#convert to raster and save the bounds to configuration file
-##############################################################
+# list categories
+v.build map=$GIS_OPT_vector option=cdump| grep '|' |cut -f1 -d '|' |\
+    tr ' ' -d > $TMP.cat
+# number of categories
+N="`grep -c "" < $TMP.cat`"
+((N= N -3))
 
-#using v.category instead of v.build with cdump
-v.category input=$GIS_OPT_vector option=print > $TMP.cat
-
-#get input vector name
-GIS_OPT_input_vector=`echo $GIS_OPT_vector| cut -d'@' -f 1`
-
-#get input vector mapset
-GIS_OPT_input_mapset=`echo $GIS_OPT_vector| cut -d'@' -f 2`
-
-#read input vector categories into CAT_LIST array
-IFS=$'\r\n' CAT_LIST=($(cat $TMP.cat))
-
-TMP_REGION="reg`g.tempfile pid=$$`"
-#save the current region settings temporarily to avoid surpirses later.
-g.region save=$TMP_REGION
-
-#process each feature in the vector having category values in the CAT_LIST array
-for CAT in "${CAT_LIST[@]}" 
-do
-    #vector to store a feature fro $GIS_OPT_vector with category value $CAT.
-    #This temporary vector will be removed at the end. 
-    EXTRACT=$GIS_OPT_input_vector"_"$CAT"_part@"$GIS_OPT_input_mapset
-    
-    #extract only a part of $GIS_OPT_vector where category = $CAT and store in $EXTRACT
-    v.extract input=$GIS_OPT_vector output=$EXTRACT type=point,line,boundary,centroid,area,face new=-1 -d where='CAT='$CAT
-    
-    #TODO: anyway to check if x1 is in use?
+#scanning categories
+I=1
+while(($I<=$N)); do
+    #extract vector[i]
+    v.extract input=$GIS_OPT_vector output=$GIS_OPT_vector"part"$I \
+	type=point,line,boundary,centroid,area,face new=-1 -d where="(CAT=$I)"
     #opening monitor x1
     d.mon stop=x1
     d.mon start=x1
     #setting region with raster resolution
-    g.region vect=$EXTRACT align=$GIS_OPT_raster
-    d.rast -o $GIS_OPT_raster    
-    #render extracted vector map
-    d.vect $EXTRACT
+    g.region vect=$GIS_OPT_vector"part"$I align=$GIS_OPT_raster
+    d.rast -o $GIS_OPT_raster
+    d.vect $GIS_OPT_vector"part"$I
     #ask the user if he wants to analyse this vector and a name for raster
     #in graphical mode using wish
     export name=$TMP.val # where find the answer
@@ -100,11 +80,10 @@
     r_name=""
     read r_name < $name.var
     echo $r_name
-
     if [ $ok -eq 1 ] ; then
 	#area selected, create mask
-	v.to.rast input=$EXTRACT output=$r_name use=cat value=1 rows=4096
-	#read the region settings to save to configuration file
+	v.to.rast input=$GIS_OPT_vector"part"$I output=$r_name use=cat value=1 rows=4096 
+	#write info in configuration file
 	g.region -g| grep "n=" | cut -f2 -d'='> $name.var
 	read north < $name.var
 	g.region -g| grep "s=" | cut -f2 -d'='  > $name.var
@@ -113,19 +92,15 @@
 	read east < $name.var
 	g.region -g| grep "w=" | cut -f2 -d'=' > $name.var
 	read west < $name.var
-	#write info in configuration file
-	echo "MASKEDOVERLAYAREA $r_name|$north|$south|$east|$west" >> $GIS_OPT_conf
+	echo "MASKEDOVERLAYAREA $r_name|n=$north|s=$south|e=$east|w=$west" >> $GIS_OPT_conf
     fi
-    #remove temporary vector map created from v.extract
-    g.remove vect=$EXTRACT
+    #clear vector map part
+    g.remove vect=$GIS_OPT_vector"part"$I
     #rm -fR "$GISDBASE"/"$LOCATION"/"$MAPSET"/vector/$GIS_OPT_vector"part"$I
     #echo DROP TABLE $GIS_OPT_vector"part"$I | db.execute 
+    ((I++))
 done
 d.mon stop=x1
-#restore user region
-g.region region=$TMP_REGION
-#remove temporary region, $TMP_REGION
-g.remove region=$TMP_REGION
 # clean tmp files
 rm -f $TMP*
 



More information about the grass-commit mailing list