本文整理汇总了C++中Rast_close函数的典型用法代码示例。如果您正苦于以下问题:C++ Rast_close函数的具体用法?C++ Rast_close怎么用?C++ Rast_close使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Rast_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cseg_read_cell
int cseg_read_cell(CSEG * cseg, char *map_name, char *mapset)
{
GW_LARGE_INT row, nrows;
int map_fd;
CELL *buffer;
cseg->name = NULL;
cseg->mapset = NULL;
map_fd = Rast_open_old(map_name, mapset);
nrows = Rast_window_rows();
buffer = Rast_allocate_c_buf();
for (row = 0; row < nrows; row++) {
Rast_get_c_row(map_fd, buffer, row);
if (Segment_put_row(&(cseg->seg), buffer, row) < 0) {
G_free(buffer);
Rast_close(map_fd);
G_warning("%s(): unable to segment put row for [%s] in [%s]",
me, map_name, mapset);
return (-1);
}
}
Rast_close(map_fd);
G_free(buffer);
cseg->name = G_store(map_name);
cseg->mapset = G_store(mapset);
return 0;
}
示例2: close_file
int close_file(char *name)
{
int cell_file, row, k;
int row_count, col_count;
CELL *buf;
cell_file = Rast_open_c_new(name);
row_count = n_rows - (PAD << 1);
col_count = n_cols - (PAD << 1);
G_message(_("Output file %d rows X %d columns"), row_count, col_count);
G_message(_("Window %d rows X %d columns"), Rast_window_rows(),
Rast_window_cols());
for (row = 0, k = PAD; row < row_count; row++, k++) {
buf = get_a_row(k);
Rast_put_row(cell_file, buf + PAD, CELL_TYPE);
}
Rast_close(cell_file);
Rowio_flush(&row_io);
close(Rowio_fileno(&row_io));
Rowio_release(&row_io);
unlink(work_file_name);
return 0;
}
示例3: get_stats
int get_stats(const char *name, struct Cell_stats *statf)
{
int fd;
CELL *cell;
int row, nrows, ncols;
fd = Rast_open_old(name, "");
nrows = Rast_window_rows();
ncols = Rast_window_cols();
cell = Rast_allocate_c_buf();
Rast_init_cell_stats(statf);
G_message(_("Reading %s ..."), name);
for (row = 0; row < nrows; row++) {
G_percent(row, nrows, 2);
Rast_get_c_row(fd, cell, row);
Rast_update_cell_stats(cell, ncols, statf);
}
if (row < nrows)
exit(1);
Rast_close(fd);
G_free(cell);
G_percent(row, nrows, 2);
return 0;
}
示例4: get_range
int get_range(const char *name, long *min, long *max)
{
struct Range range;
int nrows, ncols, row, col;
CELL *cell;
int fd;
CELL cmin, cmax;
struct Cell_head cellhd;
if (Rast_read_range(name, "", &range) < 0) {
Rast_init_range(&range); /* read the file to get the range */
Rast_get_cellhd(name, "", &cellhd);
Rast_set_window(&cellhd);
cell = Rast_allocate_c_buf();
fd = Rast_open_old(name, "");
nrows = Rast_window_rows();
ncols = Rast_window_cols();
G_message(_("Reading %s ..."), name);
for (row = 0; row < nrows; row++) {
G_percent(row, nrows, 2);
Rast_get_c_row_nomask(fd, cell, row);
for (col = 0; col < ncols; col++)
Rast_update_range(cell[col], &range);
}
G_percent(row, nrows, 2);
Rast_close(fd);
G_free(cell);
}
Rast_get_range_min_max(&range, &cmin, &cmax);
*min = cmin;
*max = cmax;
return 0;
}
示例5: randsurf
int randsurf(char *out, /* Name of raster maps to be opened. */
int min, int max, /* Minimum and maximum cell values. */
int int_map)
{ /* if map is to be written as a CELL map */
int nrows, ncols; /* Number of cell rows and columns */
DCELL *row_out_D; /* Buffer just large enough to hold one */
CELL *row_out_C; /* row of the raster map layer. */
int fd_out; /* File descriptor - used to identify */
/* open raster maps. */
int row_count, col_count;
/****** INITIALISE RANDOM NUMBER GENERATOR ******/
G_math_rand(-1 * getpid());
/****** OPEN CELL FILES AND GET CELL DETAILS ******/
fd_out = Rast_open_new(out, int_map ? CELL_TYPE : DCELL_TYPE);
nrows = Rast_window_rows();
ncols = Rast_window_cols();
if (int_map)
row_out_C = Rast_allocate_c_buf();
else
row_out_D = Rast_allocate_d_buf();
/****** PASS THROUGH EACH CELL ASSIGNING RANDOM VALUE ******/
for (row_count = 0; row_count < nrows; row_count++) {
G_percent(row_count, nrows, 2);
for (col_count = 0; col_count < ncols; col_count++) {
if (int_map)
*(row_out_C + col_count) =
(CELL) (G_math_rand(2742) * (max + 1 - min) + min);
/* under represents first and last bin */
/* *(row_out_C + col_count) = (CELL) floor(rand1(2742)*(max-min)+min +0.5); */
else
*(row_out_D + col_count) =
(DCELL) (G_math_rand(2742) * (max - min) + min);
}
/* Write contents row by row */
if (int_map)
Rast_put_c_row(fd_out, (CELL *) row_out_C);
else
Rast_put_d_row(fd_out, (DCELL *) row_out_D);
}
G_percent(1, 1, 1);
Rast_close(fd_out);
return 0;
}
示例6: closefiles
int closefiles(char *h_name, char *i_name, char *s_name,
int fd_output[3], CELL * rowbuf[3])
{
int i;
struct Colors colors;
struct Range range;
struct History history;
CELL min, max;
const char *mapset;
for (i = 0; i < 3; i++) {
Rast_close(fd_output[i]);
G_free(rowbuf[i]);
}
mapset = G_mapset();
/* write colors */
/* set to 0,max_level instead of min,max ?? */
Rast_read_range(h_name, mapset, &range);
Rast_get_range_min_max(&range, &min, &max);
Rast_make_grey_scale_colors(&colors, min, max);
Rast_write_colors(h_name, mapset, &colors);
Rast_read_range(i_name, mapset, &range);
Rast_get_range_min_max(&range, &min, &max);
Rast_make_grey_scale_colors(&colors, min, max);
Rast_write_colors(i_name, mapset, &colors);
Rast_read_range(s_name, mapset, &range);
Rast_get_range_min_max(&range, &min, &max);
Rast_make_grey_scale_colors(&colors, min, max);
Rast_write_colors(s_name, mapset, &colors);
/* write metadata */
Rast_short_history(h_name, "raster", &history);
Rast_command_history(&history);
Rast_write_history(h_name, &history);
Rast_put_cell_title(h_name, "Image hue");
Rast_short_history(i_name, "raster", &history);
Rast_command_history(&history);
Rast_write_history(i_name, &history);
Rast_put_cell_title(i_name, "Image intensity");
Rast_short_history(s_name, "raster", &history);
Rast_command_history(&history);
Rast_write_history(s_name, &history);
Rast_put_cell_title(s_name, "Image saturation");
return 0;
}
示例7: close_band_files
/*!
\brief Close and free space for the group band files.
\param refer pointer to band files structure
\param band_buffer buffer to read one row of each band
\param band_fd band files descriptors
*/
void close_band_files(struct Ref *refer, CELL ** band_buffer, int *band_fd)
{
int n, nbands;
G_debug(3, "close_band_files()");
nbands = refer->nfiles;
for (n = 0; n < nbands; n++) {
G_free(band_buffer[n]);
Rast_close(band_fd[n]);
}
G_free(band_buffer);
G_free(band_fd);
}
示例8: sg_factor
int sg_factor(void)
{
int r, c;
CELL low_elev, hih_elev;
double height, length, S, sin_theta;
G_message(_("SECTION 4: RUSLE LS and/or S factor determination."));
if (ril_flag)
ril_buf = Rast_allocate_c_buf();
for (r = 0; r < nrows; r++) {
G_percent(r, nrows, 3);
if (ril_flag) {
Rast_get_c_row(ril_fd, ril_buf, r);
}
for (c = 0; c < ncols; c++) {
low_elev = alt[SEG_INDEX(alt_seg, r, c)];
hih_elev = r_h[SEG_INDEX(r_h_seg, r, c)];
length = s_l[SEG_INDEX(s_l_seg, r, c)];
height = 1.0 * (hih_elev - low_elev) / ele_scale;
if (length > max_length) {
height *= max_length / length;
length = max_length;
}
sin_theta = height / sqrt(height * height + length * length);
if (height / length < .09)
S = 10.8 * sin_theta + .03;
else
S = 16.8 * sin_theta - .50;
if (sg_flag)
s_g[SEG_INDEX(s_g_seg, r, c)] = S;
if (ls_flag) {
length *= METER_TO_FOOT;
len_slp_equ(length, sin_theta, S, r, c);
}
}
}
G_percent(nrows, nrows, 1); /* finish it */
if (ril_flag) {
G_free(ril_buf);
Rast_close(ril_fd);
}
return 0;
}
示例9: Gs_loadmap_as_bitmap
/*!
\brief Load raster map as integer map
Calling function must have already allocated space in buff for
struct BM of wind->rows & wind->cols.
This routine simply loads the map into the bitmap by repetitve calls
to get_map_row. Any value other than 0 in the map will set the bitmap.
(may want to change later to allow specific value to set)
Changed to use null.
\param wind current window
\param map_name raster map name
\param[out] buff data buffer
\returns 1 on success
\return -1 on failure
*/
int Gs_loadmap_as_bitmap(struct Cell_head *wind, const char *map_name,
struct BM *buff)
{
FILEDESC cellfile;
const char *map_set;
int *tmp_buf;
int row, col;
G_debug(3, "Gs_loadmap_as_bitmap");
map_set = G_find_raster2(map_name, "");
if (!map_set) {
G_warning(_("Raster map <%s> not found"), map_name);
return -1;
}
cellfile = Rast_open_old(map_name, map_set);
tmp_buf = (int *)G_malloc(wind->cols * sizeof(int)); /* G_fatal_error */
if (!tmp_buf) {
return -1;
}
G_message(_("Loading raster map <%s>..."),
G_fully_qualified_name(map_name, map_set));
for (row = 0; row < wind->rows; row++) {
Rast_get_c_row(cellfile, tmp_buf, row);
for (col = 0; col < wind->cols; col++) {
if (Rast_is_c_null_value(&tmp_buf[col])) {
/* no data */
BM_set(buff, col, row, 1);
}
else {
BM_set(buff, col, row, 0);
}
}
}
Rast_close(cellfile);
G_free(tmp_buf);
return (1);
}
示例10: do_output
static void do_output(int base_fd, char **outputs, const char *covermap)
{
int *out_fd = G_malloc(num_quants * sizeof(int));
CELL *base_buf = Rast_allocate_c_buf();
DCELL *out_buf = Rast_allocate_d_buf();
const char *mapset = G_mapset();
struct Colors colors;
int have_colors;
int quant;
int row, col;
G_message(_("Writing output maps"));
for (quant = 0; quant < num_quants; quant++) {
const char *output = outputs[quant];
out_fd[quant] = Rast_open_fp_new(output);
}
have_colors = Rast_read_colors(covermap, "", &colors) > 0;
for (row = 0; row < rows; row++) {
Rast_get_c_row(base_fd, base_buf, row);
for (quant = 0; quant < num_quants; quant++) {
for (col = 0; col < cols; col++)
if (Rast_is_c_null_value(&base_buf[col]))
Rast_set_d_null_value(&out_buf[col], 1);
else
out_buf[col] = basecats[base_buf[col] - min].quants[quant];
Rast_put_d_row(out_fd[quant], out_buf);
}
G_percent(row, rows, 2);
}
G_percent(row, rows, 2);
for (quant = 0; quant < num_quants; quant++) {
Rast_close(out_fd[quant]);
if (have_colors)
Rast_write_colors(outputs[quant], mapset, &colors);
}
}
示例11: Gs_loadmap_as_float
/*!
\brief Load raster map as floating point map
Calling function must have already allocated space in buff for
wind->rows * wind->cols floats.
This routine simply loads the map into a 2d array by repetitve calls
to get_f_raster_row.
\param wind current window
\param map_name raster map name
\param[out] buff data buffer
\param[out] nullmap null map buffer
\param[out] has_null indicates if raster map contains null-data
\return 1 on success
\return 0 on failure
*/
int Gs_loadmap_as_float(struct Cell_head *wind, const char *map_name,
float *buff, struct BM *nullmap, int *has_null)
{
FILEDESC cellfile;
const char *map_set;
int offset, row, col;
G_debug(3, "Gs_loadmap_as_float(): name=%s", map_name);
map_set = G_find_raster2(map_name, "");
if (!map_set) {
G_warning(_("Raster map <%s> not found"), map_name);
return 0;
}
*has_null = 0;
cellfile = Rast_open_old(map_name, map_set);
G_message(_("Loading raster map <%s>..."),
G_fully_qualified_name(map_name, map_set));
for (row = 0; row < wind->rows; row++) {
offset = row * wind->cols;
Rast_get_f_row(cellfile, &(buff[offset]), row);
G_percent(row, wind->rows, 2);
for (col = 0; col < wind->cols; col++) {
if (Rast_is_f_null_value(buff + offset + col)) {
*has_null = 1;
BM_set(nullmap, col, row, 1);
}
/* set nm */
}
}
G_percent(1, 1, 1);
G_debug(4, " has_null=%d", *has_null);
Rast_close(cellfile);
return (1);
}
示例12: cseg_write_cellfile
int cseg_write_cellfile(CSEG * cseg, char *map_name)
{
int map_fd;
GW_LARGE_INT row, nrows;
CELL *buffer;
map_fd = Rast_open_c_new(map_name);
nrows = Rast_window_rows();
buffer = Rast_allocate_c_buf();
Segment_flush(&(cseg->seg));
for (row = 0; row < nrows; row++) {
G_percent(row, nrows, 1);
Segment_get_row(&(cseg->seg), buffer, row);
Rast_put_row(map_fd, buffer, CELL_TYPE);
}
G_percent(row, nrows, 1); /* finish it */
G_free(buffer);
Rast_close(map_fd);
return 0;
}
示例13: rast_segment_open
void rast_segment_open(SEGMENT * segment, const char *name,
RASTER_MAP_TYPE * map_type)
{
/* TODO: check if not passing the mapset is OK */
int rowio = Rast_open_old(name, "");
*map_type = Rast_get_map_type(rowio);
int segment_rows = 64;
/* we use long segments because this is how the values a binned */
int segment_cols = Rast_input_window_cols();
int segments_in_memory = 4;
if (Segment_open(segment, G_tempfile(), Rast_input_window_rows(),
Rast_input_window_cols(), segment_rows, segment_cols,
Rast_cell_size(*map_type), segments_in_memory) != 1)
G_fatal_error(_("Cannot create temporary file with segments of a raster map"));
rast_segment_load(segment, rowio, *map_type);
Rast_close(rowio); /* we won't need the raster again */
}
示例14: array2raster
void array2raster(const void* data, const char* name,
const RASTER_MAP_TYPE type, const int maxr, const int maxc) {
//ORG void* rast = G_allocate_raster_buf(type);
void* rast = Rast_allocate_buf(type);
int fd;
//ORG if ((fd = G_open_raster_new(name, type)) < 0) {
if ((fd = Rast_open_new(name, type)) < 0) {
G_fatal_error("Unable to create raster map <%s>", name);
}
int row, col;
for (row = 0; row < maxr; ++row) {
for (col = 0; col < maxc; ++col) {
int i = row * maxc + col;
switch (type) {
case CELL_TYPE:
((int*) rast)[col] = ((int*) data)[i];
break;
case FCELL_TYPE:
((float*) rast)[col] = ((float*) data)[i];
break;
case DCELL_TYPE:
((double*) rast)[col] = ((double*) data)[i];
break;
}
}
//ORG if (G_put_raster_row(fd, rast, type) < 0) {
//ORG G_fatal_error("Failed writing raster map <%s>", name);
//ORG }
Rast_put_row(fd, rast, type);
}
G_free(rast);
//ORG G_close_cell(fd);
Rast_close(fd);
return;
}
示例15: get_cats
int get_cats(const char *name, const char *mapset)
{
int fd;
int row, nrows, ncols;
CELL *cell;
struct Cell_head cellhd;
/* set the window to the cell header */
Rast_get_cellhd(name, mapset, &cellhd);
Rast_set_window(&cellhd);
/* open the raster map */
fd = Rast_open_old(name, mapset);
nrows = Rast_window_rows();
ncols = Rast_window_cols();
cell = Rast_allocate_c_buf();
Rast_init_cell_stats(&statf);
/* read the raster map */
G_verbose_message(_("Reading <%s> in <%s>"), name, mapset);
for (row = 0; row < nrows; row++) {
if (G_verbose() > G_verbose_std())
G_percent(row, nrows, 2);
Rast_get_c_row_nomask(fd, cell, row);
Rast_update_cell_stats(cell, ncols, &statf);
}
/* done */
if (G_verbose() > G_verbose_std())
G_percent(row, nrows, 2);
Rast_close(fd);
G_free(cell);
Rast_rewind_cell_stats(&statf);
return 0;
}