navit  0.5.3-trunk
Coordinate handling functions

Functions

struct coordcoord_get (unsigned char **p)
 
struct coordcoord_new (int x, int y)
 
struct coordcoord_new_from_attrs (struct attr *parent, struct attr **attrs)
 
void coord_destroy (struct coord *c)
 
struct coord_rectcoord_rect_new (struct coord *lu, struct coord *rl)
 
void coord_rect_destroy (struct coord_rect *r)
 
int coord_rect_overlap (struct coord_rect *r1, struct coord_rect *r2)
 
int coord_rect_contains (struct coord_rect *r, struct coord *c)
 
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)
 
int pcoord_parse (const char *c_str, enum projection pro, struct pcoord *pc_ret)
 
void coord_print (enum projection pro, struct coord *c, FILE *out)
 
void coord_format_with_sep (float lat, float lng, enum coord_format fmt, char *buffer, int size, const char *sep)
 Converts a lat/lon into a text formatted text string. More...
 
void coord_format (float lat, float lng, enum coord_format fmt, char *buffer, int size)
 Converts a lat/lon into a text formatted text string. More...
 
void coord_geo_format_short (const struct coord_geo *gc, char *buffer, int size, char *sep)
 Converts a WGS84 coordinate pair to its string representation. More...
 
void pcoord_format_degree_short (const struct pcoord *pc, char *buffer, int size, char *sep)
 Converts an integer mercator coordinate pair to its string representation. More...
 
void pcoord_format_absolute (const struct pcoord *pc, char *buffer, int size, char *sep)
 Converts an integer mercator coordinate pair to its string representation. More...
 
unsigned int coord_hash (const void *key)
 Generate a hash from a struct coord pointed by key. More...
 
int coord_equal (const void *a, const void *b)
 Test if two struct coord structures are equal. More...
 

Detailed Description

Navit, a modular navigation system. Copyright (C) 2005-2008 Navit Team

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Function Documentation

◆ coord_destroy()

void coord_destroy ( struct coord c)

References c.

Referenced by coord_destroy_py().

◆ coord_equal()

int coord_equal ( const void *  a,
const void *  b 
)

Test if two struct coord structures are equal.

Parameters
[in]aA pointer to the first struct coord
[in]bA pointer to the second struct coord
Returns
TRUE if a and b are equal, FALSE otherwise

References x, and y.

Referenced by coord_hash_new(), and destination_equal().

◆ coord_format()

void coord_format ( float  lat,
float  lng,
enum coord_format  fmt,
char *  buffer,
int  size 
)
inline

Converts a lat/lon into a text formatted text string.

Parameters
latThe latitude (if lat is 360 or greater, the latitude will be omitted)
lngThe longitude (if lng is 360 or greater, the longitude will be omitted)
fmtThe format to use.
  • DEGREES_DECIMAL=>Degrees with decimal places, i.e. 20.500000°N 110.500000°E
  • DEGREES_MINUTES=>Degrees and minutes, i.e. 20°30.0000' N 110°30.0000' E
  • DEGREES_MINUTES_SECONDS=>Degrees, minutes and seconds, i.e. 20°30'30.00" N 110°30'30.00" E
  • DEGREES_MINUTES_SECONDS_BRIEF=>Degrees, minutes and seconds but with the shortest possible string, i.e. 20°30'30"N 110°30'30"E
[out]bufferA buffer large enough to hold the output + a terminating NUL character (up to 31 bytes)
sizeThe size of the buffer

References coord_format_with_sep(), lat, and size.

◆ coord_format_with_sep()

void coord_format_with_sep ( float  lat,
float  lng,
enum coord_format  fmt,
char *  buffer,
int  size,
const char *  sep 
)

Converts a lat/lon into a text formatted text string.

Parameters
latThe latitude (if lat is 360 or greater, the latitude will be omitted)
lngThe longitude (if lng is 360 or greater, the longitude will be omitted)
fmtThe format to use:
  • DEGREES_DECIMAL_ABSOLUTE=>Degrees with decimal places, i.e. -20.500000 -110.500000 (max: 22 bytes)
  • DEGREES_DECIMAL=>Degrees with decimal places, i.e. 20.500000°N 110.500000°E (max: 26 bytes)
  • DEGREES_MINUTES=>Degrees and minutes, i.e. 20°30.0000' N 110°30.0000' E (max: 30 bytes)
  • DEGREES_MINUTES_SECONDS=>Degrees, minutes and seconds, i.e. 20°30'30.00" N 110°30'30.00" E (max: 32 bytes)
  • DEGREES_MINUTES_SECONDS_BRIEF=>Degrees, minutes and seconds but with the shortest possible string, i.e. 20°30'30"N 110°30'30"E (max 24 bytes)
[out]bufferA buffer large enough to hold the output (bearing in mind '°' uses 2 bytes in UTF-8). Maximum size depends on the format, see values above, and add an extra character for the terminating NUL character
sizeThe size of the buffer
[in]sepThe separator to use (if needed) between latitude and longitude (if NULL we will use a space)

References DEGREES_DECIMAL, DEGREES_DECIMAL_ABSOLUTE, DEGREES_MINUTES, DEGREES_MINUTES_SECONDS, DEGREES_MINUTES_SECONDS_BRIEF, lat, and size.

Referenced by coord_format(), coord_geo_format_short(), pcoord_format_absolute(), and pcoord_format_degree_short().

◆ coord_geo_format_short()

void coord_geo_format_short ( const struct coord_geo gc,
char *  buffer,
int  size,
char *  sep 
)
inline

Converts a WGS84 coordinate pair to its string representation.

This function takes a coordinate pair with latitude and longitude in degrees and converts them to a string of the form

