GRASS GIS 7 Programmer's Manual  7.7.svn(2018)-r73390
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vector/Vlib/box.c File Reference

Vector library - bounding box. More...

#include <stdlib.h>
#include <grass/vector.h>
#include <grass/glocale.h>
Include dependency graph for vector/Vlib/box.c:

Go to the source code of this file.

Functions

int Vect_point_in_box (double x, double y, double z, const struct bound_box *Box)
 Tests if point is in 3D box. More...
 
int Vect_point_in_box_2d (double x, double y, const struct bound_box *Box)
 Tests if point is in 2D box. More...
 
int Vect_box_overlap (const struct bound_box *A, const struct bound_box *B)
 Tests for overlap of two boxes. More...
 
int Vect_box_copy (struct bound_box *A, const struct bound_box *B)
 Copy box B to box A. More...
 
int Vect_box_extend (struct bound_box *A, const struct bound_box *B)
 Extend box A by box B. More...
 
int Vect_box_clip (double *x, double *y, double *c_x, double *c_y, const struct bound_box *Box)
 Clip coordinates to box, if necessary, lines extending outside of a box. More...
 
int Vect_get_line_box (const struct Map_info *Map, int line, struct bound_box *Box)
 Get bounding box of given feature. More...
 
int Vect_get_area_box (const struct Map_info *Map, int area, struct bound_box *Box)
 Get bounding box of area. More...
 
int Vect_get_isle_box (const struct Map_info *Map, int isle, struct bound_box *Box)
 Get bounding box of isle. More...
 
int Vect_get_map_box (const struct Map_info *Map, struct bound_box *Box)
 Get bounding box of map (all features in the map) More...
 
int Vect_get_map_box1 (struct Map_info *Map, struct bound_box *Box)
 Get bounding box of map on level 1 (all features in the map) More...
 
int Vect_region_box (const struct Cell_head *Window, struct bound_box *Box)
 Copy region window to bounding box. More...
 

Detailed Description

Vector library - bounding box.

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
Radim Blazek

Definition in file vector/Vlib/box.c.

Function Documentation

int Vect_box_clip ( double *  x,
double *  y,
double *  c_x,
double *  c_y,
const struct bound_box Box 
)

Clip coordinates to box, if necessary, lines extending outside of a box.

A line represented by the coordinates x, y and c_x, c_y is clipped to the window defined by s (south), n (north), w (west), and e (east). Note that the following constraints must be true: w <e s <n The x and c_x are values to be compared to w and e. The y and c_y are values to be compared to s and n. The x and c_x values returned lie between w and e. The y and c_y values returned lie between s and n.

Parameters
x,ycoordinates (w, e)
c_x,c_ycoordinates (s, n)
Boxboundary box
Returns
1 if any clipping occurred
0 otherwise

Definition at line 167 of file vector/Vlib/box.c.

References bound_box::E, bound_box::N, bound_box::S, bound_box::W, W, and x.

int Vect_box_copy ( struct bound_box A,
const struct bound_box B 
)
int Vect_box_extend ( struct bound_box A,
const struct bound_box B 
)

Extend box A by box B.

Parameters
Aboundary A
Bboundary B
Returns
1

Definition at line 124 of file vector/Vlib/box.c.

References bound_box::B, bound_box::E, bound_box::N, bound_box::S, bound_box::T, and bound_box::W.

Referenced by V2__add_line_to_topo_nat(), V2__delete_line_from_topo_nat(), V2_write_line_sfa(), Vect_build_nat(), and Vect_get_map_box1().

int Vect_box_overlap ( const struct bound_box A,
const struct bound_box B 
)

Tests for overlap of two boxes.

Parameters
Aboundary box A
Bboundary box B
Returns
1 boxes overlap
0 boxes do not overlap

Definition at line 84 of file vector/Vlib/box.c.

References bound_box::B, bound_box::E, bound_box::N, bound_box::S, bound_box::T, and bound_box::W.

Referenced by V1_read_next_line_nat(), V2_read_next_line_nat(), V2_read_next_line_ogr(), V2_read_next_line_pg(), Vect_line_check_intersection2(), Vect_line_intersection(), and Vect_line_intersection2().

int Vect_get_area_box ( const struct Map_info Map,
int  area,
struct bound_box Box 
)

Get bounding box of area.

Vector map must be open at topological level and built with level >= GV_BUILD_AREAS.

Parameters
Mapvector map
areaarea id
[out]Boxbounding box
Returns
1 on success
0 area is dead
-1 on error

Definition at line 306 of file vector/Vlib/box.c.

References _, Plus_head::Area, bound_box::B, dig_find_area_box(), bound_box::E, G_warning(), bound_box::N, Plus_head::n_areas, NULL, Map_info::plus, PORT_DOUBLE_MAX, bound_box::S, bound_box::T, Vect_is_3d(), and bound_box::W.

Referenced by V2__add_line_to_topo_nat(), V2__delete_line_from_topo_nat(), V2_read_line_sfa(), V2_read_next_line_ogr(), V2_read_next_line_pg(), Vect_attach_centroids(), and Vect_attach_isles().

