Esempio n. 1
0
/*!
   \brief Rewrites feature info at the given offset.

   Vector map must be opened with full topology (level 2).

   The number of points or cats or type may change. If necessary, the
   old feature is deleted and new is written.

   This function calls G_fatal_error() on error.

   \param Map pointer to vector map
   \param line feature id
   \param type feature type
   \param points feature geometry
   \param cats feature categories

   \return feature offset
   \return -1 on error
 */
off_t Vect_rewrite_line(struct Map_info *Map, int line, int type,
			const struct line_pnts *points, const struct line_cats *cats)
{
    off_t ret, offset;
    
    G_debug(3, "Vect_rewrite_line(): name = %s, line = %d", Map->name, line);
    
    if (!VECT_OPEN(Map))
	G_fatal_error(_("Unable to rewrite feature, vector map is not opened"));

    dig_line_reset_updated(&(Map->plus));
    dig_node_reset_updated(&(Map->plus));
    if (!(Map->plus.update_cidx)) {
	Map->plus.cidx_up_to_date = 0;
    }

    offset = Map->plus.Line[line]->offset;
    G_debug(3, "   offset=%lu", Map->plus.Line[line]->offset);
    ret =
	(*Vect_rewrite_line_array[Map->format][Map->level]) (Map, line, type, offset,
							     points, cats);

    if (ret == -1)
	G_fatal_error(_("Unable to rewrite feature %d"), line);

    return ret;
}
Esempio n. 2
0
File: write.c Progetto: caomw/grass
/*!
   \brief Writes a new feature

   New feature is written to the end of file (in the case of native
   format). Topological level is not required.

   A warning is printed on error.
   
   \param Map pointer to Map_info structure
   \param type feature type (see dig_defines.h for supported types)
   \param points pointer to line_pnts structure (feature geometry)
   \param cats pointer to line_cats structure (feature categories)

   \return new feature id (on level 2) (or 0 when build level < GV_BUILD_BASE)
   \return offset into file where the feature starts (on level 1)
   \return -1 on error
 */
off_t Vect_write_line(struct Map_info *Map, int type,
		      const struct line_pnts *points, const struct line_cats *cats)
{
    off_t offset;

    G_debug(3, "Vect_write_line(): name = %s, format = %d, level = %d",
	    Map->name, Map->format, Map->level);

    if (!VECT_OPEN(Map)) {
	G_warning(_("Vector map <%s> is not opened"), Vect_get_name(Map));
        return -1;
    }
    
    if (!(Map->plus.update_cidx)) {
	Map->plus.cidx_up_to_date = FALSE; /* category index will be outdated */
    }

    offset = 
	(*Vect_write_line_array[Map->format][Map->level]) (Map, type, points,
							   cats);
    
    if (offset < 0)
	G_warning(_("Unable to write feature in vector map <%s>"), Vect_get_name(Map));
    
    return offset;
}
Esempio n. 3
0
/*!
   \brief Writes new feature to the end of file

   Vector map topology is not required.

   The function calls G_fatal_error() on error.

   \param Map pointer to vector map
   \param type feature type
   \param points feature geometry
   \param cats feature categories

   \return new feature id (level 2)
   \return offset into file where the feature starts (level 1)
 */
off_t Vect_write_line(struct Map_info *Map, int type,
		      const struct line_pnts *points, const struct line_cats *cats)
{
    off_t offset;

    G_debug(3, "Vect_write_line(): name = %s, format = %d, level = %d",
	    Map->name, Map->format, Map->level);

    if (!VECT_OPEN(Map))
	G_fatal_error(_("Unable to write feature, vector map is not opened"));

    dig_line_reset_updated(&(Map->plus));
    dig_node_reset_updated(&(Map->plus));
    if (!(Map->plus.update_cidx)) {
	Map->plus.cidx_up_to_date = 0;
    }

    offset =
	(*Vect_write_line_array[Map->format][Map->level]) (Map, type, points,
						      cats);

    if (offset == -1)
	G_fatal_error(_("Unable to write feature (negative offset)"));

    /* NOTE: returns new line id on level 2 and file offset on level 1 */
    return offset;
}
Esempio n. 4
0
/*!
  \brief Close vector map

  \param Map vector map to be closed
  
  \return 0 on success
  \return non-zero on error
*/
int V1_close_nat(struct Map_info *Map)
{
    struct Coor_info CInfo;

    G_debug(1, "V1_close_nat(): name = %s mapset= %s", Map->name,
	    Map->mapset);
    if (!VECT_OPEN(Map))
	return 1;

    if (Map->mode == GV_MODE_WRITE || Map->mode == GV_MODE_RW) {
	Vect_coor_info(Map, &CInfo);
	Map->head.size = CInfo.size;
	dig__write_head(Map);

	Vect__write_head(Map);
	Vect_write_dblinks(Map);
    }

    /* close coor file */
    fclose(Map->dig_fp.file);
    dig_file_free(&(Map->dig_fp));

    /* delete temporary map ? */
    if (Map->temporary) {
        if (getenv("GRASS_VECTOR_TEMPORARY") == NULL) {
            G_debug(1, "V1_close_nat(): temporary map <%s> TO BE DELETED", Map->name);
            Vect__delete(Map->name, TRUE);
        }
        else {
            G_debug(1, "V1_close_nat(): temporary map <%s> IS NOT DELETED", Map->name);
        }
    }

    return 0;
}
Esempio n. 5
0
/*!
   \brief Read vector feature (topological level required)

   This function implements random access. Constraits are ignored.

   Note: Topology must be built at level >= GV_BUILD_BASE

   A warning is printed on failure.
   
   \param Map pointer to vector map
   \param[out] line_p feature geometry (pointer to line_pnts struct)
   \param[out] line_c feature categories (pointer to line_cats struct)
   \param line feature id (starts at 1)
   
   \return feature type
   \return -1 on failure
   \return -2 nothing to read   
 */
