当前位置: 首页>>代码示例>>C++>>正文


C++ Rast_window_cols函数代码示例

本文整理汇总了C++中Rast_window_cols函数的典型用法代码示例。如果您正苦于以下问题:C++ Rast_window_cols函数的具体用法?C++ Rast_window_cols怎么用?C++ Rast_window_cols使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Rast_window_cols函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:26,代码来源:get_stats.c

示例2: 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;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:35,代码来源:get_range.c

示例3: 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;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:26,代码来源:io.c

示例4: 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;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:54,代码来源:randsurf.c

示例5: write_fp_to_cell

/* Converts the buffer to cell and write it to disk */
static void write_fp_to_cell(int ofd, FCELL *buf)
{
    CELL *cbuf;
    int col;

    cbuf = (CELL *) Rast_allocate_buf(CELL_TYPE);

    for (col = 0; col < Rast_window_cols(); col++)
	cbuf[col] = round_c(buf[col]);
    Rast_put_row(ofd, cbuf, CELL_TYPE);
}
开发者ID:rkrug,项目名称:grass-ci,代码行数:12,代码来源:main.cpp

示例6: dseg_open

int dseg_open(DSEG * dseg, int srows, int scols, int nsegs_in_memory)
{
    char *filename;
    int errflag;
    int fd;

    dseg->filename = NULL;
    dseg->fd = -1;
    dseg->name = NULL;
    dseg->mapset = NULL;

    filename = G_tempfile();
    if (-1 == (fd = creat(filename, 0666))) {
	G_warning("dseg_open(): unable to create segment file");
	return -2;
    }
    if (0 >
	(errflag =
	 Segment_format(fd, Rast_window_rows(), Rast_window_cols(), srows, scols,
			sizeof(double)))) {
	close(fd);
	unlink(filename);
	if (errflag == -1) {
	    G_warning("dseg_open(): could not write segment file");
	    return -1;
	}
	else {
	    G_warning("dseg_open(): illegal configuration parameter(s)");
	    return -3;
	}
    }
    close(fd);
    if (-1 == (fd = open(filename, 2))) {
	unlink(filename);
	G_warning("dseg_open(): unable to re-open segment file");
	return -4;
    }
    if (0 > (errflag = Segment_init(&(dseg->seg), fd, nsegs_in_memory))) {
	close(fd);
	unlink(filename);
	if (errflag == -1) {
	    G_warning("dseg_open(): could not read segment file");
	    return -5;
	}
	else {
	    G_warning("dseg_open(): out of memory");
	    return -6;
	}
    }
    dseg->filename = filename;
    dseg->fd = fd;
    return 0;
}
开发者ID:GRASS-GIS,项目名称:grass-ci,代码行数:53,代码来源:dseg_open.c

示例7: get_cell

static int get_cell(DCELL *result, int fd, double x, double y)
{
    static DCELL *row1, *row2;
    static int cur_row = -1;
    static int row, col;
    DCELL *tmp;

    if (!row1) {
	row1 = Rast_allocate_d_buf();
	row2 = Rast_allocate_d_buf();
    }

    col = (int)floor(x - 0.5);
    row = (int)floor(y - 0.5);
    x -= col + 0.5;
    y -= row + 0.5;

    if (row < 0 || row + 1 >= Rast_window_rows() ||
	col < 0 || col + 1 >= Rast_window_cols()) {
	Rast_set_d_null_value(result, 1);
	return 0;
    }

    if (cur_row != row) {
	if (cur_row == row + 1) {
	    tmp = row1; row1 = row2; row2 = tmp;
	    Rast_get_d_row(fd, row1, row);
	}
	else if (cur_row == row - 1) {
	    tmp = row1; row1 = row2; row2 = tmp;
	    Rast_get_d_row(fd, row2, row + 1);
	}
	else {
	    Rast_get_d_row(fd, row1, row);
	    Rast_get_d_row(fd, row2, row + 1);
	}
	cur_row = row;
    }

    if (Rast_is_d_null_value(&row1[col]) || Rast_is_d_null_value(&row1[col+1]) ||
	Rast_is_d_null_value(&row2[col]) || Rast_is_d_null_value(&row2[col+1])) {
	Rast_set_d_null_value(result, 1);
	return 0;
    }

    *result = Rast_interp_bilinear(x, y,
				row1[col], row1[col+1],
				row2[col], row2[col+1]);

    return 1;
}
开发者ID:caomw,项目名称:grass,代码行数:51,代码来源:main.c

示例8: process

