diff options
Diffstat (limited to 'navit/projection.c')
-rw-r--r-- | navit/projection.c | 128 |
1 files changed, 61 insertions, 67 deletions
diff --git a/navit/projection.c b/navit/projection.c index d916689ee..512a4d888 100644 --- a/navit/projection.c +++ b/navit/projection.c @@ -24,30 +24,28 @@ #include "projection.h" struct projection_name { - enum projection projection; - char *name; + enum projection projection; + char *name; }; -struct projection_name projection_names[]={ - {projection_none, ""}, - {projection_mg, "mg"}, - {projection_garmin, "garmin"}, - {projection_utm, "utm"}, +struct projection_name projection_names[]= { + {projection_none, ""}, + {projection_mg, "mg"}, + {projection_garmin, "garmin"}, + {projection_utm, "utm"}, }; -static int -utmref_letter(char l) -{ - if (l < 'a' || l == 'i' || l == 'o') - return -1; - if (l < 'i') - return l-'a'; - if (l < 'o') - return l-'a'-1; - if (l <= 'z') - return l-'a'-2; - return -1; +static int utmref_letter(char l) { + if (l < 'a' || l == 'i' || l == 'o') + return -1; + if (l < 'i') + return l-'a'; + if (l < 'o') + return l-'a'-1; + if (l <= 'z') + return l-'a'-2; + return -1; } /** @@ -57,57 +55,53 @@ utmref_letter(char l) * @utm_offset Only for UTM projections: Used to return the offset for the UTM projection * @returns projection, or projection_none if no projection could be determined */ -enum projection -projection_from_name(const char *name, struct coord *utm_offset) -{ - int i; - int zone,baserow; - char ns,zone_field,square_x,square_y; +enum projection projection_from_name(const char *name, struct coord *utm_offset) { + int i; + int zone,baserow; + char ns,zone_field,square_x,square_y; - for (i=0 ; i < sizeof(projection_names)/sizeof(struct projection_name) ; i++) { - if (! strcmp(projection_names[i].name, name)) - return projection_names[i].projection; - } - if (utm_offset) { - if (sscanf(name,"utm%d%c",&zone,&ns) == 2 && zone > 0 && zone <= 60 && (ns == 'n' || ns == 's')) { - utm_offset->x=zone*1000000; - utm_offset->y=(ns == 's' ? -10000000:0); - return projection_utm; - } - if (sscanf(name,"utmref%d%c%c%c",&zone,&zone_field,&square_x,&square_y)) { - i=utmref_letter(zone_field); - if (i < 2 || i > 21) { - dbg(lvl_error,"invalid zone field '%c' in '%s'\n",zone_field,name); - return projection_none; - } - i-=12; - dbg(lvl_debug,"zone_field %d\n",i); - baserow=i*887.6/100; - utm_offset->x=zone*1000000; - i=utmref_letter(square_x); - utm_offset->x+=((i%8)+1)*100000; - i=utmref_letter(square_y); - dbg(lvl_debug,"baserow %d\n",baserow); - if (!(zone % 2)) - i-=5; - dbg(lvl_debug,"i=%d\n",i); - i=(i-baserow+100)%20+baserow; - utm_offset->y=i*100000; - return projection_utm; - } - } - return projection_none; + for (i=0 ; i < sizeof(projection_names)/sizeof(struct projection_name) ; i++) { + if (! strcmp(projection_names[i].name, name)) + return projection_names[i].projection; + } + if (utm_offset) { + if (sscanf(name,"utm%d%c",&zone,&ns) == 2 && zone > 0 && zone <= 60 && (ns == 'n' || ns == 's')) { + utm_offset->x=zone*1000000; + utm_offset->y=(ns == 's' ? -10000000:0); + return projection_utm; + } + if (sscanf(name,"utmref%d%c%c%c",&zone,&zone_field,&square_x,&square_y)) { + i=utmref_letter(zone_field); + if (i < 2 || i > 21) { + dbg(lvl_error,"invalid zone field '%c' in '%s'",zone_field,name); + return projection_none; + } + i-=12; + dbg(lvl_debug,"zone_field %d",i); + baserow=i*887.6/100; + utm_offset->x=zone*1000000; + i=utmref_letter(square_x); + utm_offset->x+=((i%8)+1)*100000; + i=utmref_letter(square_y); + dbg(lvl_debug,"baserow %d",baserow); + if (!(zone % 2)) + i-=5; + dbg(lvl_debug,"i=%d",i); + i=(i-baserow+100)%20+baserow; + utm_offset->y=i*100000; + return projection_utm; + } + } + return projection_none; } -char * -projection_to_name(enum projection proj) -{ - int i; +char *projection_to_name(enum projection proj) { + int i; - for (i=0 ; i < sizeof(projection_names)/sizeof(struct projection_name) ; i++) { - if (projection_names[i].projection == proj) - return projection_names[i].name; - } - return NULL; + for (i=0 ; i < sizeof(projection_names)/sizeof(struct projection_name) ; i++) { + if (projection_names[i].projection == proj) + return projection_names[i].name; + } + return NULL; } |