|
@@ -28,6 +28,7 @@
|
|
|
#include "ncb.h"
|
|
|
#include "local_proto.h"
|
|
|
|
|
|
+
|
|
|
typedef int (*ifunc) (void);
|
|
|
|
|
|
struct menu
|
|
@@ -71,9 +72,11 @@ int main(int argc, char *argv[])
|
|
|
char *p;
|
|
|
int method;
|
|
|
int in_fd;
|
|
|
+ int selection_fd;
|
|
|
int out_fd;
|
|
|
DCELL *result;
|
|
|
- RASTER_MAP_TYPE map_type;
|
|
|
+ void *selection_ptr, *selection, *input, *input_ptr;
|
|
|
+ RASTER_MAP_TYPE map_type, selection_type;
|
|
|
int row, col;
|
|
|
int readrow;
|
|
|
int nrows, ncols;
|
|
@@ -92,7 +95,7 @@ int main(int argc, char *argv[])
|
|
|
struct GModule *module;
|
|
|
struct
|
|
|
{
|
|
|
- struct Option *input, *output;
|
|
|
+ struct Option *input, *output, *selection;
|
|
|
struct Option *method, *size;
|
|
|
struct Option *title;
|
|
|
struct Option *weight;
|
|
@@ -119,9 +122,13 @@ int main(int argc, char *argv[])
|
|
|
"map layer.");
|
|
|
|
|
|
parm.input = G_define_standard_option(G_OPT_R_INPUT);
|
|
|
+ parm.selection = G_define_standard_option(G_OPT_R_INPUT);
|
|
|
+ parm.selection->key = "selection";
|
|
|
+ parm.selection->required = NO;
|
|
|
+ parm.selection->description = "Name of an input raster map to select the cells which should be processed";
|
|
|
|
|
|
parm.output = G_define_standard_option(G_OPT_R_OUTPUT);
|
|
|
-
|
|
|
+
|
|
|
parm.method = G_define_option();
|
|
|
parm.method->key = "method";
|
|
|
parm.method->type = TYPE_STRING;
|
|
@@ -215,7 +222,6 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
/* open raster maps */
|
|
|
in_fd = Rast_open_old(ncb.oldcell, "");
|
|
|
-
|
|
|
map_type = Rast_get_map_type(in_fd);
|
|
|
|
|
|
/* get the method */
|
|
@@ -281,8 +287,17 @@ int main(int argc, char *argv[])
|
|
|
for (row = 0; row < ncb.dist; row++)
|
|
|
readcell(in_fd, readrow++, nrows, ncols);
|
|
|
|
|
|
- /* open raster map */
|
|
|
- in_fd = Rast_open_old(ncb.oldcell, "");
|
|
|
+ /* open the selection raster map */
|
|
|
+ if(parm.selection->answer) {
|
|
|
+ G_message("Opening selection map %s\n", parm.selection->answer);
|
|
|
+ selection_fd = Rast_open_old(parm.selection->answer, "");
|
|
|
+ selection_type = Rast_get_map_type(selection_fd);
|
|
|
+ selection = Rast_allocate_buf(selection_type);
|
|
|
+ input = Rast_allocate_buf(map_type);
|
|
|
+ } else {
|
|
|
+ selection_fd = -1;
|
|
|
+ selection = NULL;
|
|
|
+ }
|
|
|
|
|
|
/*open the new raster map */
|
|
|
out_fd = Rast_open_new(ncb.newcell, map_type);
|
|
@@ -299,25 +314,42 @@ int main(int argc, char *argv[])
|
|
|
for (row = 0; row < nrows; row++) {
|
|
|
G_percent(row, nrows, 2);
|
|
|
readcell(in_fd, readrow++, nrows, ncols);
|
|
|
+ /* if selection map is enabled read each row of the
|
|
|
+ selection and intput map
|
|
|
+ */
|
|
|
+ if(selection != NULL) {
|
|
|
+ Rast_get_row(selection_fd, selection, row, selection_type);
|
|
|
+ Rast_get_row(in_fd, input, row, map_type);
|
|
|
+ selection_ptr = selection;
|
|
|
+ input_ptr = input;
|
|
|
+ }
|
|
|
+
|
|
|
for (col = 0; col < ncols; col++) {
|
|
|
DCELL *rp = &result[col];
|
|
|
-
|
|
|
- if (newvalue_w)
|
|
|
- n = gather_w(values_w, col);
|
|
|
- else
|
|
|
- n = gather(values, col);
|
|
|
-
|
|
|
- if (n < 0)
|
|
|
- Rast_set_d_null_value(rp, 1);
|
|
|
- else {
|
|
|
+ if((selection != NULL && Rast_is_null_value(selection_ptr, selection_type) == 1)) {
|
|
|
+ *rp = Rast_get_d_value((const void *)input_ptr, map_type);
|
|
|
+ }else {
|
|
|
if (newvalue_w)
|
|
|
- newvalue_w(rp, values_w, n, closure);
|
|
|
+ n = gather_w(values_w, col);
|
|
|
else
|
|
|
- newvalue(rp, values, n, closure);
|
|
|
-
|
|
|
- if (half && !Rast_is_d_null_value(rp))
|
|
|
- *rp += 0.5;
|
|
|
- }
|
|
|
+ n = gather(values, col);
|
|
|
+
|
|
|
+ if (n < 0)
|
|
|
+ Rast_set_d_null_value(rp, 1);
|
|
|
+ else {
|
|
|
+ if (newvalue_w)
|
|
|
+ newvalue_w(rp, values_w, n, closure);
|
|
|
+ else
|
|
|
+ newvalue(rp, values, n, closure);
|
|
|
+
|
|
|
+ if (half && !Rast_is_d_null_value(rp))
|
|
|
+ *rp += 0.5;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(selection != NULL) {
|
|
|
+ selection_ptr = G_incr_void_ptr(selection_ptr, Rast_cell_size(selection_type));
|
|
|
+ input_ptr = G_incr_void_ptr(input_ptr, Rast_cell_size(map_type));
|
|
|
+ }
|
|
|
}
|
|
|
Rast_put_d_row(out_fd, result);
|
|
|
}
|
|
@@ -326,6 +358,10 @@ int main(int argc, char *argv[])
|
|
|
Rast_close(out_fd);
|
|
|
Rast_close(in_fd);
|
|
|
|
|
|
+ if(selection != NULL)
|
|
|
+ Rast_close(selection_fd);
|
|
|
+
|
|
|
+
|
|
|
/* put out category info */
|
|
|
null_cats();
|
|
|
if ((cat_names = menu[method].cat_names))
|
|
@@ -343,3 +379,4 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
}
|
|
|
+
|