1 |
/**
|
2 |
* Navit, a modular navigation system.
|
3 |
* Copyright (C) 2005-2008 Navit Team
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
#include <string.h>
|
21 |
#include <glib.h>
|
22 |
#include "coord.h"
|
23 |
#include "debug.h"
|
24 |
#include "projection.h"
|
25 |
|
26 |
struct projection_name {
|
27 |
enum projection projection;
|
28 |
char *name;
|
29 |
};
|
30 |
|
31 |
|
32 |
struct projection_name projection_names[]={
|
33 |
{projection_none, ""},
|
34 |
{projection_mg, "mg"},
|
35 |
{projection_garmin, "garmin"},
|
36 |
{projection_utm, "utm"},
|
37 |
{projection_gk, "gk"},
|
38 |
};
|
39 |
|
40 |
|
41 |
enum projection
|
42 |
projection_from_name(const char *name, struct coord *offset)
|
43 |
{
|
44 |
int i;
|
45 |
int zone;
|
46 |
char ns;
|
47 |
|
48 |
for (i=0 ; i < sizeof(projection_names)/sizeof(struct projection_name) ; i++) {
|
49 |
if (! strcmp(projection_names[i].name, name))
|
50 |
return projection_names[i].projection;
|
51 |
}
|
52 |
if (offset) {
|
53 |
if (sscanf(name,"utm%d%c",&zone,&ns) == 2 && zone > 0 && zone <= 60 && (ns == 'n' || ns == 's')) {
|
54 |
offset->x=zone*1000000;
|
55 |
offset->y=(ns == 's' ? -10000000:0);
|
56 |
return projection_utm;
|
57 |
}
|
58 |
}
|
59 |
return projection_none;
|
60 |
}
|
61 |
|
62 |
char *
|
63 |
projection_to_name(enum projection proj, struct coord *offset)
|
64 |
{
|
65 |
int i;
|
66 |
|
67 |
for (i=0 ; i < sizeof(projection_names)/sizeof(struct projection_name) ; i++) {
|
68 |
if (projection_names[i].projection == proj)
|
69 |
return projection_names[i].name;
|
70 |
}
|
71 |
return NULL;
|
72 |
}
|
73 |
|