GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
write_nat.c File Reference

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

#include <inttypes.h>
#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)(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

◆ V1_delete_line_nat()

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 248 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, and dig_head::port.

◆ V1_restore_line_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 350 of file write_nat.c.

◆ V1_rewrite_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 105 of file write_nat.c.

◆ V1_write_line_nat()

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 45 of file write_nat.c.

◆ V2__add_line_to_topo_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(*)(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 907 of file write_nat.c.

◆ V2__delete_line_from_topo_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 656 of file write_nat.c.

◆ V2_delete_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 290 of file write_nat.c.

◆ V2_restore_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 398 of file write_nat.c.

◆ V2_rewrite_line_nat()

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 161 of file write_nat.c.

◆ V2_write_line_nat()

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 67 of file write_nat.c.