|
@@ -1,3 +1,4 @@
|
|
|
+#include <math.h>
|
|
|
#include <grass/gis.h>
|
|
|
#include <grass/raster.h>
|
|
|
#include "format.h"
|
|
@@ -11,16 +12,21 @@ static union
|
|
|
unsigned char **u;
|
|
|
short **s;
|
|
|
CELL **cell;
|
|
|
+ FCELL **fcell;
|
|
|
+ DCELL **dcell;
|
|
|
} raster;
|
|
|
static int max_rows;
|
|
|
static int at_row;
|
|
|
-static long cat;
|
|
|
+static int cat_int;
|
|
|
+static double cat_double;
|
|
|
static int cur_x, cur_y;
|
|
|
static int format;
|
|
|
static CELL *cell;
|
|
|
|
|
|
static int (*dot) ();
|
|
|
static int cell_dot(int, int);
|
|
|
+static int fcell_dot(int, int);
|
|
|
+static int dcell_dot(int, int);
|
|
|
static int uchar_dot(int, int);
|
|
|
static int char_dot(int, int);
|
|
|
static int short_dot(int, int);
|
|
@@ -80,8 +86,24 @@ int begin_rasterization(int nrows, int f)
|
|
|
raster.cell[i] = raster.cell[i - 1] + region.cols;
|
|
|
dot = cell_dot;
|
|
|
break;
|
|
|
+
|
|
|
+ case USE_FCELL:
|
|
|
+ raster.fcell = (FCELL **) G_calloc(max_rows, sizeof(FCELL *));
|
|
|
+ raster.fcell[0] = (FCELL *) G_calloc(size, sizeof(FCELL));
|
|
|
+ for (i = 1; i < max_rows; i++)
|
|
|
+ raster.fcell[i] = raster.fcell[i - 1] + region.cols;
|
|
|
+ dot = fcell_dot;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case USE_DCELL:
|
|
|
+ raster.dcell = (DCELL **) G_calloc(max_rows, sizeof(DCELL *));
|
|
|
+ raster.dcell[0] = (DCELL *) G_calloc(size, sizeof(DCELL));
|
|
|
+ for (i = 1; i < max_rows; i++)
|
|
|
+ raster.dcell[i] = raster.dcell[i - 1] + region.cols;
|
|
|
+ dot = dcell_dot;
|
|
|
+ break;
|
|
|
}
|
|
|
- if (format != USE_CELL)
|
|
|
+ if (format != USE_CELL && format != USE_FCELL && format != USE_DCELL)
|
|
|
cell = Rast_allocate_c_buf();
|
|
|
|
|
|
at_row = 0;
|
|
@@ -131,8 +153,15 @@ int configure_plot(void)
|
|
|
|
|
|
case USE_CELL:
|
|
|
for (i = 0; i < nrows; i++)
|
|
|
- for (j = 0; j < ncols; j++)
|
|
|
- raster.cell[i][j] = 0;
|
|
|
+ Rast_set_c_null_value(raster.cell[i], ncols);
|
|
|
+ break;
|
|
|
+ case USE_FCELL:
|
|
|
+ for (i = 0; i < nrows; i++)
|
|
|
+ Rast_set_f_null_value(raster.fcell[i], ncols);
|
|
|
+ break;
|
|
|
+ case USE_DCELL:
|
|
|
+ for (i = 0; i < nrows; i++)
|
|
|
+ Rast_set_d_null_value(raster.dcell[i], ncols);
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -148,54 +177,99 @@ int configure_plot(void)
|
|
|
return AGAIN;
|
|
|
}
|
|
|
|
|
|
-int output_raster(int fd)
|
|
|
+int output_raster(int fd, int *null)
|
|
|
{
|
|
|
int i, j;
|
|
|
+ FCELL *fcell;
|
|
|
+ DCELL *dcell;
|
|
|
|
|
|
for (i = 0; i < page.rows; i++, at_row++) {
|
|
|
- switch (format) {
|
|
|
-
|
|
|
- case USE_CHAR:
|
|
|
- for (j = 0; j < page.cols; j++) {
|
|
|
- cell[j] = (CELL) raster.c[i][j];
|
|
|
- if (cell[j] == 0)
|
|
|
- Rast_set_null_value(&cell[j], 1, CELL_TYPE);
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case USE_UCHAR:
|
|
|
- for (j = 0; j < page.cols; j++) {
|
|
|
- cell[j] = (CELL) raster.u[i][j];
|
|
|
- if (cell[j] == 0)
|
|
|
- Rast_set_null_value(&cell[j], 1, CELL_TYPE);
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case USE_SHORT:
|
|
|
- for (j = 0; j < page.cols; j++) {
|
|
|
- cell[j] = (CELL) raster.s[i][j];
|
|
|
- if (cell[j] == 0)
|
|
|
- Rast_set_null_value(&cell[j], 1, CELL_TYPE);
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case USE_CELL:
|
|
|
- cell = raster.cell[i];
|
|
|
- if (cell == 0)
|
|
|
- Rast_set_null_value(&cell, 1, CELL_TYPE);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- G_percent(i, page.rows, 2);
|
|
|
- Rast_put_row(fd, cell, CELL_TYPE);
|
|
|
+ switch (format) {
|
|
|
+
|
|
|
+ case USE_CHAR:
|
|
|
+ for (j = 0; j < page.cols; j++) {
|
|
|
+ cell[j] = (CELL) raster.c[i][j];
|
|
|
+ if (cell[j] == 0)
|
|
|
+ Rast_set_null_value(&cell[j], 1, CELL_TYPE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case USE_UCHAR:
|
|
|
+ for (j = 0; j < page.cols; j++) {
|
|
|
+ cell[j] = (CELL) raster.u[i][j];
|
|
|
+ if (cell[j] == 0)
|
|
|
+ Rast_set_null_value(&cell[j], 1, CELL_TYPE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case USE_SHORT:
|
|
|
+ for (j = 0; j < page.cols; j++) {
|
|
|
+ cell[j] = (CELL) raster.s[i][j];
|
|
|
+ if (cell[j] == 0)
|
|
|
+ Rast_set_null_value(&cell[j], 1, CELL_TYPE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case USE_CELL:
|
|
|
+ cell = raster.cell[i];
|
|
|
+ if (!null)
|
|
|
+ break;
|
|
|
+ for (j = 0; j < page.cols; j++) {
|
|
|
+ if (cell[j] == *null)
|
|
|
+ Rast_set_null_value(&cell[j], 1, CELL_TYPE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case USE_FCELL:
|
|
|
+ fcell = raster.fcell[i];
|
|
|
+ if (!null)
|
|
|
+ break;
|
|
|
+ for (j = 0; j < page.cols; j++) {
|
|
|
+ if (fabs(fcell[j] - (FCELL) *null) < 1e-6)
|
|
|
+ Rast_set_null_value(&fcell[j], 1, FCELL_TYPE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case USE_DCELL:
|
|
|
+ dcell = raster.dcell[i];
|
|
|
+ if (!null)
|
|
|
+ break;
|
|
|
+ for (j = 0; j < page.cols; j++) {
|
|
|
+ if (fabs(dcell[j] - (DCELL) *null) < 1e-6)
|
|
|
+ Rast_set_null_value(&dcell[j], 1, DCELL_TYPE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ switch (format) {
|
|
|
+ case USE_CHAR:
|
|
|
+ case USE_UCHAR:
|
|
|
+ case USE_SHORT:
|
|
|
+ case USE_CELL:
|
|
|
+ Rast_put_row(fd, cell, CELL_TYPE);
|
|
|
+ break;
|
|
|
+ case USE_FCELL:
|
|
|
+ Rast_put_row(fd, fcell, FCELL_TYPE);
|
|
|
+ break;
|
|
|
+ case USE_DCELL:
|
|
|
+ Rast_put_row(fd, dcell, DCELL_TYPE);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ G_percent(i, page.rows, 2);
|
|
|
}
|
|
|
G_percent(i, page.rows, 2);
|
|
|
return configure_plot();
|
|
|
}
|
|
|
|
|
|
-int set_cat(long x)
|
|
|
+int set_cat_int(int x)
|
|
|
{
|
|
|
- cat = x;
|
|
|
+ cat_int = x;
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+int set_cat_double(double x)
|
|
|
+{
|
|
|
+ cat_double = x;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -237,7 +311,23 @@ static int cont(int x, int y)
|
|
|
static int cell_dot(int x, int y)
|
|
|
{
|
|
|
if (x >= 0 && x < page.cols && y >= 0 && y < page.rows)
|
|
|
- raster.cell[y][x] = cat;
|
|
|
+ raster.cell[y][x] = (CELL) cat_int;
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static int fcell_dot(int x, int y)
|
|
|
+{
|
|
|
+ if (x >= 0 && x < page.cols && y >= 0 && y < page.rows)
|
|
|
+ raster.fcell[y][x] = (FCELL) cat_double;
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static int dcell_dot(int x, int y)
|
|
|
+{
|
|
|
+ if (x >= 0 && x < page.cols && y >= 0 && y < page.rows)
|
|
|
+ raster.dcell[y][x] = (DCELL) cat_double;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -245,7 +335,7 @@ static int cell_dot(int x, int y)
|
|
|
static int uchar_dot(int x, int y)
|
|
|
{
|
|
|
if (x >= 0 && x < page.cols && y >= 0 && y < page.rows)
|
|
|
- raster.u[y][x] = cat;
|
|
|
+ raster.u[y][x] = cat_int;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -253,7 +343,7 @@ static int uchar_dot(int x, int y)
|
|
|
static int char_dot(int x, int y)
|
|
|
{
|
|
|
if (x >= 0 && x < page.cols && y >= 0 && y < page.rows)
|
|
|
- raster.c[y][x] = cat;
|
|
|
+ raster.c[y][x] = cat_int;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -261,7 +351,7 @@ static int char_dot(int x, int y)
|
|
|
static int short_dot(int x, int y)
|
|
|
{
|
|
|
if (x >= 0 && x < page.cols && y >= 0 && y < page.rows)
|
|
|
- raster.s[y][x] = cat;
|
|
|
+ raster.s[y][x] = cat_int;
|
|
|
|
|
|
return 0;
|
|
|
}
|