int Vect_read_line(const struct Map_info *Map,
		   struct line_pnts *line_p, struct line_cats *line_c, int line)
{
    int ret;
    
    G_debug(3, "Vect_read_line(): line = %d", line);

    if (!VECT_OPEN(Map)) {
	G_warning(_("Vector map is not open for reading"));
        return -1;
    }
    
    if (line < 1 || line > Map->plus.n_lines) {
        G_warning(_("Attempt to access feature with invalid id (%d)"), line);
        return -1;
    }
    
    ret = (*Read_line_array[Map->format]) (Map, line_p, line_c, line);

    if (ret == -1)
	G_warning(_("Unable to read feature %d from vector map <%s>"),
                  line, Vect_get_full_name(Map));
    
    return ret;
}
Esempio n. 6
0
/*!
  \brief Get line id for sequential reading.

  This function returns id of feature which has been read by calling
  Vect_read_next_line().

  \param Map pointer to Map_info struct

  \return feature id
  \return -1 on error
*/
int Vect_get_next_line_id(const struct Map_info *Map)
{
    G_debug(3, "Vect_get_next_line()");

    if (!VECT_OPEN(Map)) {
	G_warning(_("Vector map is not open for reading"));
        return -1;
    }
    
    return Map->next_line - 1;
}
Esempio n. 7
0
/*!
   \brief Read next vector feature (level 1 and 2)

   This function implements sequential access.
     
   \param Map pointer vector map
   \param[out] line_p feature geometry
   \param[out] line_c feature categories

   \return feature type,
   \return -1 out of memory
   \return -2 EOF   
 */
int Vect_read_next_line(const struct Map_info *Map,
			struct line_pnts *line_p, struct line_cats *line_c)
{

    G_debug(3, "Vect_read_next_line()");

    if (!VECT_OPEN(Map))
	return -1;

    return (*Read_next_line_array[Map->format][Map->level]) (Map, line_p,
							     line_c);
}
Esempio n. 8
0
/*!
   \brief Read vector feature  (level 2 only)

   This function implements random access.

   \param Map pointer to vector map
   \param[out] line_p feature geometry
   \param[out] line_c feature categories
   \param line feature id 
   
   \return feature type
   \return -1 out of memory,
   \return -2 EOF   
 */
int Vect_read_line(const struct Map_info *Map,
		   struct line_pnts *line_p, struct line_cats *line_c, int line)
{

    G_debug(3, "Vect_read_line() line = %d", line);

    if (!VECT_OPEN(Map))
	G_fatal_error("Vect_read_line(): %s", _("vector map is not opened"));

    if (line < 1 || line > Map->plus.n_lines)
	G_fatal_error(_("Vect_read_line(): feature id %d is not reasonable "
			"(max features in vector map <%s>: %d)"),
		      line, Vect_get_full_name(Map), Map->plus.n_lines);

    return (*V2_read_line_array[Map->format]) (Map, line_p, line_c, line);
}
Esempio n. 9
0
/*!
   \brief Read next vector feature

   This function implements sequential access, constraints are
   reflected, see Vect_set_constraint_region(),
   Vect_set_constraint_type(), or Vect_set_constraint_field() for
   details.
     
   Use Vect_rewind() to reset reading. Topological level is not
   required.

   A warning is printed on failure.
   
   \param Map pointer Map_info struct
   \param[out] line_p feature geometry (pointer to line_pnts struct)
   \param[out] line_c feature categories (pointer to line_cats struct)

   \return feature type (GV_POINT, GV_LINE, ...)
   \return -1 on error
   \return -2 nothing to read
 */
int Vect_read_next_line(const struct Map_info *Map,
			struct line_pnts *line_p, struct line_cats *line_c)
{
    int ret;
    
    G_debug(3, "Vect_read_next_line(): next_line = %d", Map->next_line);

    if (!VECT_OPEN(Map)) {
	G_warning(_("Vector map is not open for reading"));
        return -1;
    }
    
    ret = (*Read_next_line_array[Map->format][Map->level]) (Map, line_p,
							    line_c);
    if (ret == -1)
        G_warning(_("Unable to read feature %d from vector map <%s>"),
                  Map->next_line, Vect_get_full_name(Map));
    
    return ret;
}
Esempio n. 10
0
File: write.c Progetto: caomw/grass
int check_map(const struct Map_info *Map)
{
    if (!VECT_OPEN(Map)) {
	G_warning(_("Vector map <%s> is not opened"), Vect_get_name(Map));
        return 0;
    }
    
    if (Map->level < 2) {
	G_warning(_("Vector map <%s> is not opened on topology level"),
                  Vect_get_name(Map));
        return 0;
    }

    if (Map->mode != GV_MODE_RW && Map->mode != GV_MODE_WRITE) {
	G_warning(_("Vector map <%s> is not opened in write mode"),
                  Vect_get_name(Map));
        return 0;
    }
    
    return 1;
}