示例#1
0
文件: point.c 项目: imincik/pkg-grass
int point_list_copy_to_line_pnts(POINT_LIST l, struct line_pnts *Points)
{

    int length, i;
    POINT_LIST *cur;

    cur = l.next;
    length = 0;

    while (cur != NULL) {
	length++;
	cur = cur->next;
    }

    if (length != Points->n_points)
	if (0 > dig_alloc_points(Points, length))
	    return (-1);

    Points->n_points = length;

    cur = l.next;
    for (i = 0; i < length; i++) {
	Points->x[i] = cur->p.x;
	Points->y[i] = cur->p.y;
	Points->z[i] = cur->p.z;
	cur = cur->next;
    }

    return 0;
}
示例#2
0
文件: line.c 项目: caomw/grass
/*!
  \brief Appends points to the end of a line.
  
  Note, this will append to whatever is in line_pnts structure. If you
  are re-using a line struct, be sure to clear out old data first by
  calling Vect_reset_line().

  \param Points pointer to line_pnts structure
  \param APoints points to be included
  \param direction direction (GV_FORWARD, GV_BACKWARD)
  
  \return new number of points
  \return -1 on out of memory
*/
int Vect_append_points(struct line_pnts *Points, const struct line_pnts *APoints,
		       int direction)
{
    int i, n, on, an;

    on = Points->n_points;
    an = APoints->n_points;
    n = on + an;

    /* Should be OK, dig_alloc_points calls realloc */
    if (0 > dig_alloc_points(Points, n))
	return (-1);

    if (direction == GV_FORWARD) {
	for (i = 0; i < an; i++) {
	    Points->x[on + i] = APoints->x[i];
	    Points->y[on + i] = APoints->y[i];
	    Points->z[on + i] = APoints->z[i];
	}
    }
    else {
	for (i = 0; i < an; i++) {
	    Points->x[on + i] = APoints->x[an - i - 1];
	    Points->y[on + i] = APoints->y[an - i - 1];
	    Points->z[on + i] = APoints->z[an - i - 1];
	}
    }

    Points->n_points = n;
    return n;
}
示例#3
0
文件: line.c 项目: caomw/grass
/*!
  \brief Insert new point at index position and move all old points
  at that position and above up
   
  \param Points pointer to line_pnts structure 
  \param index (from 0 to Points->n_points-1)
  \param x,y,z point coordinates

  \return number of points
  \return -1 on error (alocation)
 */
int Vect_line_insert_point(struct line_pnts *Points, int index, double x,
			   double y, double z)
{
    int n;

    if (index < 0 || index > Points->n_points - 1)
	G_fatal_error("Vect_line_insert_point(): %s",
		      _("Index out of range in"));

    if (0 > dig_alloc_points(Points, Points->n_points + 1))
	return -1;

    /* move up */
    for (n = Points->n_points; n > index; n--) {
	Points->x[n] = Points->x[n - 1];
	Points->y[n] = Points->y[n - 1];
	Points->z[n] = Points->z[n - 1];
    }

    Points->x[index] = x;
    Points->y[index] = y;
    Points->z[index] = z;
    
    return ++(Points->n_points);
}
示例#4
0
/*!
  \brief Appends one point to the end of a line.

  If you are re-using a line struct, be sure to clear out old data
  first by calling Vect_reset_line().
  
  \param Points pointer to line_pnts structure
  \param x,y,z point coordinates to be added

  \return number of points
  \return -1 on error (out of memory)
 */
int Vect_append_point(struct line_pnts *Points, double x, double y, double z)
{
    register int n;

    if (0 > dig_alloc_points(Points, Points->n_points + 1))
	return (-1);

    n = Points->n_points;
    Points->x[n] = x;
    Points->y[n] = y;
    Points->z[n] = z;

    return ++(Points->n_points);
}
示例#5
0
文件: line.c 项目: caomw/grass
/*!
  \brief Appends one point to the end of a line.

  If you are re-using a line struct, be sure to clear out old data
  first by calling Vect_reset_line().
  
  Calls G_fatal_error() when out of memory.
  
  \param Points pointer to line_pnts structure
  \param x,y,z point coordinates to be added

  \return number of points
  \return -1 on error (out of memory)
 */
int Vect_append_point(struct line_pnts *Points, double x, double y, double z)
{
    register int n;

    if (0 > dig_alloc_points(Points, Points->n_points + 1)) {
	G_fatal_error(_("Out of memory"));
	return -1;
    }
    
    n = Points->n_points;
    Points->x[n] = x;
    Points->y[n] = y;
    Points->z[n] = z;

    return ++(Points->n_points);
}
示例#6
0
文件: line.c 项目: caomw/grass
/*!
   \brief Copy points from array to line_pnts structure

   \param Points pointer to line_ptns structure
   \param x,y,z  array of coordinates
   \param n number of points to be copied

   \return 0 on success
   \return -1 on out of memory
 */
int Vect_copy_xyz_to_pnts(struct line_pnts *Points, const double *x, const double *y,
			  const double *z, int n)
{
    int i;

    if (0 > dig_alloc_points(Points, n))
	return -1;

    for (i = 0; i < n; i++) {
	Points->x[i] = x[i];
	Points->y[i] = y[i];
	if (z != NULL)
	    Points->z[i] = z[i];
	else
	    Points->z[i] = 0;
	Points->n_points = n;
    }
    
    return 0;
}
示例#7
0
/* read_line() reads element from file
   returns element type
 */
