GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
build.c File Reference

Vector library - Building topology. More...

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

Go to the source code of this file.

Macros

#define SEP   "-----------------------------------\n"
 

Functions

int Vect_build_line_area (struct Map_info *Map, int iline, int side)
 Build area on given side of line (GV_LEFT or GV_RIGHT) More...
 
int Vect_isle_find_area (struct Map_info *Map, int isle, const struct bound_box *box)
 Find area outside island. More...
 
int Vect_attach_isle (struct Map_info *Map, int isle, const struct bound_box *box)
 (Re)Attach isle to area More...
 
int Vect_attach_isles (struct Map_info *Map, const struct bound_box *box)
 (Re)Attach isles in given bounding box to areas More...
 
int Vect_attach_centroids (struct Map_info *Map, const struct bound_box *box)
 (Re)Attach centroids in given bounding box to areas More...
 
int Vect_build (struct Map_info *Map)
 Build topology for vector map. More...
 
int Vect_topo_check (struct Map_info *Map, struct Map_info *Err)
 Extensive tests for correct topology. More...
 
int Vect_get_built (const struct Map_info *Map)
 Return current highest built level (part) More...
 
void Vect__build_downgrade (struct Map_info *Map, int build)
 Downgrade build level (for internal use only) More...
 
int Vect_build_partial (struct Map_info *Map, int build)
 Build partial topology for vector map. More...
 
int Vect_save_topo (struct Map_info *Map)
 Save topology file for vector map. More...
 
int Vect_topo_dump (const struct Map_info *Map, FILE *out)
 Dump topology to file. More...
 
int Vect_build_sidx (struct Map_info *Map)
 Create spatial index if necessary. More...
 
int Vect_build_sidx_from_topo (const struct Map_info *Map)
 Create spatial index from topology if necessary (not longer supported) More...
 
int Vect_save_sidx (struct Map_info *Map)
 Save spatial index file for vector map. More...
 
int Vect_sidx_dump (const struct Map_info *Map, FILE *out)
 Dump spatial index to file. More...
 

Detailed Description

Vector library - Building topology.

Higher level functions for reading/writing/manipulating vectors.

(C) 2001-2010, 2012-2013 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.

Definition in file build.c.

Macro Definition Documentation

◆ SEP

#define SEP   "-----------------------------------\n"

Definition at line 32 of file build.c.

Function Documentation

◆ Vect__build_downgrade()

void Vect__build_downgrade ( struct Map_info Map,
int  build 
)

Downgrade build level (for internal use only)

See Vect_build_nat(), Vect__build_sfa(), and Vect_build_pg() for implementation issues.

Parameters
Mappointer to Map_info
build

Definition at line 760 of file build.c.

Referenced by Vect__build_sfa().

◆ Vect_attach_centroids()

int Vect_attach_centroids ( struct Map_info Map,
const struct bound_box box 
)

(Re)Attach centroids in given bounding box to areas

Warning: If map is updated on level2, it may happen that previously correct island becomes incorrect. In that case, centroid of area forming the island is reattached to outer area, because island polygon is not excluded.

   +-----------+     +-----------+
   |   1       |     |   1       |
   | +---+---+ |     | +---+---+ |     
   | | 2 | 3 | |     | | 2 |     |   
   | | x |   | |  -> | | x |     |  
   | |   |   | |     | |   |     | 
   | +---+---+ |     | +---+---+ |
   |           |     |           |
   +-----------+     +-----------+
   centroid is       centroid is
   attached to 2     reattached to 1
 

Because of this, when the centroid is reattached to another area, it is always necessary to check if original area exist, unregister centroid from previous area. To simplify code, this is implemented so that centroid is always first unregistered and if new area is found, it is registered again.

Parameters
Mapvector map
boxbounding box
Returns
0

Definition at line 495 of file build.c.

◆ Vect_attach_isle()

int Vect_attach_isle ( struct Map_info Map,
int  isle,
const struct bound_box box 
)

(Re)Attach isle to area

Parameters
Mapvector map
isleisle id
boxisle bbox
Returns
0

Definition at line 378 of file build.c.

References P_isle::area, dig_area_add_isle(), G_debug(), Plus_head::Isle, Map_info::plus, and Vect_isle_find_area().

Referenced by Vect_attach_isles().

◆ Vect_attach_isles()

int Vect_attach_isles ( struct Map_info Map,
const struct bound_box box 
)

(Re)Attach isles in given bounding box to areas

The warning for Vect_attach_centroids() applies here as well

Parameters
Mapvector map
boxbounding box
Returns
0

Definition at line 417 of file build.c.

References P_isle::area, boxlist::box, dig_area_del_isle(), bound_box::E, G_debug(), boxlist::id, Plus_head::Isle, bound_box::N, boxlist::n_values, NULL, Map_info::plus, bound_box::S, TRUE, Vect_attach_isle(), Vect_get_area_box(), Vect_new_boxlist(), Vect_select_isles_by_box(), and bound_box::W.

◆ Vect_build()

int Vect_build ( struct Map_info Map)

Build topology for vector map.

Parameters
Mapvector map
Returns
1 on success
0 on error

Definition at line 576 of file build.c.

References GV_BUILD_ALL, and Vect_build_partial().

Referenced by Vect_close().

◆ Vect_build_line_area()

int Vect_build_line_area ( struct Map_info Map,
int  iline,
int  side 
)

Build area on given side of line (GV_LEFT or GV_RIGHT)

Parameters
Mappointer to Map_info structure
ilineline id
sideside (GV_LEFT or GV_RIGHT)
Returns
> 0 area id
< 0 isle id
0 not created (may also already exist)

