Gosmore/Internals

From OpenStreetMap Wiki
Jump to navigation Jump to search

An overview of the internals of Gosmore 1.0

File Format

Consists of a header and 5 arrays. Currently they are uncompressed, but it would be nice to do it in the future. The file format design was adapted as follows:

1 wayType array

a It has been replaced by an index into the styleStruct array that is encoded into bits

b encoded into bits

c clon & clat

d dlon & dlat

e not '\n' but a null character ('\0')

f The Osm2Gosmore() function generates these strings

g

h not '\n' but a null character ('\0')

2 ndType array

a lat

b lon

c wayPtr in an offset

d other[0] is offset of the next ndType relative to this ndType. 0 indicates end of way

e other[0] is offset of the previous ndType relative to this ndType. 0 indicates start of way

3 array of 32 bit integers See Hash(), hashTable, bucketsMin1, etc. Extra code was added for super tiles, reducing the average distance between nearby nodes even further.

4 array of 32 bit integers See ZEnc(), which I later found out is also called Morton numbers.

I think the string search algorithm was changed. You will have to look at the code to see how it's done.

5 A new part of the file to store the styleStructs

6 A new part of the file to store the header. It include a magic number, bucketsMin1, number of styles etc.

Rendering function

  • In map mode:
  1. Determine the 4 corners of the screen. (3 corners in 3D mode)
  2. Iterate through the smallest bbox that includes them all. Store the Nds that are found in arrays that will make it easy to perform the actions below.
  3. Sort the areas from largest to smallest, then render them. Determine if there are appropriate places to render the names and remember that for later.
  4. Render the ways one layer at a time. First render all the casing for all ways in this layer, then the insides. While doing this, look for appropriate places to render the names and store them on the list.
  5. Render the icons and store the names. Always check to make sure no icon is already rendered there.
  6. Render the names with a background, but check that no way or icon already use the screen space.
  • Search mode
  • Option mode
  • Edit mode

Routing functions

  • Route () sets up the routing and is fast. RouteLoop () does the hard work, is slow and should be called until it indicates that it is done. Even when it indicates that it is still busy, all other functions can still be called. This includes rendering, searching and the turn-by-turn information below, although the latter will be of dubious value.
  • The application can query the generated route:
  1. Latitude and Longitude of the node
  2. The distance to the node in meters.
  3. The node type: No a junction, traffic signal, mini-roundabout or stop sign.
  4. The type of action required: Keep straight, turn left or right, exit freeway, exit roundabout with exit number, the destination is on the left or right. Some more obscure things, like make a u-turn at a mini-roundabout.
  5. Weather or not this road ends there (e.g. T junction).
  6. The name of the road, ref, or other sign posting info.

Searching

Given a partial search string, a latitude and a longitude, the function will generate the results required.