int read_line(struct gvfile * Gvf, struct line_pnts *nline)
{
    int n_points;
    long itype;

    if (0 >= dig__fread_port_L(&itype, 1, Gvf))
	return (-2);
    itype = dig_old_to_new_type((char)itype);

    if (0 >= dig__fread_port_I(&n_points, 1, Gvf))
	return (-2);

    if (0 > dig_alloc_points(nline, n_points))
	G_fatal_error("Cannot allocate points");

    nline->n_points = n_points;
    if (0 >= dig__fread_port_D(nline->x, n_points, Gvf))
	return (-2);
    if (0 >= dig__fread_port_D(nline->y, n_points, Gvf))
	return (-2);

    return ((int)itype);
}
示例#8
0
/*!  
  \brief Read line from coor file 
  
  \param Map vector map layer
  \param[out] p container used to store line points within
  \param[out] c container used to store line categories within
  \param offset given offset
  
  \return line type ( > 0 )
  \return 0 dead line
  \return -1 out of memory
  \return -2 end of file
*/
int read_line_nat(struct Map_info *Map,
		  struct line_pnts *p, struct line_cats *c, off_t offset)
{
    register int i, dead = 0;
    int n_points;
    off_t size;
    int n_cats, do_cats;
    int type;
    char rhead, nc;
    short field;

    G_debug(3, "Vect__Read_line_nat: offset = %lu", (unsigned long) offset);

    Map->head.last_offset = offset;

    /* reads must set in_head, but writes use default */
    dig_set_cur_port(&(Map->head.port));

    dig_fseek(&(Map->dig_fp), offset, 0);

    if (0 >= dig__fread_port_C(&rhead, 1, &(Map->dig_fp)))
	return (-2);

    if (!(rhead & 0x01))	/* dead line */
	dead = 1;

    if (rhead & 0x02)		/* categories exists */
	do_cats = 1;		/* do not return here let file offset moves forward to next */
    else			/* line */
	do_cats = 0;

    rhead >>= 2;
    type = dig_type_from_store((int)rhead);

    G_debug(3, "    type = %d, do_cats = %d dead = %d", type, do_cats, dead);

    if (c != NULL)
	c->n_cats = 0;

    if (do_cats) {
	if (Map->head.Version_Minor == 1) {	/* coor format 5.1 */
	    if (0 >= dig__fread_port_I(&n_cats, 1, &(Map->dig_fp)))
		return (-2);
	}
	else {			/* coor format 5.0 */
	    if (0 >= dig__fread_port_C(&nc, 1, &(Map->dig_fp)))
		return (-2);
	    n_cats = (int)nc;
	}
	G_debug(3, "    n_cats = %d", n_cats);

	if (c != NULL) {
	    c->n_cats = n_cats;
	    if (n_cats > 0) {
		if (0 > dig_alloc_cats(c, (int)n_cats + 1))
		    return (-1);

		if (Map->head.Version_Minor == 1) {	/* coor format 5.1 */
		    if (0 >=
			dig__fread_port_I(c->field, n_cats, &(Map->dig_fp)))
			return (-2);
		}
		else {		/* coor format 5.0 */
		    for (i = 0; i < n_cats; i++) {
			if (0 >= dig__fread_port_S(&field, 1, &(Map->dig_fp)))
			    return (-2);
			c->field[i] = (int)field;
		    }
		}
		if (0 >= dig__fread_port_I(c->cat, n_cats, &(Map->dig_fp)))
		    return (-2);

	    }
	}
	else {
	    if (Map->head.Version_Minor == 1) {	/* coor format 5.1 */
		size = (off_t) (2 * PORT_INT) * n_cats;
	    }
	    else {		/* coor format 5.0 */
		size = (off_t) (PORT_SHORT + PORT_INT) * n_cats;
	    }

	    dig_fseek(&(Map->dig_fp), size, SEEK_CUR);
	}
    }

    if (type & GV_POINTS) {
	n_points = 1;
    }
    else {
	if (0 >= dig__fread_port_I(&n_points, 1, &(Map->dig_fp)))
	    return (-2);
    }

    G_debug(3, "    n_points = %d", n_points);

    if (p != NULL) {
	if (0 > dig_alloc_points(p, n_points + 1))
	    return (-1);

	p->n_points = n_points;
	if (0 >= dig__fread_port_D(p->x, n_points, &(Map->dig_fp)))
	    return (-2);
	if (0 >= dig__fread_port_D(p->y, n_points, &(Map->dig_fp)))
	    return (-2);

	if (Map->head.with_z) {
	    if (0 >= dig__fread_port_D(p->z, n_points, &(Map->dig_fp)))
		return (-2);
	}
	else {
	    for (i = 0; i < n_points; i++)
		p->z[i] = 0.0;
	}
    }
    else {
	if (Map->head.with_z)
	    size = (off_t) n_points * 3 * PORT_DOUBLE;
	else
	    size = (off_t) n_points * 2 * PORT_DOUBLE;

	dig_fseek(&(Map->dig_fp), size, SEEK_CUR);
    }

    G_debug(3, "    off = %lu", (unsigned long) dig_ftell(&(Map->dig_fp)));

    if (dead)
	return 0;

    return type;
}