Definition at line 77 of file build.c.

References _, dig_add_area(), dig_add_isle(), dig_build_area_with_line(), dig_find_area_poly(), dig_line_box(), dig_line_get_area(), G_debug(), G_fatal_error(), G_warning(), line_pnts::n_points, NULL, Map_info::plus, Vect__get_area_points(), Vect_line_prune(), and Vect_new_line_struct().

◆ Vect_build_partial()

int Vect_build_partial ( struct Map_info Map,
int  build 
)

Build partial topology for vector map.

Should only be used in special cases of vector processing.

This functions optionally builds only some parts of topology. Highest level is specified by build parameter which may be:

  • GV_BUILD_NONE - nothing is build
  • GV_BUILD_BASE - basic topology, nodes, lines, spatial index;
  • GV_BUILD_AREAS - build areas and islands, but islands are not attached to areas;
  • GV_BUILD_ATTACH_ISLES - attach islands to areas;
  • GV_BUILD_CENTROIDS - assign centroids to areas, build category index;
  • GV_BUILD_ALL - top level, the same as GV_BUILD_CENTROIDS.

If functions is called with build lower than current value of the Map, the level is downgraded to requested value.

All calls to Vect_write_line(), Vect_rewrite_line(), Vect_delete_line() respect the last value of build used in this function.

Note that the functions has effect only if requested level is higher than current level, to rebuild part of topology, call first downgrade and then upgrade, for example:

  • Vect_build()
  • Vect_build_partial(,GV_BUILD_BASE,)
  • Vect_build_partial(,GV_BUILD_AREAS,)
Parameters
Mapvector map
buildhighest level of build
Returns
1 on success
0 on error

Definition at line 847 of file build.c.

References _, Plus_head::built, dig_cidx_free(), dig_cidx_init(), Map_info::fInfo, Map_info::format, G_debug(), G_fatal_error(), G_message(), GV_BUILD_ALL, GV_BUILD_NONE, GV_FORMAT_OGR_DIRECT, GV_FORMAT_POSTGIS, Map_info::head, Map_info::level, LEVEL_1, Format_info::pg, Map_info::plus, Plus_head::Spidx_built, Plus_head::spidx_with_z, Map_info::support_updated, Map_info::temporary, Format_info_pg::toposchema_name, TRUE, Vect_get_full_name(), Vect_open_sidx(), dig_head::with_z, and Plus_head::with_z.

Referenced by Vect_build().

◆ Vect_build_sidx()

int Vect_build_sidx ( struct Map_info Map)

Create spatial index if necessary.

To be used in modules. Map must be opened on level 2.

Parameters
[in,out]Mappointer to vector map
Returns
0 OK
1 error

Definition at line 1208 of file build.c.

References _, G_fatal_error(), Map_info::level, Map_info::plus, Plus_head::Spidx_built, and Vect_build_sidx_from_topo().

◆ Vect_build_sidx_from_topo()

int Vect_build_sidx_from_topo ( const struct Map_info Map)

Create spatial index from topology if necessary (not longer supported)

Parameters
Mappointer to vector map
Returns
1

Definition at line 1228 of file build.c.

References _, G_debug(), G_warning(), and Vect_get_full_name().

Referenced by Vect_build_sidx(), and Vect_sidx_dump().

◆ Vect_get_built()

int Vect_get_built ( const struct Map_info Map)

Return current highest built level (part)

Parameters
Mapvector map
Returns
current highest built level

Definition at line 746 of file build.c.

References Plus_head::built, and Map_info::plus.

◆ Vect_isle_find_area()

int Vect_isle_find_area ( struct Map_info Map,
int  isle,
const struct bound_box box 
)

Find area outside island.

Parameters
Mapvector map
isleisle id
boxisle bbox
Returns
area id
0 if not found

Definition at line 177 of file build.c.

Referenced by Vect_attach_isle().

◆ Vect_save_sidx()

int Vect_save_sidx ( struct Map_info Map)

◆ Vect_save_topo()

int Vect_save_topo ( struct Map_info Map)

Save topology file for vector map.

Parameters
Mappointer to Map_info structure
Returns
1 on success
0 on error

Definition at line 999 of file build.c.

References _, dig__byte_order_out(), dig_file_init(), dig_init_portable(), dig_write_plus_file(), gvfile::file, G_debug(), G_fopen_new(), G_warning(), GPATH_MAX, GV_TOPO_ELEMENT, Map_info::name, NULL, Map_info::plus, Plus_head::port, and Vect__get_path().

◆ Vect_sidx_dump()

int Vect_sidx_dump ( const struct Map_info Map,
FILE *  out 
)

Dump spatial index to file.

Parameters
Mapvector map
outfile for output (stdout/stderr for example)
Returns
1 on success
0 on error

Definition at line 1300 of file build.c.

References dig_dump_spidx(), Map_info::plus, Plus_head::Spidx_built, and Vect_build_sidx_from_topo().

◆ Vect_topo_check()

int Vect_topo_check ( struct Map_info Map,
struct Map_info Err 
)

Extensive tests for correct topology.

  • lines or boundaries of zero length
  • intersecting boundaries, ie. overlapping areas
  • areas without centroids that are not isles
Parameters
Mapvector map
[out]Errvector map where errors will be written or NULL
Returns
1 on success
0 on error

Definition at line 594 of file build.c.

◆ Vect_topo_dump()

int Vect_topo_dump ( const struct Map_info Map,
FILE *  out 
)

Dump topology to file.

Parameters
Mapvector map
outfile for output (stdout/stderr for example)
Returns
1 on success
0 on error

Definition at line 1040 of file build.c.