21 #include <grass/gis.h>
22 #include <grass/Vect.h>
23 #include <grass/glocale.h>
24 #include <grass/gstypes.h>
31 static int Tot_mem = 0;
48 struct line_pnts *points;
49 geoline *top, *gln, *prev;
50 int np, i,
n, nareas, nl = 0, area,
type, is3d;
51 struct Cell_head wind;
57 G_warning(_(
"Vector map <%s> not found"), grassname);
63 G_warning(_(
"Unable to open vector map <%s>"),
68 top = gln = (geoline *) G_malloc(
sizeof(geoline));
76 Tot_mem +=
sizeof(geoline);
83 wind.west, PORT_DOUBLE_MAX, -PORT_DOUBLE_MAX);
90 G_debug(3,
"Reading vector areas (nareas = %d)", n);
91 for (area = 1; area <=
n; area++) {
95 if (points->n_points < 3)
97 gln->type = OGSF_POLYGON;
98 gln->npts = np = points->n_points;
103 gln->p3 = (Point3 *) G_calloc(np,
sizeof(Point3));
108 Tot_mem += (np *
sizeof(Point3));
113 gln->p2 = (Point2 *) G_calloc(np,
sizeof(Point2));
118 Tot_mem += (np *
sizeof(Point2));
122 for (i = 0; i < np; i++) {
124 gln->p3[i][
X] = points->x[i];
125 gln->p3[i][
Y] = points->y[i];
126 gln->p3[i][Z] = points->z[i];
129 gln->p2[i][
X] = points->x[i];
130 gln->p2[i][
Y] = points->y[i];
135 vect[0][
X] = (float)(gln->p3[0][
X] - gln->p3[1][
X]);
136 vect[0][
Y] = (float)(gln->p3[0][
Y] - gln->p3[1][
Y]);
137 vect[0][Z] = (float)(gln->p3[0][Z] - gln->p3[1][Z]);
138 vect[1][
X] = (float)(gln->p3[2][
X] - gln->p3[1][
X]);
139 vect[1][
Y] = (float)(gln->p3[2][
Y] - gln->p3[1][
Y]);
140 vect[1][Z] = (float)(gln->p3[2][Z] - gln->p3[1][Z]);
145 gln->next = (geoline *) G_malloc(
sizeof(geoline));
151 Tot_mem +=
sizeof(geoline);
158 G_debug(3,
"%d areas loaded", nareas);
161 G_debug(3,
"Reading vector lines ...");
163 G_debug(3,
"line type = %d", type);
167 gln->type = OGSF_LINE;
170 gln->type = OGSF_POLYGON;
174 gln->npts = np = points->n_points;
179 gln->p3 = (Point3 *) G_calloc(np,
sizeof(Point3));
184 Tot_mem += (np *
sizeof(Point3));
189 gln->p2 = (Point2 *) G_calloc(np,
sizeof(Point2));
194 Tot_mem += (np *
sizeof(Point2));
198 for (i = 0; i < np; i++) {
200 gln->p3[i][
X] = points->x[i];
201 gln->p3[i][
Y] = points->y[i];
202 gln->p3[i][Z] = points->z[i];
205 gln->p2[i][
X] = points->x[i];
206 gln->p2[i][
Y] = points->y[i];
210 if (is3d && gln->type == OGSF_POLYGON) {
211 vect[0][
X] = (float)(gln->p3[0][
X] - gln->p3[1][
X]);
212 vect[0][
Y] = (float)(gln->p3[0][
Y] - gln->p3[1][
Y]);
213 vect[0][Z] = (float)(gln->p3[0][Z] - gln->p3[1][Z]);
214 vect[1][
X] = (float)(gln->p3[2][
X] - gln->p3[1][
X]);
215 vect[1][
Y] = (float)(gln->p3[2][
Y] - gln->p3[1][
Y]);
216 vect[1][Z] = (float)(gln->p3[2][Z] - gln->p3[1][Z]);
218 G_debug(3,
"norm %f %f %f", gln->norm[0], gln->norm[1],
222 gln->next = (geoline *) G_malloc(
sizeof(geoline));
227 Tot_mem +=
sizeof(geoline);
235 G_debug(3,
"%d lines loaded", nl);
243 Tot_mem -=
sizeof(geoline);
249 G_warning(_(
"No features from vector map <%s> fall within current region"),
254 G_message(_(
"Vector map <%s> loaded (%d features)"),
261 G_debug(3,
"Total vect memory = %d Kbytes", Tot_mem / 1000);
void G_free(void *buf)
Free allocated memory.
int G_get_set_window(struct Cell_head *window)
Get the current working window.
geoline * Gv_load_vect(const char *grassname, int *nlines)
Load vector map to memory.
int Vect_read_next_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c)
Read next vector feature (level 1 and 2)
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
int Vect_get_num_areas(struct Map_info *map)
Get number of areas in vector map.
char * G_find_vector2(const char *name, const char *mapset)
find a vector map (look but don't touch)
void GS_v3cross(float *v1, float *v2, float *v3)
Get the cross product v3 = v1 cross v2.
int Vect_get_area_points(struct Map_info *Map, int area, struct line_pnts *BPoints)
Returns the polygon array of points in BPoints.
int Vect_set_open_level(int level)
Predetermine level at which a map will be opened for reading.
void G_message(const char *msg,...)
Print a message to stderr.
int Vect_set_constraint_region(struct Map_info *Map, double n, double s, double e, double w, double t, double b)
Set constraint region.
int Vect_open_old(struct Map_info *Map, const char *name, const char *mapset)
Open existing vector for reading.
int Vect_close(struct Map_info *Map)
Close vector data file.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
char * G_fully_qualified_name(const char *name, const char *mapset)
fully qualified file name
void sub_Vectmem(int minus)
Tracking memory.