int process(void)
{

    /*-------------------------------------------------------------------*/
    /*                              INITIALISE                           */

    /*-------------------------------------------------------------------*/

    int nrows,			/* Will store the current number of     */
      ncols,			/* rows and columns in the raster.      */
      nn;			/* Size of raster to nearest power of 2. */

    double *data[2];		/* Array holding complex data.          */


    /*------------------------------------------------------------------*/
    /*                       GET DETAILS OF INPUT RASTER                */

    /*------------------------------------------------------------------*/

    nrows = Rast_window_rows();	/* Find out the number of rows and */
    ncols = Rast_window_cols();	/* columns of the raster view.     */

    nn = G_math_max_pow2(MAX(nrows, ncols));	/* Find smallest power of 2 that   */
    /* largest side of raster will fit. */

    /*------------------------------------------------------------------*/
    /*                      CREATE SQUARE ARRAY OF SIDE 2^n             */

    /*------------------------------------------------------------------*/

    if (nn * nn * sizeof(double) < 1)
	G_fatal_error(_("Unable to allocate data buffer. "
			"Check current region with g.region."));
    
    data[0] = (double *)G_malloc(nn * nn * sizeof(double));
    data[1] = (double *)G_malloc(nn * nn * sizeof(double));

    /*------------------------------------------------------------------*/
    /*                   Apply spectral synthesis algorithm.            */

    /*------------------------------------------------------------------*/

    specsyn(data, nn);

    G_free(data[0]);
    G_free(data[1]);

    return 0;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:50,代码来源:process.c

示例9: calc_mu

static int calc_mu(int *fds, double *mu, int bands)
{
    int i;
    int rows = Rast_window_rows();
    int cols = Rast_window_cols();
    void *rowbuf = NULL;

    for (i = 0; i < bands; i++) {
	RASTER_MAP_TYPE maptype;
	int row, col;
	double sum = 0.;

	maptype = Rast_get_map_type(fds[i]);

	/* don't assume each image is of the same type */
	if (rowbuf)
	    G_free(rowbuf);
	if ((rowbuf = Rast_allocate_buf(maptype)) == NULL)
	    G_fatal_error(_("Unable allocate memory for row buffer"));

	G_message(_("Computing means for band %d..."), i + 1);
	for (row = 0; row < rows; row++) {
	    void *ptr = rowbuf;

	    G_percent(row, rows - 1, 2);

	    Rast_get_row(fds[i], rowbuf, row, maptype);

	    for (col = 0; col < cols; col++) {
		/* skip null cells */
		if (Rast_is_null_value(ptr, maptype)) {
		    ptr = G_incr_void_ptr(ptr, Rast_cell_size(maptype));
		    continue;
		}

		sum += Rast_get_d_value(ptr, maptype);
		ptr = G_incr_void_ptr(ptr, Rast_cell_size(maptype));
	    }
	}

	mu[i] = sum / (double)(rows * cols);
    }

    if (rowbuf)
	G_free(rowbuf);

    return 0;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:48,代码来源:main.c

示例10: Rast_window_rows

void *read_raster(void *buf, const int fd, const RASTER_MAP_TYPE rtype)
{
    void *tmpbuf = buf;
    int rows = Rast_window_rows();
    int i;

    G_message(_("Reading raster map..."));

    for (i = 0; i < rows; i++) {
	G_percent(i + 1, rows, 10);

	Rast_get_row(fd, tmpbuf, i, rtype);
	tmpbuf =
	    G_incr_void_ptr(tmpbuf, Rast_cell_size(rtype) * Rast_window_cols());
    }

    return tmpbuf;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:18,代码来源:raster.c

示例11: get_region_range

static void get_region_range(int fd)
{
    DCELL *buf = Rast_allocate_d_buf();

    int nrows = Rast_window_rows();
    int ncols = Rast_window_cols();
    int row, col;

    min = 1e300;
    max = -1e300;

    for (row = 0; row < nrows; row++) {
	Rast_get_d_row(fd, buf, row);
	for (col = 0; col < ncols; col++) {
	    if (min > buf[col])
		min = buf[col];
	    if (max < buf[col])
		max = buf[col];
	}
    }
}
开发者ID:caomw,项目名称:grass,代码行数:21,代码来源:main.c

示例12: Rast_get_sample_nearest

/*!
 *  \brief Extract a cell value from raster map (neighbor interpolation)
 *
 *  Extract a cell value from raster map at given northing and easting
 *  with a sampled 3x3 window using a neighbor interpolation.
 *
 *  \param fd file descriptor
 *  \param window region settings
 *  \param cats categories
 *  \param north northing position
 *  \param east easting position
 *  \param usedesc flag to scan category label
 *
 *  \return cell value at given position
 */
DCELL Rast_get_sample_nearest(int fd,
			      const struct Cell_head * window,
			      struct Categories * cats,
			      double north, double east, int usedesc)
{
    int row, col;
    DCELL result;
    DCELL *maprow = Rast_allocate_d_buf();

    /* convert northing and easting to row and col, resp */
    row = (int)floor(Rast_northing_to_row(north, window));
    col = (int)floor(Rast_easting_to_col(east, window));

    if (row < 0 || row >= Rast_window_rows() ||
	col < 0 || col >= Rast_window_cols()) {
	Rast_set_d_null_value(&result, 1);
	goto done;
    }

    Rast_get_d_row(fd, maprow, row);

    if (Rast_is_d_null_value(&maprow[col])) {
	Rast_set_d_null_value(&result, 1);
	goto done;
    }

    if (usedesc) {
	char *buf = Rast_get_c_cat((CELL *) & (maprow[col]), cats);

	G_squeeze(buf);
	result = scancatlabel(buf);
    }
    else
	result = maprow[col];

  done:
    G_free(maprow);

    return result;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:55,代码来源:sample.c

示例13: read_data

int read_data(struct files *files, struct SigSet *S)
{
    int n;
    int b;
    int nrows, ncols, row, col;
    CELL *class;
    struct ClassData *Data;

    nrows = Rast_window_rows();
    ncols = Rast_window_cols();
    class = (CELL *) G_calloc(ncols, sizeof(CELL));

    G_message(_("Reading raster maps..."));

    for (row = 0; row < nrows; row++) {
	G_percent(row, nrows, 2);
	read_training_map(class, row, ncols, files);
	for (b = 0; b < files->nbands; b++)
	    Rast_get_d_row(files->band_fd[b], files->band_cell[b], row);

	for (col = 0; col < ncols; col++) {
	    n = class[col];
	    if (n < 0)
		continue;
	    Data = &S->ClassSig[n].ClassData;
	    for (b = 0; b < files->nbands; b++) {
		if (Rast_is_d_null_value(&files->band_cell[b][col]))
		    Rast_set_d_null_value(&Data->x[Data->count][b], 1);
		else
		    Data->x[Data->count][b] = files->band_cell[b][col];
	    }
	    Data->count++;
	}
    }
    G_percent(nrows, nrows, 2);
    G_free(class);

    return 0;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:39,代码来源:read_data.c

示例14: openfiles

int openfiles(struct parms *parms, struct files *files)
{
    struct Ref Ref;		/* subgroup reference list */
    int n;


    if (!I_get_subgroup_ref(parms->group, parms->subgroup, &Ref))
	G_fatal_error(_("Unable to read REF file for subgroup <%s> in group <%s>"),
		      parms->subgroup, parms->group);

    if (Ref.nfiles <= 0)
	G_fatal_error(_("Subgroup <%s> in group <%s> contains no raster maps"),
		      parms->subgroup, parms->group);

    /* allocate file descriptors, and io buffer */
    files->cellbuf = Rast_allocate_d_buf();
    files->outbuf = Rast_allocate_c_buf();

    files->isdata = G_malloc(Rast_window_cols());

    files->nbands = Ref.nfiles;
    files->band_fd = (int *)G_calloc(Ref.nfiles, sizeof(int));

    /* open all group maps for reading */
    for (n = 0; n < Ref.nfiles; n++)
	files->band_fd[n] =
	    open_cell_old(Ref.file[n].name, Ref.file[n].mapset);

    /* open output map */
    files->output_fd = open_cell_new(parms->output_map);

    if (parms->goodness_map)
	files->goodness_fd = Rast_open_new(parms->goodness_map, FCELL_TYPE);
    else
	files->goodness_fd = -1;

    return 0;
}
开发者ID:felipebetancur,项目名称:grass-ci,代码行数:38,代码来源:openfiles.c

示例15: P_Aux_to_Raster

/*---------------------------------------------------------------------------------------*/
void P_Aux_to_Raster(double **matrix, int fd)
{
    int ncols, col, nrows, row;
    void *ptr, *raster;

    nrows = Rast_window_rows();
    ncols = Rast_window_cols();

    raster = Rast_allocate_buf(DCELL_TYPE);

    for (row = 0; row < nrows; row++) {
	G_percent(row, nrows, 2);

	Rast_set_d_null_value(raster, ncols);

	for (col = 0, ptr = raster; col < ncols;
	     col++, ptr = G_incr_void_ptr(ptr, Rast_cell_size(DCELL_TYPE))) {
	    Rast_set_d_value(ptr, (DCELL) (matrix[row][col]), DCELL_TYPE);
	}
	Rast_put_d_row(fd, raster);
    }
    G_percent(row, nrows, 2);
}
开发者ID:GRASS-GIS,项目名称:grass-ci,代码行数:24,代码来源:zones.c


注:本文中的Rast_window_cols函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。