int Vect_get_isle_box ( const struct Map_info Map,
int  isle,
struct bound_box Box 
)

Get bounding box of isle.

Vector map must be open at topological level and built with level >= GV_BUILD_AREAS.

Parameters
Mapvector map
isleisle id
[out]Boxbounding box
Returns
1 on success
0 isle is dead / bounding box not found
-1 on error

Definition at line 351 of file vector/Vlib/box.c.

References _, bound_box::B, dig_find_isle_box(), bound_box::E, G_warning(), Plus_head::Isle, bound_box::N, Plus_head::n_isles, NULL, Map_info::plus, PORT_DOUBLE_MAX, bound_box::S, bound_box::T, Vect_is_3d(), and bound_box::W.

Referenced by V2__add_line_to_topo_nat(), V2__delete_line_from_topo_nat(), Vect_build_nat(), Vect_find_area(), and Vect_point_in_area().

int Vect_get_line_box ( const struct Map_info Map,
int  line,
struct bound_box Box 
)

Get bounding box of given feature.

Vector map must be open at topological level and built with level >= GV_BUILD_BASE.

Parameters
Mapvector map
linefeature id
[out]Boxbounding box
Returns
1 on success
0 line is dead
-1 on error

Definition at line 240 of file vector/Vlib/box.c.

References _, bound_box::B, dig_find_line_box(), dig_line_box(), bound_box::E, G_warning(), GV_LINES, Plus_head::Line, bound_box::N, Plus_head::n_lines, NULL, Map_info::plus, PORT_DOUBLE_MAX, bound_box::S, bound_box::T, P_line::type, Vect_is_3d(), Vect_new_line_struct(), Vect_read_line(), and bound_box::W.

int Vect_get_map_box ( const struct Map_info Map,
struct bound_box Box 
)

Get bounding box of map (all features in the map)

Requires level 2. On level 1 error code is returned.

Parameters
Mapvector map
[out]Boxbounding box
Returns
1 on success
0 on error

Definition at line 394 of file vector/Vlib/box.c.

References Plus_head::box, Map_info::plus, Vect_box_copy(), and Vect_level().

int Vect_get_map_box1 ( struct Map_info Map,
struct bound_box Box 
)

Get bounding box of map on level 1 (all features in the map)

This subroutine determines bounding box by reading all features sequentially.

Parameters
Mapvector map
[out]Boxbounding box
Returns
1 on success
0 on error

Definition at line 419 of file vector/Vlib/box.c.

References _, dig_line_box(), FALSE, G_verbose_message(), G_warning(), NULL, TRUE, Vect_box_copy(), Vect_box_extend(), Vect_destroy_line_struct(), Vect_get_full_name(), Vect_new_line_struct(), Vect_read_next_line(), and Vect_rewind().

int Vect_point_in_box ( double  x,
double  y,
double  z,
const struct bound_box Box 
)

Tests if point is in 3D box.

This function considers 3D point and 3D bounding box.

Example
struct bound_box bbox;
bbox.N = 135;
bbox.S = 125;
bbox.E = 220;
bbox.W = 215;
bbox.T = 340;
bbox.B = 330;
Vect_point_in_box(217, 130, 335, &bbox);
Parameters
xcoordinate (W-E direction)
ycoordinate (S-N direction)
zcoordinate (B-T direction)
Boxboundary box
Returns
1 if point is in box
0 if point is not in box

Definition at line 48 of file vector/Vlib/box.c.

References bound_box::B, N, bound_box::S, and bound_box::W.

Referenced by P_estimate_splinestep(), P_Mean_Calc(), P_Read_Raster_Region_Map(), P_Read_Vector_Region_Map(), P_Regular_Points(), and P_Sparse_Points().

int Vect_point_in_box_2d ( double  x,
double  y,
const struct bound_box Box 
)

Tests if point is in 2D box.

Only x and y are tested. Top and bottom of the bounding box are ignored.

Parameters
xcoordinate (W-E direction)
ycoordinate (S-N direction)
Boxboundary box (only W, E, S, N are used)
Returns
1 if point is in box
0 if point is not in box

Definition at line 68 of file vector/Vlib/box.c.

References N, bound_box::S, and bound_box::W.

int Vect_region_box ( const struct Cell_head Window,
struct bound_box Box 
)

Copy region window to bounding box.

Parameters
Windowregion structure (raster-based)
[out]Boxboundary box (vector-based)
Returns
1 on success
0 on error

Definition at line 467 of file vector/Vlib/box.c.

References bound_box::B, bound_box::E, Cell_head::east, bound_box::N, Cell_head::north, PORT_DOUBLE_MAX, bound_box::S, Cell_head::south, bound_box::T, bound_box::W, and Cell_head::west.

Referenced by P_estimate_splinestep(), P_Mean_Calc(), P_Read_Raster_Region_Map(), and P_Read_Vector_Region_Map().