From 68afffb83a69dce8381cd78240aee6f428d2d533 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Mon, 23 May 2022 06:21:04 +0200 Subject: [PATCH 01/23] Initial commit From fd91e400dfc5bfa83ee4565c2ab9e222188eee77 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Thu, 5 Jan 2023 18:42:26 +0100 Subject: [PATCH 02/23] Fix:#1185 --- navit/navit.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/navit/navit.c b/navit/navit.c index e6e43064d5..8b06489507 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -3539,11 +3539,12 @@ void navit_layout_switch(struct navit *n) { //Ok, we know that we have profile to switch //Check that we aren't calculating too fast + //attr_position_time_iso8601 has to be in UTC time if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) { currTs=iso8601_to_secs(iso8601_attr.u.str); - dbg(lvl_debug,"currTs: %u:%u",currTs%86400/3600,((currTs%86400)%3600)/60); + dbg(lvl_debug,"currTs: %02u:%02u",currTs%86400/3600,((currTs%86400)%3600)/60); } - dbg(lvl_debug,"prevTs: %u:%u",n->prevTs%86400/3600,((n->prevTs%86400)%3600)/60); + dbg(lvl_debug,"prevTs: %02u:%02u",n->prevTs%86400/3600,((n->prevTs%86400)%3600)/60); if (n->auto_switch == FALSE) return; @@ -3602,18 +3603,32 @@ void navit_layout_switch(struct navit *n) { return; } trise_actual=trise; - dbg(lvl_debug,"trise: %u:%u",HOURS(trise),MINUTES(trise)); - dbg(lvl_debug,"tset: %u:%u",HOURS(tset),MINUTES(tset)); + dbg(lvl_debug,"trise: %02u:%02u",HOURS(trise),MINUTES(trise)); + dbg(lvl_debug,"tset: %02u:%02u",HOURS(tset),MINUTES(tset)); + dbg(lvl_debug,"currTs: %02u:%02u",currTs%86400/3600,((currTs%86400)%3600)/60); dbg(lvl_debug,"dayname = %s, name =%s ",l->dayname, l->name); dbg(lvl_debug,"nightname = %s, name = %s ",l->nightname, l->name); - if (HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60) { - after_sunrise = TRUE; - } - if (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) || - ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))) { - after_sunset = TRUE; - } + int tr=HOURS(trise)*60+MINUTES(trise); + int ts=HOURS(tset)*60+MINUTES(tset); + int tcur = (currTs%86400)/60; + + if (ts > tr) { + if (tr < tcur) { + after_sunrise = TRUE; + } + if (((ts < tcur) || (tr > tcur))) { + after_sunset = TRUE; + } + } else { + if(tcur < ts || tcur > tr) { + after_sunrise = TRUE; + } + if(tcur > ts && tcur < tr) { + after_sunset = TRUE; + } + } + if (after_sunrise && !after_sunset && l->dayname) { navit_set_layout_by_name(n,l->dayname); dbg(lvl_debug,"layout set to day"); From be87cd30a0b153158bc68b3eb83601aadeda322c Mon Sep 17 00:00:00 2001 From: OLFDB Date: Thu, 5 Jan 2023 18:42:36 +0100 Subject: [PATCH 03/23] Fix:#1185 --- navit/sunriset.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/sunriset.h b/navit/sunriset.h index 60ad4fa767..16de935973 100644 --- a/navit/sunriset.h +++ b/navit/sunriset.h @@ -4,7 +4,7 @@ extern long int timezone_offset; #define TMOD(x) ((x)<0?(x)+24:((x)>=24?(x)-24:(x))) #define DAYSOFF(x) ((x)<0?"(-1) ":((x)>=24?"(+1) ":"")) -#define HOURS(h) ((int)(floor(h))) +#define HOURS(h) ((((int)(floor(h)))<0.0)?(1440/60+((int)(floor(h)))):((int)(floor(h)))) #define MINUTES(h) ((int)(60*(h-floor(h)))) #ifndef ABS From a2ffdea11859fcd354673e84b794e0cbbc65c549 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 7 Jan 2023 17:35:01 +0100 Subject: [PATCH 04/23] Update after further tests --- navit/navit.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/navit/navit.c b/navit/navit.c index 8b06489507..142a81874d 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -3613,21 +3613,21 @@ void navit_layout_switch(struct navit *n) { int ts=HOURS(tset)*60+MINUTES(tset); int tcur = (currTs%86400)/60; - if (ts > tr) { - if (tr < tcur) { - after_sunrise = TRUE; - } - if (((ts < tcur) || (tr > tcur))) { - after_sunset = TRUE; - } - } else { - if(tcur < ts || tcur > tr) { - after_sunrise = TRUE; - } - if(tcur > ts && tcur < tr) { - after_sunset = TRUE; - } - } + if (ts>tr) { + if (tr<=tcur) { + after_sunrise = TRUE; + } + if (ts1440 || tr>tcur) { + after_sunset = TRUE; + } + } else { + if((tcur<=ts) || (tcur>=tr)) { + after_sunrise = TRUE; + } + if(tcur>ts || tcurdayname) { navit_set_layout_by_name(n,l->dayname); From 31c48d4cd9a7d4c82f86936ce59b03359fab5907 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 7 Jan 2023 19:08:22 +0100 Subject: [PATCH 05/23] Update navit.c Missing opening bracket. --- navit/navit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/navit/navit.c b/navit/navit.c index 142a81874d..635f414e71 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -3624,8 +3624,8 @@ void navit_layout_switch(struct navit *n) { if((tcur<=ts) || (tcur>=tr)) { after_sunrise = TRUE; } - if(tcur>ts || tcurts || tcur Date: Sat, 7 Jan 2023 19:18:33 +0100 Subject: [PATCH 06/23] Update navit.c Needs AND not OR when combining if clauses. --- navit/navit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/navit.c b/navit/navit.c index 635f414e71..56fd8e509b 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -3624,7 +3624,7 @@ void navit_layout_switch(struct navit *n) { if((tcur<=ts) || (tcur>=tr)) { after_sunrise = TRUE; } - if(tcur>ts || tcurts && tcur Date: Sun, 8 Jan 2023 07:12:41 +0100 Subject: [PATCH 07/23] Revert "Fix:#1185" This reverts commit fd91e400dfc5bfa83ee4565c2ab9e222188eee77. --- navit/navit.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/navit/navit.c b/navit/navit.c index 8b06489507..e6e43064d5 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -3539,12 +3539,11 @@ void navit_layout_switch(struct navit *n) { //Ok, we know that we have profile to switch //Check that we aren't calculating too fast - //attr_position_time_iso8601 has to be in UTC time if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) { currTs=iso8601_to_secs(iso8601_attr.u.str); - dbg(lvl_debug,"currTs: %02u:%02u",currTs%86400/3600,((currTs%86400)%3600)/60); + dbg(lvl_debug,"currTs: %u:%u",currTs%86400/3600,((currTs%86400)%3600)/60); } - dbg(lvl_debug,"prevTs: %02u:%02u",n->prevTs%86400/3600,((n->prevTs%86400)%3600)/60); + dbg(lvl_debug,"prevTs: %u:%u",n->prevTs%86400/3600,((n->prevTs%86400)%3600)/60); if (n->auto_switch == FALSE) return; @@ -3603,32 +3602,18 @@ void navit_layout_switch(struct navit *n) { return; } trise_actual=trise; - dbg(lvl_debug,"trise: %02u:%02u",HOURS(trise),MINUTES(trise)); - dbg(lvl_debug,"tset: %02u:%02u",HOURS(tset),MINUTES(tset)); - dbg(lvl_debug,"currTs: %02u:%02u",currTs%86400/3600,((currTs%86400)%3600)/60); + dbg(lvl_debug,"trise: %u:%u",HOURS(trise),MINUTES(trise)); + dbg(lvl_debug,"tset: %u:%u",HOURS(tset),MINUTES(tset)); dbg(lvl_debug,"dayname = %s, name =%s ",l->dayname, l->name); dbg(lvl_debug,"nightname = %s, name = %s ",l->nightname, l->name); + if (HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60) { + after_sunrise = TRUE; + } - int tr=HOURS(trise)*60+MINUTES(trise); - int ts=HOURS(tset)*60+MINUTES(tset); - int tcur = (currTs%86400)/60; - - if (ts > tr) { - if (tr < tcur) { - after_sunrise = TRUE; - } - if (((ts < tcur) || (tr > tcur))) { - after_sunset = TRUE; - } - } else { - if(tcur < ts || tcur > tr) { - after_sunrise = TRUE; - } - if(tcur > ts && tcur < tr) { - after_sunset = TRUE; - } - } - + if (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) || + ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))) { + after_sunset = TRUE; + } if (after_sunrise && !after_sunset && l->dayname) { navit_set_layout_by_name(n,l->dayname); dbg(lvl_debug,"layout set to day"); From 57cba4eb58d63c516b3ed5eed4d89c5b870f759f Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sun, 8 Jan 2023 07:16:23 +0100 Subject: [PATCH 08/23] Revert "Fix:#1185" This reverts commit be87cd30a0b153158bc68b3eb83601aadeda322c. --- navit/sunriset.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/sunriset.h b/navit/sunriset.h index 16de935973..60ad4fa767 100644 --- a/navit/sunriset.h +++ b/navit/sunriset.h @@ -4,7 +4,7 @@ extern long int timezone_offset; #define TMOD(x) ((x)<0?(x)+24:((x)>=24?(x)-24:(x))) #define DAYSOFF(x) ((x)<0?"(-1) ":((x)>=24?"(+1) ":"")) -#define HOURS(h) ((((int)(floor(h)))<0.0)?(1440/60+((int)(floor(h)))):((int)(floor(h)))) +#define HOURS(h) ((int)(floor(h))) #define MINUTES(h) ((int)(60*(h-floor(h)))) #ifndef ABS From 34fcdb91f403376d44dd5b01bd17f0f1dfd534a6 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 14 Jan 2023 18:59:57 +0100 Subject: [PATCH 09/23] Taken from wiki and added UTM coordinate description --- docs/configuration/coordinates.rst | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 docs/configuration/coordinates.rst diff --git a/docs/configuration/coordinates.rst b/docs/configuration/coordinates.rst new file mode 100644 index 0000000000..be8c67b6ea --- /dev/null +++ b/docs/configuration/coordinates.rst @@ -0,0 +1,84 @@ +## Coordinates in Navit + +Various parts of Navit will read geographical coordinates provided as text: + +- the [textfile](https://wiki.navit-project.org/index.php/Textfile) map format +- the "center=" attribute in the configuration file +- some Navit commands (e.g. set_position), which can be invoked via the [internal GUI](https://wiki.navit-project.org/index.php/Internal_GUI) or the [Dbus](https://wiki.navit-project.org/index.php/Dbus) bindings +- the files for bookmarks and last map position (bookmarks.txt and center.txt) + +This page documents the coordinate systems and formats that Navit will accept. + +## Supported coordinate systems and formats + +### Longitude / Latitude in decimal degrees + +Longitude / latitude in degrees can be specified as signed decimal fractions: + +``` +-33.3553 6.334 +``` + +That would be about 33° West, 6° North. Note that in this format longitude comes first. The coordinates are assumed to be based on WGS84 (the coordinate system used by the GPS system, and by practically all common navigation systems). + +### Latitude / Longitude in degrees and minutes + +Latitude / Longitude can also be specified in degress and minutes with compass directions (N/S, E/W): + +``` +4808 N 1134 E +``` + +Latitude and longitude are multiplied by 100, so the position above corresponds to 48°8' N, 11°34' (Munich). + +For greater precision you can write the minutes as decimal fractions: + +``` +4808.2356 N 1134.5252 E +``` + +That is 48°8.2356' N 11°34.5252' E, the center of the Marienplatz in Munich. + +Notes: + +- This format is rather unusual (because it uses arcminutes, but not arcseconds). It is probably easier to just use decimal fractions of degrees. +- The spaces are relevant for parsing. Use exactly one space between the number and the letter N/S/E/W. + +### Cartesian coordinates + +Internally, Navit uses a cartesian coordinate system induced by a Mercator projection. Coordinates are written as hexadecimal integers: + +``` +0x13a3d7 0x5d6d6d +``` + +or specifying a projection: + +``` +mg: 0x13a3d7 0x5d6d6d +``` + +That is again 48°8.2356' N 11°34.5252' E. The part up to and including the colon is optional, it names the projection to use. Possible values: + +- mg - the projection used by Map&Guide (the default) +- garmin - "Garmin" projection (TODO: When would it be useful?) + +This format is used internally by Navit, but is probably not very useful for other purposes. + +### UTM coordinates + +Navit can read coordinates in the [Universal Transverse Mercator coordinate system](http://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system) (UTM). + +``` +utm32U: 674499.306 5328063.675 +``` + +``` +utmref32UPU:74499.306 28063.675 +``` + + + +## Development notes + +The coordinates are parsed in function coord_parse() in coord.c. This code is used everywhere where Navit parses coordinates, except for the manual coordinate input in the Internal GUI (which uses its own format and parsing function). \ No newline at end of file From ca0fd3c218c3636c07c4f9507b8bf8ed8c00a688 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 14 Jan 2023 19:02:18 +0100 Subject: [PATCH 10/23] Convinience Macro to get projection names in text Fix for #1218 Crash when setting first destination Changes to make UTM coordinates working --- navit/coord.c | 254 +++++++++++++++++++++++++------------------------- 1 file changed, 128 insertions(+), 126 deletions(-) diff --git a/navit/coord.c b/navit/coord.c index 03dec06b9b..ede1b0a451 100644 --- a/navit/coord.c +++ b/navit/coord.c @@ -39,6 +39,9 @@ * @returns the coordinate */ +int projection_enum_size[SIZE]; +#define PROJASSTRING(x) (x==0?"projection_none":x==1?"projection_mg":x==2?"projection_garmin":x==3?"projection_screen":x==4?"projection_utm":"UNKNOWN") + struct coord * coord_get(unsigned char **p) { struct coord *ret=(struct coord *)(*p); *p += sizeof(*ret); @@ -132,11 +135,11 @@ void coord_rect_extend(struct coord_rect *r, struct coord *c) { * Parses \c char \a *coord_input and writes back the coordinates to \c coord \a *result, using \c projection \a output_projection. * \a *coord_input may specify its projection at the beginning. * The format for \a *coord_input can be: - * \li [Proj:][-]0xXX.... [-]0xXX... - Mercator coordinates, hex integers (XX), Proj can be "mg" or "garmin", defaults to mg - * \li [Proj:][D][D]Dmm.mm.. N/S [D][D]DMM.mm... E/W - lat/long (WGS 84), integer degrees (DD) and minutes as decimal fraction (MM), Proj must be "geo" or absent - * \li [Proj:][-][D]D.d[d]... [-][D][D]D.d[d]... - long/lat (WGS 84, note order!), degrees as decimal fraction, Proj does not matter - * \li utm[zoneinfo]:[-][D]D.d[d]... [-][D][D]D.d[d] - UTM coordinates, as decimal fraction, with optional zone information (?) - * \li [-][D]D.d[d]...,[-][D][D]D.d[d]... - comma-separated (but without space inside the string) lat/long degrees as decimal fraction, Proj does not matter + * \li [Proj:][-]0xXX.... [-]0xXX... - Mercator coordinates, hex integers (XX), Proj can be "mg" or "garmin", defaults to mg + * \li [Proj:][D][D]Dmm.mm.. N/S [D][D]DMM.mm... E/W - lat/long (WGS 84), integer degrees (DD) and minutes as decimal fraction (MM), Proj must be "geo" or absent + * \li [Proj:][-][D]D.d[d]... [-][D][D]D.d[d]... - long/lat (WGS 84, note order!), degrees as decimal fraction, Proj does not matter + * \li utm[zoneinfo]:[-][D]D.d[d]... [-][D][D]D.d[d] - UTM coordinates, as decimal fraction, with optional zone information (?) + * \li [-][D]D.d[d]...,[-][D][D]D.d[d]... - comma-separated (but without space inside the string) lat/long degrees as decimal fraction, Proj does not matter * Note that the spaces are relevant for parsing. * * @param *coord_input String to be parsed @@ -145,126 +148,125 @@ void coord_rect_extend(struct coord_rect *r, struct coord *c) { * @returns The lenght of the parsed string */ -int coord_parse(const char *coord_input, enum projection output_projection, struct coord *result) { - char *proj=NULL,*s,*co; - const char *str=coord_input; - int args,ret = 0; - struct coord_geo g; - struct coord c,offset; - enum projection str_pro=projection_none; - int space_as_sep = 0; - - dbg(lvl_debug,"enter('%s',%d,%p)", coord_input, output_projection, result); - s=strchr(str, ' '); - if (!s) { - space_as_sep = 1; - s=strchr(str, ','); - } - co=strchr(str,':'); - if (co && co < s) { - proj=g_malloc(co-str+1); - g_strlcpy(proj, str, 1+co-str); - dbg(lvl_debug,"projection=%s", proj); - str=co+1; - s=strchr(str,space_as_sep?' ':','); - if (!strcmp(proj, "geo")) - str_pro = projection_none; - else { - str_pro = projection_from_name(proj,&offset); - if (str_pro == projection_none) { - dbg(lvl_error, "Unknown projection: %s", proj); - goto out; - } - } - } - if (! s) { - ret=0; - goto out; - } - while (*s == ' ') { - s++; - } - if (!space_as_sep && (!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3))) { - args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret); - if (args < 2) - goto out; - dbg(lvl_debug,"str='%s' x=0x%x y=0x%x c=%d", str, c.x, c.y, ret); - dbg(lvl_debug,"rest='%s'", str+ret); - - if (str_pro == projection_none) - str_pro=projection_mg; - if (str_pro != output_projection) { - transform_to_geo(str_pro, &c, &g); - transform_from_geo(output_projection, &g, &c); - } - *result=c; - } else if (!space_as_sep && (*s == 'N' || *s == 'n' || *s == 'S' || *s == 's')) { - double lng, lat; - char ns, ew; - dbg(lvl_debug,"str='%s'", str); - args=sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret); - dbg(lvl_debug,"args=%d", args); - dbg(lvl_debug,"lat=%f %c lon=%f %c", lat, ns, lng, ew); - if (args < 4) - goto out; - dbg(lvl_debug,"projection=%d str_pro=%d projection_none=%d", output_projection, str_pro, projection_none); - if (str_pro == projection_none) { - g.lat=floor(lat/100); - lat-=g.lat*100; - g.lat+=lat/60; - g.lng=floor(lng/100); - lng-=g.lng*100; - g.lng+=lng/60; - if (ns == 's' || ns == 'S') - g.lat=-g.lat; - if (ew == 'w' || ew == 'W') - g.lng=-g.lng; - dbg(lvl_debug,"transform_from_geo(%f,%f)",g.lat,g.lng); - transform_from_geo(output_projection, &g, result); - dbg(lvl_debug,"result 0x%x,0x%x", result->x,result->y); - } - dbg(lvl_debug,"str='%s' x=%f ns=%c y=%f ew=%c c=%d", str, lng, ns, lat, ew, ret); - dbg(lvl_debug,"rest='%s'", str+ret); - } else if (!space_as_sep && (str_pro == projection_utm)) { - double x,y; - args=sscanf(str, "%lf %lf%n", &x, &y, &ret); - if (args < 2) - goto out; - c.x=x+offset.x; - c.y=y+offset.y; - if (str_pro != output_projection) { - transform_to_geo(str_pro, &c, &g); - transform_from_geo(output_projection, &g, &c); - } - *result=c; - } else if (space_as_sep) { - // When entering coords like google's format, we actually get strings like "52.5219,19.4127" - double lng, lat; - args=sscanf(str, "%lf,%lf%n", &lat, &lng, &ret); - if (args < 2) - goto out; - dbg(lvl_debug,"str='%s' x=%f y=%f c=%d", str, lng, lat, ret); - dbg(lvl_debug,"rest='%s'", str+ret); - g.lng=lng; - g.lat=lat; - transform_from_geo(output_projection, &g, result); - } - else { - double lng, lat; - args=sscanf(str, "%lf %lf%n", &lng, &lat, &ret); - if (args < 2) - goto out; - dbg(lvl_debug,"str='%s' x=%f y=%f c=%d", str, lng, lat, ret); - dbg(lvl_debug,"rest='%s'", str+ret); - g.lng=lng; - g.lat=lat; - transform_from_geo(output_projection, &g, result); - } - ret+=str-coord_input; - dbg(lvl_info, "ret=%d delta=%d ret_str='%s'", ret, GPOINTER_TO_INT(str-coord_input), coord_input+ret); -out: - g_free(proj); - return ret; +int coord_parse(const char *coord_input, enum projection output_projection, struct coord *result) { + char *proj = NULL, *s = NULL, *co; + const char *str = coord_input; + int args, ret = 0; + struct coord_geo g; + struct coord c, offset; + enum projection str_pro = projection_none; + int space_as_sep = 0; + + dbg(lvl_debug, "enter('%s',%s,%p)\n", coord_input, + PROJASSTRING(output_projection), result); + co = strchr(str, ':'); + if (co) + s = strstr(str, ": "); + if (s) { + space_as_sep = 1; + } + if (co) { + proj = g_malloc(co - str + 1); + g_strlcpy(proj, str, 1 + co - str); + dbg(lvl_debug, "projection=%s\n", proj); + str = co + 1; + if (space_as_sep) + str++; + s = (char*) str; + if (!strcmp(proj, "geo")) + str_pro = projection_none; + else { + str_pro = projection_from_name(proj, &offset); + if (str_pro == projection_none) { + dbg(lvl_debug, "Unknown projection: %s\n", proj); + goto out; + } + } + } else { + s = (char*) str; + } + if ((!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3))) { + args = sscanf(str, "%i %i%n", &c.x, &c.y, &ret); + if (args < 2) + goto out; + dbg(lvl_debug, "str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret); + dbg(lvl_debug, "rest='%s'\n", str + ret); + + if (str_pro == projection_none) + str_pro = projection_mg; + if (str_pro != output_projection) { + transform_to_geo(str_pro, &c, &g); + transform_from_geo(output_projection, &g, &c); + } + *result = c; + } else if ((*s == 'N' || *s == 'n' || *s == 'S' || *s == 's')) { + double lng, lat; + char ns, ew; + dbg(lvl_debug, "str='%s'\n", str); + args = sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret); + dbg(lvl_debug, "args=%d\n", args); + dbg(lvl_debug, "lat=%f %c lon=%f %c\n", lat, ns, lng, ew); + if (args < 4) + goto out; + dbg(lvl_debug, "projection=%s str_pro=%d projection_none=%d\n", + PROJASSTRING(output_projection), str_pro, projection_none); + if (str_pro == projection_none) { + g.lat = floor(lat / 100); + lat -= g.lat * 100; + g.lat += lat / 60; + g.lng = floor(lng / 100); + lng -= g.lng * 100; + g.lng += lng / 60; + if (ns == 's' || ns == 'S') + g.lat = -g.lat; + if (ew == 'w' || ew == 'W') + g.lng = -g.lng; + dbg(lvl_debug, "transform_from_geo(%f,%f)\n", g.lat, g.lng); + transform_from_geo(output_projection, &g, result); + dbg(lvl_debug, "result 0x%x,0x%x\n", result->x, result->y); + } + dbg(lvl_debug, "str='%s' x=%f ns=%c y=%f ew=%c c=%d\n", str, lng, ns, + lat, ew, ret); + dbg(lvl_debug, "rest='%s'\n", str + ret); + } else if (str_pro == projection_utm) { + double x, y; + args = sscanf(str, "%lf %lf%n", &x, &y, &ret); + if (args < 2) + goto out; + c.x = x + offset.x; + c.y = y + offset.y; + if (str_pro != output_projection) { + transform_to_geo(str_pro, &c, &g); + transform_from_geo(output_projection, &g, &c); + } + *result = c; + } else if (!space_as_sep) { + // When entering coords like google's format, we actually get strings like "52.5219,19.4127" + double lng, lat; + args = sscanf(str, "%lf,%lf%n", &lat, &lng, &ret); + if (args < 2) + goto out; + dbg(lvl_debug, "str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); + dbg(lvl_debug, "rest='%s'\n", str + ret); + g.lng = lng; + g.lat = lat; + transform_from_geo(output_projection, &g, result); + } else { + double lng, lat; + args = sscanf(str, "%lf %lf%n", &lng, &lat, &ret); + if (args < 2) + goto out; + dbg(lvl_debug, "str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); + dbg(lvl_debug, "rest='%s'\n", str + ret); + g.lng = lng; + g.lat = lat; + transform_from_geo(output_projection, &g, result); + } + ret += str - coord_input; + dbg(lvl_debug, "ret=%d delta=%d ret_str='%s'\n", ret, + GPOINTER_TO_INT(str - coord_input), coord_input + ret); + out: g_free(proj); + return ret; } /** @@ -300,7 +302,7 @@ void coord_print(enum projection pro, struct coord *c, FILE *out) { } else { y = c->y; } - fprintf( out, "%s: %s0x%x %s0x%x\n", + fprintf( out, "%s:%s0x%x %s0x%x\n", projection_to_name( pro ), sign_x, x, sign_y, y ); From 7620dc4ce1a7869bfab7c4a128d0d220975d29a3 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 14 Jan 2023 19:03:17 +0100 Subject: [PATCH 11/23] Added SIZE enum member to calculate size of enum --- navit/projection.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/navit/projection.h b/navit/projection.h index d67952b1fb..06f74e4ea4 100644 --- a/navit/projection.h +++ b/navit/projection.h @@ -21,11 +21,12 @@ #define NAVIT_PROJECTION_H enum projection { - projection_none, /*!< No projection or unknown projection */ - projection_mg, /*!< Mercator projection */ - projection_garmin, /*!< Garmin projection */ - projection_screen, /*!< Screen projection */ - projection_utm /*!< UTM projection */ + projection_none, /*!< No projection or unknown projection */ + projection_mg, /*!< Mercator projection */ + projection_garmin, /*!< Garmin projection */ + projection_screen, /*!< Screen projection */ + projection_utm, /*!< UTM projection */ + SIZE }; enum map_datum { From 5d0bfe0710bd185b0630507ecff919ed318752df Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 14 Jan 2023 19:04:53 +0100 Subject: [PATCH 12/23] Changes to fix handling of UTM coordinates. Allow capital letters in UTM coordinates. --- navit/projection.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/navit/projection.c b/navit/projection.c index 512a4d8883..88737604f4 100644 --- a/navit/projection.c +++ b/navit/projection.c @@ -65,28 +65,34 @@ enum projection projection_from_name(const char *name, struct coord *utm_offset) 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')) { + int scanres = sscanf(name,"utm%d%c",&zone,&ns); + ns = tolower(ns); + if (scanres == 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)) { + zone=tolower(zone); + zone_field=tolower(zone_field); + square_x=tolower(square_x); + square_y=tolower(square_y); i=utmref_letter(zone_field); if (i < 2 || i > 21) { - dbg(lvl_error,"invalid zone field '%c' in '%s'",zone_field,name); + printf("invalid zone field '%c' in '%s'",zone_field,name); return projection_none; } i-=12; - dbg(lvl_debug,"zone_field %d",i); + printf("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); + printf("baserow %d",baserow); if (!(zone % 2)) i-=5; - dbg(lvl_debug,"i=%d",i); + printf("i=%d",i); i=(i-baserow+100)%20+baserow; utm_offset->y=i*100000; return projection_utm; From 223b8b36dfe2719623e2a4398979fc4b055a0f0d Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 14 Jan 2023 19:11:55 +0100 Subject: [PATCH 13/23] Changed SIZE to projection_enumsize --- navit/coord.c | 2 +- navit/projection.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/navit/coord.c b/navit/coord.c index ede1b0a451..a790c5a65a 100644 --- a/navit/coord.c +++ b/navit/coord.c @@ -39,7 +39,7 @@ * @returns the coordinate */ -int projection_enum_size[SIZE]; +int projection_enum_size[projection_enumsize]; #define PROJASSTRING(x) (x==0?"projection_none":x==1?"projection_mg":x==2?"projection_garmin":x==3?"projection_screen":x==4?"projection_utm":"UNKNOWN") struct coord * coord_get(unsigned char **p) { diff --git a/navit/projection.h b/navit/projection.h index 06f74e4ea4..26126d7b3f 100644 --- a/navit/projection.h +++ b/navit/projection.h @@ -26,7 +26,7 @@ enum projection { projection_garmin, /*!< Garmin projection */ projection_screen, /*!< Screen projection */ projection_utm, /*!< UTM projection */ - SIZE + projection_enumsize }; enum map_datum { From fb0afeb3d31a79ce033edd6a667941aa33d5b5f8 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 21 Jan 2023 08:42:44 +0100 Subject: [PATCH 14/23] Removed unneccessary macro PROJASSTRING --- navit/coord.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/navit/coord.c b/navit/coord.c index a790c5a65a..f88ea75a49 100644 --- a/navit/coord.c +++ b/navit/coord.c @@ -39,9 +39,6 @@ * @returns the coordinate */ -int projection_enum_size[projection_enumsize]; -#define PROJASSTRING(x) (x==0?"projection_none":x==1?"projection_mg":x==2?"projection_garmin":x==3?"projection_screen":x==4?"projection_utm":"UNKNOWN") - struct coord * coord_get(unsigned char **p) { struct coord *ret=(struct coord *)(*p); *p += sizeof(*ret); @@ -158,7 +155,7 @@ int coord_parse(const char *coord_input, enum projection output_projection, stru int space_as_sep = 0; dbg(lvl_debug, "enter('%s',%s,%p)\n", coord_input, - PROJASSTRING(output_projection), result); + projection_to_name(output_projection), result); co = strchr(str, ':'); if (co) s = strstr(str, ": "); @@ -178,7 +175,7 @@ int coord_parse(const char *coord_input, enum projection output_projection, stru else { str_pro = projection_from_name(proj, &offset); if (str_pro == projection_none) { - dbg(lvl_debug, "Unknown projection: %s\n", proj); + dbg(lvl_error, "Unknown projection: %s\n", proj); goto out; } } @@ -209,7 +206,7 @@ int coord_parse(const char *coord_input, enum projection output_projection, stru if (args < 4) goto out; dbg(lvl_debug, "projection=%s str_pro=%d projection_none=%d\n", - PROJASSTRING(output_projection), str_pro, projection_none); + projection_to_name(output_projection), str_pro, projection_none); if (str_pro == projection_none) { g.lat = floor(lat / 100); lat -= g.lat * 100; From 90d36d7b1a049eccbe5dab9542de85e2f1f6ec6f Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 21 Jan 2023 08:43:10 +0100 Subject: [PATCH 15/23] Removed unneccessary enum value projection_enumsize --- navit/projection.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/navit/projection.h b/navit/projection.h index 26126d7b3f..26a3284f7b 100644 --- a/navit/projection.h +++ b/navit/projection.h @@ -21,12 +21,11 @@ #define NAVIT_PROJECTION_H enum projection { - projection_none, /*!< No projection or unknown projection */ + projection_none, /*!< No projection or unknown projection */ projection_mg, /*!< Mercator projection */ projection_garmin, /*!< Garmin projection */ projection_screen, /*!< Screen projection */ - projection_utm, /*!< UTM projection */ - projection_enumsize + projection_utm /*!< UTM projection */ }; enum map_datum { From 7c2492af1b117413c044adf4e2e954571b0f32ce Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 21 Jan 2023 08:44:15 +0100 Subject: [PATCH 16/23] Use dbg instead of printf again --- navit/projection.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/navit/projection.c b/navit/projection.c index 88737604f4..61d4c2b13a 100644 --- a/navit/projection.c +++ b/navit/projection.c @@ -79,20 +79,20 @@ enum projection projection_from_name(const char *name, struct coord *utm_offset) square_y=tolower(square_y); i=utmref_letter(zone_field); if (i < 2 || i > 21) { - printf("invalid zone field '%c' in '%s'",zone_field,name); + dbg(lvl_error,"invalid zone field '%c' in '%s'",zone_field,name); return projection_none; } i-=12; - printf("zone_field %d",i); + 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); - printf("baserow %d",baserow); + dbg(lvl_debug,"baserow %d",baserow); if (!(zone % 2)) i-=5; - printf("i=%d",i); + dbg(lvl_debug,"i=%d",i); i=(i-baserow+100)%20+baserow; utm_offset->y=i*100000; return projection_utm; From c187fda939b8b08b65d76a5e8555bad12742e47e Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 21 Jan 2023 08:44:46 +0100 Subject: [PATCH 17/23] Linked new file coordinates.rst --- docs/configuration/general.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration/general.rst b/docs/configuration/general.rst index 34b201d614..52813adaaa 100644 --- a/docs/configuration/general.rst +++ b/docs/configuration/general.rst @@ -18,7 +18,7 @@ On Navit's very first startup, it needs a **center** to look at on the map. By d center="11.5666 48.1333" -Coordinates can be written in different formats; see [[Coordinate_format]] for the full list. +Coordinates can be written in different formats; see :doc:`coordinates` for the full list. To determine a specific latitude and longitude for your location you can use http://itouchmap.com/latlong.html. Usually, changing the "center" setting is not necessary, since it is only used during the first start. On subsequent starts, Navit will remember the last map position (stored in "center.txt") and ignore the "center" setting. From d9c0f975d2a4e1832b74e1cf2919650da73b6ac8 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 21 Jan 2023 10:54:41 +0100 Subject: [PATCH 18/23] astyle --- navit/coord.c | 237 +++++++++++++++++++++++++------------------------- 1 file changed, 119 insertions(+), 118 deletions(-) diff --git a/navit/coord.c b/navit/coord.c index f88ea75a49..77f0662f28 100644 --- a/navit/coord.c +++ b/navit/coord.c @@ -146,124 +146,125 @@ void coord_rect_extend(struct coord_rect *r, struct coord *c) { */ int coord_parse(const char *coord_input, enum projection output_projection, struct coord *result) { - char *proj = NULL, *s = NULL, *co; - const char *str = coord_input; - int args, ret = 0; - struct coord_geo g; - struct coord c, offset; - enum projection str_pro = projection_none; - int space_as_sep = 0; - - dbg(lvl_debug, "enter('%s',%s,%p)\n", coord_input, - projection_to_name(output_projection), result); - co = strchr(str, ':'); - if (co) - s = strstr(str, ": "); - if (s) { - space_as_sep = 1; - } - if (co) { - proj = g_malloc(co - str + 1); - g_strlcpy(proj, str, 1 + co - str); - dbg(lvl_debug, "projection=%s\n", proj); - str = co + 1; - if (space_as_sep) - str++; - s = (char*) str; - if (!strcmp(proj, "geo")) - str_pro = projection_none; - else { - str_pro = projection_from_name(proj, &offset); - if (str_pro == projection_none) { - dbg(lvl_error, "Unknown projection: %s\n", proj); - goto out; - } - } - } else { - s = (char*) str; - } - if ((!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3))) { - args = sscanf(str, "%i %i%n", &c.x, &c.y, &ret); - if (args < 2) - goto out; - dbg(lvl_debug, "str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret); - dbg(lvl_debug, "rest='%s'\n", str + ret); - - if (str_pro == projection_none) - str_pro = projection_mg; - if (str_pro != output_projection) { - transform_to_geo(str_pro, &c, &g); - transform_from_geo(output_projection, &g, &c); - } - *result = c; - } else if ((*s == 'N' || *s == 'n' || *s == 'S' || *s == 's')) { - double lng, lat; - char ns, ew; - dbg(lvl_debug, "str='%s'\n", str); - args = sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret); - dbg(lvl_debug, "args=%d\n", args); - dbg(lvl_debug, "lat=%f %c lon=%f %c\n", lat, ns, lng, ew); - if (args < 4) - goto out; - dbg(lvl_debug, "projection=%s str_pro=%d projection_none=%d\n", - projection_to_name(output_projection), str_pro, projection_none); - if (str_pro == projection_none) { - g.lat = floor(lat / 100); - lat -= g.lat * 100; - g.lat += lat / 60; - g.lng = floor(lng / 100); - lng -= g.lng * 100; - g.lng += lng / 60; - if (ns == 's' || ns == 'S') - g.lat = -g.lat; - if (ew == 'w' || ew == 'W') - g.lng = -g.lng; - dbg(lvl_debug, "transform_from_geo(%f,%f)\n", g.lat, g.lng); - transform_from_geo(output_projection, &g, result); - dbg(lvl_debug, "result 0x%x,0x%x\n", result->x, result->y); - } - dbg(lvl_debug, "str='%s' x=%f ns=%c y=%f ew=%c c=%d\n", str, lng, ns, - lat, ew, ret); - dbg(lvl_debug, "rest='%s'\n", str + ret); - } else if (str_pro == projection_utm) { - double x, y; - args = sscanf(str, "%lf %lf%n", &x, &y, &ret); - if (args < 2) - goto out; - c.x = x + offset.x; - c.y = y + offset.y; - if (str_pro != output_projection) { - transform_to_geo(str_pro, &c, &g); - transform_from_geo(output_projection, &g, &c); - } - *result = c; - } else if (!space_as_sep) { - // When entering coords like google's format, we actually get strings like "52.5219,19.4127" - double lng, lat; - args = sscanf(str, "%lf,%lf%n", &lat, &lng, &ret); - if (args < 2) - goto out; - dbg(lvl_debug, "str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); - dbg(lvl_debug, "rest='%s'\n", str + ret); - g.lng = lng; - g.lat = lat; - transform_from_geo(output_projection, &g, result); - } else { - double lng, lat; - args = sscanf(str, "%lf %lf%n", &lng, &lat, &ret); - if (args < 2) - goto out; - dbg(lvl_debug, "str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); - dbg(lvl_debug, "rest='%s'\n", str + ret); - g.lng = lng; - g.lat = lat; - transform_from_geo(output_projection, &g, result); - } - ret += str - coord_input; - dbg(lvl_debug, "ret=%d delta=%d ret_str='%s'\n", ret, - GPOINTER_TO_INT(str - coord_input), coord_input + ret); - out: g_free(proj); - return ret; + char *proj = NULL, *s = NULL, *co; + const char *str = coord_input; + int args, ret = 0; + struct coord_geo g; + struct coord c, offset; + enum projection str_pro = projection_none; + int space_as_sep = 0; + + dbg(lvl_debug, "enter('%s',%s,%p)\n", coord_input, + projection_to_name(output_projection), result); + co = strchr(str, ':'); + if (co) + s = strstr(str, ": "); + if (s) { + space_as_sep = 1; + } + if (co) { + proj = g_malloc(co - str + 1); + g_strlcpy(proj, str, 1 + co - str); + dbg(lvl_debug, "projection=%s\n", proj); + str = co + 1; + if (space_as_sep) + str++; + s = (char*) str; + if (!strcmp(proj, "geo")) + str_pro = projection_none; + else { + str_pro = projection_from_name(proj, &offset); + if (str_pro == projection_none) { + dbg(lvl_error, "Unknown projection: %s\n", proj); + goto out; + } + } + } else { + s = (char*) str; + } + if ((!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3))) { + args = sscanf(str, "%i %i%n", &c.x, &c.y, &ret); + if (args < 2) + goto out; + dbg(lvl_debug, "str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret); + dbg(lvl_debug, "rest='%s'\n", str + ret); + + if (str_pro == projection_none) + str_pro = projection_mg; + if (str_pro != output_projection) { + transform_to_geo(str_pro, &c, &g); + transform_from_geo(output_projection, &g, &c); + } + *result = c; + } else if ((*s == 'N' || *s == 'n' || *s == 'S' || *s == 's')) { + double lng, lat; + char ns, ew; + dbg(lvl_debug, "str='%s'\n", str); + args = sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret); + dbg(lvl_debug, "args=%d\n", args); + dbg(lvl_debug, "lat=%f %c lon=%f %c\n", lat, ns, lng, ew); + if (args < 4) + goto out; + dbg(lvl_debug, "projection=%s str_pro=%d projection_none=%d\n", + projection_to_name(output_projection), str_pro, projection_none); + if (str_pro == projection_none) { + g.lat = floor(lat / 100); + lat -= g.lat * 100; + g.lat += lat / 60; + g.lng = floor(lng / 100); + lng -= g.lng * 100; + g.lng += lng / 60; + if (ns == 's' || ns == 'S') + g.lat = -g.lat; + if (ew == 'w' || ew == 'W') + g.lng = -g.lng; + dbg(lvl_debug, "transform_from_geo(%f,%f)\n", g.lat, g.lng); + transform_from_geo(output_projection, &g, result); + dbg(lvl_debug, "result 0x%x,0x%x\n", result->x, result->y); + } + dbg(lvl_debug, "str='%s' x=%f ns=%c y=%f ew=%c c=%d\n", str, lng, ns, + lat, ew, ret); + dbg(lvl_debug, "rest='%s'\n", str + ret); + } else if (str_pro == projection_utm) { + double x, y; + args = sscanf(str, "%lf %lf%n", &x, &y, &ret); + if (args < 2) + goto out; + c.x = x + offset.x; + c.y = y + offset.y; + if (str_pro != output_projection) { + transform_to_geo(str_pro, &c, &g); + transform_from_geo(output_projection, &g, &c); + } + *result = c; + } else if (!space_as_sep) { + // When entering coords like google's format, we actually get strings like "52.5219,19.4127" + double lng, lat; + args = sscanf(str, "%lf,%lf%n", &lat, &lng, &ret); + if (args < 2) + goto out; + dbg(lvl_debug, "str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); + dbg(lvl_debug, "rest='%s'\n", str + ret); + g.lng = lng; + g.lat = lat; + transform_from_geo(output_projection, &g, result); + } else { + double lng, lat; + args = sscanf(str, "%lf %lf%n", &lng, &lat, &ret); + if (args < 2) + goto out; + dbg(lvl_debug, "str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); + dbg(lvl_debug, "rest='%s'\n", str + ret); + g.lng = lng; + g.lat = lat; + transform_from_geo(output_projection, &g, result); + } + ret += str - coord_input; + dbg(lvl_debug, "ret=%d delta=%d ret_str='%s'\n", ret, + GPOINTER_TO_INT(str - coord_input), coord_input + ret); +out: + g_free(proj); + return ret; } /** From 4f64b746c74b20a2094cca77115e071f441a312a Mon Sep 17 00:00:00 2001 From: OLFDB Date: Sat, 21 Jan 2023 14:36:39 +0100 Subject: [PATCH 19/23] Update after testing with all coordinate formats. Google Maps included. --- navit/coord.c | 136 +++++++++++++++++++++++++++----------------------- 1 file changed, 73 insertions(+), 63 deletions(-) diff --git a/navit/coord.c b/navit/coord.c index 77f0662f28..d2c4f61a95 100644 --- a/navit/coord.c +++ b/navit/coord.c @@ -145,123 +145,133 @@ void coord_rect_extend(struct coord_rect *r, struct coord *c) { * @returns The lenght of the parsed string */ -int coord_parse(const char *coord_input, enum projection output_projection, struct coord *result) { - char *proj = NULL, *s = NULL, *co; - const char *str = coord_input; - int args, ret = 0; +int coord_parse(const char *coord_input, enum projection output_projection, struct coord *result) { + char *proj=NULL,*s=NULL,*co; + const char *str=coord_input; + int args,ret = 0; struct coord_geo g; - struct coord c, offset; - enum projection str_pro = projection_none; + struct coord c,offset; + enum projection str_pro=projection_none; int space_as_sep = 0; + c.x=0; + c.y=0; + + dbg(lvl_debug,"enter('%s',%s,%p)\n", coord_input, projection_to_name(output_projection), result); + co=strchr(str,':'); + if(co) + s=strstr(str, ": "); + else { + while(*str==' ') { + str++; + } + s=strstr(str, " "); + while(s && *s==' ') { + s++; + } + } + - dbg(lvl_debug, "enter('%s',%s,%p)\n", coord_input, - projection_to_name(output_projection), result); - co = strchr(str, ':'); - if (co) - s = strstr(str, ": "); - if (s) { + if (s && !strstr(str, ",")) { space_as_sep = 1; } if (co) { - proj = g_malloc(co - str + 1); - g_strlcpy(proj, str, 1 + co - str); - dbg(lvl_debug, "projection=%s\n", proj); - str = co + 1; - if (space_as_sep) + proj=g_malloc(co-str+1); + g_strlcpy(proj, str, 1+co-str); + dbg(lvl_debug,"projection=%s\n", proj); + str=co+1; + if(space_as_sep) str++; - s = (char*) str; + s=(char*)str; if (!strcmp(proj, "geo")) str_pro = projection_none; else { - str_pro = projection_from_name(proj, &offset); + str_pro = projection_from_name(proj,&offset); if (str_pro == projection_none) { dbg(lvl_error, "Unknown projection: %s\n", proj); goto out; } } - } else { - s = (char*) str; + } else if (!space_as_sep || strstr(str, "0x")) { + s=(char*)str; } if ((!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3))) { - args = sscanf(str, "%i %i%n", &c.x, &c.y, &ret); + args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret); if (args < 2) goto out; - dbg(lvl_debug, "str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret); - dbg(lvl_debug, "rest='%s'\n", str + ret); + dbg(lvl_debug,"str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret); + dbg(lvl_debug,"rest='%s'\n", str+ret); if (str_pro == projection_none) - str_pro = projection_mg; + str_pro=projection_mg; if (str_pro != output_projection) { transform_to_geo(str_pro, &c, &g); transform_from_geo(output_projection, &g, &c); } - *result = c; + *result=c; } else if ((*s == 'N' || *s == 'n' || *s == 'S' || *s == 's')) { double lng, lat; char ns, ew; - dbg(lvl_debug, "str='%s'\n", str); - args = sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret); - dbg(lvl_debug, "args=%d\n", args); - dbg(lvl_debug, "lat=%f %c lon=%f %c\n", lat, ns, lng, ew); + dbg(lvl_debug,"str='%s'\n", str); + args=sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret); + dbg(lvl_debug,"args=%d\n", args); + dbg(lvl_debug,"lat=%f %c lon=%f %c\n", lat, ns, lng, ew); if (args < 4) goto out; - dbg(lvl_debug, "projection=%s str_pro=%d projection_none=%d\n", - projection_to_name(output_projection), str_pro, projection_none); + dbg(lvl_debug,"projection=%s str_pro=%d projection_none=%d\n", projection_to_name(output_projection), str_pro, + projection_none); if (str_pro == projection_none) { - g.lat = floor(lat / 100); - lat -= g.lat * 100; - g.lat += lat / 60; - g.lng = floor(lng / 100); - lng -= g.lng * 100; - g.lng += lng / 60; + g.lat=floor(lat/100); + lat-=g.lat*100; + g.lat+=lat/60; + g.lng=floor(lng/100); + lng-=g.lng*100; + g.lng+=lng/60; if (ns == 's' || ns == 'S') - g.lat = -g.lat; + g.lat=-g.lat; if (ew == 'w' || ew == 'W') - g.lng = -g.lng; - dbg(lvl_debug, "transform_from_geo(%f,%f)\n", g.lat, g.lng); + g.lng=-g.lng; + dbg(lvl_debug,"transform_from_geo(%f,%f)\n",g.lat,g.lng); transform_from_geo(output_projection, &g, result); - dbg(lvl_debug, "result 0x%x,0x%x\n", result->x, result->y); + dbg(lvl_debug,"result 0x%x,0x%x\n", result->x,result->y); } - dbg(lvl_debug, "str='%s' x=%f ns=%c y=%f ew=%c c=%d\n", str, lng, ns, - lat, ew, ret); - dbg(lvl_debug, "rest='%s'\n", str + ret); + dbg(lvl_debug,"str='%s' x=%f ns=%c y=%f ew=%c c=%d\n", str, lng, ns, lat, ew, ret); + dbg(lvl_debug,"rest='%s'\n", str+ret); } else if (str_pro == projection_utm) { - double x, y; - args = sscanf(str, "%lf %lf%n", &x, &y, &ret); + double x,y; + args=sscanf(str, "%lf %lf%n", &x, &y, &ret); if (args < 2) goto out; - c.x = x + offset.x; - c.y = y + offset.y; + c.x=x+offset.x; + c.y=y+offset.y; if (str_pro != output_projection) { transform_to_geo(str_pro, &c, &g); transform_from_geo(output_projection, &g, &c); } - *result = c; + *result=c; } else if (!space_as_sep) { // When entering coords like google's format, we actually get strings like "52.5219,19.4127" double lng, lat; - args = sscanf(str, "%lf,%lf%n", &lat, &lng, &ret); + args=sscanf(str, "%lf,%lf%n", &lat, &lng, &ret); if (args < 2) goto out; - dbg(lvl_debug, "str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); - dbg(lvl_debug, "rest='%s'\n", str + ret); - g.lng = lng; - g.lat = lat; + dbg(lvl_debug,"str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); + dbg(lvl_debug,"rest='%s'\n", str+ret); + g.lng=lng; + g.lat=lat; transform_from_geo(output_projection, &g, result); } else { double lng, lat; - args = sscanf(str, "%lf %lf%n", &lng, &lat, &ret); + args=sscanf(str, "%lf %lf%n", &lng, &lat, &ret); if (args < 2) goto out; - dbg(lvl_debug, "str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); - dbg(lvl_debug, "rest='%s'\n", str + ret); - g.lng = lng; - g.lat = lat; + dbg(lvl_debug,"str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); + dbg(lvl_debug,"rest='%s'\n", str+ret); + g.lng=lng; + g.lat=lat; transform_from_geo(output_projection, &g, result); } - ret += str - coord_input; - dbg(lvl_debug, "ret=%d delta=%d ret_str='%s'\n", ret, - GPOINTER_TO_INT(str - coord_input), coord_input + ret); + ret+=str-coord_input; + dbg(lvl_debug, "ret=%d delta=%d ret_str='%s'\n", ret, GPOINTER_TO_INT(str-coord_input), coord_input+ret); out: g_free(proj); return ret; From c3dba1b14c7d72f2bea99fe2ef3c768eb686d589 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Tue, 31 Jan 2023 19:04:39 +0100 Subject: [PATCH 20/23] Changed to rst format and added Google Maps coordinates description --- docs/configuration/coordinates.rst | 148 +++++++++++++++++++---------- 1 file changed, 100 insertions(+), 48 deletions(-) diff --git a/docs/configuration/coordinates.rst b/docs/configuration/coordinates.rst index be8c67b6ea..a127f299ec 100644 --- a/docs/configuration/coordinates.rst +++ b/docs/configuration/coordinates.rst @@ -1,84 +1,136 @@ -## Coordinates in Navit +Coordinates in Navit +==================== -Various parts of Navit will read geographical coordinates provided as text: +Various parts of Navit will read geographical coordinates provided as +text: -- the [textfile](https://wiki.navit-project.org/index.php/Textfile) map format -- the "center=" attribute in the configuration file -- some Navit commands (e.g. set_position), which can be invoked via the [internal GUI](https://wiki.navit-project.org/index.php/Internal_GUI) or the [Dbus](https://wiki.navit-project.org/index.php/Dbus) bindings -- the files for bookmarks and last map position (bookmarks.txt and center.txt) +- the `textfile `__ + map format -This page documents the coordinate systems and formats that Navit will accept. +- the "center=" attribute in the configuration file -## Supported coordinate systems and formats +- some Navit commands (e.g. set_position), which can be invoked via + the `internal + GUI `__ or the + `Dbus `__ bindings -### Longitude / Latitude in decimal degrees +- the files for bookmarks and last map position (bookmarks.txt and + center.txt) -Longitude / latitude in degrees can be specified as signed decimal fractions: +This page documents the coordinate systems and formats that Navit will +accept. -``` --33.3553 6.334 -``` +Supported coordinate systems and formats +======================================== -That would be about 33° West, 6° North. Note that in this format longitude comes first. The coordinates are assumed to be based on WGS84 (the coordinate system used by the GPS system, and by practically all common navigation systems). +.. _longitude--latitude-in-decimal-degrees: -### Latitude / Longitude in degrees and minutes +Longitude / Latitude in decimal degrees +--------------------------------------- -Latitude / Longitude can also be specified in degress and minutes with compass directions (N/S, E/W): +Longitude / latitude in degrees can be specified as signed decimal +fractions: -``` -4808 N 1134 E -``` +.. code:: -Latitude and longitude are multiplied by 100, so the position above corresponds to 48°8' N, 11°34' (Munich). + -33.3553 6.334 + +That would be about 33° West, 6° North. Note that in this format +longitude comes first. The coordinates are assumed to be based on WGS84 +(the coordinate system used by the GPS system, and by practically all +common navigation systems). + +.. _latitude--longitude-in-degrees-and-minutes: + +Latitude / Longitude in degrees and minutes +------------------------------------------- + +Latitude / Longitude can also be specified in degress and minutes with +compass directions (N/S, E/W): + +.. code:: + + 4808 N 1134 E + +Latitude and longitude are multiplied by 100, so the position above +corresponds to 48°8' N, 11°34' (Munich). For greater precision you can write the minutes as decimal fractions: -``` -4808.2356 N 1134.5252 E -``` +.. code:: + + 4808.2356 N 1134.5252 E -That is 48°8.2356' N 11°34.5252' E, the center of the Marienplatz in Munich. +That is 48°8.2356' N 11°34.5252' E, the center of the Marienplatz in +Munich. Notes: -- This format is rather unusual (because it uses arcminutes, but not arcseconds). It is probably easier to just use decimal fractions of degrees. -- The spaces are relevant for parsing. Use exactly one space between the number and the letter N/S/E/W. +- This format is rather unusual (because it uses arcminutes, but not + arcseconds). It is probably easier to just use decimal fractions of + degrees. -### Cartesian coordinates +- The spaces are relevant for parsing. Use exactly one space between + the number and the letter N/S/E/W. -Internally, Navit uses a cartesian coordinate system induced by a Mercator projection. Coordinates are written as hexadecimal integers: +Cartesian coordinates +--------------------- -``` -0x13a3d7 0x5d6d6d -``` +Internally, Navit uses a cartesian coordinate system induced by a +Mercator projection. Coordinates are written as hexadecimal integers: + +.. code:: + + 0x13a3d7 0x5d6d6d or specifying a projection: -``` -mg: 0x13a3d7 0x5d6d6d -``` +.. code:: + + mg: 0x13a3d7 0x5d6d6d + +That is again 48°8.2356' N 11°34.5252' E. The part up to and including +the colon is optional, it names the projection to use. Possible values: + +- mg - the projection used by Map&Guide (the default) + +- garmin - "Garmin" projection (TODO: When would it be useful?) + +This format is used internally by Navit, but is probably not very useful +for other purposes. + +Google Maps Format +------------------ -That is again 48°8.2356' N 11°34.5252' E. The part up to and including the colon is optional, it names the projection to use. Possible values: +.. code:: -- mg - the projection used by Map&Guide (the default) -- garmin - "Garmin" projection (TODO: When would it be useful?) + 48.137260, 11.575420 -This format is used internally by Navit, but is probably not very useful for other purposes. +That is again 48°8.2356' N 11°34.5252' E. The values are comma +separated. You can pick such values from Google Maps with right click on +a location and then click on the coordinate in the context menu. This is +useful when planning a route online by creating a waypoint file. -### UTM coordinates +UTM coordinates +--------------- -Navit can read coordinates in the [Universal Transverse Mercator coordinate system](http://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system) (UTM). +Navit can read coordinates in the `Universal Transverse Mercator +coordinate +system `__ +(UTM). -``` -utm32U: 674499.306 5328063.675 -``` +.. code:: -``` -utmref32UPU:74499.306 28063.675 -``` + utm32U: 674499.306 5328063.675 +.. code:: + utmref32UPU:74499.306 28063.675 -## Development notes +Development notes +================= -The coordinates are parsed in function coord_parse() in coord.c. This code is used everywhere where Navit parses coordinates, except for the manual coordinate input in the Internal GUI (which uses its own format and parsing function). \ No newline at end of file +The coordinates are parsed in function coord_parse() in coord.c. This +code is used everywhere where Navit parses coordinates, except for the +manual coordinate input in the Internal GUI (which uses its own format +and parsing function). From 55f0c86eec4cbd20d6fe7a6607b629f90f43e2fc Mon Sep 17 00:00:00 2001 From: OLFDB Date: Tue, 26 Dec 2023 08:05:19 +0100 Subject: [PATCH 21/23] Revert "Merge branch 'trunk' into bookmarkissue" This reverts commit 1167d944f6b6580747f55e2bfd812f3afbb4fcb1, reversing changes made to c3dba1b14c7d72f2bea99fe2ef3c768eb686d589. --- README.md | 2 +- navit/attr.h | 23 +- navit/attr_type_def.h | 37 --- navit/debug.c | 5 +- navit/item.h | 9 +- navit/item_type_def.h | 22 -- navit/map/garmin/garmin.c | 416 ++++++++++++++++---------------- navit/maptool/osm.c | 2 +- navit/search_houseno_interpol.c | 5 +- navit/search_houseno_interpol.h | 1 - navit/speech.h | 2 - navit/util.c | 2 +- po/nl.po.in | 2 +- po/sr.po.in | 2 +- po/zh_TW.po.in | 1 - 15 files changed, 242 insertions(+), 289 deletions(-) delete mode 100644 navit/attr_type_def.h delete mode 100644 navit/item_type_def.h diff --git a/README.md b/README.md index ebba63b567..af7d457033 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Current vehicle position from gpsd or directly from NMEA (GPS) sensors. \ Optimal routes and directions spoken in 70+ languages. \ Points of interest (POIs) in many formats. -Help and more info available on [the wiki](https://navit.readthedocs.io/en/v0.5.6/). \ +Help and more info available on [the wiki](https://wiki.navit-project.org/index.php/Main_Page). \ The [Reporting Bugs](http://wiki.navit-project.org/index.php/Reporting_Bugs) document helps you file issues. Maps diff --git a/navit/attr.h b/navit/attr.h index 5eed1718f4..cae591ffd6 100644 --- a/navit/attr.h +++ b/navit/attr.h @@ -28,7 +28,28 @@ extern "C" { enum item_type; -#include "attr_type_def.h" +/** + * Attribute type values, created using macro magic. + */ +enum attr_type { +#define ATTR2(x,y) attr_##y=x, +#define ATTR(x) attr_##x, + + /* Special macro for unused attribute types. Creates a placeholder entry + * in the enum so the following values do not change. */ +#define ATTR_UNUSED ATTR_UNUSED_L(__LINE__) +#define ATTR_UNUSED_L(x) ATTR_UNUSED_WITH_LINE_NUMBER(x) +#define ATTR_UNUSED_WITH_LINE_NUMBER(x) ATTR_UNUSED_##x, + +#include "attr_def.h" + +#undef ATTR_UNUSED_WITH_LINE_NUMBER +#undef ATTR_UNUSED_L +#undef ATTR_UNUSED + +#undef ATTR2 +#undef ATTR +}; enum attr_format { attr_format_default=0, diff --git a/navit/attr_type_def.h b/navit/attr_type_def.h deleted file mode 100644 index af0b6571f7..0000000000 --- a/navit/attr_type_def.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef NAVIT_ATTR_TYPE_DEFH -#define NAVIT_ATTR_TYPE_DEFH - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Attribute type values, created using macro magic. - */ -enum attr_type { -#define ATTR2(x,y) attr_##y=x, -#define ATTR(x) attr_##x, - - /* Special macro for unused attribute types. Creates a placeholder entry - * in the enum so the following values do not change. */ -#define ATTR_UNUSED ATTR_UNUSED_L(__LINE__) -#define ATTR_UNUSED_L(x) ATTR_UNUSED_WITH_LINE_NUMBER(x) -#define ATTR_UNUSED_WITH_LINE_NUMBER(x) ATTR_UNUSED_##x, - -#include "attr_def.h" - -#undef ATTR_UNUSED_WITH_LINE_NUMBER -#undef ATTR_UNUSED_L -#undef ATTR_UNUSED - -#undef ATTR2 -#undef ATTR -}; - -#ifdef __cplusplus -} -/* __cplusplus */ -#endif - -/* NAVIT_ATTR_TYPE_DEFH */ -#endif diff --git a/navit/debug.c b/navit/debug.c index 9c615f8398..e46637cb21 100644 --- a/navit/debug.c +++ b/navit/debug.c @@ -472,9 +472,6 @@ void debug_dump_mallocs(void) { } } - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wframe-address" // We know what we are doing here, suppress warning void *debug_malloc(const char *where, int line, const char *func, int size) { struct malloc_head *head; struct malloc_tail *tail; @@ -511,7 +508,7 @@ void *debug_malloc(const char *where, int line, const char *func, int size) { tail->magic=0xdeadbef0; return head; } -#pragma GCC diagnostic pop + void *debug_malloc0(const char *where, int line, const char *func, int size) { void *ret=debug_malloc(where, line, func, size); diff --git a/navit/item.h b/navit/item.h index d1ee433b98..d3e222196b 100644 --- a/navit/item.h +++ b/navit/item.h @@ -25,7 +25,14 @@ extern "C" { #endif #include -#include "item_type_def.h" + +enum item_type { +#define ITEM2(x,y) type_##y=x, +#define ITEM(x) type_##x, +#include "item_def.h" +#undef ITEM2 +#undef ITEM +}; #define route_item_first type_street_0 #define route_item_last type_street_parking_lane diff --git a/navit/item_type_def.h b/navit/item_type_def.h deleted file mode 100644 index cecad21cb3..0000000000 --- a/navit/item_type_def.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef NAVIT_ITEM_TYPE_DEFH -#define NAVIT_ITEM_TYPE_DEFH - -#ifdef __cplusplus -extern "C" { -#endif - -enum item_type { -#define ITEM2(x,y) type_##y=x, -#define ITEM(x) type_##x, -#include "item_def.h" -#undef ITEM2 -#undef ITEM -}; - -#ifdef __cplusplus -} -/* __cplusplus */ -#endif - -/* NAVIT_ITEM_TYPE_DEFH */ -#endif diff --git a/navit/map/garmin/garmin.c b/navit/map/garmin/garmin.c index 79768bcc3d..2f4808b3bf 100644 --- a/navit/map/garmin/garmin.c +++ b/navit/map/garmin/garmin.c @@ -95,44 +95,44 @@ struct gscale { int bits; }; -//static struct gscale mapscales[] = { -// {"7000 km", 70000.0, 8} -// ,{"5000 km", 50000.0, 8} -// ,{"3000 km", 30000.0, 9} -// ,{"2000 km", 20000.0, 9} -// ,{"1500 km", 15000.0, 10} -// ,{"1000 km", 10000.0, 10} -// ,{"700 km", 7000.0, 11} -// ,{"500 km", 5000.0, 11} -// ,{"300 km", 3000.0, 13} -// ,{"200 km", 2000.0, 13} -// ,{"150 km", 1500.0, 13} -// ,{"100 km", 1000.0, 14} -// ,{"70 km", 700.0, 15} -// ,{"50 km", 500.0, 16} -// ,{"30 km", 300.0, 16} -// ,{"20 km", 200.0, 17} -// ,{"15 km", 150.0, 17} -// ,{"10 km", 100.0, 18} -// ,{"7 km", 70.0, 18} -// ,{"5 km", 50.0, 19} -// ,{"3 km", 30.0, 19} -// ,{"2 km", 20.0, 20} -// ,{"1.5 km", 15.0, 22} -// ,{"1 km", 10.0, 24} -// ,{"700 m", 7.0, 24} -// ,{"500 m", 5.0, 24} -// ,{"300 m", 3.0, 24} -// ,{"200 m", 2.0, 24} -// ,{"150 m", 1.5, 24} -// ,{"100 m", 1.0, 24} -// ,{"70 m", 0.7, 24} -// ,{"50 m", 0.5, 24} -// ,{"30 m", 0.3, 24} -// ,{"20 m", 0.2, 24} -// ,{"15 m", 0.1, 24} -// ,{"10 m", 0.15, 24} -//}; +static struct gscale mapscales[] = { + {"7000 km", 70000.0, 8} + ,{"5000 km", 50000.0, 8} + ,{"3000 km", 30000.0, 9} + ,{"2000 km", 20000.0, 9} + ,{"1500 km", 15000.0, 10} + ,{"1000 km", 10000.0, 10} + ,{"700 km", 7000.0, 11} + ,{"500 km", 5000.0, 11} + ,{"300 km", 3000.0, 13} + ,{"200 km", 2000.0, 13} + ,{"150 km", 1500.0, 13} + ,{"100 km", 1000.0, 14} + ,{"70 km", 700.0, 15} + ,{"50 km", 500.0, 16} + ,{"30 km", 300.0, 16} + ,{"20 km", 200.0, 17} + ,{"15 km", 150.0, 17} + ,{"10 km", 100.0, 18} + ,{"7 km", 70.0, 18} + ,{"5 km", 50.0, 19} + ,{"3 km", 30.0, 19} + ,{"2 km", 20.0, 20} + ,{"1.5 km", 15.0, 22} + ,{"1 km", 10.0, 24} + ,{"700 m", 7.0, 24} + ,{"500 m", 5.0, 24} + ,{"300 m", 3.0, 24} + ,{"200 m", 2.0, 24} + ,{"150 m", 1.5, 24} + ,{"100 m", 1.0, 24} + ,{"70 m", 0.7, 24} + ,{"50 m", 0.5, 24} + ,{"30 m", 0.3, 24} + ,{"20 m", 0.2, 24} + ,{"15 m", 0.1, 24} + ,{"10 m", 0.15, 24} +}; static int garmin_object_label(struct gobject *o, struct attr *attr) { @@ -342,8 +342,6 @@ static int point_attr_get(void *priv_data, enum attr_type attr_type, struct attr mr->last_oattr = g; mr->last_attr = 0; } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough=" switch(mr->last_attr) { case 0: mr->last_attr++; @@ -378,7 +376,6 @@ static int point_attr_get(void *priv_data, enum attr_type attr_type, struct attr default: return 0; } -#pragma GCC diagnostic pop break; case attr_label: attr->type = attr_label; @@ -423,171 +420,168 @@ static struct item_methods methods_garmin_poly = { coord_is_node, }; -//static int search_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) { -// struct gobject *g = priv_data; -// struct map_rect_priv *mr = g->priv_data; -// int rc; -// switch (attr_type) { -// case attr_any: -// if (g != mr->last_oattr) { -// mr->last_oattr = g; -// mr->last_attr = 0; -// } -//#pragma GCC diagnostic push -//#pragma GCC diagnostic ignored "-Wimplicit-fallthrough=" -// switch(mr->last_attr) { -// case 0: -// mr->last_attr++; -// attr->type = attr_label; -// rc = garmin_object_label(g, attr); -// if (rc) -// return rc; -// case 1: -// mr->last_attr++; -// attr->type = attr_debug; -// rc = garmin_object_debug(g, attr); -// if (rc) -// return rc; -// case 2: -// mr->last_attr++; -// if (g->type == GO_POLYLINE) { -// attr->type = attr_street_name; -// rc = garmin_object_label(g, attr); -// if (rc) -// return rc; -// } -// case 3: -// mr->last_attr++; -// attr->type = attr_flags; -// attr->u.num = 0; -// rc = gar_object_flags(g); -// if (rc & F_ONEWAY) -// attr->u.num |= AF_ONEWAY; -// if (rc & F_SEGMENTED) -// attr->u.num |= AF_SEGMENTED; -// return 1; -// default: -// return 0; -// } -//#pragma GCC diagnostic pop -// break; -// case attr_label: -// attr->type = attr_label; -// return garmin_object_label(g, attr); -// case attr_town_name: -// attr->type = attr_town_name; -// if (mr->label) -// free(mr->label); -// mr->label = gar_srch_get_city(g); -// attr->u.str = mr->label; -// if (attr->u.str) -// return 1; -// return 0; -// case attr_town_id: -// rc = gar_srch_get_cityid(g); -// if (rc) { -// attr->type = attr_town_id; -// attr->u.num = rc; -// return 1; -// } -// return 0; -// case attr_town_postal: -// attr->type = attr_town_postal; -// attr->u.str = gar_srch_get_zip(g); -// if (attr->u.str) -// return 1; -// return 0; -// case attr_street_name: -// attr->type = attr_street_name; -// if (mr->label) -// free(mr->label); -// mr->label = gar_srch_get_roadname(g); -// attr->u.str = mr->label; -// if (attr->u.str) -// return 1; -// return 0; -// case attr_street_id: -// attr->type = attr_street_id; -// attr->u.num = gar_srch_get_roadid(g); -// if (attr->u.num) -// return 1; -// return 0; -// case attr_flags: -// attr->type = attr_flags; -// attr->u.num = 0; -// rc = gar_object_flags(g); -// if (rc & F_ONEWAY) -// attr->u.num |= AF_ONEWAY; -// if (rc & F_SEGMENTED) -// attr->u.num |= AF_SEGMENTED; -// return 1; -// case attr_country_id: -// rc = gar_srch_get_countryid(g); -// if (rc) { -// attr->type = attr_country_id; -// attr->u.num = rc; -// return 1; -// } -// return 0; -// case attr_country_name: -// attr->type = attr_country_name; -// attr->u.str = gar_srch_get_country(g); -// if (attr->u.str) -// return 1; -// return 0; -// case attr_district_id: -// rc = gar_srch_get_regionid(g); -// if (rc) { -// attr->type = attr_district_id; -// attr->u.num = rc; -// return 1; -// } -// return 0; -// case attr_district_name: -// attr->type = attr_district_name; -// attr->u.str = gar_srch_get_region(g); -// if (attr->u.str) -// return 1; -// return 0; -// case attr_town_streets_item: -// return 0; -// default: -// dlog(1, "Don't know about attribute %d[%04X]=%s yet\n", -// attr_type,attr_type, attr_to_name(attr_type)); -// } -// -// return 0; -//} - -//static int search_coord_get(void *priv_data, struct coord *c, int count) { -// struct gobject *g = priv_data; -// struct map_rect_priv *mr = g->priv_data; -// struct gcoord gc; -// if (!count) -// return 0; -// if (g != mr->last_itterated) { -// mr->last_itterated = g; -// mr->last_coord = 0; -// } -// -// if (mr->last_coord > 0) -// return 0; -// -// if (gar_get_object_coord(mr->gmap, g, &gc)) { -// c->x = gc.x; -// c->y = gc.y; -// mr->last_coord++; -// return 1; -// } -// return 0; -//} - -//static struct item_methods methods_garmin_search = { -// coord_rewind, -// search_coord_get, -// attr_rewind, -// search_attr_get, -//}; +static int search_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) { + struct gobject *g = priv_data; + struct map_rect_priv *mr = g->priv_data; + int rc; + switch (attr_type) { + case attr_any: + if (g != mr->last_oattr) { + mr->last_oattr = g; + mr->last_attr = 0; + } + switch(mr->last_attr) { + case 0: + mr->last_attr++; + attr->type = attr_label; + rc = garmin_object_label(g, attr); + if (rc) + return rc; + case 1: + mr->last_attr++; + attr->type = attr_debug; + rc = garmin_object_debug(g, attr); + if (rc) + return rc; + case 2: + mr->last_attr++; + if (g->type == GO_POLYLINE) { + attr->type = attr_street_name; + rc = garmin_object_label(g, attr); + if (rc) + return rc; + } + case 3: + mr->last_attr++; + attr->type = attr_flags; + attr->u.num = 0; + rc = gar_object_flags(g); + if (rc & F_ONEWAY) + attr->u.num |= AF_ONEWAY; + if (rc & F_SEGMENTED) + attr->u.num |= AF_SEGMENTED; + return 1; + default: + return 0; + } + break; + case attr_label: + attr->type = attr_label; + return garmin_object_label(g, attr); + case attr_town_name: + attr->type = attr_town_name; + if (mr->label) + free(mr->label); + mr->label = gar_srch_get_city(g); + attr->u.str = mr->label; + if (attr->u.str) + return 1; + return 0; + case attr_town_id: + rc = gar_srch_get_cityid(g); + if (rc) { + attr->type = attr_town_id; + attr->u.num = rc; + return 1; + } + return 0; + case attr_town_postal: + attr->type = attr_town_postal; + attr->u.str = gar_srch_get_zip(g); + if (attr->u.str) + return 1; + return 0; + case attr_street_name: + attr->type = attr_street_name; + if (mr->label) + free(mr->label); + mr->label = gar_srch_get_roadname(g); + attr->u.str = mr->label; + if (attr->u.str) + return 1; + return 0; + case attr_street_id: + attr->type = attr_street_id; + attr->u.num = gar_srch_get_roadid(g); + if (attr->u.num) + return 1; + return 0; + case attr_flags: + attr->type = attr_flags; + attr->u.num = 0; + rc = gar_object_flags(g); + if (rc & F_ONEWAY) + attr->u.num |= AF_ONEWAY; + if (rc & F_SEGMENTED) + attr->u.num |= AF_SEGMENTED; + return 1; + case attr_country_id: + rc = gar_srch_get_countryid(g); + if (rc) { + attr->type = attr_country_id; + attr->u.num = rc; + return 1; + } + return 0; + case attr_country_name: + attr->type = attr_country_name; + attr->u.str = gar_srch_get_country(g); + if (attr->u.str) + return 1; + return 0; + case attr_district_id: + rc = gar_srch_get_regionid(g); + if (rc) { + attr->type = attr_district_id; + attr->u.num = rc; + return 1; + } + return 0; + case attr_district_name: + attr->type = attr_district_name; + attr->u.str = gar_srch_get_region(g); + if (attr->u.str) + return 1; + return 0; + case attr_town_streets_item: + return 0; + default: + dlog(1, "Don't know about attribute %d[%04X]=%s yet\n", + attr_type,attr_type, attr_to_name(attr_type)); + } + + return 0; +} + +static int search_coord_get(void *priv_data, struct coord *c, int count) { + struct gobject *g = priv_data; + struct map_rect_priv *mr = g->priv_data; + struct gcoord gc; + if (!count) + return 0; + if (g != mr->last_itterated) { + mr->last_itterated = g; + mr->last_coord = 0; + } + + if (mr->last_coord > 0) + return 0; + + if (gar_get_object_coord(mr->gmap, g, &gc)) { + c->x = gc.x; + c->y = gc.y; + mr->last_coord++; + return 1; + } + return 0; +} + +static struct item_methods methods_garmin_search = { + coord_rewind, + search_coord_get, + attr_rewind, + search_attr_get, +}; static struct item *garmin_poi2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype) { @@ -617,11 +611,11 @@ static struct item *garmin_pg2item(struct map_rect_priv *mr, struct gobject *o, return &mr->item; } -//static struct item *garmin_srch2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype) { -// mr->item.type = type_country_label; -// mr->item.meth = &methods_garmin_search; -// return &mr->item; -//} +static struct item *garmin_srch2item(struct map_rect_priv *mr, struct gobject *o, unsigned short otype) { + mr->item.type = type_country_label; + mr->item.meth = &methods_garmin_search; + return &mr->item; +} static struct item *garmin_obj2item(struct map_rect_priv *mr, struct gobject *o) { unsigned short otype; diff --git a/navit/maptool/osm.c b/navit/maptool/osm.c index c9531144b7..f76120e3e4 100644 --- a/navit/maptool/osm.c +++ b/navit/maptool/osm.c @@ -2163,7 +2163,7 @@ static void osm_process_town_by_boundary_update_attrs(struct item_bin *town, str /* Administrative centres are not to be contained in their own districts. */ if(max_adm_level>0) for(a=max_possible_adm_level-1; a>max_adm_level && a>2; a--) - tc->attrs[a-2].type=attr_none; + tc->attrs[a-2].type=type_none; } /** diff --git a/navit/search_houseno_interpol.c b/navit/search_houseno_interpol.c index 4ba39b9932..b08bfacea6 100644 --- a/navit/search_houseno_interpol.c +++ b/navit/search_houseno_interpol.c @@ -64,8 +64,7 @@ void house_number_interpolation_clear_current(struct house_number_interpolation g_free(inter->last); g_free(inter->curr); inter->first=inter->last=inter->curr=NULL; - inter->increment=-1; - inter->include_end_nodes=end_nodes_undefined; + inter->increment=inter->include_end_nodes=-1; } void house_number_interpolation_clear_all(struct house_number_interpolation *inter) { @@ -112,8 +111,6 @@ static char *search_next_house_number_curr_interpol(struct house_number_interpol hn=search_next_house_number_curr_interpol_with_ends(inter); } while (hn!=NULL && house_number_is_end_number(hn, inter)); break; - case end_nodes_undefined: - break; } return hn; } diff --git a/navit/search_houseno_interpol.h b/navit/search_houseno_interpol.h index 417cb63ccd..460d236c7f 100644 --- a/navit/search_houseno_interpol.h +++ b/navit/search_houseno_interpol.h @@ -20,7 +20,6 @@ enum include_end_nodes { end_nodes_yes, end_nodes_no, - end_nodes_undefined=-1, }; /** Data for a house number interpolation. */ diff --git a/navit/speech.h b/navit/speech.h index a928c700c3..8e4d3d91c1 100644 --- a/navit/speech.h +++ b/navit/speech.h @@ -20,8 +20,6 @@ #ifndef NAVIT_SPEECH_H #define NAVIT_SPEECH_H -#include "attr_type_def.h" - struct speech_priv; struct attr_iter; diff --git a/navit/util.c b/navit/util.c index 3e26d14af4..0dfdab20ec 100644 --- a/navit/util.c +++ b/navit/util.c @@ -766,7 +766,7 @@ unsigned int iso8601_to_secs(char *iso8601) { a=val[0]/100; b=2-a+a/4; - if (val[1] < 3) { + if (val[1] < 2) { val[0]--; val[1]+=12; } diff --git a/po/nl.po.in b/po/nl.po.in index d5683d14c8..6b19361226 100644 --- a/po/nl.po.in +++ b/po/nl.po.in @@ -2369,7 +2369,7 @@ msgid "" "Sorry, we currently do not support maps above 3.8G on Android, please select " "a smaller one." msgstr "" -"Kaarten gorter dan 3,8GB zijn momenteel niet ondersteund op Android.\n" +"Kaarten gorter dan 3,8GB zijn momenteel niet ondersteund op Android.\r\n" "Kies a.u.b. een kleinere kaart." #. Android resource: @strings/map_no_fix diff --git a/po/sr.po.in b/po/sr.po.in index a3ad42c5ce..fe3ef64dc2 100644 --- a/po/sr.po.in +++ b/po/sr.po.in @@ -21,7 +21,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && " "n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" -"Language: sr\n" +"Language: \n" "X-Report-Errors: https://translations.launchpad.net/navit/trunk/+pots/navit\n" msgid "Running from source directory\n" diff --git a/po/zh_TW.po.in b/po/zh_TW.po.in index 6d152d63a1..426155840b 100644 --- a/po/zh_TW.po.in +++ b/po/zh_TW.po.in @@ -15,7 +15,6 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"Language: zh_TW\n" msgid "Running from source directory\n" msgstr "自源目錄執行\n" From 8a3fa0d94513a894415afae8efb054f5d212726f Mon Sep 17 00:00:00 2001 From: OLFDB Date: Tue, 26 Dec 2023 08:17:20 +0100 Subject: [PATCH 22/23] Fixes for testcases --- navit/coord.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/navit/coord.c b/navit/coord.c index d2c4f61a95..cefa995aca 100644 --- a/navit/coord.c +++ b/navit/coord.c @@ -249,9 +249,9 @@ int coord_parse(const char *coord_input, enum projection output_projection, stru } *result=c; } else if (!space_as_sep) { - // When entering coords like google's format, we actually get strings like "52.5219,19.4127" + // When entering coords like google's format, we actually get strings like "52.5219, 19.4127" double lng, lat; - args=sscanf(str, "%lf,%lf%n", &lat, &lng, &ret); + args=sscanf(str, "%lf, %lf%n", &lat, &lng, &ret); if (args < 2) goto out; dbg(lvl_debug,"str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); From cf5587ba43d465c8b7e9f53c4c8a9bcb1788c737 Mon Sep 17 00:00:00 2001 From: OLFDB Date: Tue, 26 Dec 2023 08:18:37 +0100 Subject: [PATCH 23/23] Fix for testcases --- navit/projection.c | 1 + 1 file changed, 1 insertion(+) diff --git a/navit/projection.c b/navit/projection.c index 61d4c2b13a..f00c44c8b3 100644 --- a/navit/projection.c +++ b/navit/projection.c @@ -37,6 +37,7 @@ struct projection_name projection_names[]= { }; static int utmref_letter(char l) { + l=tolower(l); if (l < 'a' || l == 'i' || l == 'o') return -1; if (l < 'i')