45°28'0"N 9°11'26"E

.

Parameters
gcA WGS84 coordinate pair
[out]bufferA buffer large enough to hold the output + a terminating NUL character (at least 25 bytes)
sizeThe size of the buffer
[in]sepThe separator to use (if needed) between latitude and longitude (if NULL we will use a space)

References coord_format_with_sep(), dbg_assert, DEGREES_MINUTES_SECONDS_BRIEF, coord_geo::lat, coord_geo::lng, and size.

Referenced by gui_internal_append_attr().

◆ coord_get()

struct coord * coord_get ( unsigned char **  p)

Get a coordinate

Parameters
pPointer to the coordinate
Returns
the coordinate

References p.

Referenced by street_name_number_get(), and street_name_numbers_get().

◆ coord_hash()

unsigned int coord_hash ( const void *  key)

Generate a hash from a struct coord pointed by key.

Parameters
[in]keyA pointer to the struct coord to hash
Returns
The resulting hash

References c, key, pcoord::x, and pcoord::y.

Referenced by coord_hash_new().

◆ coord_new()

struct coord * coord_new ( int  x,
int  y 
)

◆ coord_new_from_attrs()

struct coord * coord_new_from_attrs ( struct attr parent,
struct attr **  attrs 
)

◆ coord_parse()

int coord_parse ( const char *  coord_input,
enum projection  output_projection,
struct coord result 
)

Parses char *coord_input and writes back the coordinates to coord *result, using projection output_projection. *coord_input may specify its projection at the beginning. The format for *coord_input can be:

  • [Proj:][-]0xXX.... [-]0xXX... - Mercator coordinates, hex integers (XX), Proj can be "mg" or "garmin", defaults to mg
  • [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
  • [Proj:][-][D]D.d[d]... [-][D][D]D.d[d]... - long/lat (WGS 84, note order!), degrees as decimal fraction, Proj does not matter
  • utm[zoneinfo]:[-][D]D.d[d]... [-][D][D]D.d[d] - UTM coordinates, as decimal fraction, with optional zone information (?)
  • [-][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.
Parameters
*coord_inputString to be parsed
output_projectionDesired projection of the result
*resultFor returning result
Returns
The lenght of the parsed string

References c, dbg, coord_geo::lat, lat, coord_geo::lng, lvl_debug, lvl_error, lvl_info, offset, projection_from_name(), projection_mg, projection_none, projection_utm, transform_from_geo(), transform_to_geo(), x, pcoord::x, y, and pcoord::y.

Referenced by attr_new_from_text(), bookmarks_set_center_from_file(), navit_get_coord(), parse_line(), pcoord_parse(), pcoord_py(), and traffic_message_restore_segments().

◆ coord_print()

void coord_print ( enum projection  pro,
struct coord c,
FILE *  out 
)

◆ coord_rect_contains()

◆ coord_rect_destroy()

void coord_rect_destroy ( struct coord_rect r)

Referenced by coord_rect_destroy_py().

◆ coord_rect_extend()

◆ coord_rect_new()

struct coord_rect * coord_rect_new ( struct coord lu,
struct coord rl 
)

References dbg_assert, coord_rect::lu, coord_rect::rl, x, and y.

Referenced by coord_rect_new_py().

◆ coord_rect_overlap()

◆ pcoord_format_absolute()

void pcoord_format_absolute ( const struct pcoord pc,
char *  buffer,
int  size,
char *  sep 
)
inline

Converts an integer mercator coordinate pair to its string representation.

This function takes a coordinate pair, transforms it to WGS84 and converts it to a string of the form

45.28 -9.114333

.

Parameters
pcCoordinates as integer mercator
[out]bufferA buffer large enough to hold the output + a terminating NUL character (at least 23 bytes)
sizeThe size of the buffer
[in]sepThe separator to use (if needed) between latitude and longitude (if NULL we will use a space)

References c, coord_format_with_sep(), dbg_assert, DEGREES_DECIMAL_ABSOLUTE, coord_geo::lat, coord_geo::lng, pcoord::pro, size, transform_to_geo(), pcoord::x, and pcoord::y.

Referenced by Java_org_navitproject_navit_NavitGraphics_getCoordForPoint().

◆ pcoord_format_degree_short()

void pcoord_format_degree_short ( const struct pcoord pc,
char *  buffer,
int  size,
char *  sep 
)
inline

Converts an integer mercator coordinate pair to its string representation.

This function takes a coordinate pair, transforms it to WGS84 and converts it to a string of the form

45°28'0"N 9°11'26"E

.

Parameters
pcCoordinates as integer mercator
[out]bufferA buffer large enough to hold the output + a terminating NUL character (at least 25 bytes)
sizeThe size of the buffer
[in]sepThe separator to use (if needed) between latitude and longitude (if NULL we will use a space)

References c, coord_format_with_sep(), dbg_assert, DEGREES_MINUTES_SECONDS_BRIEF, coord_geo::lat, coord_geo::lng, pcoord::pro, size, transform_to_geo(), pcoord::x, and pcoord::y.

Referenced by gui_internal_cmd_position_do(), Java_org_navitproject_navit_NavitCallbackHandler_callbackMessageChannel(), and Java_org_navitproject_navit_NavitGraphics_getCoordForPoint().

◆ pcoord_parse()

int pcoord_parse ( const char *  c_str,
enum projection  pro,
struct pcoord pc_ret 
)

A wrapper for coord_parse that also returns the projection. For parameters see coord_parse.

References c, coord_parse(), pcoord::pro, pcoord::x, and pcoord::y.

Referenced by gui_internal_cmd_enter_coord_do(), and pcoord_get_from_message().