[GRASS-SVN] r38994 - grass/trunk/vector/v.info
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Sep 5 13:10:22 EDT 2009
Author: martinl
Date: 2009-09-05 13:10:21 -0400 (Sat, 05 Sep 2009)
New Revision: 38994
Added:
grass/trunk/vector/v.info/level1.c
grass/trunk/vector/v.info/local_proto.h
grass/trunk/vector/v.info/parse.c
grass/trunk/vector/v.info/print.c
Modified:
grass/trunk/vector/v.info/main.c
grass/trunk/vector/v.info/v.info.html
Log:
v.info: major clean up
Added: grass/trunk/vector/v.info/level1.c
===================================================================
--- grass/trunk/vector/v.info/level1.c (rev 0)
+++ grass/trunk/vector/v.info/level1.c 2009-09-05 17:10:21 UTC (rev 38994)
@@ -0,0 +1,88 @@
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+/* code taken from Vect_build_nat() */
+int level_one_info(struct Map_info *Map)
+{
+ struct Plus_head *plus;
+ int i, type, first = 1;
+ off_t offset;
+ struct line_pnts *Points;
+ struct line_cats *Cats;
+ struct bound_box box;
+
+ int n_primitives, n_points, n_lines, n_boundaries, n_centroids, n_kernels;
+
+ G_debug(1, "Count vector objects for level 1");
+
+ plus = &(Map->plus);
+
+ n_primitives = n_points = n_lines = n_boundaries = n_centroids = n_kernels = 0;
+
+ Points = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
+
+ Vect_rewind(Map);
+ /* G_message(_("Registering primitives...")); */
+ i = 1;
+ while (1) {
+ /* register line */
+ type = Vect_read_next_line(Map, Points, Cats);
+
+ /* Note: check for dead lines is not needed, because they are skipped by V1_read_next_line_nat() */
+ if (type == -1) {
+ G_warning(_("Unable to read vector map"));
+ return 0;
+ }
+ else if (type == -2) {
+ break;
+ }
+
+ /* count features */
+ n_primitives++;
+
+ if (type & GV_POINT) /* probably most common */
+ n_points++;
+ else if (type & GV_LINE)
+ n_lines++;
+ else if (type & GV_BOUNDARY)
+ n_boundaries++;
+ else if (type & GV_CENTROID)
+ n_centroids++;
+ else if (type & GV_KERNEL)
+ n_kernels++;
+
+ offset = Map->head.last_offset;
+
+ G_debug(3, "Register line: offset = %lu", (unsigned long)offset);
+ dig_line_box(Points, &box);
+ if (first == 1) {
+ Vect_box_copy(&(plus->box), &box);
+ first = 0;
+ }
+ else
+ Vect_box_extend(&(plus->box), &box);
+
+ /* can't print progress, unfortunately */
+/*
+ if (G_verbose() > G_verbose_min() && i % 1000 == 0) {
+ if (format == G_INFO_FORMAT_PLAIN)
+ fprintf(stderr, "%d..", i);
+ else
+ fprintf(stderr, "%11d\b\b\b\b\b\b\b\b\b\b\b", i);
+ }
+ i++;
+*/
+ }
+
+ /* save result in plus */
+ plus->n_lines = n_primitives;
+ plus->n_plines = n_points;
+ plus->n_llines = n_lines;
+ plus->n_blines = n_boundaries;
+ plus->n_clines = n_centroids;
+ plus->n_klines = n_kernels;
+
+ return 1;
+}
Property changes on: grass/trunk/vector/v.info/level1.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Added: grass/trunk/vector/v.info/local_proto.h
===================================================================
--- grass/trunk/vector/v.info/local_proto.h (rev 0)
+++ grass/trunk/vector/v.info/local_proto.h 2009-09-05 17:10:21 UTC (rev 38994)
@@ -0,0 +1,16 @@
+#include <grass/vector.h>
+
+/* level1.c */
+int level_one_info(struct Map_info *);
+
+/* parse.c */
+void parse_args(int, char**,
+ char **, char**,
+ int *, int *, int *, int *, int *, int *);
+
+/* print.c */
+void format_double(double, char *);
+void print_region(const struct Map_info *);
+void print_topo(const struct Map_info *);
+void print_columns(const struct Map_info *, const char *, const char *);
+void print_info(const struct Map_info *);
Property changes on: grass/trunk/vector/v.info/local_proto.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Modified: grass/trunk/vector/v.info/main.c
===================================================================
--- grass/trunk/vector/v.info/main.c 2009-09-05 17:05:59 UTC (rev 38993)
+++ grass/trunk/vector/v.info/main.c 2009-09-05 17:10:21 UTC (rev 38994)
@@ -1,62 +1,36 @@
-
/***************************************************************
*
* MODULE: v.info
*
* AUTHOR(S): CERL, updated to 5.7 by Markus Neteler
+ * Update to 7.0 by Martin Landa
+ * Support for level 1 by Markus Metz (2009)
*
- * PURPOSE: print vector map info
+ * PURPOSE: Print vector map info
*
- * COPYRIGHT: (C) 2002 by the GRASS Development Team
+ * COPYRIGHT: (C) 2002-2009 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.
+ * This program is free software under the GNU General
+ * Public License (>=v2). Read the file COPYING that
+ * comes with GRASS for details.
*
**************************************************************/
-#include <string.h>
-#include <stdlib.h>
+
#include <grass/gis.h>
#include <grass/vector.h>
-#include <grass/dbmi.h>
#include <grass/glocale.h>
-#define printline(x) fprintf (stdout, " | %-74.74s |\n", x)
-#define divider(x) \
- fprintf (stdout, " %c", x); \
- for (i = 0; i < 76; i++ ) \
- fprintf ( stdout, "-" ); \
- fprintf (stdout, "%c\n", x)
+#include "local_proto.h"
-/* the vector header is here:
- include/vect/dig_structs.h
-
- the vector API is here:
- lib/vector/Vlib/level_two.c
- */
-
-void format_double(double, char *);
-int level_one_info(struct Map_info *);
-
int main(int argc, char *argv[])
{
struct GModule *module;
- struct Option *in_opt, *fieldopt;
- struct Flag *histf, *columns, *gflag, *tflag, *mflag, *lflag;
- struct Map_info Map;
- struct bound_box box;
- char line[200], buf[1001];
- int i;
- int with_z;
- struct field_info *fi;
- dbDriver *driver = NULL;
- dbHandle handle;
- dbString table_name;
- dbTable *table;
- int field, num_dblinks, ncols, col;
- char tmp1[100], tmp2[100];
+ char *input_opt, *field_opt;
+ int hist_flag, col_flag, reg_flag, topo_flag, title_flag, level1_flag;
+
+ struct Map_info Map;
+
G_gisinit(argv[0]);
module = G_define_module();
@@ -64,282 +38,53 @@
G_add_keyword(_("metadata"));
G_add_keyword(_("history"));
module->description =
- _("Outputs basic information about a user-specified vector map.");
+ _("Outputs basic information about a vector map.");
- /* get G_OPT_ from include/gis.h */
- in_opt = G_define_standard_option(G_OPT_V_MAP);
+ parse_args(argc, argv,
+ &input_opt, &field_opt,
+ &hist_flag, &col_flag, ®_flag, &topo_flag, &title_flag, &level1_flag);
- fieldopt = G_define_standard_option(G_OPT_V_FIELD);
-
- histf = G_define_flag();
- histf->key = 'h';
- histf->description = _("Print vector history instead of info");
- histf->guisection = _("Print");
-
- columns = G_define_flag();
- columns->key = 'c';
- columns->description =
- _("Print types/names of table columns for specified layer instead of info");
- columns->guisection = _("Print");
-
- gflag = G_define_flag();
- gflag->key = 'g';
- gflag->description = _("Print map region only");
- gflag->guisection = _("Print");
-
- mflag = G_define_flag();
- mflag->key = 'm';
- mflag->description = _("Print map title only");
- mflag->guisection = _("Print");
-
- tflag = G_define_flag();
- tflag->key = 't';
- tflag->description = _("Print topology information only");
- tflag->guisection = _("Print");
-
- lflag = G_define_flag();
- lflag->key = 'l';
- lflag->description = _("Open Vector without topology (level 1)");
-
- if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
-
- if (lflag->answer) {
+ if (level1_flag) {
Vect_set_open_level(1); /* no topology */
- tflag->answer = 0;
+ if (topo_flag)
+ G_warning(_("Vector map requested on level1 (flag -t ignored)"));
+ topo_flag = 0;
}
else
Vect_set_open_level(2); /* topology requested */
-
- if (lflag->answer) {
- Vect_open_old(&Map, in_opt->answer, "");
+
+ if (level1_flag) {
+ Vect_open_old(&Map, input_opt, ""); /* level 1 */
level_one_info(&Map);
}
else
- Vect_open_old_head(&Map, in_opt->answer, "");
+ Vect_open_old_head(&Map, input_opt, ""); /* level 2 */
- with_z = Vect_is_3d(&Map);
-
- if (histf->answer) {
+ if (hist_flag) {
+ char buf[1001];
+
Vect_hist_rewind(&Map);
while (Vect_hist_read(buf, 1000, &Map) != NULL) {
fprintf(stdout, "%s\n", buf);
}
}
- else if (mflag->answer) {
+ else if (title_flag) {
fprintf(stdout, "%s\n", Vect_get_map_name(&Map));
}
- else if (gflag->answer || tflag->answer) {
- if (gflag->answer) {
- Vect_get_map_box(&Map, &box);
- G_format_northing(box.N, tmp1, Vect_get_proj(&Map));
- G_format_northing(box.S, tmp2, Vect_get_proj(&Map));
- fprintf(stdout, "north=%s\n", tmp1);
- fprintf(stdout, "south=%s\n", tmp2);
-
- G_format_easting(box.E, tmp1, Vect_get_proj(&Map));
- G_format_easting(box.W, tmp2, Vect_get_proj(&Map));
- fprintf(stdout, "east=%s\n", tmp1);
- fprintf(stdout, "west=%s\n", tmp2);
- fprintf(stdout, "top=%f\n", box.T);
- fprintf(stdout, "bottom=%f\n", box.B);
+ else if (reg_flag || topo_flag) {
+ if (reg_flag) {
+ print_region(&Map);
}
- if (tflag->answer) {
- long int nprimitives = 0;
-
- nprimitives += (long)Vect_get_num_primitives(&Map, GV_POINT);
- nprimitives += (long)Vect_get_num_primitives(&Map, GV_LINE);
- nprimitives += (long)Vect_get_num_primitives(&Map, GV_BOUNDARY);
- nprimitives += (long)Vect_get_num_primitives(&Map, GV_FACE);
- nprimitives += (long)Vect_get_num_primitives(&Map, GV_CENTROID);
- nprimitives += (long)Vect_get_num_primitives(&Map, GV_KERNEL);
-
-
- fprintf(stdout, "nodes=%ld\n", (long)Vect_get_num_nodes(&Map));
- fflush(stdout);
- fprintf(stdout, "points=%ld\n",
- (long)Vect_get_num_primitives(&Map, GV_POINT));
- fflush(stdout);
-
- fprintf(stdout, "lines=%ld\n",
- (long)Vect_get_num_primitives(&Map, GV_LINE));
- fflush(stdout);
-
- fprintf(stdout, "boundaries=%ld\n",
- (long)Vect_get_num_primitives(&Map, GV_BOUNDARY));
- fflush(stdout);
-
- fprintf(stdout, "centroids=%ld\n",
- (long)Vect_get_num_primitives(&Map, GV_CENTROID));
- fflush(stdout);
-
- fprintf(stdout, "areas=%ld\n", (long)Vect_get_num_areas(&Map));
- fflush(stdout);
-
- fprintf(stdout, "islands=%ld\n",
- (long)Vect_get_num_islands(&Map));
- fflush(stdout);
-
- fprintf(stdout, "faces=%ld\n",
- (long)Vect_get_num_primitives(&Map, GV_FACE));
- fflush(stdout);
-
- fprintf(stdout, "kernels=%ld\n",
- (long)Vect_get_num_primitives(&Map, GV_KERNEL));
- fflush(stdout);
-
- fprintf(stdout, "primitives=%ld\n", nprimitives);
- fflush(stdout);
-
- fprintf(stdout, "map3d=%d\n", Vect_is_3d(&Map));
- fflush(stdout);
+ if (topo_flag) {
+ print_topo(&Map);
}
}
else {
- if (columns->answer) {
- num_dblinks = Vect_get_num_dblinks(&Map);
- if (num_dblinks <= 0) {
- G_fatal_error(_("Database connection for map <%s> is not defined in DB file"),
- in_opt->answer);
- }
- else { /* num_dblinks > 0 */
-
- field = atoi(fieldopt->answer);
- G_message(_("Displaying column types/names for database connection of layer %d:"),
- field);
- if ((fi = Vect_get_field(&Map, field)) == NULL)
- G_fatal_error(_("Database connection not defined for layer %d"),
- field);
- driver = db_start_driver(fi->driver);
- if (driver == NULL)
- G_fatal_error(_("Unable to open driver <%s>"),
- fi->driver);
- db_init_handle(&handle);
- db_set_handle(&handle, fi->database, NULL);
- if (db_open_database(driver, &handle) != DB_OK)
- G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
- fi->database, fi->driver);
- db_init_string(&table_name);
- db_set_string(&table_name, fi->table);
- if (db_describe_table(driver, &table_name, &table) != DB_OK)
- G_fatal_error(_("Unable to describe table <%s>"),
- fi->table);
-
- ncols = db_get_table_number_of_columns(table);
- for (col = 0; col < ncols; col++)
- fprintf(stdout, "%s|%s\n",
- db_sqltype_name(db_get_column_sqltype
- (db_get_table_column
- (table, col))),
- db_get_column_name(db_get_table_column
- (table, col)));
-
- db_close_database(driver);
- db_shutdown_driver(driver);
- }
+ if (col_flag) {
+ print_columns(&Map, input_opt, field_opt);
}
else {
- divider('+');
- sprintf(line, _("Layer: %s"), Vect_get_name(&Map));
- printline(line);
- sprintf(line, _("Mapset: %s"), Vect_get_mapset(&Map));
- printline(line);
- sprintf(line, _("Location: %s"), G_location());
- printline(line);
- sprintf(line, _("Database: %s"), G_gisdbase());
- printline(line);
- sprintf(line, _("Title: %s"), Vect_get_map_name(&Map));
- printline(line);
- sprintf(line, _("Map scale: 1:%d"), Vect_get_scale(&Map));
- printline(line);
- sprintf(line, _("Map format: %s"), Vect_maptype_info(&Map));
- printline(line);
- sprintf(line, _("Name of creator: %s"), Vect_get_person(&Map));
- printline(line);
- sprintf(line, _("Organization: %s"),
- Vect_get_organization(&Map));
- printline(line);
- sprintf(line, _("Source date: %s"), Vect_get_map_date(&Map));
- printline(line);
-
- divider('|');
-
- sprintf(line, _(" Type of Map: %s (level: %i) "),
- _("vector"), Vect_level(&Map));
-
- printline(line);
-
- if (Vect_level(&Map) > 0) {
- printline("");
- sprintf(line,
- _(" Number of points: %-9ld Number of areas: %-9ld"),
- (long)Vect_get_num_primitives(&Map, GV_POINT),
- (long)Vect_get_num_areas(&Map));
- printline(line);
- sprintf(line,
- _(" Number of lines: %-9ld Number of islands: %-9ld"),
- (long)Vect_get_num_primitives(&Map, GV_LINE),
- (long)Vect_get_num_islands(&Map));
- printline(line);
- sprintf(line,
- _(" Number of boundaries: %-9ld Number of faces: %-9ld"),
- (long)Vect_get_num_primitives(&Map, GV_BOUNDARY),
- (long)Vect_get_num_primitives(&Map, GV_FACE));
- printline(line);
- sprintf(line,
- _(" Number of centroids: %-9ld Number of kernels: %-9ld"),
- (long)Vect_get_num_primitives(&Map, GV_CENTROID),
- (long)Vect_get_num_primitives(&Map, GV_KERNEL));
- printline(line);
- printline("");
- sprintf(line, _(" Map is 3D: %s"),
- Vect_is_3d(&Map) ? "Yes" : "No");
- printline(line);
- sprintf(line, _(" Number of dblinks: %-9ld"),
- (long)Vect_get_num_dblinks(&Map));
- printline(line);
- }
-
- printline("");
- /* this differs from r.info in that proj info IS taken from the map here, not the location settings */
- /* Vect_get_proj_name() and _zone() are typically unset?! */
- if (G_projection() == PROJECTION_UTM)
- sprintf(line, _(" Projection: %s (zone %d)"),
- Vect_get_proj_name(&Map), Vect_get_zone(&Map));
- else
- sprintf(line, _(" Projection: %s"),
- Vect_get_proj_name(&Map));
- printline(line);
-
- Vect_get_map_box(&Map, &box);
-
- G_format_northing(box.N, tmp1, G_projection());
- G_format_northing(box.S, tmp2, G_projection());
- sprintf(line, " N: %17s S: %17s", tmp1, tmp2);
- printline(line);
-
- G_format_easting(box.E, tmp1, G_projection());
- G_format_easting(box.W, tmp2, G_projection());
- sprintf(line, " E: %17s W: %17s", tmp1, tmp2);
- printline(line);
-
- if (Vect_is_3d(&Map)) {
- format_double(box.B, tmp1);
- format_double(box.T, tmp2);
- sprintf(line, " B: %17s T: %17s", tmp1, tmp2);
- printline(line);
- }
- printline("");
-
- format_double(Vect_get_thresh(&Map), tmp1);
- sprintf(line, _(" Digitization threshold: %s"), tmp1);
- printline(line);
- sprintf(line, _(" Comments:"));
- printline(line);
- sprintf(line, " %s", Vect_get_comment(&Map));
- printline(line);
- divider('+');
- fprintf(stdout, "\n");
+ print_info(&Map);
}
}
@@ -348,95 +93,3 @@
return (EXIT_SUCCESS);
}
-
-/* cloned from lib/gis/wind_format.c */
-void format_double(double value, char *buf)
-{
- sprintf(buf, "%.8f", value);
- G_trim_decimal(buf);
-}
-
-/* code taken from Vect_build_nat() */
-int level_one_info(struct Map_info *Map)
-{
- struct Plus_head *plus;
- int i, type, first = 1;
- off_t offset;
- struct line_pnts *Points;
- struct line_cats *Cats;
- struct bound_box box;
-
- int n_primitives, n_points, n_lines, n_boundaries, n_centroids, n_kernels;
-
- G_debug(1, "Count vector objects for level 1");
-
- plus = &(Map->plus);
-
- n_primitives = n_points = n_lines = n_boundaries = n_centroids = n_kernels = 0;
-
- Points = Vect_new_line_struct();
- Cats = Vect_new_cats_struct();
-
- Vect_rewind(Map);
- /* G_message(_("Registering primitives...")); */
- i = 1;
- while (1) {
- /* register line */
- type = Vect_read_next_line(Map, Points, Cats);
-
- /* Note: check for dead lines is not needed, because they are skipped by V1_read_next_line_nat() */
- if (type == -1) {
- G_warning(_("Unable to read vector map"));
- return 0;
- }
- else if (type == -2) {
- break;
- }
-
- /* count features */
- n_primitives++;
-
- if (type & GV_POINT) /* probably most common */
- n_points++;
- else if (type & GV_LINE)
- n_lines++;
- else if (type & GV_BOUNDARY)
- n_boundaries++;
- else if (type & GV_CENTROID)
- n_centroids++;
- else if (type & GV_KERNEL)
- n_kernels++;
-
- offset = Map->head.last_offset;
-
- G_debug(3, "Register line: offset = %lu", (unsigned long)offset);
- dig_line_box(Points, &box);
- if (first == 1) {
- Vect_box_copy(&(plus->box), &box);
- first = 0;
- }
- else
- Vect_box_extend(&(plus->box), &box);
-
- /* can't print progress, unfortunately */
-/*
- if (G_verbose() > G_verbose_min() && i % 1000 == 0) {
- if (format == G_INFO_FORMAT_PLAIN)
- fprintf(stderr, "%d..", i);
- else
- fprintf(stderr, "%11d\b\b\b\b\b\b\b\b\b\b\b", i);
- }
- i++;
-*/
- }
-
- /* save result in plus */
- plus->n_lines = n_primitives;
- plus->n_plines = n_points;
- plus->n_llines = n_lines;
- plus->n_blines = n_boundaries;
- plus->n_clines = n_centroids;
- plus->n_klines = n_kernels;
-
- return 1;
-}
Added: grass/trunk/vector/v.info/parse.c
===================================================================
--- grass/trunk/vector/v.info/parse.c (rev 0)
+++ grass/trunk/vector/v.info/parse.c 2009-09-05 17:10:21 UTC (rev 38994)
@@ -0,0 +1,59 @@
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+void parse_args(int argc, char** argv,
+ char** input, char** field,
+ int* history, int* columns, int* region, int* topo, int* title, int* level1)
+{
+ struct Option *input_opt, *field_opt;
+ struct Flag *hist_flag, *col_flag, *region_flag, *topo_flag, *title_flag, *level1_flag;
+
+ input_opt = G_define_standard_option(G_OPT_V_MAP);
+
+ field_opt = G_define_standard_option(G_OPT_V_FIELD);
+
+ hist_flag = G_define_flag();
+ hist_flag->key = 'h';
+ hist_flag->description = _("Print vector history instead of info");
+ hist_flag->guisection = _("Print");
+
+ col_flag = G_define_flag();
+ col_flag->key = 'c';
+ col_flag->description =
+ _("Print types/names of table columns for specified layer instead of info");
+ col_flag->guisection = _("Print");
+
+ region_flag = G_define_flag();
+ region_flag->key = 'g';
+ region_flag->description = _("Print map region only");
+ region_flag->guisection = _("Print");
+
+ title_flag = G_define_flag();
+ title_flag->key = 'm';
+ title_flag->description = _("Print map title only");
+ title_flag->guisection = _("Print");
+
+ topo_flag = G_define_flag();
+ topo_flag->key = 't';
+ topo_flag->description = _("Print topology information only");
+ topo_flag->guisection = _("Print");
+
+ level1_flag = G_define_flag();
+ level1_flag->key = 'l';
+ level1_flag->description = _("Open Vector without topology (level 1)");
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ *input = G_store(input_opt->answer);
+ *field = G_store(field_opt->answer);
+
+ *history = hist_flag-> answer ? 1 : 0;
+ *columns = col_flag-> answer ? 1 : 0;
+ *region = region_flag-> answer ? 1 : 0;
+ *title = title_flag-> answer ? 1 : 0;
+ *topo = topo_flag-> answer ? 1 : 0;
+ *level1 = level1_flag-> answer ? 1 : 0;
+}
Property changes on: grass/trunk/vector/v.info/parse.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Added: grass/trunk/vector/v.info/print.c
===================================================================
--- grass/trunk/vector/v.info/print.c (rev 0)
+++ grass/trunk/vector/v.info/print.c 2009-09-05 17:10:21 UTC (rev 38994)
@@ -0,0 +1,312 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+#define printline(x) fprintf (stdout, " | %-74.74s |\n", x)
+#define divider(x) \
+ fprintf (stdout, " %c", x); \
+ for (i = 0; i < 76; i++ ) \
+ fprintf ( stdout, "-" ); \
+ fprintf (stdout, "%c\n", x)
+
+/* cloned from lib/gis/wind_format.c */
+void format_double(double value, char *buf)
+{
+ sprintf(buf, "%.8f", value);
+ G_trim_decimal(buf);
+}
+
+void print_region(const struct Map_info *Map)
+{
+ char tmp1[100], tmp2[100];
+
+ struct bound_box box;
+
+ Vect_get_map_box(Map, &box);
+ G_format_northing(box.N, tmp1, Vect_get_proj(Map));
+ G_format_northing(box.S, tmp2, Vect_get_proj(Map));
+ fprintf(stdout, "north=%s\n", tmp1);
+ fprintf(stdout, "south=%s\n", tmp2);
+
+ G_format_easting(box.E, tmp1, Vect_get_proj(Map));
+ G_format_easting(box.W, tmp2, Vect_get_proj(Map));
+ fprintf(stdout, "east=%s\n", tmp1);
+ fprintf(stdout, "west=%s\n", tmp2);
+ fprintf(stdout, "top=%f\n", box.T);
+ fprintf(stdout, "bottom=%f\n", box.B);
+}
+
+void print_topo(const struct Map_info *Map)
+{
+ int with_z;
+ long nprimitives;
+
+ nprimitives = 0;
+ with_z = Vect_is_3d(Map);
+
+ nprimitives += Vect_get_num_primitives(Map, GV_POINT);
+ nprimitives += Vect_get_num_primitives(Map, GV_LINE);
+ nprimitives += Vect_get_num_primitives(Map, GV_BOUNDARY);
+ nprimitives += Vect_get_num_primitives(Map, GV_CENTROID);
+
+ if (with_z) {
+ nprimitives += Vect_get_num_primitives(Map, GV_FACE);
+ nprimitives += Vect_get_num_primitives(Map, GV_KERNEL);
+ }
+
+
+ fprintf(stdout, "nodes=%ld\n",
+ Vect_get_num_nodes(Map));
+ fflush(stdout);
+
+ fprintf(stdout, "points=%ld\n",
+ Vect_get_num_primitives(Map, GV_POINT));
+ fflush(stdout);
+
+ fprintf(stdout, "lines=%ld\n",
+ Vect_get_num_primitives(Map, GV_LINE));
+ fflush(stdout);
+
+ fprintf(stdout, "boundaries=%ld\n",
+ Vect_get_num_primitives(Map, GV_BOUNDARY));
+ fflush(stdout);
+
+ fprintf(stdout, "centroids=%ld\n",
+ Vect_get_num_primitives(Map, GV_CENTROID));
+ fflush(stdout);
+
+ fprintf(stdout, "areas=%ld\n", Vect_get_num_areas(Map));
+ fflush(stdout);
+
+ fprintf(stdout, "islands=%ld\n",
+ Vect_get_num_islands(Map));
+ fflush(stdout);
+
+ if (with_z) {
+ fprintf(stdout, "faces=%ld\n",
+ Vect_get_num_primitives(Map, GV_FACE));
+ fflush(stdout);
+
+ fprintf(stdout, "kernels=%ld\n",
+ Vect_get_num_primitives(Map, GV_KERNEL));
+ fflush(stdout);
+
+ fprintf(stdout, "volumes=%ld\n",
+ Vect_get_num_primitives(Map, GV_VOLUME));
+ fflush(stdout);
+
+ fprintf(stdout, "holes=%ld\n",
+ Vect_get_num_holes(Map));
+ fflush(stdout);
+ }
+
+ fprintf(stdout, "primitives=%ld\n", nprimitives);
+ fflush(stdout);
+
+ fprintf(stdout, "map3d=%d\n", Vect_is_3d(Map));
+ fflush(stdout);
+}
+
+void print_columns(const struct Map_info *Map, const char *input_opt, const char *field_opt)
+{
+ int num_dblinks, field, col, ncols;
+
+ struct field_info *fi;
+ dbDriver *driver = NULL;
+ dbHandle handle;
+ dbString table_name;
+ dbTable *table;
+
+ num_dblinks = Vect_get_num_dblinks(Map);
+
+ if (num_dblinks <= 0) {
+ G_fatal_error(_("Database connection for map <%s> is not defined in DB file"),
+ input_opt);
+ }
+
+ field = atoi(field_opt);
+ G_message(_("Displaying column types/names for database connection of layer %d:"),
+ field);
+
+ if ((fi = Vect_get_field(Map, field)) == NULL)
+ G_fatal_error(_("Database connection not defined for layer %d"),
+ field);
+ driver = db_start_driver(fi->driver);
+ if (driver == NULL)
+ G_fatal_error(_("Unable to open driver <%s>"),
+ fi->driver);
+ db_init_handle(&handle);
+ db_set_handle(&handle, fi->database, NULL);
+ if (db_open_database(driver, &handle) != DB_OK)
+ G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+ fi->database, fi->driver);
+ db_init_string(&table_name);
+ db_set_string(&table_name, fi->table);
+ if (db_describe_table(driver, &table_name, &table) != DB_OK)
+ G_fatal_error(_("Unable to describe table <%s>"),
+ fi->table);
+
+ ncols = db_get_table_number_of_columns(table);
+ for (col = 0; col < ncols; col++)
+ fprintf(stdout, "%s|%s\n",
+ db_sqltype_name(db_get_column_sqltype
+ (db_get_table_column
+ (table, col))),
+ db_get_column_name(db_get_table_column
+ (table, col)));
+
+ db_close_database(driver);
+ db_shutdown_driver(driver);
+}
+
+void print_info(const struct Map_info *Map)
+{
+ int i;
+ char line[100];
+ char tmp1[100], tmp2[100];
+
+ struct bound_box box;
+
+ divider('+');
+ sprintf(line, "%-17s%s", _("Name:"),
+ Vect_get_name(Map));
+ printline(line);
+ sprintf(line, "%-17s%s", _("Mapset:"),
+ Vect_get_mapset(Map));
+ printline(line);
+ sprintf(line, "%-17s%s", _("Location:"),
+ G_location());
+ printline(line);
+ sprintf(line, "%-17s%s", _("Database:"),
+ G_gisdbase());
+ printline(line);
+ sprintf(line, "%-17s%s", _("Title:"),
+ Vect_get_map_name(Map));
+ printline(line);
+ sprintf(line, "%-17s1:%d", _("Map scale:"),
+ Vect_get_scale(Map));
+ printline(line);
+ sprintf(line, "%-17s%s", _("Map format:"),
+ Vect_maptype_info(Map));
+ printline(line);
+ sprintf(line, "%-17s%s", _("Name of creator:"),
+ Vect_get_person(Map));
+ printline(line);
+ sprintf(line, "%-17s%s", _("Organization:"),
+ Vect_get_organization(Map));
+ printline(line);
+ sprintf(line, "%-17s%s", _("Source date:"),
+ Vect_get_map_date(Map));
+ printline(line);
+
+ divider('|');
+
+ sprintf(line, " %s: %s (%s: %i)",
+ _("Type of map"), _("vector"), _("level"), Vect_level(Map));
+
+ printline(line);
+
+ if (Vect_level(Map) > 0) {
+ printline("");
+ sprintf(line,
+ " %-24s%-9ld %-22s%-9ld",
+ _("Number of points:"),
+ Vect_get_num_primitives(Map, GV_POINT),
+ _("Number of centroids:"),
+ Vect_get_num_primitives(Map, GV_CENTROID));
+ printline(line);
+ sprintf(line,
+ " %-24s%-9ld %-22s%-9ld",
+ _("Number of lines:"),
+ Vect_get_num_primitives(Map, GV_LINE),
+ _("Number of boundaries:"),
+ Vect_get_num_primitives(Map, GV_BOUNDARY));
+ printline(line);
+ sprintf(line,
+ " %-24s%-9ld %-22s%-9ld",
+ _("Number of areas:"),
+ Vect_get_num_areas(Map),
+ _("Number of islands:"),
+ Vect_get_num_islands(Map));
+ printline(line);
+ if (Vect_is_3d(Map)) {
+ sprintf(line,
+ " %-24s%-9ld %-22s%-9ld",
+ _("Number of faces:"),
+ Vect_get_num_primitives(Map, GV_FACE),
+ _("Number of kernels:"),
+ Vect_get_num_primitives(Map, GV_KERNEL));
+ printline(line);
+ sprintf(line,
+ " %-24s%-9ld %-22s%-9ld",
+ _("Number of volumes:"),
+ Vect_get_num_volumes(Map),
+ _("Number of holes:"),
+ Vect_get_num_holes(Map));
+ printline(line);
+ }
+ printline("");
+ sprintf(line, " %-24s%s",
+ _("Map is 3D:"),
+ Vect_is_3d(Map) ? _("Yes") : _("No"));
+ printline(line);
+ sprintf(line, " %-24s%-9d",
+ _("Number of dblinks:"),
+ Vect_get_num_dblinks(Map));
+ printline(line);
+ }
+
+ printline("");
+ /* this differs from r.info in that proj info IS taken from the map here, not the location settings */
+ /* Vect_get_proj_name() and _zone() are typically unset?! */
+ if (G_projection() == PROJECTION_UTM)
+ sprintf(line, " %s: %s (%s %d)",
+ _("Projection:"),
+ Vect_get_proj_name(Map),
+ _("zone"), Vect_get_zone(Map));
+ else
+ sprintf(line, " %s: %s",
+ _("Projection"),
+ Vect_get_proj_name(Map));
+
+ printline(line);
+ printline("");
+
+ Vect_get_map_box(Map, &box);
+
+ G_format_northing(box.N, tmp1, G_projection());
+ G_format_northing(box.S, tmp2, G_projection());
+ sprintf(line, " %c: %17s %c: %17s",
+ 'N', tmp1, 'S', tmp2);
+ printline(line);
+
+ G_format_easting(box.E, tmp1, G_projection());
+ G_format_easting(box.W, tmp2, G_projection());
+ sprintf(line, " %c: %17s %c: %17s",
+ 'E', tmp1, 'W', tmp2);
+ printline(line);
+
+ if (Vect_is_3d(Map)) {
+ format_double(box.B, tmp1);
+ format_double(box.T, tmp2);
+ sprintf(line, " %c: %17s %c: %17s",
+ 'B', tmp1, 'T', tmp2);
+ printline(line);
+ }
+ printline("");
+
+ format_double(Vect_get_thresh(Map), tmp1);
+ sprintf(line, " %s: %s", _("Digitization threshold"), tmp1);
+ printline(line);
+ sprintf(line, " %s:", _("Comment"));
+ printline(line);
+ sprintf(line, " %s", Vect_get_comment(Map));
+ printline(line);
+ divider('+');
+ fprintf(stdout, "\n");
+}
Property changes on: grass/trunk/vector/v.info/print.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Modified: grass/trunk/vector/v.info/v.info.html
===================================================================
--- grass/trunk/vector/v.info/v.info.html 2009-09-05 17:05:59 UTC (rev 38993)
+++ grass/trunk/vector/v.info/v.info.html 2009-09-05 17:10:21 UTC (rev 38994)
@@ -1,49 +1,57 @@
<h2>DESCRIPTION</h2>
-<em>v.info</em> reports some basic information about a
-user-specified vector map layer and the topology status.
+<em>v.info</em> reports some basic information (metadata) about a
+user-specified vector map and its topology status.
+
<p>
-Vector are opened without topology on level 1 when the <b>-l</b> flag is
-used. With the <b>-l</b> flag set, vector map extends and number of
-features need to be counted on the fly which may take some time.
+Vector map is opened without topology (i.e., on level 1) when
+the <b>-l</b> flag is used. With the <b>-l</b> flag set, vector map
+extends and number of features need to be counted on the fly which may
+take some time.
<h2>EXAMPLE</h2>
<div class="code"><pre>
-v.info map=test
+v.info map=geology
+----------------------------------------------------------------------------+
- | Mapset: PERMANENT Organization: GRASS Team |
- | Layer: test Source Date: |
- | Orig. Scale: 1:1 |
- | Location: spearfish Name of creator: GRASSUSER |
- | DataBase: /home/user/grassdata |
- | Title: |
- | Map format: native |
+ | Name: geology |
+ | Mapset: PERMANENT |
+ | Location: nc_spm_08 |
+ | Database: /home/martin/grassdata |
+ | Title: North Carolina geology map (polygon map) |
+ | Map scale: 1:1 |
+ | Map format: native |
+ | Name of creator: helena |
+ | Organization: NC OneMap |
+ | Source date: Mon Nov 6 15:48:53 2006 |
|----------------------------------------------------------------------------|
- | Type of Map: Vector (level: 2) |
- | Number of points: 7 |
- | Number of lines: 1386 |
- | Number of centroids: 0 |
- | Number of areas: 0 |
- | Number of faces: 0 |
- | Number of kernels: 0 |
- | Number of islands: 0 |
- | Map is 3D: 0 |
- | Number of dblinks: 1 |
- | Projection: Transverse Mercator (zone 0) |
- | N: 5945486.383 S: 5941117.075 |
- | E: 3573006.924 W: 3567822.941 |
- | B: 0.000 T: 0.000 |
+ | Type of map: vector (level: 2) |
| |
- | Digitize threshold: 0.00000 |
- | Comments: |
+ | Number of points: 0 Number of centroids: 1832 |
+ | Number of lines: 0 Number of boundaries: 3649 |
+ | Number of areas: 1832 Number of islands: 907 |
| |
+ | Map is 3D: No |
+ | Number of dblinks: 1 |
+ | |
+ | Projection: Lambert Conformal Conic |
+ | |
+ | N: 318117.43741634 S: 10875.82723209 |
+ | E: 930172.31282271 W: 123971.19498978 |
+ | |
+ | Digitization threshold: 0 |
+ | Comment: |
+ | |
+----------------------------------------------------------------------------+
</pre></div>
<h2>AUTHOR</h2>
-Radim Blazek, ITC-Irst, Trento, Italy
+Original author CERL<br>
+Updated to GRASS 6 by Radim Blazek, ITC-Irst, Trento, Italy<br>
+Level 1 support by Markus Metz<br>
+Updated to GRASS 7 by Martin Landa, CTU in Prague, Czech Republic
-<p><i>Last changed: $Date$</i></p>
+<p>
+<i>Last changed: $Date$</i></p>
More information about the grass-commit
mailing list