/*! \brief Writes head information to text file (GV_HEAD_ELEMENT) \param Map pointer to Map_info structure \return 0 on success \return -1 on error */ int Vect__write_head(const struct Map_info *Map) { char *path; FILE *head_fp; path = Vect__get_path(Map); head_fp = G_fopen_new(path, GV_HEAD_ELEMENT); G_free(path); if (head_fp == NULL) { G_warning(_("Unable to create header file for vector map <%s>"), Vect_get_full_name(Map)); return -1; } fprintf(head_fp, "ORGANIZATION: %s\n", Vect_get_organization(Map)); fprintf(head_fp, "DIGIT DATE: %s\n", Vect_get_date(Map)); fprintf(head_fp, "DIGIT NAME: %s\n", Vect_get_person(Map)); fprintf(head_fp, "MAP NAME: %s\n", Vect_get_map_name(Map)); fprintf(head_fp, "MAP DATE: %s\n", Vect_get_map_date(Map)); fprintf(head_fp, "MAP SCALE: %d\n", Vect_get_scale(Map)); fprintf(head_fp, "OTHER INFO: %s\n", Vect_get_comment(Map)); if (Vect_get_proj(Map) > 0) fprintf(head_fp, "PROJ: %d\n", Vect_get_proj(Map)); fprintf(head_fp, "ZONE: %d\n", Vect_get_zone(Map)); fprintf(head_fp, "MAP THRESH: %f\n", Vect_get_thresh(Map)); fclose(head_fp); return 0; }
void print_shell(const struct Map_info *Map) { if (Vect_maptype(Map) & (GV_FORMAT_OGR | GV_FORMAT_OGR_DIRECT)) { fprintf(stdout, "ogr_layer=%s\n", Vect_get_ogr_layer_name(Map)); fprintf(stdout, "ogr_dsn=%s\n", Vect_get_ogr_dsn_name(Map)); } else { fprintf(stdout, "name=%s\n", Vect_get_name(Map)); fprintf(stdout, "mapset=%s\n", Vect_get_mapset(Map)); } fprintf(stdout, "location=%s\n", G_location()); fprintf(stdout, "database=%s\n", G_gisdbase()); fprintf(stdout, "title=%s\n", Vect_get_map_name(Map)); fprintf(stdout, "scale=1:%d\n", Vect_get_scale(Map)); if (Vect_maptype(Map) & (GV_FORMAT_OGR | GV_FORMAT_OGR_DIRECT)) { fprintf(stdout, "format=%s,%s\n", Vect_maptype_info(Map), Vect_get_ogr_format_info(Map)); } else { fprintf(stdout, "format=%s\n", Vect_maptype_info(Map)); } fprintf(stdout, "creator=%s\n", Vect_get_person(Map)); fprintf(stdout, "organization=%s\n", Vect_get_organization(Map)); fprintf(stdout, "source_date=%s\n", Vect_get_map_date(Map)); fprintf(stdout, "level=%d\n", Vect_level(Map)); if (Vect_level(Map) > 0) { fprintf(stdout, "num_dblinks=%d\n", Vect_get_num_dblinks(Map)); } fprintf(stdout, "projection=%s\n", Vect_get_proj_name(Map)); if (G_projection() == PROJECTION_UTM) { fprintf(stdout, "zone=%d\n", Vect_get_zone(Map)); } fprintf(stdout, "digitization_threshold=%f\n", Vect_get_thresh(Map)); fprintf(stdout, "comment=%s\n", Vect_get_comment(Map)); }
/*! \brief Copy header data from one to another map \param from target vector map \param[out] to destination vector map \return 0 */ int Vect_copy_head_data(const struct Map_info *from, struct Map_info *to) { Vect_set_organization(to, Vect_get_organization(from)); Vect_set_date(to, Vect_get_date(from)); Vect_set_person(to, Vect_get_person(from)); Vect_set_map_name(to, Vect_get_map_name(from)); Vect_set_map_date(to, Vect_get_map_date(from)); Vect_set_comment(to, Vect_get_comment(from)); Vect_set_scale(to, Vect_get_scale(from)); Vect_set_zone(to, Vect_get_zone(from)); Vect_set_thresh(to, Vect_get_thresh(from)); return 0; }
/*! \brief Write data to GRASS ASCII vector format \param[out] dascii pointer to the output ASCII file \param Map pointer to Map_info structure */ void Vect_write_ascii_head(FILE *dascii, struct Map_info *Map) { fprintf(dascii, "ORGANIZATION: %s%s", Vect_get_organization(Map), HOST_NEWLINE); fprintf(dascii, "DIGIT DATE: %s%s", Vect_get_date(Map), HOST_NEWLINE); fprintf(dascii, "DIGIT NAME: %s%s", Vect_get_person(Map), HOST_NEWLINE); fprintf(dascii, "MAP NAME: %s%s", Vect_get_map_name(Map), HOST_NEWLINE); fprintf(dascii, "MAP DATE: %s%s", Vect_get_map_date(Map), HOST_NEWLINE); fprintf(dascii, "MAP SCALE: %d%s", Vect_get_scale(Map), HOST_NEWLINE); fprintf(dascii, "OTHER INFO: %s%s", Vect_get_comment(Map), HOST_NEWLINE); fprintf(dascii, "ZONE: %d%s", Vect_get_zone(Map), HOST_NEWLINE); fprintf(dascii, "MAP THRESH: %f%s", Vect_get_thresh(Map), HOST_NEWLINE); }
/*- * Fills in site_head struct. */ int G_site_get_head(struct Map_info *Map, Site_head * head) { head->name = Vect_get_name(Map); head->desc = Vect_get_comment(Map); head->form = NULL; head->labels = NULL; /* head->stime = Vect_get_date(Map); *//* crashes, G_scan_timestamp() needed? */ head->stime = NULL; head->time = NULL; if (head->stime && strlen(head->stime) > 0) { if ((head->time = (struct TimeStamp *)G_malloc(sizeof(struct TimeStamp))) == NULL) G_fatal_error(_("Memory error in allocating timestamp")); if (G_scan_timestamp(head->time, head->stime) < 0) { G_warning(datetime_error_msg()); head->time = NULL; head->stime = NULL; } } return 0; }
void print_info(const struct Map_info *Map) { int i; char line[100]; char tmp1[100], tmp2[100]; struct bound_box box; divider('+'); if (Vect_maptype(Map) & (GV_FORMAT_OGR | GV_FORMAT_OGR_DIRECT)) { /* for OGR format print also datasource and layer */ sprintf(line, "%-17s%s", _("OGR layer:"), Vect_get_ogr_layer_name(Map)); printline(line); sprintf(line, "%-17s%s", _("OGR datasource:"), Vect_get_ogr_dsn_name(Map)); printline(line); } else { 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); if (Vect_maptype(Map) & (GV_FORMAT_OGR | GV_FORMAT_OGR_DIRECT)) { sprintf(line, "%-17s%s (%s)", _("Map format:"), Vect_maptype_info(Map), Vect_get_ogr_format_info(Map)); } else { 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%-9d %-22s%-9d", _("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%-9d %-22s%-9d", _("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%-9d %-22s%-9d", _("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%-9d %-22s%-9d", _("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%-9d %-22s%-9d", _("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"); }
void print_info(const struct Map_info *Map) { int i, map_type; char line[1024]; char timebuff[256]; struct TimeStamp ts; int time_ok, first_time_ok, second_time_ok; struct bound_box box; char tmp1[1024], tmp2[1024]; time_ok = first_time_ok = second_time_ok = FALSE; map_type = Vect_maptype(Map); /* Check the Timestamp */ time_ok = G_read_vector_timestamp(Vect_get_name(Map), NULL, "", &ts); /* Check for valid entries, show none if no timestamp available */ if (time_ok == TRUE) { if (ts.count > 0) first_time_ok = TRUE; if (ts.count > 1) second_time_ok = TRUE; } 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", _("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); /* This shows the TimeStamp (if present) */ if (time_ok == TRUE && (first_time_ok || second_time_ok)) { G_format_timestamp(&ts, timebuff); sprintf(line, "%-17s%s", _("Timestamp (first layer): "), timebuff); printline(line); } else { strcpy(line, _("Timestamp (first layer): none")); printline(line); } divider('|'); if (map_type == GV_FORMAT_OGR || map_type == GV_FORMAT_OGR_DIRECT) { sprintf(line, "%-17s%s (%s)", _("Map format:"), Vect_maptype_info(Map), Vect_get_finfo_format_info(Map)); printline(line); /* for OGR format print also datasource and layer */ sprintf(line, "%-17s%s", _("OGR layer:"), Vect_get_finfo_layer_name(Map)); printline(line); sprintf(line, "%-17s%s", _("OGR datasource:"), Vect_get_finfo_dsn_name(Map)); printline(line); sprintf(line, "%-17s%s", _("Feature type:"), Vect_get_finfo_geometry_type(Map)); printline(line); } else if (map_type == GV_FORMAT_POSTGIS) { int topo_format; char *toposchema_name, *topogeom_column; int topo_geo_only; const struct Format_info *finfo; finfo = Vect_get_finfo(Map); sprintf(line, "%-17s%s (%s)", _("Map format:"), Vect_maptype_info(Map), Vect_get_finfo_format_info(Map)); printline(line); /* for PostGIS format print also datasource and layer */ sprintf(line, "%-17s%s", _("DB table:"), Vect_get_finfo_layer_name(Map)); printline(line); sprintf(line, "%-17s%s", _("DB name:"), Vect_get_finfo_dsn_name(Map)); printline(line); sprintf(line, "%-17s%s", _("Geometry column:"), finfo->pg.geom_column); printline(line); sprintf(line, "%-17s%s", _("Feature type:"), Vect_get_finfo_geometry_type(Map)); printline(line); topo_format = Vect_get_finfo_topology_info(Map, &toposchema_name, &topogeom_column, &topo_geo_only); if (topo_format == GV_TOPO_POSTGIS) { sprintf(line, "%-17s%s (%s %s%s)", _("Topology:"), "PostGIS", _("schema:"), toposchema_name, topo_geo_only ? ", topo-geo-only: yes" : ""); printline(line); sprintf(line, "%-17s%s", _("Topology column:"), topogeom_column); } else sprintf(line, "%-17s%s", _("Topology:"), "pseudo (simple features)"); printline(line); } else { sprintf(line, "%-17s%s", _("Map format:"), Vect_maptype_info(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%-9d %-22s%-9d", _("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%-9d %-22s%-9d", _("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%-9d %-22s%-9d", _("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%-9d %-22s%-9d", _("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%-9d %-22s%-9d", _("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) { int utm_zone; utm_zone = Vect_get_zone(Map); if (utm_zone < 0 || utm_zone > 60) strcpy(tmp1, _("invalid")); else if (utm_zone == 0) strcpy(tmp1, _("unspecified")); else sprintf(tmp1, "%d", utm_zone); sprintf(line, " %s: %s (%s %s)", _("Projection"), Vect_get_proj_name(Map), _("zone"), tmp1); } 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"); }
void print_shell(const struct Map_info *Map, const char *field_opt) { int map_type; int time_ok, first_time_ok, second_time_ok; char timebuff[256]; struct field_info *fi; struct TimeStamp ts; time_ok = first_time_ok = second_time_ok = FALSE; /* Check the Timestamp */ time_ok = G_read_vector_timestamp(Vect_get_name(Map), NULL, "", &ts); /* Check for valid entries, show none if no timestamp available */ if (time_ok == TRUE) { if (ts.count > 0) first_time_ok = TRUE; if (ts.count > 1) second_time_ok = TRUE; } map_type = Vect_maptype(Map); fprintf(stdout, "name=%s\n", Vect_get_name(Map)); fprintf(stdout, "mapset=%s\n", Vect_get_mapset(Map)); fprintf(stdout, "location=%s\n", G_location()); fprintf(stdout, "database=%s\n", G_gisdbase()); fprintf(stdout, "title=%s\n", Vect_get_map_name(Map)); fprintf(stdout, "scale=1:%d\n", Vect_get_scale(Map)); fprintf(stdout, "creator=%s\n", Vect_get_person(Map)); fprintf(stdout, "organization=%s\n", Vect_get_organization(Map)); fprintf(stdout, "source_date=%s\n", Vect_get_map_date(Map)); /* This shows the TimeStamp (if present) */ if (time_ok == TRUE && (first_time_ok || second_time_ok)) { G_format_timestamp(&ts, timebuff); fprintf(stdout, "timestamp=%s\n", timebuff); } else { fprintf(stdout, "timestamp=none\n"); } if (map_type == GV_FORMAT_OGR || map_type == GV_FORMAT_OGR_DIRECT) { fprintf(stdout, "format=%s,%s\n", Vect_maptype_info(Map), Vect_get_finfo_format_info(Map)); fprintf(stdout, "ogr_layer=%s\n", Vect_get_finfo_layer_name(Map)); fprintf(stdout, "ogr_dsn=%s\n", Vect_get_finfo_dsn_name(Map)); fprintf(stdout, "feature_type=%s\n", Vect_get_finfo_geometry_type(Map)); } else if (map_type == GV_FORMAT_POSTGIS) { int topo_format; char *toposchema_name, *topogeom_column; const struct Format_info *finfo; finfo = Vect_get_finfo(Map); fprintf(stdout, "format=%s,%s\n", Vect_maptype_info(Map), Vect_get_finfo_format_info(Map)); fprintf(stdout, "pg_table=%s\n", Vect_get_finfo_layer_name(Map)); fprintf(stdout, "pg_dbname=%s\n", Vect_get_finfo_dsn_name(Map)); fprintf(stdout, "geometry_column=%s\n", finfo->pg.geom_column); fprintf(stdout, "feature_type=%s\n", Vect_get_finfo_geometry_type(Map)); topo_format = Vect_get_finfo_topology_info(Map, &toposchema_name, &topogeom_column, NULL); if (topo_format == GV_TOPO_POSTGIS) { fprintf(stdout, "pg_topo_schema=%s\n", toposchema_name); fprintf(stdout, "pg_topo_column=%s\n", topogeom_column); } } else { fprintf(stdout, "format=%s\n", Vect_maptype_info(Map)); } fprintf(stdout, "level=%d\n", Vect_level(Map)); if (Vect_level(Map) > 0) { fprintf(stdout, "num_dblinks=%d\n", Vect_get_num_dblinks(Map)); if (Vect_get_num_dblinks(Map) > 0) { fi = Vect_get_field2(Map, field_opt); if(fi != NULL) { fprintf(stdout, "attribute_layer_number=%i\n",fi->number); fprintf(stdout, "attribute_layer_name=%s\n",fi->name); fprintf(stdout, "attribute_database=%s\n",fi->database); fprintf(stdout, "attribute_database_driver=%s\n",fi->driver); fprintf(stdout, "attribute_table=%s\n",fi->table); fprintf(stdout, "attribute_primary_key=%s\n",fi->key); } } } fprintf(stdout, "projection=%s\n", Vect_get_proj_name(Map)); if (G_projection() == PROJECTION_UTM) { fprintf(stdout, "zone=%d\n", Vect_get_zone(Map)); } fprintf(stdout, "digitization_threshold=%f\n", Vect_get_thresh(Map)); fprintf(stdout, "comment=%s\n", Vect_get_comment(Map)); }