GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72636
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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

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

Definition at line 32 of file build.c.

Referenced by Vect_topo_dump().

Function Documentation

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.

References Plus_head::Area, P_topo_c::area, boxlist::box, P_area::centroid, bound_box::E, G_debug(), GV_CENTROID, boxlist::id, if(), Plus_head::Line, bound_box::N, boxlist::n_values, Map_info::plus, bound_box::S, P_line::topo, Vect_find_area(), Vect_get_area_box(), Vect_new_boxlist(), Vect_select_lines_by_box(), and bound_box::W.

Referenced by V2__add_line_to_topo_nat(), and V2__delete_line_from_topo_nat().

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(), and Vect_build_nat().

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.

Referenced by V2__add_line_to_topo_nat(), and V2__delete_line_from_topo_nat().

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__open_old(), Vect_close(), and Vect_topo_check().

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().

Referenced by V2__add_line_to_topo_nat(), V2__delete_line_from_topo_nat(), Vect_build_nat(), and Vect_remove_small_areas_nat().

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 _, P_topo_c::area, Plus_head::built, Plus_head::cidx_up_to_date, dig_cidx_free(), dig_cidx_init(), dig_cidx_sort(), Map_info::fInfo, Map_info::format, G_debug(), G_fatal_error(), G_message(), G_verbose_message(), G_warning(), GV_BOUNDARY, GV_BUILD_ALL, GV_BUILD_AREAS, GV_BUILD_NONE, GV_CENTROID, GV_FORMAT_OGR_DIRECT, GV_FORMAT_POSTGIS, GV_MODE_WRITE, Map_info::head, if(), P_topo_b::left, Map_info::level, LEVEL_1, LEVEL_2, Plus_head::Line, Plus_head::mode, Plus_head::n_areas, Plus_head::n_blines, Plus_head::n_clines, Plus_head::n_flines, Plus_head::n_isles, Plus_head::n_klines, Plus_head::n_lines, Plus_head::n_llines, Plus_head::n_nodes, Plus_head::n_plines, Format_info::pg, Map_info::plus, P_topo_b::right, Plus_head::Spidx_built, Plus_head::spidx_with_z, Map_info::support_updated, Map_info::temporary, P_line::topo, Format_info_pg::toposchema_name, TRUE, P_line::type, Vect_area_alive(), Vect_get_area_centroid(), Vect_get_full_name(), Vect_get_num_areas(), Vect_get_num_lines(), Vect_open_sidx(), dig_head::with_z, and Plus_head::with_z.

Referenced by Vect_build(), and Vect_topo_check().

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().

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().

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.

Referenced by Vect_topo_check().

int Vect_save_sidx ( struct Map_info Map)
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(), fclose(), 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().

Referenced by Vect_close().

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().

int Vect_topo_check ( struct Map_info Map,
struct Map_info Err 
)