source: subversion/applications/rendering/gosmore/geonames2osm.c @ 29350

Last change on this file since 29350 was 18429, checked in by nic, 10 years ago

Add icons for menu. Art work from openclipart.org
On the fly switching of pak file when bbox test fails.
All ports now use the same options.
Translations once again functional..
WinCE port is once again operational.
Display routing decisions to user with icons.

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1// To run this program :
2// wget http://download.geonames.org/export/dump/cities1000.zip
3// unzip cities1000.zip
4// gcc geonames2osm.c && sort -nr -t$'\t' -k 15 cities1000.txt |
5//   ./a.out >lowres.osm
6
7#include <stdio.h>
8#include <strings.h>
9
10char list[180000][80], line[5000]; // Space for Jerusalem and its translations
11
12int main (void)
13{
14  int cnt = 0, i, j, idx[30], ppl; // Do we need to set idx[0] = 0 ?
15  while (fgets (line, sizeof (line), stdin)) {
16    for (i = 0, j = 1; line[i] != '\0' && j < 30; i++) {
17      if (line[i] == '\t') idx[j++] = i + 1;
18    }
19    if (j < 14) continue; // Bad line
20    // For each geonames entry we generate 2 names and convert the ones that
21    // are unique into OSM-XML.
22    for (i = 1; i >= 0; i--) {
23      sprintf (list[cnt], i ? "%.2s %.*s" : "%.0s%.*s", line +
24        idx[line[idx[8]] == 'U' && line[idx[8]+1] == 'S' ? 10 : 8],
25        idx[2] - idx[1] - 1, line + idx[1]);
26      for (j = 0; j < cnt && strcasecmp (list[j], list[cnt]) != 0; j++) {}
27      if (j < cnt) break; // If seen before
28      ppl = atoi (line + idx[14]);
29      if (i == 1) printf ("<node id='%d' lat='%.*s' lon='%.*s'>\n"
30        "  <tag k='place' v='%s' />\n", 0x7fffffff - cnt,
31        idx[5] - idx[4] - 1, line + idx[4],
32        idx[6] - idx[5] - 1, line + idx[5], ppl > 456789 ? "city" :
33        ppl > 23456 ? "town" : ppl > 789 ? "village" : "hamlet");
34      printf ("  <tag k='%s' v=\"%s\" />\n", i ? "ref" : "name", list[cnt++]);
35    }
36    if (i < 1) printf ("</node>\n");
37  }
38}
Note: See TracBrowser for help on using the repository browser.