23 #include <grass/glocale.h>
24 #include <grass/gis.h>
25 #include <grass/Vect.h>
31 G_fatal_error(_(
"Requested format is not compiled in this version"));
36 static int (*Build_array[]) () = {
68 return (Map->plus.built);
109 struct Plus_head *plus;
112 G_debug(3,
"Vect_build(): build = %d", build);
117 Map->support_updated = 1;
119 Map->plus.Spidx_built = 1;
122 if (build > GV_BUILD_NONE) {
123 G_message(_(
"Building topology for vector map <%s>..."),
126 plus->with_z = Map->head.with_z;
127 plus->spidx_with_z = Map->head.with_z;
129 if (build == GV_BUILD_ALL) {
134 ret = ((*Build_array[Map->format]) (Map, build));
140 if (build > GV_BUILD_NONE) {
144 Map->level = LEVEL_2;
145 plus->mode = GV_MODE_WRITE;
147 if (build == GV_BUILD_ALL) {
148 plus->cidx_up_to_date = 1;
152 if (build > GV_BUILD_NONE) {
153 G_message(_(
"Number of nodes: %d"), plus->n_nodes);
154 G_message(_(
"Number of primitives: %d"), plus->n_lines);
155 G_message(_(
"Number of points: %d"), plus->n_plines);
156 G_message(_(
"Number of lines: %d"), plus->n_llines);
157 G_message(_(
"Number of boundaries: %d"), plus->n_blines);
158 G_message(_(
"Number of centroids: %d"), plus->n_clines);
160 if (plus->n_flines > 0)
161 G_message(_(
"Number of faces: %d"), plus->n_flines);
163 if (plus->n_klines > 0)
164 G_message(_(
"Number of kernels: %d"), plus->n_klines);
167 if (plus->built >= GV_BUILD_AREAS) {
168 int line, nlines, area, nareas, err_boundaries, err_centr_out,
169 err_centr_dupl, err_nocentr;
171 struct Plus_head *Plus;
176 err_boundaries = err_centr_out = err_centr_dupl = 0;
177 for (line = 1; line <= nlines; line++) {
178 Line = Plus->Line[line];
181 if (Line->type == GV_BOUNDARY &&
182 (Line->left == 0 || Line->right == 0)) {
183 G_debug(3,
"line = %d left = %d right = %d", line, Line->left,
187 if (Line->type == GV_CENTROID) {
190 else if (Line->left < 0)
197 for (area = 1; area <= nareas; area++) {
205 G_message(_(
"Number of areas: %d"), plus->n_areas);
206 G_message(_(
"Number of isles: %d"), plus->n_isles);
209 G_message(_(
"Number of incorrect boundaries: %d"),
213 G_message(_(
"Number of centroids outside area: %d"),
217 G_message(_(
"Number of duplicate centroids: %d"),
221 G_message(_(
"Number of areas without centroid: %d"),
225 else if (build > GV_BUILD_NONE) {
241 struct Plus_head *plus;
242 char fname[GPATH_MAX],
buf[GPATH_MAX];
245 G_debug(1,
"Vect_save_topo()");
250 sprintf(buf,
"%s/%s", GRASS_VECT_DIRECTORY, Map->name);
252 G_debug(1,
"Open topo: %s", fname);
254 fp.file = fopen(fname,
"w");
255 if (fp.file ==
NULL) {
256 G_warning(_(
"Unable to open topo file for write <%s>"), fname);
264 G_warning(_(
"Error writing out topo file"));
284 int i, j, line, isle;
290 struct Plus_head *plus;
294 fprintf(out,
"---------- TOPOLOGY DUMP ----------\n");
298 fprintf(out,
"N,S,E,W,T,B: %f, %f, %f, %f, %f, %f\n", box.N, box.S,
299 box.E, box.W, box.T, box.B);
302 fprintf(out,
"Nodes (%d nodes, alive + dead ):\n", plus->n_nodes);
303 for (i = 1; i <= plus->n_nodes; i++) {
304 if (plus->Node[i] ==
NULL) {
307 Node = plus->Node[i];
308 fprintf(out,
"node = %d, n_lines = %d, xyz = %f, %f, %f\n", i,
309 Node->n_lines, Node->x, Node->y, Node->z);
310 for (j = 0; j < Node->n_lines; j++) {
311 line = Node->lines[j];
312 Line = plus->Line[abs(line)];
313 fprintf(out,
" line = %3d, type = %d, angle = %f\n", line,
314 Line->type, Node->angles[j]);
319 fprintf(out,
"Lines (%d lines, alive + dead ):\n", plus->n_lines);
320 for (i = 1; i <= plus->n_lines; i++) {
321 if (plus->Line[i] ==
NULL) {
324 Line = plus->Line[i];
325 fprintf(out,
"line = %d, type = %d, offset = %ld n1 = %d, n2 = %d, "
326 "left/area = %d, right = %d\n",
327 i, Line->type, Line->offset, Line->N1, Line->N2,
328 Line->left, Line->right);
329 fprintf(out,
"N,S,E,W,T,B: %f, %f, %f, %f, %f, %f\n", Line->N,
330 Line->S, Line->E, Line->W, Line->T, Line->B);
334 fprintf(out,
"Areas (%d areas, alive + dead ):\n", plus->n_areas);
335 for (i = 1; i <= plus->n_areas; i++) {
336 if (plus->Area[i] ==
NULL) {
339 Area = plus->Area[i];
341 fprintf(out,
"area = %d, n_lines = %d, n_isles = %d centroid = %d\n",
342 i, Area->n_lines, Area->n_isles, Area->centroid);
344 fprintf(out,
"N,S,E,W,T,B: %f, %f, %f, %f, %f, %f\n", Area->N,
345 Area->S, Area->E, Area->W, Area->T, Area->B);
347 for (j = 0; j < Area->n_lines; j++) {
348 line = Area->lines[j];
349 Line = plus->Line[abs(line)];
350 fprintf(out,
" line = %3d\n", line);
352 for (j = 0; j < Area->n_isles; j++) {
353 isle = Area->isles[j];
354 fprintf(out,
" isle = %3d\n", isle);
359 fprintf(out,
"Islands (%d islands, alive + dead ):\n", plus->n_isles);
360 for (i = 1; i <= plus->n_isles; i++) {
361 if (plus->Isle[i] ==
NULL) {
364 Isle = plus->Isle[i];
366 fprintf(out,
"isle = %d, n_lines = %d area = %d\n", i, Isle->n_lines,
369 fprintf(out,
"N,S,E,W,T,B: %f, %f, %f, %f, %f, %f\n", Isle->N,
370 Isle->S, Isle->E, Isle->W, Isle->T, Isle->B);
372 for (j = 0; j < Isle->n_lines; j++) {
373 line = Isle->lines[j];
374 Line = plus->Line[abs(line)];
375 fprintf(out,
" line = %3d\n", line);
392 struct Plus_head *plus;
393 char fname[GPATH_MAX],
buf[GPATH_MAX];
396 G_debug(1,
"Vect_save_spatial_index()");
401 sprintf(buf,
"%s/%s", GRASS_VECT_DIRECTORY, Map->name);
403 G_debug(1,
"Open sidx: %s", fname);
405 fp.file = fopen(fname,
"w");
406 if (fp.file ==
NULL) {
407 G_warning(_(
"Unable open spatial index file for write <%s>"), fname);
415 G_warning(_(
"Error writing out spatial index file"));
435 if (!(Map->plus.Spidx_built)) {
439 fprintf(out,
"---------- SPATIAL INDEX DUMP ----------\n");
int Vect_build_nat(struct Map_info *Map, int build)
Build topology.
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int Vect_get_area_centroid(struct Map_info *Map, int area)
Returns centroid number of area.
int dig_dump_spidx(FILE *fp, struct Plus_head *Plus)
int Vect_save_spatial_index(struct Map_info *Map)
Save spatial index file.
int Vect_build_sidx_from_topo(struct Map_info *Map)
Create spatial index from topo if necessary.
int Vect_build_ogr(struct Map_info *Map, int build)
Build topology.
int Vect_save_topo(struct Map_info *Map)
Save topology file for vector map.
int Vect_get_num_areas(struct Map_info *map)
Get number of areas in vector map.
int dig_write_plus_file(GVFILE *fp_plus, struct Plus_head *Plus)
Writes topo structure to topo file.
void dig_init_portable(struct Port_info *port, int byte_order)
char * G__file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
void G_verbose_message(const char *msg,...)
Print a message to stderr but only if module is in verbose mode.
int Vect_build(struct Map_info *Map)
Build topology for vector map.
void G_message(const char *msg,...)
Print a message to stderr.
int Vect_topo_dump(struct Map_info *Map, FILE *out)
Dump topology to file.
void dig_cidx_sort(struct Plus_head *Plus)
int Vect_box_copy(BOUND_BOX *A, BOUND_BOX *B)
Copy box B to box A.
void dig_cidx_free(struct Plus_head *Plus)
int dig_write_spidx(GVFILE *fp, struct Plus_head *Plus)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int dig_cidx_init(struct Plus_head *Plus)
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int Vect_get_num_lines(struct Map_info *map)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
int Vect_get_built(struct Map_info *Map)
Return current highest built level (part)
int G_debug(int level, const char *msg,...)
Print debugging message.
void dig_file_init(GVFILE *file)
Initialize GVFILE.
int Vect_spatial_index_dump(struct Map_info *Map, FILE *out)
Dump spatial index to file.
int dig__byte_order_out()
int Vect_area_alive(struct Map_info *Map, int area)
Check if area is alive or dead.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int Vect_build_partial(struct Map_info *Map, int build)
Build partial topology for vector map.