Skip to content

Commit 76d5988

Browse files
committed
v.info/v.proj: fix printing UTM zone (#892) (#977)
* v.info: fix printing UTM zone (#892) print UTM zone <X> according to hemisphere as <X>N or <X>S * v.info / v.proj fix UTM zone info reporting of vector maps
1 parent 449cc67 commit 76d5988

3 files changed

Lines changed: 26 additions & 11 deletions

File tree

lib/vector/Vlib/header.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,11 @@ int Vect_set_zone(struct Map_info *Map, int zone)
479479
*/
480480
int Vect_get_zone(const struct Map_info *Map)
481481
{
482-
return Map->head.plani_zone;
482+
/* return Map->head.plani_zone; */
483+
484+
/* use utm zone of current location,
485+
* a vector in a given location can not be in a different CRS */
486+
return G_zone();
483487
}
484488

485489
/*!

vector/v.info/print.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ void format_double(double value, char *buf)
2121
G_trim_decimal(buf);
2222
}
2323

24+
/* convert UTM zone number X to XN or XS */
25+
static char *format_zone(int zone_num)
26+
{
27+
char *zone_str = NULL;
28+
29+
if (zone_num < -60 || zone_num > 60)
30+
G_asprintf(&zone_str, _("%s"), "invalid");
31+
else if (zone_num == 0)
32+
G_asprintf(&zone_str, _("%s"), "unspecified");
33+
else if (zone_num < 0)
34+
G_asprintf(&zone_str, "%dS", -zone_num);
35+
else
36+
G_asprintf(&zone_str, "%dN", zone_num);
37+
38+
return zone_str;
39+
}
40+
2441
void print_region(const struct Map_info *Map)
2542
{
2643
char tmp1[1024], tmp2[1024];
@@ -492,18 +509,14 @@ void print_info(const struct Map_info *Map)
492509
/* Vect_get_proj_name() and _zone() are typically unset?! */
493510
if (G_projection() == PROJECTION_UTM) {
494511
int utm_zone;
512+
char *utm_zone_str;
495513

496514
utm_zone = Vect_get_zone(Map);
497-
if (utm_zone < 0 || utm_zone > 60)
498-
strcpy(tmp1, _("invalid"));
499-
else if (utm_zone == 0)
500-
strcpy(tmp1, _("unspecified"));
501-
else
502-
sprintf(tmp1, "%d", utm_zone);
515+
utm_zone_str = format_zone(utm_zone);
503516

504517
sprintf(line, " %s: %s (%s %s)",
505518
_("Projection"), Vect_get_proj_name(Map),
506-
_("zone"), tmp1);
519+
_("zone"), utm_zone_str);
507520
}
508521
else
509522
sprintf(line, " %s: %s",

vector/v.proj/main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ int main(int argc, char *argv[])
3636
{
3737
int i, type, stat;
3838
int day, yr, Out_proj;
39-
int out_zone = 0;
4039
int overwrite; /* overwrite output map */
4140
const char *mapset;
4241
const char *omap_name, *map_name, *iset_name, *iloc_name;
@@ -408,8 +407,7 @@ int main(int argc, char *argv[])
408407
Vect_hist_copy(&Map, &Out_Map);
409408
Vect_hist_command(&Out_Map);
410409

411-
out_zone = info_out.zone;
412-
Vect_set_zone(&Out_Map, out_zone);
410+
Vect_set_zone(&Out_Map, G_zone());
413411

414412
/* Read and write header info */
415413
sprintf(date, "%s", G_date());

0 commit comments

Comments
 (0)