GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
constraint.c
Go to the documentation of this file.
1/*!
2 \file lib/vector/Vlib/constraint.c
3
4 \brief Vector library - constraints for reading features
5
6 Higher level functions for reading/writing/manipulating vectors.
7
8 These routines can affect the Vect_read_next_line() functions by
9 restricting what they return. They are applied on a per map basis.
10
11 These do not affect the lower level direct read functions.
12
13 Normally, all 'Alive' lines will be returned unless overridden by
14 this function. You can specified all the types you are interested
15 in (by oring their types together). You can use this to say exclude
16 'boundary' type features.
17
18 By default all DEAD lines are ignored by the Vect_read_next_line()
19 functions. This too can be overridden by including their types.
20
21 SPDX-FileCopyrightText: 2001-2009, 2011-2012 GRASS Development Team
22 SPDX-License-Identifier: GPL-2.0-or-later
23
24 \author Original author CERL, probably Dave Gerdes or Mike Higgins.
25 \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
26 */
27
28#include <grass/vector.h>
29#include <grass/glocale.h>
30
31/*!
32 \brief Set constraint region
33
34 Vect_read_next_line() will read only features inside of given
35 region or features with overlapping bounding box.
36
37 \note Constraint is ignored for random access - Vect_read_line().
38
39 \param Map pointer to Map_info struct
40 \param n,s,e,w,t,b bbox definition (north, south, east, west, top, and bottom
41 coordinates)
42
43 \return 0 on success
44 \return -1 on error (invalid region)
45 */
46int Vect_set_constraint_region(struct Map_info *Map, double n, double s,
47 double e, double w, double t, double b)
48{
49 if (n <= s)
50 return -1;
51 if (e <= w)
52 return -1;
53
54 Map->constraint.region_flag = TRUE;
55 Map->constraint.box.N = n;
56 Map->constraint.box.S = s;
57 Map->constraint.box.E = e;
58 Map->constraint.box.W = w;
59 Map->constraint.box.T = t;
60 Map->constraint.box.B = b;
61 Map->head.proj = G_projection();
62
63 return 0;
64}
65
66/*!
67 \brief Get constraint box
68
69 Constraint box can be defined by Vect_set_constraint_region().
70
71 \param Map vector map
72 \param[out] Box bounding box
73
74 \return 0 on success
75 \return -1 no region constraint defined
76 */
78{
79 if (!Map->constraint.region_flag)
80 return -1;
81
82 Box->N = Map->constraint.box.N;
83 Box->S = Map->constraint.box.S;
84 Box->E = Map->constraint.box.E;
85 Box->W = Map->constraint.box.W;
86 Box->T = Map->constraint.box.T;
87 Box->B = Map->constraint.box.B;
88
89 return 0;
90}
91
92/*!
93 \brief Set constraint type
94
95 Vect_read_next_line() will read only features of given
96 type. Constraint is ignored for random access - Vect_read_line().
97
98 \param Map pointer to Map_info struct
99 \param type constraint feature type (GV_POINT, GV_LINE, ...)
100
101 \return 0 on success
102 \return -1 invalid feature type
103 */
105{
106 if (!(type & (GV_POINTS | GV_LINES | GV_FACE | GV_KERNEL)))
107 return -1;
108
109 Map->constraint.type = type;
110 Map->constraint.type_flag = TRUE;
111
112 return 0;
113}
114
115/*!
116 \brief Remove all constraints
117
118 \param Map pointer to Map_info struct
119 */
121{
122 Map->constraint.region_flag = FALSE;
123 Map->constraint.type_flag = FALSE;
124 Map->constraint.field_flag = FALSE;
125}
126
127/*!
128 \brief Set constraint field
129
130 Vect_read_next_line() will read only features of given type. Note
131 that categories must be read otherwise this constraint is
132 ignored. Constraint is ignored for random access -
133 Vect_read_line().
134
135 Ignored for non-native vector formats.
136
137 Note: Field is called layer on user level.
138
139 \param Map pointer to Map_info struct
140 \param field field number (-1 for all fields)
141
142 \return 0 on success
143 \return -1 invalid field
144 */
146{
147 if (Map->format != GV_FORMAT_NATIVE) {
148 G_warning(_("Layer constraint ignored for non-native vector formats"));
149 return -1;
150 }
151
152 if (field == -1) {
153 Map->constraint.field_flag = FALSE;
154 return 0;
155 }
156 if (field < 1) {
157 return -1;
158 }
159 Map->constraint.field = field;
160 Map->constraint.field_flag = TRUE;
161
162 return 0;
163}
int Vect_set_constraint_type(struct Map_info *Map, int type)
Set constraint type.
Definition constraint.c:104
int Vect_set_constraint_field(struct Map_info *Map, int field)
Set constraint field.
Definition constraint.c:145
int Vect_set_constraint_region(struct Map_info *Map, double n, double s, double e, double w, double t, double b)
Set constraint region.
Definition constraint.c:46
int Vect_get_constraint_box(struct Map_info *Map, struct bound_box *Box)
Get constraint box.
Definition constraint.c:77
void Vect_remove_constraints(struct Map_info *Map)
Remove all constraints.
Definition constraint.c:120
void G_warning(const char *,...) __attribute__((format(printf
int G_projection(void)
Query cartographic projection.
Definition proj1.c:30
#define GV_LINES
#define GV_FACE
#define GV_POINTS
#define GV_FORMAT_NATIVE
Geometry data formats supported by lib Don't change GV_FORMAT_* values, this order is hardcoded in li...
Definition dig_defines.h:83
#define GV_KERNEL
#define TRUE
Definition gis.h:75
#define FALSE
Definition gis.h:79
#define _(str)
Definition glocale.h:10
float Box[8][3]
Vertices for box.
Definition gsd_objs.c:1451
double b
Definition r_raster.c:37
double t
Definition r_raster.c:37
Vector map info.
Bounding box.
Definition dig_structs.h:62