GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72729
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
write_nat.c File Reference

Vector library - write/modify/delete vector feature (native format) More...

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <grass/vector.h>
#include <grass/glocale.h>
#include "local_proto.h"
Include dependency graph for write_nat.c:

Go to the source code of this file.

Functions

off_t V1_write_line_nat (struct Map_info *Map, int type, const struct line_pnts *points, const struct line_cats *cats)
 Writes feature to 'coor' file at level 1 (internal use only) More...
 
off_t V2_write_line_nat (struct Map_info *Map, int type, const struct line_pnts *points, const struct line_cats *cats)
 Writes feature to 'coor' file at topological level (internal use only) More...
 
off_t V1_rewrite_line_nat (struct Map_info *Map, off_t offset, int type, const struct line_pnts *points, const struct line_cats *cats)
 Rewrites feature to 'coor' file at level 1 (internal use only) More...
 
off_t V2_rewrite_line_nat (struct Map_info *Map, off_t line, int type, const struct line_pnts *points, const struct line_cats *cats)
 Rewrites feature to 'coor' file at topological level (internal use only) More...
 
int V1_delete_line_nat (struct Map_info *Map, off_t offset)
 Deletes feature at level 1 (internal use only) More...
 
int V2_delete_line_nat (struct Map_info *Map, off_t line)
 Deletes feature at topological level (internal use only) More...
 
int V1_restore_line_nat (struct Map_info *Map, off_t offset, off_t line)
 Restores feature at level 1 (internal use only) More...
 
int V2_restore_line_nat (struct Map_info *Map, off_t offset, off_t line)
 Restores feature at topological level (internal use only) More...
 
int V2__delete_line_from_topo_nat (struct Map_info *Map, int line, int type, const struct line_pnts *points, const struct line_cats *cats)
 Delete feature from topology (internal use only) More...
 
int V2__add_line_to_topo_nat (struct Map_info *Map, off_t offset, int type, const struct line_pnts *points, const struct line_cats *cats, int restore_line, int(*external_routine)(const struct Map_info *, int))
 Add feature (line) to topology (internal use only) More...
 

Detailed Description

Vector library - write/modify/delete vector feature (native format)

Higher level functions for reading/writing/manipulating vectors.

(C) 2001-2015 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Original author CERL, probably Dave Gerdes or Mike Higgins.
Update to GRASS 5.7 Radim Blazek and David D. Gray.
V*_restore_line() by Martin Landa <landa.martin gmail.com> (2008)

Definition in file write_nat.c.

Function Documentation

int V1_delete_line_nat ( struct Map_info Map,
off_t  offset 
)

Deletes feature at level 1 (internal use only)

Parameters
Mappointer Map_info structure
offsetfeature offset
Returns
0 on success
-1 on error

Definition at line 239 of file write_nat.c.

References dig__fread_port_C(), dig__fwrite_port_C(), dig_fflush(), Map_info::dig_fp, dig_fseek(), dig_set_cur_port(), G_debug(), Map_info::head, dig_head::port, and PRI_OFF_T.

Referenced by V1_rewrite_line_nat(), V2_delete_line_nat(), V2_rewrite_line_nat(), and Vect_remove_small_areas_nat().

int V1_restore_line_nat ( struct Map_info Map,
off_t  offset,
off_t  line 
)

Restores feature at level 1 (internal use only)

Parameters
Mappointer to Map_info structure
offsetfeature offset
linefeature id (not used)
Returns
0 on success
-1 on error

Definition at line 340 of file write_nat.c.

References dig__fread_port_C(), dig__fwrite_port_C(), dig_fflush(), Map_info::dig_fp, dig_fseek(), dig_set_cur_port(), G_debug(), Map_info::head, dig_head::port, and PRI_OFF_T.

Referenced by V2_restore_line_nat().

off_t V1_rewrite_line_nat ( struct Map_info Map,
off_t  offset,
int  type,
const struct line_pnts points,
const struct line_cats cats 
)

Rewrites feature to 'coor' file at level 1 (internal use only)

If the number of points or cats differs from the original one or the type is changed: GV_POINTS -> GV_LINES or GV_LINES -> GV_POINTS, the old one is deleted and the new is appended to the end of the file.

Old feature is deleted (marked as dead), and a new feature written.

Parameters
Mappointer to Map_info structure
offsetfeature offset
typefeature type (GV_POINT, GV_LINE, ...)
pointsfeature geometry
catsfeature categories
Returns
feature offset (rewritten feature)
-1 on error

Definition at line 101 of file write_nat.c.

