6 #include <grass/lidar.h>
87 Overlap->
N = General->
N;
94 Overlap->
S = General->
S;
100 General->
W = orig.
west;
102 Overlap->
W = General->
W;
108 General->
E = orig.
east;
109 Overlap->
E = General->
E;
120 int total_splines, edge_splines, n_windows;
121 int lastsplines, lastsplines_min, lastsplines_max;
122 double E_extension, N_extension, edgeE, edgeN;
128 E_extension = orig.
east - orig.
west;
140 total_splines = ceil(E_extension / pe);
141 edge_splines = edgeE / pe;
142 n_windows = E_extension / edgeE;
152 lastsplines = total_splines - edge_splines * n_windows;
153 while (lastsplines > lastsplines_max || lastsplines < lastsplines_min) {
158 edge_splines = edgeE / pe;
159 n_windows = E_extension / edgeE;
160 lastsplines = total_splines - edge_splines * n_windows;
166 total_splines = ceil(N_extension / pn);
167 edge_splines = edgeN / pn;
168 n_windows = N_extension / edgeN;
178 lastsplines = total_splines - edge_splines * n_windows;
179 while (lastsplines > lastsplines_max || lastsplines < lastsplines_min) {
184 edge_splines = edgeN / pn;
185 n_windows = N_extension / edgeN;
186 lastsplines = total_splines - edge_splines * n_windows;
223 return (2 * nsplines + 1);
226 return (4 * nsplines + 3);
234 int i, mean_count = 0;
244 for (i = 0; i < npoints; i++) {
254 mean /= (double)mean_count;
261 int type, npoints = 0;
262 double xmin = 0, xmax = 0, ymin = 0, ymax = 0;
282 if (points->
z !=
NULL)
312 *dist = sqrt(((xmax - xmin) * (ymax - ymin)) / npoints);
314 *dens = npoints / ((xmax - xmin) * (ymax - ymin));
324 int *num_points,
int dim_vect,
int layer)
326 int line_num, pippo, npoints,
cat, type;
355 if (points->
z !=
NULL)
363 if (npoints >= pippo) {
366 (
void *)obs, (
signed int)pippo *
sizeof(
struct Point));
371 obs[npoints - 1].
coordY = y;
372 obs[npoints - 1].
coordZ = z;
377 obs[npoints - 1].
cat =
cat;
383 *num_points = npoints;
390 int *num_points,
int dim_vect)
392 int col, row, startcol, endcol, startrow, endrow, nrows, ncols;
405 nrows = Original->
rows;
406 ncols = Original->
cols;
420 if (Elaboration->
west > Original->
west)
421 startcol = (Elaboration->
west - Original->
west) / Original->
ew_res - 1;
425 endcol = (Elaboration->
east - Original->
west) / Original->
ew_res + 1;
432 for (row = startrow; row < endrow; row++) {
433 for (col = startcol; col < endcol; col++) {
444 if (npoints >= pippo) {
448 (
signed int)pippo *
sizeof(
struct Point));
453 obs[npoints - 1].
coordY = y;
454 obs[npoints - 1].
coordZ = z;
460 *num_points = npoints;
483 G_debug(1,
_(
"<%s> created in database."), tab_name);
487 G_warning(
_(
"<%s> has not been created in database."), tab_name);
519 G_debug(1,
_(
"<%s> created in database."), tab_name);
523 G_warning(
_(
"<%s> has not been created in database."), tab_name);
542 int ncols, col, nrows, row;
550 for (row = 0; row < nrows; row++) {
555 for (col = 0, ptr = raster; col < ncols;
588 sprintf(buf,
"select ID, X, Y, sum(Interp) from %s group by ID, X, Y",
#define DB_SQL_TYPE_INTEGER
#define DB_SQL_TYPE_DOUBLE_PRECISION
dbValue * db_get_column_value(dbColumn *)
Returns column value for given column structure.
dbColumn * db_get_table_column(dbTable *, int)
Returns column structure for given table and column number.
double db_get_value_double(dbValue *)
Get double precision value.
int db_sqltype_to_Ctype(int)
Get C data type based on given SQL data type.
int db_get_column_sqltype(dbColumn *)
Returns column sqltype for column.
void db_set_column_sqltype(dbColumn *, int)
Define column sqltype for column.
dbTable * db_get_cursor_table(dbCursor *)
Get table allocated by cursor.
int db_set_table_description(dbTable *, const char *)
Set the description of the table.
void db_zero_string(dbString *)
Zero string.
int db_set_table_name(dbTable *, const char *)
Set the name of the table.
int db_execute_immediate(dbDriver *, dbString *)
Execute SQL statements.
dbTable * db_alloc_table(int)
Allocate a table with a specific number of columns.
void db_init_string(dbString *)
Initialize dbString.
int db_open_select_cursor(dbDriver *, dbString *, dbCursor *, int)
Open select cursor.
int db_set_column_name(dbColumn *, const char *)
Set column name.
int db_append_string(dbString *, const char *)
Append string to dbString.
int db_create_table(dbDriver *, dbTable *)
Create table.
int db_fetch(dbCursor *, int, int *)
Fetch data from open cursor.
void G_percent(long, long, int)
Print percent complete messages.
void G_warning(const char *,...) __attribute__((format(printf
void G_get_set_window(struct Cell_head *)
Get the current working window (region)
#define G_incr_void_ptr(ptr, size)
int G_debug(int, const char *,...) __attribute__((format(printf
void G_get_window(struct Cell_head *)
Get the current region.
void * Rast_allocate_buf(RASTER_MAP_TYPE)
Allocate memory for a raster map of given type.
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
void Rast_set_d_value(void *, DCELL, RASTER_MAP_TYPE)
Places a DCELL raster value.
size_t Rast_cell_size(RASTER_MAP_TYPE)
Returns size of a raster cell in bytes.
void Rast_put_d_row(int, const DCELL *)
Writes the next row for dcell file (DCELL version)
int Rast_window_cols(void)
Number of columns in active window.
int Rast_window_rows(void)
Number of rows in active window.
#define Rast_is_d_null_value(dcellVal)
double Rast_row_to_northing(double, const struct Cell_head *)
Row to northing.
double Rast_col_to_easting(double, const struct Cell_head *)
Column to easting.
int Segment_get(SEGMENT *, void *, off_t, off_t)
Get value from segment file.
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
int Vect_reset_cats(struct line_cats *)
Reset category structure to make sure cats structure is clean to be re-used.
int Vect_region_box(const struct Cell_head *, struct bound_box *)
Copy region window to bounding box.
int Vect_cat_set(struct line_cats *, int, int)
Add new field/cat to category structure if doesn't exist yet.
int Vect_cat_get(const struct line_cats *, int, int *)
Get first found category of given field.
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_copy_xyz_to_pnts(struct line_pnts *, const double *, const double *, const double *, int)
Copy points from array to line_pnts structure.
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *, const struct line_cats *)
Writes a new feature.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
int Vect_rewind(struct Map_info *)
Rewind vector map to cause reads to start at beginning.
int Vect_read_next_line(struct Map_info *, struct line_pnts *, struct line_cats *)
Read next vector feature.
int Vect_point_in_box(double, double, double, const struct bound_box *)
Tests if point is in 3D box.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
#define GV_POINT
Feature types used in memory on run time (may change)
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
float mean(IClass_statistics *statistics, int band)
Helper function for computing mean.
2D/3D raster map header (used also for region)
double ew_res
Resolution - east to west cell size for 2D data.
double north
Extent coordinates (north)
double east
Extent coordinates (east)
double ns_res
Resolution - north to south cell size for 2D data.
int rows
Number of rows for 2D data.
int cols
Number of columns for 2D data.
double south
Extent coordinates (south)
double west
Extent coordinates (west)
int * cat
Array of categories.
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
double * z
Array of Z coordinates.
struct Point * P_Read_Vector_Region_Map(struct Map_info *Map, struct Cell_head *Elaboration, int *num_points, int dim_vect, int layer)
void P_Aux_to_Raster(double **matrix, int fd)
double P_Mean_Calc(struct Cell_head *Elaboration, struct Point *obs, int npoints)
struct Point * P_Read_Raster_Region_Map(SEGMENT *in_seg, struct Cell_head *Elaboration, struct Cell_head *Original, int *num_points, int dim_vect)
double P_estimate_splinestep(struct Map_info *Map, double *dens, double *dist)
void P_Aux_to_Vector(struct Map_info *Map UNUSED, struct Map_info *Out, dbDriver *driver, char *tab_name)
int P_get_edge(int interpolator, struct Reg_dimens *dim, double pe, double pn)
void P_zero_dim(struct Reg_dimens *dim)
int P_get_BandWidth(int interpolator, int nsplines)
int P_Create_Aux2_Table(dbDriver *driver, char *tab_name)
int P_set_dim(struct Reg_dimens *dim, double pe, double pn, int *nsplx, int *nsply)
int P_Drop_Aux_Table(dbDriver *driver, char *tab_name)
int P_Create_Aux4_Table(dbDriver *driver, char *tab_name)
int P_set_regions(struct Cell_head *Elaboration, struct bound_box *General, struct bound_box *Overlap, struct Reg_dimens dim, int type)