GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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

◆ Vect_box_clip()

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.

◆ Vect_box_copy()

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

Copy box B to box A.

Parameters
Aboundary A
Bboundary B
Returns
1

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

Referenced by Vect_get_map_box().

◆ Vect_box_extend()

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.

◆ Vect_box_overlap()

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.

◆ Vect_get_area_box()

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

◆ Vect_get_isle_box()

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

◆ Vect_get_line_box()

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.

◆ Vect_get_map_box()

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

◆ Vect_get_map_box1()

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.

◆ Vect_point_in_box()

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

◆ Vect_point_in_box_2d()

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.

◆ Vect_region_box()

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