References G_debug(), GV_LINES, GV_POINTS, line_cats::n_cats, line_pnts::n_points, NULL, PRI_OFF_T, V1_delete_line_nat(), V1_read_line_nat(), Vect_new_cats_struct(), and Vect_new_line_struct().

off_t V1_write_line_nat ( struct Map_info Map,
int  type,
const struct line_pnts points,
const struct line_cats cats 
)

Writes feature to 'coor' file at level 1 (internal use only)

Parameters
Mappointer to Map_info structure
typefeature type (GV_POINT, GV_LINE, ...)
pointsfeature geometry
catsfeature categories
Returns
feature offset into file
-1 on error

Definition at line 43 of file write_nat.c.

Referenced by V2_write_line_nat().

int V2__add_line_to_topo_nat ( struct Map_info Map,
off_t  offset,
int  type,
const struct line_pnts points,
const struct line_cats cats,
int  restore_line,
int(*)(const struct Map_info *, int external_routine 
)

Add feature (line) to topology (internal use only)

Also updates category index if requested.

Update areas. Areas are modified if:

1) first or/and last point are existing nodes ->

  • drop areas/islands whose boundaries are neighbour to this boundary at these nodes
  • try build areas and islands for this boundary and neighbour boundaries going through these nodes

Question: may be by adding line created new area/isle which doesn't go through nodes of this line

           old         new line 
       +----+----+                    +----+----+                 +----+----+ 
       | A1 | A2 |  +      /      ->  | A1 |   /|   or +   \   -> | A1 | A2 | \
       |    |    |                    |    |    |                 |    |    |
       +----+----+                    +----+----+                 +----+----+
         I1   I1                        I1   I1                      
 
  • re-attach all centroids/isles inside new area(s)
  • attach new isle to area outside

2) line is closed ring (node at the end is new, so it is not case above)

  • build new area/isle
  • check if it is island or contains island(s)
  • re-attach all centroids/isles inside new area(s)
  • attach new isle to area outside

Note that 1) and 2) is done by the same code.

Parameters
Mappointer to Map_info structure
offsetfeature offset to be added
pointspointer to line_pnts structure (feature's geometry)
catspointer to line_cats structure (feature's categories)
restore_linefeature id to be restored (>0) or added (<=0)
external_routinepointer to external routine (used by PostGIS Topology)
Returns
feature id to be added
0 nothing to do (build level must be >= GV_BUILD_BASE)
-1 on error

Definition at line 871 of file write_nat.c.

References P_topo_c::area, line_cats::cat, P_area::centroid, dig_add_line(), dig_angle_next_line(), dig_cidx_add_cat_sorted(), dig_del_area(), dig_del_isle(), dig_line_box(), dig_restore_line(), FALSE, line_cats::field, for(), G_debug(), GV_BOUNDARY, GV_BUILD_AREAS, GV_BUILD_ATTACH_ISLES, GV_BUILD_BASE, GV_BUILD_CENTROIDS, GV_CENTROID, GV_LEFT, GV_RIGHT, if(), P_topo_b::left, P_node::lines, P_topo_b::N1, P_topo_b::N2, line_cats::n_cats, P_node::n_lines, NULL, Map_info::plus, P_topo_b::right, P_line::topo, TRUE, P_line::type, Vect_attach_centroids(), Vect_attach_isles(), Vect_box_copy(), Vect_box_extend(), Vect_build_line_area(), Vect_find_area(), Vect_get_area_box(), Vect_get_isle_box(), line_pnts::x, and line_pnts::y.

Referenced by V2_restore_line_nat(), V2_rewrite_line_nat(), and V2_write_line_nat().

int V2__delete_line_from_topo_nat ( struct Map_info Map,
int  line,
int  type,
const struct line_pnts points,
const struct line_cats cats 
)

Delete feature from topology (internal use only)

Note: This function requires build level >= GV_BUILD_BASE.

Also updates category index if requested.

Calls G_warning() on error.

Parameters
Mappointer to Map_info struct
linefeature id to be removed
Pointsfeature geometry (pointer to line_pnts struct)
external_routineexternal subroutine to execute (used by PostGIS Topology)
Returns
0 on success
-1 on failure

Definition at line 636 of file write_nat.c.

References _, Plus_head::Area, P_topo_c::area, Plus_head::built, line_cats::cat, P_area::centroid, dig_angle_next_line(), dig_cidx_del_cat(), dig_del_area(), dig_del_isle(), dig_del_line(), Plus_head::do_uplist, line_cats::field, G_debug(), G_warning(), GV_BOUNDARY, GV_BUILD_AREAS, GV_BUILD_ATTACH_ISLES, GV_BUILD_CENTROIDS, GV_CENTROID, GV_LEFT, GV_RIGHT, if(), P_topo_b::left, Plus_head::Line, line_cats::n_cats, Plus_head::n_lines, Plus_head::n_uplines, Plus_head::n_upnodes, NULL, Map_info::plus, P_topo_b::right, P_line::topo, P_line::type, Plus_head::update_cidx, Plus_head::uplist, Vect_attach_centroids(), Vect_attach_isles(), Vect_box_copy(), Vect_box_extend(), Vect_build_line_area(), Vect_get_area_box(), Vect_get_isle_box(), line_pnts::x, line_pnts::y, and line_pnts::z.

Referenced by V2_delete_line_nat(), and V2_rewrite_line_nat().

int V2_delete_line_nat ( struct Map_info Map,
off_t  line 
)

Deletes feature at topological level (internal use only)

Note: requires topology level >= GV_BUILD_BASE.

Parameters
pointerto Map_info structure
linefeature id
Returns
0 on success
-1 on error

Definition at line 281 of file write_nat.c.

References _, Plus_head::cidx_up_to_date, FALSE, G_debug(), G_warning(), Plus_head::Line, Plus_head::n_lines, NULL, P_line::offset, Map_info::plus, Plus_head::update_cidx, V1_delete_line_nat(), V2__delete_line_from_topo_nat(), V2_read_line_nat(), Vect_new_cats_struct(), and Vect_new_line_struct().

Referenced by V2_rewrite_line_nat().

int V2_restore_line_nat ( struct Map_info Map,
off_t  offset,
off_t  line 
)

Restores feature at topological level (internal use only)

Note: requires topology level >= GV_BUILD_BASE.

Parameters
Mappointer to Map_info structure
offsetfeature offset to be restored
linefeature id to be restored
Returns
0 on success
-1 on error

Definition at line 385 of file write_nat.c.

References _, Plus_head::cidx_up_to_date, G_debug(), G_warning(), Plus_head::Line, Plus_head::n_lines, NULL, Map_info::plus, PRI_OFF_T, Plus_head::update_cidx, V1_read_line_nat(), V1_restore_line_nat(), V2__add_line_to_topo_nat(), Vect_new_cats_struct(), and Vect_new_line_struct().

off_t V2_rewrite_line_nat ( struct Map_info Map,
off_t  line,
int  type,
const struct line_pnts points,
const struct line_cats cats 
)

Rewrites feature to 'coor' file at topological level (internal use only)

Note: requires topology level >= GV_BUILD_BASE.

Note: Function returns feature id, but is defined as off_t for compatibility with level 1 functions.

Parameters
Mappointer to Map_info structure
linefeature id to be rewritten
typefeature type (GV_POINT, GV_LINE, ...)
pointsfeature geometry
catsfeature categories
Returns
new feature id or 0 (build level < GV_BUILD_BASE)
-1 on error

Definition at line 156 of file write_nat.c.

References _, Plus_head::cidx_up_to_date, Plus_head::do_uplist, FALSE, G_warning(), GV_LINES, GV_POINTS, Plus_head::Line, line_cats::n_cats, Plus_head::n_lines, line_pnts::n_points, NULL, P_line::offset, Map_info::plus, Plus_head::update_cidx, Plus_head::uplist, V1_delete_line_nat(), V2__add_line_to_topo_nat(), V2__delete_line_from_topo_nat(), V2_delete_line_nat(), V2_read_line_nat(), V2_write_line_nat(), Vect_new_cats_struct(), and Vect_new_line_struct().

off_t V2_write_line_nat ( struct Map_info Map,
int  type,
const struct line_pnts points,
const struct line_cats cats 
)

Writes feature to 'coor' file at topological level (internal use only)

Note: Function returns feature id, but is defined as off_t for compatibility with level 1 functions.

Parameters
Mappointer to Map_info structure
typefeature type (GV_POINT, GV_LINE, ...)
pointsfeature geometry
catsfeature categories
Returns
new feature id
0 topology is not requested to be built (build level < GV_BUILD_BASE)
-1 on error

Definition at line 64 of file write_nat.c.

References Plus_head::cidx_up_to_date, FALSE, G_debug(), NULL, Map_info::plus, Plus_head::update_cidx, V1_write_line_nat(), and V2__add_line_to_topo_nat().

Referenced by V2_rewrite_line_nat().