\( \def\bold#1{\bf #1} \newcommand{\d}{\mathrm{d}} \) BTP: Manual and Source Code Documentation

Power Uphill

bike mass [kg]
body mass [kg]
altitude gain [m]
climb length [km]
gradient [%]
time [s]
speed [km/h]
power [W]
power/mass [W/kg]
climbrate [m/min]

average power on climb stage

BTP  3.0
Routing/ClimbAnalysis/PowerCalculation
osm.cpp
1 #include "osm.h"
2 
3 OSM::OSM(string fileName){
4  setfilename(fileName);
5  initiallists();
6 }
7 OSM::OSM(){
8  initiallists();
9 }
10 OSM::~OSM(){
11  delete_AVL(*(D.nodes));
12  delete_AVL(*(D.waysavl));
13  delete_lines(*motorWay);
14  delete_lines(*highway);
15  delete_lines(*primary);
16  delete_lines(*secondary);
17  delete_lines(*track);
18  delete_lines(*track2);
19  delete_lines(*creek);
20  delete_lines(*river);
21  delete_lines(*NoHeight);
22  delete_lines(*wood);
23  delete_lines(* water);
24  delete_points(*metropolis);
25  delete_points(*city);
26  delete_points(*town);
27  delete_points(*village);
28  delete_points(*locality);
29  delete_points(*col);
30  delete_points(*peak);
31  delete_relation(*woodr);
32  delete_relation(*waterr);
33 }
34 qint64 OSM::extract_valuei(char* s, const char* a){
35  char *x1;
36  char *x2;
37  x1 = strstr(s,a)+strlen(a)+2*sizeof(char);
38  if(x1 == NULL)
39  QMessageBox(QMessageBox::NoIcon,"Error",QString("Could not extract integer value from '%1'").arg(s)).exec();
40  x2 = strchr(x1,'\'');
41  *x2 = '\0';
42  qint64 result = QString(x1).toLongLong();
43  *x2 = '\'';
44  return result;
45 }
46 double OSM::extract_valuef(char* s, const char* a){
47  char *x1;
48  char *x2;
49  x1 = strstr(s,a)+strlen(a)+2*sizeof(char);
50  if(x1 == NULL)
51  QMessageBox(QMessageBox::NoIcon,"Error",QString("Could not extract double value from '%1'").arg(s)).exec();
52 
53  x2 = strchr(x1,'\'');
54  *x2 = '\0';
55  double result = atof(x1);
56  *x2 = '\'';
57  return result;
58 }
60  if(status >= 1){
61  FILE *f;
62  f = fopen(filename.c_str(),"r");
63  if (f == NULL){
64  printf("Fehler beim öffnen der Datei ");
65  printf(filename.c_str());
66  }
67  else{
68  char line[10000],lineattr[10000],linename[10000];
69 
70  qint64 currentseek;
71  dminlat = 0;
72  dmaxlat = 0;
73  dminlon = 0;
74  dmaxlon = 0;
75 
76  fseek(f,0,SEEK_SET);
77  while(!feof(f)){
78  currentseek = _ftelli64(f);
79  fgets(line,999,f);
80  quotationreplace(line);
81  if(strstr(line,"bbox=") != NULL
82  || strstr(line,"<bound box=") != NULL)
83  extract_bbox(line);
84  if(strstr(line,"<bounds ") != NULL){
85  dminlat = extract_valuef(line," minlat");
86  dmaxlat = extract_valuef(line," maxlat");
87  dminlon = extract_valuef(line," minlon");
88  dmaxlon = extract_valuef(line," maxlon");
89  }
90  if (strstr(line,"<node ") != NULL)
91  nodehandling(f,line,lineattr,linename);
92  if (strstr(line,"<way ") != NULL)
93  Wayhandling(f,line,lineattr,linename,&currentseek);
94  if (strstr(line,"<relation ") != NULL)
95  relationhandling(f,line,lineattr,linename,&currentseek);
96  }
97  fclose(f);
98  status = 2;
99  }
100  }
101  else{
102  printf("Initialisieren korrekten Dateinamen mit OSM(fileName)!\n");
103  }
104 }
105 KOO* OSM::search(qint64 id, KOO* s){
106  while (s != NULL && s->id != id){
107  if(s->id > id) s = s->l;
108  else s = s->r;
109  }
110  return s;
111 }
112 KOO* OSM::insert(qint64 id, KOO* s){
113  KOO* p = s;
114  if (s != NULL){
115  /*Falls der Baum schon angelegt ist*/
116  while (s != NULL && s->id != id){
117  /*suche das zugehörige Blatt*/
118  if(s->id > id){
119  p = s;
120  s = s->l;
121  }
122  else
123  if(s->id < id){
124  p = s;
125  s = s->r;
126  }
127  }
128  if(s != NULL)
129  /*das Blatt ist schon vorhanden*/
130  return s;
131  else{
132  /*Blatt muss angelegt werden*/
133  if(p->id > id){
134  /*Blatt links*/
135  p->l = new KOO;
136  s = p->l;
137  s->prev = p;
138  s->id = id;
139  s->l = NULL;
140  s->r = NULL;
141  s->lat = 200;
142  s->lon = 200;
143  s->balance = 0;
144  s->status = -1;
145  s->cd = NULL;
146  return s;
147  }
148  else{
149  /*Blatt rechts*/
150  p->r = new KOO;
151  s = p->r;
152  s->prev = p;
153  s->id = id;
154  s->l = NULL;
155  s->r = NULL;
156  s->lat = 200;
157  s->lon = 200;
158  s->balance = 0;
159  s->status = -1;
160  s->cd = NULL;
161  return s;
162  }
163  }
164  }
165  else{
166  /*Baum anlegen, weil noch nicht geschehen*/
167  s = new KOO;
168  s->prev = NULL;
169  s->id = id;
170  s->l = NULL;
171  s->r = NULL;
172  s->lat = 200;
173  s->lon = 200;
174  s->balance = 0;
175  s->status = -1;
176  s->cd = NULL;
177  return s;
178  }
179 }
180 KOO* OSM::rotate(KOO** s, branch b){
181  KOO* k;
182  switch(b){
183  case l: switch((*s)->balance){
184  case +1:switch((*s)->r->balance){
185  case -1:(*s)->balance = 0;
186  (*s)->r->balance = -2;
187  break;
188  case 0: (*s)->balance = 0;
189  (*s)->r->balance = -1;
190  break;
191  case 1: (*s)->balance = -1;
192  (*s)->r->balance = -1;
193  break;
194  }
195  break;
196  case +2:switch((*s)->r->balance){
197  case -1:(*s)->balance = 1;
198  (*s)->r->balance = -2;
199  break;
200  case 0: (*s)->balance = 1;
201  (*s)->r->balance = -1;
202  break;
203  case 1: (*s)->balance = 0;
204  (*s)->r->balance = 0;
205  break;
206  case 2: (*s)->balance = -1;
207  (*s)->r->balance = 0;
208  break;
209  }
210  break;
211  }
212  break;
213  case r: switch((*s)->balance){
214  case -1:switch((*s)->l->balance){
215  case -1:(*s)->balance = 1;
216  (*s)->l->balance = 1;
217  break;
218  case 0: (*s)->balance = 0;
219  (*s)->l->balance = 1;
220  break;
221  case 1: (*s)->balance = 0;
222  (*s)->l->balance = 2;
223  break;
224  }
225  break;
226  case -2:switch((*s)->l->balance){
227  case -2:(*s)->balance = 1;
228  (*s)->l->balance = 0;
229  break;
230  case -1:(*s)->balance = 0;
231  (*s)->l->balance = 0;
232  break;
233  case 0: (*s)->balance = -1;
234  (*s)->l->balance = 1;
235  break;
236  case 1: (*s)->balance = -1;
237  (*s)->l->balance = 2;
238  break;
239  }
240  break;
241  }
242  break;
243  default: break;
244  }
245  if (b == l){
246  k = (*s)->r->l;
247  (*s)->r->l = (*s);
248  (*s) = (*s)->r;
249  (*s)->l->r = k;
250  (*s)->prev = (*s)->l->prev;
251  (*s)->l->prev = (*s);
252  if (k != NULL) k->prev = (*s)->l;
253  return (*s);
254  }
255  else{
256  k = (*s)->l->r;
257  (*s)->l->r = (*s);
258  (*s) = (*s)->l;
259  (*s)->r->l = k;
260  (*s)->prev = (*s)->r->prev;
261  (*s)->r->prev = (*s);
262  if (k != NULL) k->prev = (*s)->r;
263  return (*s);
264  }
265 }
266 KOO* OSM::insert_AVL(qint64 id, KOO** s){
267  if(*s != NULL){
268  int fertig = 0;
269  KOO* i = insert(id,*s);
270  KOO* result = i;
271  if(i->status > -1) //Falls die KOO schon vorhanden war
272  return i; //ist die gesammte Routine zu beenden
273 
274  i->status = 0;
275  while(!fertig){
276  i = i->prev;
277  if (id < i->id){
278  i->balance--;
279  switch(i->balance){
280  case-2: switch(i->l->balance){
281  case -1: i = rotate(&i,r);
282  break;
283  case 1: rotate(&(i->l),l);
284  i = rotate(&i,r);
285  break;
286  }
287  fertig = 1;
288  if(i->prev != NULL){
289  if(i->prev->id > i->id)
290  i->prev->l = i;
291  else
292  i->prev->r = i;
293  }
294  break;
295  case-1: if(i->prev == NULL) fertig = 1;
296  break;
297  case 0: fertig = 1;
298  break;
299  }
300  }
301  else{
302  i->balance++;
303  switch(i->balance){
304  case 2: switch(i->r->balance){
305  case 1: i = rotate(&i,l);
306  break;
307  case -1: rotate(&(i->r),r);
308  i = rotate(&i,l);
309  break;
310  }
311  fertig = 1;
312  if(i->prev != NULL){
313  if(i->prev->id > i->id)
314  i->prev->l = i;
315  else
316  i->prev->r = i;
317  }
318  break;
319  case 1: if(i->prev == NULL) fertig = 1;
320  break;
321  case 0: fertig = 1;
322  break;
323  }
324  }
325  }
326  if (i->prev == NULL){
327  *s = i;
328  return result;
329  }
330  else
331  return result;
332  }
333  else{
334  KOO* result = new KOO;
335  result->balance = 0;
336  result->id = id;
337  result->prev = NULL;
338  result->l = NULL;
339  result->r = NULL;
340  result->lat = 200;
341  result->lon = 200;
342  result->status = 0;
343  result->cd = NULL;
344  *s = result;
345  return result;
346  }
347 }
348 Way* OSM::search(qint64 id, Way* s){
349  while (s != NULL && s->id != id){
350  if(s->id > id) s = s->l;
351  else s = s->r;
352  }
353  return s;
354 }
355 Way* OSM::insert(qint64 id, Way* s){
356  Way* p = s;
357  if (s != NULL){
358  /*Falls der Baum schon angelegt ist*/
359  while (s != NULL && s->id != id){
360  /*suche das zugehörige Blatt*/
361  if(s->id > id){
362  p = s;
363  s = s->l;
364  }
365  else
366  if(s->id < id){
367  p = s;
368  s = s->r;
369  }
370  }
371  if(s != NULL)
372  /*das Blatt ist schon vorhanden*/
373  return s;
374  else{
375  /*Blatt muss angelegt werden*/
376  if(p->id > id){
377  /*Blatt links*/
378  p->l = new Way;
379  s = p->l;
380  s->prev = p;
381  s->id = id;
382  s->l = NULL;
383  s->r = NULL;
384  s->balance = 0;
385  s->type = -1;
386  return s;
387  }
388  else{
389  /*Blatt rechts*/
390  p->r = new Way;
391  s = p->r;
392  s->prev = p;
393  s->id = id;
394  s->l = NULL;
395  s->r = NULL;
396  s->balance = 0;
397  s->type = -1;
398  return s;
399  }
400  }
401  }
402  else{
403  /*Baum anlegen, weil noch nicht geschehen*/
404  s = new Way;
405  s->prev = NULL;
406  s->id = id;
407  s->l = NULL;
408  s->r = NULL;
409  s->balance = 0;
410  s->type = -1;
411  return s;
412  }
413 }
414 Way* OSM::rotate(Way** s, branch b){
415  Way* k;
416  switch(b){
417  case l: switch((*s)->balance){
418  case +1:switch((*s)->r->balance){
419  case -1:(*s)->balance = 0;
420  (*s)->r->balance = -2;
421  break;
422  case 0: (*s)->balance = 0;
423  (*s)->r->balance = -1;
424  break;
425  case 1: (*s)->balance = -1;
426  (*s)->r->balance = -1;
427  break;
428  }
429  break;
430  case +2:switch((*s)->r->balance){
431  case -1:(*s)->balance = 1;
432  (*s)->r->balance = -2;
433  break;
434  case 0: (*s)->balance = 1;
435  (*s)->r->balance = -1;
436  break;
437  case 1: (*s)->balance = 0;
438  (*s)->r->balance = 0;
439  break;
440  case 2: (*s)->balance = -1;
441  (*s)->r->balance = 0;
442  break;
443  }
444  break;
445  }
446  break;
447  case r: switch((*s)->balance){
448  case -1:switch((*s)->l->balance){
449  case -1:(*s)->balance = 1;
450  (*s)->l->balance = 1;
451  break;
452  case 0: (*s)->balance = 0;
453  (*s)->l->balance = 1;
454  break;
455  case 1: (*s)->balance = 0;
456  (*s)->l->balance = 2;
457  break;
458  }
459  break;
460  case -2:switch((*s)->l->balance){
461  case -2:(*s)->balance = 1;
462  (*s)->l->balance = 0;
463  break;
464  case -1:(*s)->balance = 0;
465  (*s)->l->balance = 0;
466  break;
467  case 0: (*s)->balance = -1;
468  (*s)->l->balance = 1;
469  break;
470  case 1: (*s)->balance = -1;
471  (*s)->l->balance = 2;
472  break;
473  }
474  break;
475  }
476  break;
477  default: break;
478  }
479  if (b == l){
480  k = (*s)->r->l;
481  (*s)->r->l = (*s);
482  (*s) = (*s)->r;
483  (*s)->l->r = k;
484  (*s)->prev = (*s)->l->prev;
485  (*s)->l->prev = (*s);
486  if (k != NULL) k->prev = (*s)->l;
487  return (*s);
488  }
489  else{
490  k = (*s)->l->r;
491  (*s)->l->r = (*s);
492  (*s) = (*s)->l;
493  (*s)->r->l = k;
494  (*s)->prev = (*s)->r->prev;
495  (*s)->r->prev = (*s);
496  if (k != NULL) k->prev = (*s)->r;
497  return (*s);
498  }
499 }
500 Way* OSM::insert_AVL(qint64 id, Way** s){
501  if(*s != NULL){
502  int fertig = 0;
503  Way* i = insert(id,*s);
504  if(i->type > -1) //der Weg war schon vorhanden und die
505  fertig = 1; //Routine kann beendet werden
506  Way* result = i;
507  while(!fertig){
508  i = i->prev;
509  if (id < i->id){
510  i->balance--;
511  switch(i->balance){
512  case-2: switch(i->l->balance){
513  case -1: i = rotate(&i,r);
514  break;
515  case 1: rotate(&(i->l),l);
516  i = rotate(&i,r);
517  break;
518  }
519  fertig = 1;
520  if(i->prev != NULL){
521  if(i->prev->id > i->id)
522  i->prev->l = i;
523  else
524  i->prev->r = i;
525  }
526  break;
527  case-1: if(i->prev == NULL) fertig = 1;
528  break;
529  case 0: fertig = 1;
530  break;
531  }
532  }
533  else{
534  i->balance++;
535  switch(i->balance){
536  case 2: switch(i->r->balance){
537  case 1: i = rotate(&i,l);
538  break;
539  case -1: rotate(&(i->r),r);
540  i = rotate(&i,l);
541  break;
542  }
543  fertig = 1;
544  if(i->prev != NULL){
545  if(i->prev->id > i->id)
546  i->prev->l = i;
547  else
548  i->prev->r = i;
549  }
550  break;
551  case 1: if(i->prev == NULL) fertig = 1;
552  break;
553  case 0: fertig = 1;
554  break;
555  }
556  }
557  }
558  if (i->prev == NULL){
559  *s = i;
560  return result;
561  }
562  else
563  return result;
564  }
565  else{
566  Way* result = new Way;
567  result->balance = 0;
568  result->id = id;
569  result->prev = NULL;
570  result->l = NULL;
571  result->r = NULL;
572  result->nodec = 0;
573  result->type = -1;
574  *s = result;
575  return result;
576  }
577 }
579  get_KOO_Waysavl(*(D.waysavl),1);
580 }
581 void OSM::get_KOO_Waysavl(Way* l,short next){
582  if(status >=2){
583  status = 3;
584  qint64 id;
585  if(l != NULL){
586  l->maxlat = -90;
587  l->maxlon = -180;
588  l->minlat = 90;
589  l->minlon = 180;
590 
591  for(int j = 0; j < l->nodec; j++){
592  id = l->node[j]->id;
593  delete(l->node[j]);
594  l->node[j] = search(id, *D.nodes);
595  if(l->node[j] == NULL){
596  l->type = 99;
597  break;
598  }
599 
600  /*Bestimme das umrandende Rechteck*/
601  if(l->node[j]->lat > l->maxlat )
602  l->maxlat = float(l->node[j]->lat);
603  if(l->node[j]->lat < l->minlat )
604  l->minlat = float(l->node[j]->lat);
605  if(l->node[j]->lon > l->maxlon )
606  l->maxlon = float(l->node[j]->lon);
607  if(l->node[j]->lon < l->minlon )
608  l->minlon = float(l->node[j]->lon);
609  }
610  if(next){
611  get_KOO_Waysavl(l->l,1); //rekursiver Aufruf des linken Kindes
612  get_KOO_Waysavl(l->r,1); //rekursiver Aufruf des rechten Kindes
613  }
614  }
615  }
616  else{
617  printf("Zuerst Datei einlesen mittels read_OSM_all()\n");
618  }
619 }
620 char* OSM::extract_valuec(char* s, const char* a){
621  char *x1;
622  char *x2;
623  x1 = strstr(s,a)+strlen(a)+2*sizeof(char);
624  if(x1 == NULL)
625  QMessageBox(QMessageBox::NoIcon,"Error",QString("Could not char value from '%1'").arg(s)).exec();
626  x2 = strchr(x1,'\'');
627  *x2 = '\0';
628  return x1;
629 }
630 void OSM::extract_bbox(char* s){
631  if(strstr(s,"bbox=") != NULL){
632  char* t = strstr(s,"bbox=");
633  t = &(t[5]);
634  char* t2 = strstr(t,",");
635  t2[0]='\0';
636  dminlon = atof(t);
637  t = &(t2[1]);
638  t2 = strstr(t,",");
639  t2[0]='\0';
640  dminlat = atof(t);
641  t = &(t2[1]);
642  t2 = strstr(t,",");
643  t2[0]='\0';
644  dmaxlon = atof(t);
645  t = &(t2[1]);
646  t2 = strstr(t,"'");
647  t2[0]='\0';
648  dmaxlat = atof(t);
649  }
650  else{
651  char* t = strstr(s,"box=");
652  t = &(t[5]);
653  char* t2 = strstr(t,",");
654  t2[0]='\0';
655  dminlat = atof(t);
656  t = &(t2[1]);
657  t2 = strstr(t,",");
658  t2[0]='\0';
659  dminlon = atof(t);
660  t = &(t2[1]);
661  t2 = strstr(t,",");
662  t2[0]='\0';
663  dmaxlat = atof(t);
664  t = &(t2[1]);
665  t2 = strstr(t,"'");
666  t2[0]='\0';
667  dmaxlon = atof(t);
668  }
669 }
670 short OSM::isin(lines* l,double minlat, double maxlat,
671  double minlon, double maxlon){
672  if ( ( (l->way->minlat >= minlat && l->way->minlat <= maxlat)
673  ||(l->way->maxlat <= maxlat && l->way->maxlat >= minlat)
674  ||(l->way->minlat <= minlat && l->way->maxlat >= maxlat)
675  )
676  &&
677  ( (l->way->minlon >= minlon && l->way->minlon <= maxlon)
678  ||(l->way->maxlon <= maxlon && l->way->maxlon >= minlon)
679  ||(l->way->minlon <= minlon && l->way->maxlon >= maxlon)
680  ) )
681  return 1;
682  else
683  return 0;
684 }
685 short OSM::isin(points* l,double minlat, double maxlat,
686  double minlon, double maxlon){
687  return isin(l->k,minlat,maxlat,minlon,maxlon);
688 }
689 short OSM::isin(KOO* k,double minlat, double maxlat,
690  double minlon, double maxlon){
691  if( k->lat < maxlat
692  && k->lat > minlat
693  && k->lon > minlon
694  && k->lon < maxlon)
695  return 1;
696  else
697  return 0;
698 }
699 short OSM::isin(Way* w,double minlat, double maxlat,
700  double minlon, double maxlon){
701  if ( ( (w->minlat >= minlat && w->minlat <= maxlat)
702  ||(w->maxlat <= maxlat && w->maxlat >= minlat)
703  ||(w->minlat <= minlat && w->maxlat >= maxlat)
704  )
705  &&
706  ( (w->minlon >= minlon && w->minlon <= maxlon)
707  ||(w->maxlon <= maxlon && w->maxlon >= minlon)
708  ||(w->minlon <= minlon && w->maxlon >= maxlon)
709  ) )
710  return 1;
711  else
712  return 0;
713 }
714 short OSM::iscompletein(Way* w,double minlat, double maxlat,
715  double minlon, double maxlon){
716  if( w->minlat > minlat
717  && w->maxlat < maxlat
718  && w->minlon > minlon
719  && w->maxlon < maxlon)
720  return 1;
721  else
722  return 0;
723 }
724 void OSM::setfilename(string fileName){
725  if(fileName.compare(fileName.size()-4,4,".osm") == 0){
726  filename = fileName;
727  status = 1;
728  }
729  else{
730  printf("%s ist keien .osm-Datei!\n",fileName.c_str());
731  status = 0;
732  }
733 }
735  maxlat = -90;
736  minlat = 90;
737  maxlon = -180;
738  minlon = 180;
739  dmaxlat = -90;
740  dminlat = 90;
741  dmaxlon = -180;
742  dminlon = 180;
743 
744  D.nodes = new KOO*;
745  D.waysavl = new Way*;
746  *(D.nodes) = NULL;
747  *(D.waysavl) = NULL;
748 
749  motorWay = new lines*;
750  highway = new lines*;
751  primary = new lines*;
752  secondary = new lines*;
753  track = new lines*;
754  track2 = new lines*;
755  creek = new lines*;
756  river = new lines*;
757  NoHeight = new lines*;
758  *motorWay = *highway = *primary = *secondary = *track = *track2
759  = *creek = *river = *NoHeight = NULL;
760 
761  wood =new lines*;
762  water =new lines*;
763  *wood = *water = NULL;
764 
765  metropolis = new points*;
766  city = new points*;
767  town = new points*;
768  village = new points*;
769  locality = new points*;
770  col = new points*;
771  *metropolis = *city = *town = *village = *locality = *col = NULL;
772 
773  woodr = new relation*;
774  waterr = new relation*;
775  *woodr = *waterr = NULL;
776 
777  peak = new points*;
778  *peak = NULL;
779 
780  ExclCheck[0] = motorWay;
781  ExclCheck[1] = highway;
782  ExclCheck[2] = primary;
783  ExclCheck[3] = secondary;
784  ExclCheck[4] = track;
785  ExclCheck[5] = track2;
786  ExclCheck[6] = river;
787  ExclCheck[7] = creek;
788 
789 }
791  return status;
792 }
794  if(k != NULL){
795  if(k->cd != NULL)
796  return 1+count_cross(k->l)+count_cross(k->r);
797  else
798  return count_cross(k->l)+count_cross(k->r);
799  }
800  else
801  return 0;
802 }
804  if(k != NULL){
805  if(k->cd != NULL && k->cd->s != NULL)
806  return 1+count_STRONG(k->l)+count_STRONG(k->r);
807  else
808  return count_STRONG(k->l)+count_STRONG(k->r);
809  }
810  else
811  return 0;
812 }
813 
814 void OSM::nodehandling(FILE *f,char* line,char* lineattr,char* linename){
815  char* attr = &line[0];
816  char* name = NULL;
817  short foundplace = 0,foundpeak = 0, foundpopulation = 0, foundname = 0, foundcol = 0;
818  int population = 0;
819  int normalname = 0;
820 
821 
822  KOO* k;
823  k = insert_AVL(extract_valuei(line," id"),D.nodes);
824  k->lat = extract_valuef(line," lat");
825  k->lon = extract_valuef(line," lon");
826  k->cd = NULL;
827 
828  while(strstr(line,"</node>") == NULL &&
829  !(strstr(line,"<node ")!=NULL && strstr(line,"/>") != NULL)){
830  fgets(line,999,f);
831  quotationreplace(line);
832  if(strstr(line,"<tag k='place' v='") != NULL){
833  strcpy(lineattr,line);
834  attr = extract_valuec(lineattr,"v");
835  foundplace = 1;
836  }
837  if(strstr(line,"<tag k='tourism' v='alpine_hut'/>") != NULL){
838  attr = "alpine_hut";
839  foundplace = 1;
840  }
841  if(strstr(line,"<tag k='natural' v='peak'/>") != NULL){
842  foundpeak = 1;
843  }
844  if(strstr(line,"<tag k='natural' v='saddle'/>") != NULL ||
845  strstr(line,"<tag k='mountain_pass' v='yes'/>") != NULL){
846  foundcol = 1;
847  }
848  if(strstr(line,"<tag k='name' v='") != NULL){
849  // primary name source
850  strcpy(linename,line);
851  name = extract_valuec(linename,"v");
852  normalname = 2;
853  foundname = 1;
854  }
855  if(normalname < 2 &&
856  strstr(line,"<tag k='openGeoDB:name' v='")!=NULL){
857  // secondary name source
858  strcpy(linename,line);
859  name = extract_valuec(linename,"v");
860  normalname = 1;
861  foundname = 1;
862  }
863  if(normalname < 1 &&
864  strstr(line,"<tag k='name:")!=NULL){
865  // tertiary name source
866  strcpy(linename,line);
867  name = extract_valuec(linename,"v");
868  foundname = 1;
869  }
870  if(strstr(line,"tag k='population' v='") != NULL){
871  population = extract_valuei(line,"v");
872  foundpopulation = 1;
873  }
874  }
875  //falls kein Name gefunden sollte Punkt nicht verzeichnet werden
876  if(name == NULL)
877  foundplace = foundpeak = 0;
878  else
879  htmlreplace(name);
880 
881  if(foundpopulation && foundplace && !foundcol)
882  //d.h. ein Ort mit Einwohnerzahlangabe ist ausgelesen wurden
883  if(population > 0){
884  //Klassifizierung nach Einwohnerzahl ist sicherer
885  if(population>100000)
886  add_points(metropolis,k,name,float(population));
887  else{
888  if(population>10000)
889  add_points(city,k,name,float(population));
890  else{
891  if(population>3000 || !strcmp(attr,"town"))
892  add_points(town,k,name,float(population));
893  else
894  if(population>50)
895  add_points(village,k,name,float(population));
896  else
897  add_points(locality,k,name,float(population));
898 
899  }
900  }
901  }
902  if(foundplace && !foundpopulation && !foundcol){
903  //...als Klassifizierung nach OSM-tags, da keine Einwohnerzahl
904  if(!strcmp(attr,"city"))
905  add_points(metropolis,k,name,500000);
906  else{
907  if(!strcmp(attr,"town"))
908  add_points(town,k,name,5000);
909  else{
910  if( !strcmp(attr,"suburb")
911  ||!strcmp(attr,"village"))
912  add_points(village,k,name,500);
913  else
914  if( !strcmp(attr,"hamlet")
915  ||!strcmp(attr,"locality")
916  ||!strcmp(attr,"alpine_hut")
917  ||!strcmp(attr,"isolated_dwelling"))
918  add_points(locality,k,name,20);
919  }
920  }
921  }
922  if(foundcol && foundname){
923  add_points(col,k,name,20);
924  }
925  if(foundpeak && foundname && !foundcol)
926  add_points(peak,k,name,0);
927 }
928 
929 /*void OSM::nodehandling(FILE *f,char* line,char* lineattr,char* linename){
930  //SKIKEmap
931  char* attr = &line[0];
932  char* name = NULL;
933  short foundplace = 0,foundpeak = 0, foundpopulation = 0, foundname = 0, foundcol = 0;
934  int population = 0;
935  int normalname = 0;
936 
937 
938  KOO* k;
939  k = insert_AVL(extract_valuei(line," id"),D.nodes);
940  k->lat = extract_valuef(line," lat");
941  k->lon = extract_valuef(line," lon");
942  k->cd = NULL;
943 
944  while(strstr(line,"</node>") == NULL &&
945  !(strstr(line,"<node ")!=NULL && strstr(line,"/>") != NULL)){
946  fgets(line,999,f);
947  quotationreplace(line);
948  if(strstr(line,"<tag k='place' v='") != NULL){
949  strcpy(lineattr,line);
950  attr = extract_valuec(lineattr,"v");
951  foundplace = 1;
952  }
953  if(strstr(line,"<tag k='tourism' v='alpine_hut'/>") != NULL){
954  attr = "alpine_hut";
955  foundplace = 1;
956  }
957  if( strstr(line,"<tag k='shop' v='supermarket'/>") != NULL||
958  strstr(line,"<tag k='shop' v='general'/>") != NULL||
959  strstr(line,"<tag k='shop' v='convenience'/>") != NULL||
960  strstr(line,"<tag k='amenity' v='bar'/>") != NULL||
961  strstr(line,"<tag k='amenity' v='bar'/>") != NULL||
962  strstr(line,"<tag k='amenity' v='bbq'/>") != NULL||
963  strstr(line,"<tag k='amenity' v='biergarten'/>") != NULL||
964  strstr(line,"<tag k='amenity' v='cafe'/>") != NULL||
965  strstr(line,"<tag k='amenity' v='fast_food'/>") != NULL||
966  strstr(line,"<tag k='amenity' v='food_court'/>") != NULL||
967  strstr(line,"<tag k='amenity' v='ice_cream'/>") != NULL||
968  strstr(line,"<tag k='amenity' v='restaurant'/>") != NULL||
969  strstr(line,"<tag k='amenity' v='fuel'/>") != NULL||
970  strstr(line,"<tag k='amenity' v='pub'/>") != NULL){
971  attr = "city";
972  foundplace = 1;
973  }
974  if(strstr(line,"<tag k='natural' v='peak'/>") != NULL){
975  foundpeak = 1;
976  }
977  if(strstr(line,"<tag k='natural' v='saddle'/>") != NULL ||
978  strstr(line,"<tag k='mountain_pass' v='yes'/>") != NULL||
979  strstr(line,"<tag k='railway' v='station'/>") != NULL||
980  strstr(line,"<tag k='railway' v='halt'/>") != NULL||
981  strstr(line,"<tag k='amenity' v='bus_station'/>") != NULL||
982  strstr(line,"<tag k='public_transport' v='station'/>") != NULL){
983  foundcol = 1;
984  }
985  if(strstr(line,"<tag k='name' v='") != NULL){
986  // primary name source
987  strcpy(linename,line);
988  name = extract_valuec(linename,"v");
989  normalname = 2;
990  foundname = 1;
991  }
992  if(normalname < 2 &&
993  strstr(line,"<tag k='openGeoDB:name' v='")!=NULL){
994  // secondary name source
995  strcpy(linename,line);
996  name = extract_valuec(linename,"v");
997  normalname = 1;
998  foundname = 1;
999  }
1000  if(normalname < 1 &&
1001  strstr(line,"<tag k='name:")!=NULL){
1002  // tertiary name source
1003  strcpy(linename,line);
1004  name = extract_valuec(linename,"v");
1005  foundname = 1;
1006  }
1007  if(strstr(line,"tag k='population' v='") != NULL){
1008  population = extract_valuei(line,"v");
1009  foundpopulation = 1;
1010  }
1011  }
1012  //falls kein Name gefunden sollte Punkt nicht verzeichnet werden
1013  if(name == NULL)
1014  foundplace = foundpeak = 0;
1015  else
1016  htmlreplace(name);
1017 
1018  if(foundpopulation && foundplace && !foundcol)
1019  //d.h. ein Ort mit Einwohnerzahlangabe ist ausgelesen wurden
1020  if(population > 0){
1021  //Klassifizierung nach Einwohnerzahl ist sicherer...
1022  if(0 && population>100000)
1023  add_points(metropolis,k,name,float(population));
1024  else{
1025  if(population>10000)
1026  add_points(city,k,name,float(population));
1027  else{
1028  if(population>3000 || !strcmp(attr,"town"))
1029  add_points(town,k,name,float(population));
1030  else
1031  if(population>50)
1032  add_points(village,k,name,float(population));
1033  else
1034  add_points(locality,k,name,float(population));
1035 
1036  }
1037  }
1038  }
1039  if(foundplace && !foundpopulation && !foundcol){
1040  //...als Klassifizierung nach OSM-tags, da keine Einwohnerzahl
1041  if(!strcmp(attr,"city"))
1042  add_points(metropolis,k,name,500000);
1043  else{
1044  if(!strcmp(attr,"town"))
1045  add_points(town,k,name,5000);
1046  else{
1047  if( !strcmp(attr,"suburb")
1048  ||!strcmp(attr,"village"))
1049  add_points(village,k,name,500);
1050  else
1051  if( !strcmp(attr,"hamlet")
1052  ||!strcmp(attr,"locality")
1053  ||!strcmp(attr,"alpine_hut")
1054  ||!strcmp(attr,"isolated dwelling"))
1055  add_points(locality,k,name,20);
1056  }
1057  }
1058  }
1059  if(foundcol && foundname){
1060  add_points(col,k,name,20);
1061  }
1062  if(foundpeak && foundname && !foundcol)
1063  add_points(peak,k,name,0);
1064 }*/
1065 
1066 void OSM::relationhandling(FILE *f,char* line,char* lineattr,char* linename,
1067  qint64* currentseek){
1068 
1069  int relationlength = 0;
1070  int iswood = 0, iswater = 0;
1071  qint64 tID;
1072  Way* tw;
1073  while(strstr(line,"</relation>") == NULL){
1074  if(strstr(line,"<member type='way'") != NULL){
1075  relationlength++;
1076  tID = extract_valuei(line,"ref");
1077  tw = search(tID,*(D.waysavl));
1078  if(tw != NULL && tw->type == 6)
1079  iswood = 1;
1080  }
1081  if(strstr(line,"<tag k='landuse' v='forest'/>") != NULL
1082  || strstr(line,"<tag k='natural' v='wood'/>") != NULL)
1083  iswood = 1;
1084  if(strstr(line,"<tag k='waterWay' v='riverbank'/>") != NULL
1085  || strstr(line,"<tag k='landuse' v='reservoir'/>") != NULL
1086  || strstr(line,"<tag k='natural' v='water'/>") != NULL)
1087  iswater = 1;
1088  fgets(line,999,f);
1089  quotationreplace(line);
1090  }
1091 
1092  if ((iswood || iswater) && relationlength > 0){
1093  relation* r =new relation;
1094  r->memberscount = relationlength;
1095  r->members = new Way*[relationlength];
1096  _fseeki64(f,*currentseek,SEEK_SET);
1097  fgets(line,999,f);
1098  quotationreplace(line);
1099 
1100  relationlength = -1;
1101  while(strstr(line,"</relation>") == NULL){
1102  fgets(line,999,f);
1103  quotationreplace(line);
1104  if(strstr(line,"<member type='way'") != NULL){
1105  relationlength++;
1106  r->members[relationlength] = new Way;
1107  r->members[relationlength]->id = extract_valuei(line,"ref");
1108  }
1109  }
1110  if(!iswater){
1111  add_relation(woodr,r);
1112  r->type = 6;
1113  }
1114  else{
1115  add_relation(waterr,r);
1116  r->type = 7;
1117  }
1118  }
1119 }
1120 void OSM::Wayhandling(FILE *f,char* line,char* lineattr,char* linename,
1121  qint64* currentseek){
1122  char* attr = &line[0];
1123  char* name = NULL;
1124  int Waylength = 0;
1125  while(strstr(line,"</way>") == NULL){
1126  if(strstr(line,"<nd ref=") != NULL) Waylength++;
1127  fgets(line,999,f);
1128  quotationreplace(line);
1129  if(name == NULL && strstr(line,"<tag k='name' v='") != NULL){
1130  // take name only if no ref tag
1131  strcpy(linename,line);
1132  name = extract_valuec(linename,"v");
1133  htmlreplace(name);
1134  }
1135  if(strstr(line,"<tag k='ref' v='") != NULL){
1136  // take re
1137  strcpy(linename,line);
1138  name = extract_valuec(linename,"v");
1139  htmlreplace(name);
1140  }
1141  }
1142 
1143  if (Waylength > 0){
1144  _fseeki64(f,*currentseek,SEEK_SET); //fur id neu lesen
1145  fgets(line,999,f);
1146  quotationreplace(line);
1147  Way* k = insert_AVL(extract_valuei(line,"id"),D.waysavl);
1148  k->nodec = Waylength;
1149  k->node = new KOO*[Waylength];
1150  k->type = 98; //falls sich erweisen sollte, dass der
1151  //Way ungenutzt bleibt, muss er beim
1152  //speichern der fertig berechneten
1153  //Daten verworfen werden
1154  Waylength = -1;
1155  while(strstr(line,"</way>") == NULL){
1156  fgets(line,999,f);
1157  quotationreplace(line);
1158  if(strstr(line,"<nd ref=") != NULL){
1159  Waylength++;
1160  k->node[Waylength] = new KOO;
1161  k->node[Waylength]->id = extract_valuei(line,"ref");
1162  }
1163  if(strstr(line,"<tag k='highway' v='") != NULL){
1164  strcpy(lineattr,line);
1165  attr = extract_valuec(lineattr,"v");
1166  if(!strcmp(attr,"motorway")||
1167  !strcmp(attr,"motorway_link")||
1168  !strcmp(attr,"trunk")||
1169  !strcmp(attr,"trunk_link"))
1170  k->type = qMin(k->type,(char)0);
1171  if(!strcmp(attr,"primary")||
1172  !strcmp(attr,"primary_link"))
1173  k->type = qMin(k->type,(char)1);
1174  if((!strcmp(attr,"secondary")
1175  ||!strcmp(attr,"secondary_link")))
1176  k->type = qMin(k->type,(char)2);
1177  if(!strcmp(attr,"tertiary"))
1178  k->type = qMin(k->type,(char)3);
1179  if(!strcmp(attr,"residential")
1180  ||!strcmp(attr,"unclassified")
1181  ||!strcmp(attr,"road")
1182  ||!strcmp(attr,"service"))
1183  k->type = qMin(k->type,(char)4);
1184  if( !strcmp(attr,"cycleway")||
1185  !strcmp(attr,"track")||
1186  !strcmp(attr,"footway"))
1187  k->type = qMin(k->type,(char)5);
1188  }
1189  if(strstr(line,"<tag k='surface' v='") != NULL){
1190  strcpy(lineattr,line);
1191  attr = extract_valuec(lineattr,"v");
1192  if(!strcmp(attr,"asphalt")||
1193  !strcmp(attr,"concrete")||
1194  !strcmp(attr,"concrete:lanes")||
1195  !strcmp(attr,"concrete:plates")||
1196  !strcmp(attr,"paving_stones ")||
1197  !strcmp(attr,"paved"))
1198  k->type = qMin(k->type,(char)4);
1199  if(!strcmp(attr,"compacted")||
1200  !strcmp(attr,"fine_gravel ")||
1201  !strcmp(attr,"sett"))
1202  k->type = qMin(k->type,(char)5);
1203  if(!strcmp(attr,"cobblestone:flattened"))
1204  k->type = qMin(k->type,(char)4);
1205  if(!strcmp(attr,"cobblestone"))
1206  k->type = qMin(k->type,(char)4);
1207  }
1208  if(strstr(line,"<tag k='tracktype' v='") != NULL){
1209  strcpy(lineattr,line);
1210  attr = extract_valuec(lineattr,"v");
1211  if(!strcmp(attr,"grade1"))
1212  k->type = qMin(k->type,(char)4);
1213  if(!strcmp(attr,"grade2"))
1214  k->type = qMin(k->type,(char)5);
1215  if(!strcmp(attr,"grade3")||
1216  !strcmp(attr,"grade4")||
1217  !strcmp(attr,"grade5"))
1218  k->type = 98;
1219  }
1220  if(strstr(line,"<tag k='tunnel' v='yes'/>") != NULL
1221  || strstr(line,"<tag k='bridge' v='") != NULL){
1222  add_line(NoHeight,k,name);
1223  }
1224  if((strstr(line,"<tag k='landuse' v='forest'/>") != NULL
1225  || strstr(line,"<tag k='natural' v='wood'/>") != NULL))
1226  k->type = qMin(k->type,(char)6);
1227  if((strstr(line,"<tag k='waterway' v='riverbank'/>") != NULL
1228  || strstr(line,"<tag k='landuse' v='reservoir'/>") != NULL
1229  || strstr(line,"<tag k='natural' v='water'/>") != NULL))
1230  k->type = qMin(k->type,(char)7);
1231  if(strstr(line,"<tag k='waterway' v='river'/>") != NULL)
1232  k->type = qMin(k->type,(char)8);
1233  if(strstr(line,"<tag k='waterway' v='stream'/>") != NULL)
1234  k->type = qMin(k->type,(char)9);
1235  }
1236  switch(k->type){
1237  case 0: add_line(motorWay,k,name); break;
1238  case 1: add_line(highway,k,name); break;
1239  case 2: add_line(primary,k,name); break;
1240  case 3: add_line(secondary,k,name); break;
1241  case 4: add_line(track,k,name); break;
1242  case 5: add_line(track2,k,name); break;
1243  case 6: add_line(wood,k,name); break;
1244  case 7: add_line(water,k,name); break;
1245  case 8: add_line(river,k,name); break;
1246  case 9: add_line(creek,k,name); break;
1247  default:;
1248  }
1249  }
1250 }
1251 /*void OSM::Wayhandling(FILE *f,char* line,char* lineattr,char* linename,
1252  qint64* currentseek){
1253  //SKIKEMAP wayhandling
1254  char* attr = &line[0];
1255  char* name = NULL;
1256  short namestate = -1; //-1: nicht vorhanden, 0: zu lang fuer
1257  //Strasse, 1: nehmen,2: wieder loeschen
1258  int Waylength = 0;
1259  int foundWay = 0;
1260  while(strstr(line,"</way>") == NULL){
1261  if(strstr(line,"<nd ref=") != NULL) Waylength++;
1262  fgets(line,999,f);
1263  quotationreplace(line);
1264  if( strstr(line,"<tag k='name' v='") != NULL
1265  ||strstr(line,"<tag k='ref' v='") != NULL){
1266  strcpy(linename,line);
1267  name = extract_valuec(linename,"v");
1268  htmlreplace(name);
1269  if(strlen(name)>0) namestate = 1;
1270  //else namestate = 0;
1271  }
1272  }
1273 
1274  if (Waylength > 0){
1275  _fseeki64(f,*currentseek,SEEK_SET); //fur id neu lesen
1276  fgets(line,999,f);
1277  quotationreplace(line);
1278  Way* k = insert_AVL(extract_valuei(line,"id"),D.waysavl);
1279  k->nodec = Waylength;
1280  k->node = new KOO*[Waylength];
1281  k->type = 98; //falls sich erweisen sollte, dass der
1282  //Way ungenutzt bleibt, muss er beim
1283  //speichern der fertig berechneten
1284  //Daten verworfen werden
1285  Waylength = -1;
1286  while(strstr(line,"</way>") == NULL){
1287  fgets(line,999,f);
1288  quotationreplace(line);
1289  if(strstr(line,"<nd ref=") != NULL){
1290  Waylength++;
1291  k->node[Waylength] = new KOO;
1292  k->node[Waylength]->id = extract_valuei(line,"ref");
1293  }
1294  if(strstr(line,"<tag k='highway' v='") != NULL){
1295  strcpy(lineattr,line);
1296  attr = extract_valuec(lineattr,"v");
1297  if(!strcmp(attr,"primary")||
1298  !strcmp(attr,"primary_link")||
1299  !strcmp(attr,"motorway")||
1300  !strcmp(attr,"motorway_link")||
1301  !strcmp(attr,"trunk")||
1302  !strcmp(attr,"trunk_link"))
1303  k->type = qMin(k->type,(char)0);
1304  if((!strcmp(attr,"secondary")
1305  ||!strcmp(attr,"secondary_link")))
1306  k->type = qMin(k->type,(char)2);
1307  if(!strcmp(attr,"tertiary"))
1308  k->type = qMin(k->type,(char)3);
1309  if(!strcmp(attr,"residential")
1310  ||!strcmp(attr,"road")
1311  ||!strcmp(attr,"service"))
1312  k->type = qMin(k->type,(char)4);
1313  if( !strcmp(attr,"unclassified")||
1314  !strcmp(attr,"cycleway")||
1315  !strcmp(attr,"track")||
1316  !strcmp(attr,"footway"))
1317  k->type = qMin(k->type,(char)5);
1318  }
1319  if(strstr(line,"<tag k='tracktype' v='") != NULL
1320  &&!foundWay){
1321  strcpy(lineattr,line);
1322  attr = extract_valuec(lineattr,"v");
1323 
1324  if(!strcmp(attr,"grade1"))
1325  k->type = qMin(k->type,(char)4);
1326  if(!strcmp(attr,"grade2"))
1327  k->type = qMin(k->type,(char)5);
1328  if(!strcmp(attr,"grade3"))
1329  k->type = qMin(k->type,(char)1);
1330  if(!strcmp(attr,"grade4"))
1331  k->type = 98;
1332  if(!strcmp(attr,"grade5"))
1333  k->type = 98;
1334  }
1335  if(strstr(line,"<tag k='tunnel' v='yes'/>") != NULL
1336  || strstr(line,"<tag k='bridge' v='") != NULL){
1337  add_line(NoHeight,k,name);
1338  }
1339  if((strstr(line,"<tag k='landuse' v='forest'/>") != NULL
1340  || strstr(line,"<tag k='natural' v='wood'/>") != NULL)
1341  &&!foundWay){
1342  add_line(wood,k,name);
1343  k->type = 6;
1344  foundWay++;
1345  }
1346  if((strstr(line,"<tag k='waterway' v='riverbank'/>") != NULL
1347  || strstr(line,"<tag k='landuse' v='reservoir'/>") != NULL
1348  || strstr(line,"<tag k='natural' v='water'/>") != NULL)
1349  &&!foundWay){
1350  add_line(water,k,name);
1351  k->type = 7;
1352  foundWay++;
1353  }
1354  if(strstr(line,"<tag k='waterway' v='river'/>") != NULL
1355  &&!foundWay){
1356  add_line(river,k,name);
1357  k->type = 8;
1358  foundWay++;
1359  }
1360 
1361  if(strstr(line,"<tag k='waterway' v='stream'/>") != NULL
1362  &&!foundWay){
1363  add_line(creek,k,NULL);
1364  namestate = 2;
1365  k->type = 9;
1366  foundWay++;
1367  }
1368  if(strstr(line,"<tag k='surface' v='") != NULL){
1369  strcpy(lineattr,line);
1370  attr = extract_valuec(lineattr,"v");
1371  if(!strcmp(attr,"cobblestone")||
1372  !strcmp(attr,"cobblestone:flattened"))
1373  k->type = qMin(k->type,(char)1);
1374  if(!strcmp(attr,"asphalt")||
1375  !strcmp(attr,"concrete")||
1376  !strcmp(attr,"concrete:lanes")||
1377  !strcmp(attr,"concrete:plates")||
1378  !strcmp(attr,"paving_stones ")||
1379  !strcmp(attr,"paved"))
1380  k->type = qMin(k->type,(char)4);
1381  if(!strcmp(attr,"compacted")||
1382  !strcmp(attr,"fine_gravel ")||
1383  !strcmp(attr,"sett"))
1384  k->type = qMin(k->type,(char)5);
1385  }
1386  switch(k->type){
1387  case 0: add_line(motorWay,k,name); break;
1388  case 1: add_line(highway,k,name); break;
1389  case 2: add_line(primary,k,name); break;
1390  case 3: add_line(secondary,k,name); break;
1391  case 4: add_line(track,k,name); break;
1392  case 5: add_line(track2,k,name); break;
1393  }
1394  }
1395  }
1396 }*/
1397 
1398 void OSM::add_line(lines** l,Way* Way,char* name){
1399  lines* a = new lines;
1400  a->way = Way;
1401  if(*l == NULL) a->next = NULL;
1402  else a->next = *l;
1403  *l = a;
1404  if(name != NULL){
1405  Way->name = a->name = new char[strlen(name)+1];
1406  strcpy(a->name,name);
1407  }
1408  else
1409  a->name = Way->name = NULL;
1410 }
1411 points* OSM::add_points(points** l,KOO* KOO,char* name, float index){
1412  points* a =new points;
1413  a->index = index;
1414  a->k = KOO;
1415  a->k->status = 3;
1416  a->name = new char[strlen(name)+1];
1417  strcpy(a->name,name);
1418  if(*l == NULL){
1419  /*leere Liste, erstes Element*/
1420  a->next = NULL;
1421  a->prev = NULL;
1422  *l = a;
1423  }
1424  else{
1425  if((*l)->index < index){
1426  /*an Listenanfang einfuegen*/
1427  a->next = *l;
1428  a->prev = NULL;
1429  (*l)->prev = a;
1430  *l = a;
1431  }
1432  else{
1433  /*Liste durchgehen bis zur richtigen Position*/
1434  points* p = *l;
1435  while(p->next != NULL && p->index >= index)
1436  p = p->next;
1437  if(p->index >= index){
1438  /*Anfuegen an das Listenende*/
1439  p->next = a;
1440  a->prev = p;
1441  a->next = NULL;
1442  }
1443  else{
1444  /*Einfuegen mitten in die Liste*/
1445  p->prev->next = a;
1446  a->prev = p->prev;
1447  p->prev = a;
1448  a->next = p;
1449  }
1450  }
1451  }
1452  return a;
1453 }
1455  r->next = *l;
1456  *l = r;
1457 }
1459  points* b = *l;
1460  points* p = *l;
1461  while(b != NULL){
1462  p = b;
1463  b = p->next;
1464  p->next = p->prev;
1465  p->prev = b;
1466  }
1467  *l = p;
1468 }
1470  relation* r = *l;
1471  short *used, exists,foundneighbourmember;
1472  used = new short;
1473  lines* cf;
1474  int i,j,k,cm,cn;
1475  Way** Ways = new Way*;
1476  Way* grandWay;
1477  Way* tempWay;
1478  int nodecount;
1479  while(r != NULL){
1480  delete used;
1481  KOO *e,*s;
1482  used = new short[r->memberscount];
1483  for(i = 0; i < r->memberscount; i++){
1484  used[i] = 0;
1485  tempWay = search(r->members[i]->id,*(D.waysavl));
1486  if(tempWay != NULL && tempWay->type != 99){
1487  /*der Weg existiert und kennt alle seine nodes*/
1488  r->members[i] = tempWay;
1489  used[i] = 0;
1490  }
1491  else
1492  used[i] = 1;
1493  }
1494  for(i = 0; i < r->memberscount; i++)
1495  if(!used[i]){
1496  if(r->members[i]->node[0 ]->id ==
1497  r->members[i]->node[r->members[i]->nodec-1]->id){
1498  /*falls der Member geschlossen ist, dann pruefen, ob er in
1499  f schon existiert, falls nicht und der Weg noch keinen Typ
1500  hat soll er in f eingefuegt werden*/
1501  exists = 0;
1502  cf = *f;
1503  while(cf != NULL){
1504  if(cf->way->id == r->members[i]->id){
1505  exists = 1;
1506  cf = NULL;
1507  }
1508  else
1509  cf = cf->next;
1510  }
1511  if(!exists && r->members[i]->type > 8){
1512  add_line(f,r->members[i],NULL);
1513  }
1514  used[i] = 1;
1515  }
1516  else{
1517  /*falls der Member nicht geschlossen ist muss versucht
1518  werden, mit Hilfe der anderen Member eine geschlossene
1519  kurve zu konzentrieren. Members, die dabei helfen, liegen
1520  im Array Ways*/
1521  delete(Ways);
1522  Ways = new Way*[r->memberscount];
1523  cm = 0;
1524  e = r->members[i]->node[0];
1525  s = r->members[i]->node[r->members[i]->nodec-1];
1526  Ways[cm]=r->members[i];
1527  used[i] = 1;
1528  do{
1529  foundneighbourmember = 0;
1530  for(j = 0; j < r->memberscount; j++){
1531  if(!used[j]
1532  &&( s->id == r->members[j]->node[0]->id
1533  ||s->id == r->members[j]->node[r->members[j]->nodec-1]->id)
1534  ){
1535  /*falls der Weg j an den cm-Weg anknuepft*/
1536  cm++;
1537  Ways[cm] = r->members[j];
1538  if(s->id == r->members[j]->node[0]->id)
1539  s = r->members[j]->node[r->members[j]->nodec-1];
1540  else
1541  s = r->members[j]->node[0];
1542  used[j] = 1;
1543  j = r->memberscount;
1544  foundneighbourmember = 1;
1545  }
1546  }
1547  }while( foundneighbourmember
1548  && (e->id != Ways[cm]->node[0] ->id)
1549  && (e->id != Ways[cm]->node[Ways[cm]->nodec-1]->id));
1550  /*falls es gelungen ist, Members zu einer geschlossenen
1551  Kurve zu gruppieren, soll nun diese Kurve erstellt werden
1552  und in f abgelegt werden*/
1553  if(foundneighbourmember){
1554  /*suche nach Weg unter Ways, der exklusiv von Relation
1555  genutzt wird*/
1556  int FoundExclusive = 1;
1557  int CheckMax = 6; if(l == woodr) CheckMax = 8;
1558  for(j = 0; j <= cm; j++){
1559  FoundExclusive = 1;
1560  for(int k = 0; k < CheckMax; k++){
1561  cf = *(ExclCheck[k]);
1562  while(cf != NULL){
1563  if(Ways[j]->id == cf->way->id){
1564  FoundExclusive = -1;
1565  cf = NULL;
1566  k = CheckMax;
1567  }
1568  else
1569  cf = cf->next;
1570  }
1571  }
1572  if(FoundExclusive == 1){
1573  FoundExclusive = j;
1574  j = cm + 1;
1575  }
1576  }
1577  if(FoundExclusive > -1){
1578  /*es gibt einen exklusiven Weg der zum verknuepfen
1579  genutzt werden kann*/
1580  nodecount = 0;
1581  for(j = 0; j <= cm; j++)
1582  nodecount = nodecount + Ways[j]->nodec;
1583  nodecount = nodecount - cm;
1584  grandWay = new Way;
1585 
1586  /*grandWay intialisieren*/
1587  grandWay->balance = r->members[i]->balance;
1588  grandWay->id = Ways[FoundExclusive]->id;
1589  grandWay->nodec = nodecount;
1590  grandWay->node =new KOO*[nodecount];
1591  grandWay->type = r->type;
1592 
1593  cn = 0;
1594  s = r->members[i]->node[0];
1595 
1596  grandWay->maxlat = -90;
1597  grandWay->minlat = 90;
1598  grandWay->maxlon = -180;
1599  grandWay->minlon = 180;
1600  for(j = 0; j <= cm; j++){
1601  if(Ways[j]->node[0]->id == s->id){
1602  /*vorwaerts fuellen*/
1603  for(k = 0; k < Ways[j]->nodec-1; k++){
1604  grandWay->node[cn] = Ways[j]->node[k];
1605  cn++;
1606  }
1607  s = Ways[j]->node[Ways[j]->nodec-1];
1608  }
1609  else{
1610  /*rueckwaerts fuellen*/
1611  for(k = Ways[j]->nodec-1; k > 0; k--){
1612  grandWay->node[cn] = Ways[j]->node[k];
1613  cn++;
1614  }
1615  s = Ways[j]->node[0];
1616  }
1617  /*umrandendes Rechteck bestimmen*/
1618  if(Ways[j]->maxlat > grandWay->maxlat )
1619  grandWay->maxlat = Ways[j]->maxlat;
1620  if(Ways[j]->minlat < grandWay->minlat )
1621  grandWay->minlat = Ways[j]->minlat;
1622  if(Ways[j]->maxlon > grandWay->maxlon )
1623  grandWay->maxlon = Ways[j]->maxlon;
1624  if(Ways[j]->minlon < grandWay->minlon )
1625  grandWay->minlon = Ways[j]->minlon;
1626  }
1627  grandWay->node[grandWay->nodec-1]=grandWay->node[0];
1628  add_line(f,grandWay,NULL);
1629  }
1630  }
1631  }
1632  }
1633  r = r->next;
1634  }
1635  delete(used);
1636 }
1637 void OSM::reset_KOO_status(KOO* k,char i){
1638  if(k != NULL){
1639  k->status = i;
1640  reset_KOO_status(k->l,i);
1641  reset_KOO_status(k->r,i);
1642  }
1643 }
1645  maxlat = -90;
1646  minlat = 90;
1647  maxlon = -180;
1648  minlon = 180;
1649  calc_brect(motorWay );
1650  calc_brect(highway );
1651  calc_brect(primary );
1653  calc_brect(track );
1654  calc_brect(track2 );
1655  calc_brect(river );
1656  calc_brect(creek );
1657  calc_brect(wood );
1658  calc_brect(water );
1660  calc_brect(city);
1661  calc_brect(town);
1664  calc_brect(col);
1665  calc_brect(peak);
1666 }
1668  points* p = *l;
1669  while(p != NULL){
1670  if(p->k->lat > maxlat) maxlat = p->k->lat;
1671  if(p->k->lat < minlat) minlat = p->k->lat;
1672  if(p->k->lon > maxlon) maxlon = p->k->lon;
1673  if(p->k->lon < minlon) minlon = p->k->lon;
1674  p = p->next;
1675  }
1676 }
1678  lines* p = *l;
1679  while(p != NULL){
1680  for(int i = 0; i < p->way->nodec; i++){
1681  if(p->way->node[i]->lat > maxlat) maxlat = p->way->node[i]->lat;
1682  if(p->way->node[i]->lat < minlat) minlat = p->way->node[i]->lat;
1683  if(p->way->node[i]->lon > maxlon) maxlon = p->way->node[i]->lon;
1684  if(p->way->node[i]->lon < minlon) minlon = p->way->node[i]->lon;
1685  }
1686  p = p->next;
1687  }
1688 }
1690  return *(D.waysavl);
1691 }
1693  return *(D.nodes);
1694 }
1695 Neighbour* OSM::add_Neighbour(KOO* k, KOO** node, KOO* nb, Way* w, float d,
1696  int KOOc, readdirection rd){
1697  Neighbour *n;
1698  if( k->cd->neighbours == NULL){
1699  k->cd->neighbours =new Neighbour;
1700  n = k->cd->neighbours;
1701  n->next = NULL;
1702  }
1703  else{
1704  n = k->cd->neighbours;
1705  while(n->next != NULL && (n->nb != nb || n->way != w))
1706  /*Eine Nachbarbeziehung ist dann identisch, wenn die 2 Kreuzungen
1707  und der benutzte Weg übereinstimmen*/
1708  n = n->next;
1709 
1710  if(n->nb != nb || n->way != w){
1711  /*Die Nachbarbeziehung war ueberhaupt noch nicht vorhanden*/
1712  n->next =new Neighbour;
1713  n = n->next;
1714  n->next = NULL;
1715  }
1716  else{
1717  if(d < n->d){
1718  /*Die Nachbarbeziehung war mit einer laengeren Distanz
1719  vorhanden und sollte ueberschrieben werden*/
1720  if(n->tp != NULL){
1721  delete(n->tp);
1722  n->tp = NULL;
1723  n->brthr->tp = NULL;
1724  }
1725 
1726  }
1727  else
1728  /*die bestehende Nachbarbezieung hat einen kuerzeren Weg,
1729  einfuegen abbrechen*/
1730  return NULL;
1731  }
1732  }
1733  n->d = d;
1734  n->hm = 0;
1735  n->nb = nb;
1736  n->brthr = NULL;
1737  n->way = w;
1738  n->nodec = KOOc;
1739  n->node = node;
1740  n->rd = rd;
1741  n->tpc = 0;
1742  n->tp = NULL;
1743  k->status = 2;
1744  return n;
1745 }
1747  return minlat;
1748 }
1750  return minlon;
1751 }
1753  return maxlat;
1754 }
1756  return maxlon;
1757 }
1758 
1760  points* p = *peak;
1761  int wc = 50, j, i, ac = 10;
1762  float h0;
1763  float d = float(0.2);
1764 
1765  float* index = new float[ac];
1766  float* index2 = new float[ac];
1767  float is,is2;
1768  float Ahigher;
1769  qint64**c = new qint64*[ac];
1770  for(i = 0; i < ac; i++)
1771  c[i] = new qint64[wc];
1772  float mperlon, mperlat;
1773  while(p != NULL){
1774  mperlon = 2*M_PI*6371/360*cos(p->k->lat/180.*M_PI) * 1000/1200;
1775  mperlat = 2*M_PI*6371/360 * 1000/1200;
1776  h0 = h->height_t(p->k->lon,p->k->lat,NULL,0);
1777  h->paek_pro(p->k->lon,p->k->lat,c,&Ahigher,wc,ac,d,mperlon,mperlat);
1778  for(i = 0; i < ac; i++){
1779  index[i] = 0;
1780  index2[i] = 0;
1781  /*Berechnet Volumen*/
1782  if( h0 > c[i][0])
1783  for(j = 1; j < wc; j++)
1784  if(c[i][j]<c[i][j-1])
1785  index[i] = index[i] + (h0 - c[i][j]);
1786  else
1787  j = wc;
1788  /*Berechnet Bergformel*/
1789  for(j = 0; j < wc; j++)
1790  if( h0 > c[i][j]
1791  &&(h0-c[i][j])*(h0-c[i][j])/(i*d*1000) > index2[i])
1792  index2[i] = float((h0-c[i][j])*(h0-c[i][j])/((0.5+j)*d*1000));
1793  }
1794  is = 0;
1795  is2 = 0;
1796  p->index = 0;
1797  for(j = 0; j < ac; j++){
1798  is = is + sqrt(index[j]);
1799  is2 = is2 + index2[j];
1800  }
1801  p->index = sqrt(is*is*is2/ac);
1802  p->index = float(p->index * max(1.,1+(0.002-Ahigher)*500));
1803 
1804  p = p->next;
1805  }
1806 
1807  for(i = 0; i < ac; i++)
1808  delete(c[i]);
1809  delete(c);
1810  delete(index);
1811  delete(index2);
1812 }
1814  short change = 1;
1815  points p,*l = *peak;
1816  if(l != NULL){
1817  p.next = l;
1818  l->prev = &p;
1819  FILE* f;
1820  f = fopen("pointssortiert.txt","w");
1821  while(change){
1822  change = 0;
1823  l = p.next;
1824  while(l->next != NULL){
1825  /*a-b-c-d ==> a-c-b-d*/
1826  if(l->index < l->next->index){
1827  l->prev->next = l->next;//a->c
1828  l->next->prev = l->prev;//a<-c
1829  l->prev = l->next; //c<-b
1830  if(l->next->next != NULL){
1831  l->next->next->prev = l;//b<-d
1832  l->next = l->next->next;//b->d;
1833  }
1834  else
1835  l->next = 0;
1836  l->prev->next = l; //c->b;
1837  change = 1;
1838  }
1839  else
1840  l = l->next;
1841  }
1842  }
1843  l = p.next;
1844  while(l != NULL){
1845  fprintf(f,"%f - %s - %f N %f E\n",l->index,l->name,l->k->lat,l->k->lon);
1846  l = l->next;
1847  }
1848 
1849  fclose(f);
1850 
1851  p.next->prev = NULL; //Abkoppeln vom Pufferelement
1852  *peak = p.next; //Listenanfang setzen
1853  }
1854 }
1855 void OSM::save(char* filename, double minlat, double maxlat,
1856  double minlon, double maxlon){
1857  FILE* f;
1858  f = fopen(filename,"wb");
1859  if( dmaxlat == -90
1860  && dminlat == 90
1861  && dmaxlon == -180
1862  && dminlon == 180){
1863  dmaxlat = maxlat;
1864  dminlat = minlat;
1865  dmaxlon = maxlon;
1866  dminlon = minlon;
1867  }
1868 
1869  fwrite(&minlat,sizeof(double),1,f);
1870  fwrite(&maxlat,sizeof(double),1,f);
1871  fwrite(&minlon,sizeof(double),1,f);
1872  fwrite(&maxlon,sizeof(double),1,f);
1873 
1874  save_lines(motorWay ,f,minlat,maxlat,minlon,maxlon);
1875  save_lines(highway ,f,minlat,maxlat,minlon,maxlon);
1876  save_lines(primary ,f,minlat,maxlat,minlon,maxlon);
1877  save_lines(secondary,f,minlat,maxlat,minlon,maxlon);
1878  save_lines(track ,f,minlat,maxlat,minlon,maxlon);
1879  /*lines* b = NULL;
1880  save_lines(&b ,f,minlat,maxlat,minlon,maxlon);*/
1881  save_lines(track2 ,f,minlat,maxlat,minlon,maxlon);
1882  save_lines(river ,f,minlat,maxlat,minlon,maxlon);
1883  save_lines(creek ,f,minlat,maxlat,minlon,maxlon);
1884  save_lines(wood ,f,minlat,maxlat,minlon,maxlon);
1885  save_lines(water ,f,minlat,maxlat,minlon,maxlon);
1886 
1887  save_points(metropolis, f,minlat,maxlat,minlon,maxlon);
1888  save_points(city, f,minlat,maxlat,minlon,maxlon);
1889  save_points(town, f,minlat,maxlat,minlon,maxlon);
1890  save_points(village, f,minlat,maxlat,minlon,maxlon);
1891  save_points(locality, f,minlat,maxlat,minlon,maxlon);
1892  save_points(col, f,minlat,maxlat,minlon,maxlon);
1893 
1894  /*Bergliste rückwärts speichern, da sie sortiert durch insert_points
1895  geladen werden soll*/
1897  save_points(peak, f,minlat,maxlat,minlon,maxlon);
1899 
1900  /*speichere Kreuzungsdaten ab, vorher Kreuzungen durchzählen, nachher
1901  diese Anzahl bei currentseek speichern*/
1902  int c = 0;
1903  qint64 currentseek = _ftelli64(f);
1904  fwrite(&c,sizeof(int),1,f);
1905  save_cross(*D.nodes, f, &c, minlat, maxlat, minlon, maxlon);
1906  _fseeki64(f,currentseek,SEEK_SET);
1907  fwrite(&c,sizeof(int),1,f);
1908 
1909  fclose(f);
1910  reset_KOO_status(*D.nodes);
1911 }
1912 void OSM::save_lines(lines** l, FILE* f, double minlat, double maxlat,
1913  double minlon, double maxlon){
1914  int c = 0;
1915  int len;
1916  if(*l == NULL)
1917  fwrite(&c,sizeof(int),1,f);
1918  else{
1919  lines* k = *l;
1920  while(k != NULL){
1921  if(isin(k->way,minlat,maxlat,minlon,maxlon))
1922  c++;
1923  k = k->next;
1924  }
1925  fwrite(&c,sizeof(int),1,f);
1926  k = *l;
1927  while(k != NULL){
1928  if(isin(k->way,minlat,maxlat,minlon,maxlon)){
1929  save_Way(k->way,f);
1930  len = 0;
1931  if(k->name == NULL){
1932  fwrite(&len,sizeof(int),1,f);
1933  }
1934  else{
1935  len = strlen(k->name);
1936  fwrite(&len,sizeof(int),1,f);
1937  fwrite(k->name,sizeof(char),len,f);
1938  }
1939  }
1940  k = k->next;
1941  }
1942  }
1943 }
1944 void OSM::save_points(points** p, FILE* f, double minlat, double maxlat,
1945  double minlon, double maxlon){
1946  int c = 0;
1947  int len;
1948  if(*p == NULL)
1949  fwrite(&c,sizeof(int),1,f);
1950  else{
1951  points* k = *p;
1952  while(k != NULL){
1953  if(isin(k->k,minlat,maxlat,minlon,maxlon))
1954  c++;
1955  k = k->next;
1956  }
1957  fwrite(&c,sizeof(int),1,f);
1958  k = *p;
1959  while(k != NULL){
1960  if(isin(k->k,minlat,maxlat,minlon,maxlon)){
1961  save_node(k->k,f);
1962  fwrite(&(k->index),sizeof(float),1,f);
1963  len = 0;
1964  if(k->name == NULL){
1965  fwrite(&len,sizeof(int),1,f);
1966  }
1967  else{
1968  len = strlen(k->name);
1969  fwrite(&len,sizeof(int),1,f);
1970  fwrite(k->name,sizeof(char),len,f);
1971  }
1972  }
1973  k = k->next;
1974  }
1975  }
1976 }
1977 void OSM::save_node(KOO* k, FILE* f){
1978  fwrite(&(k->id),sizeof(qint64),1,f);
1979  fwrite(&(k->lon),sizeof(double),1,f);
1980  fwrite(&(k->lat),sizeof(double),1,f);
1981  if(k->cd != NULL)
1982  /*markiere den Node als noch zu speichernde Kreuzung*/
1983  k->status = 10;
1984 }
1985 void OSM::save_Way(Way* w, FILE* f){
1986  fwrite(&(w->id),sizeof(qint64),1,f);
1987  fwrite(&(w->type),sizeof(char),1,f);
1988  fwrite(&(w->nodec),sizeof(int),1,f);
1989  for(int i = 0; i < w->nodec; i++)
1990  save_node(w->node[i],f);
1991 }
1992 void OSM::save_cross(KOO* k, FILE* f, int* c, double minlat,
1993  double maxlat, double minlon, double maxlon){
1994  if(k != NULL){
1995  if(k->status == 10
1996  && isin(k,dminlat,dmaxlat,dminlon,dmaxlon)){
1997  (*c)++;
1998  fwrite(&(k->id),sizeof(qint64),1,f);
1999  /*Anzahl i der Nachbarkreuzungen bestimmen*/
2000  short i = 0;
2001  Neighbour* n = k->cd->neighbours;
2002  while(n != NULL){
2003  /*gespeichert werden immer nur die VorwärtsNachbarrelationen,
2004  sonst ist das gespeichert redundant. Beim Laden werden dann
2005  beider Kreuzungen befuellt werden*/
2006  if(n->nb->status == 10 && n->rd == fw
2007  &&isin(n->nb,dminlat,dmaxlat,dminlon,dmaxlon))
2008  i++;
2009  n = n->next;
2010  }
2011  fwrite(&i,sizeof(short),1,f);
2012 
2013  n = k->cd->neighbours;
2014  while(n != NULL){
2015  if(n->nb->status == 10 && n->rd == fw
2016  && isin(n->nb,dminlat,dmaxlat,dminlon,dmaxlon)){
2017  fwrite(&(n->rd), sizeof(readdirection),1,f);
2018  fwrite(&(n->d), sizeof(float),1,f);
2019  fwrite(&(n->hm), sizeof(float),1,f);
2020  fwrite(&(n->nb->id), sizeof(qint64),1,f);
2021  fwrite(&(n->way->id), sizeof(qint64),1,f);
2022  fwrite(&(n->nodec), sizeof(int),1,f);
2023  int j = 0;
2024  for(int l = n->way->nodec-1; l >=0; l--){
2025  if(n->way->node[l] == k)
2026  j = l; //findet zugehoerigen Index in der
2027  } //KOO-Liste des Weges
2028  fwrite(&j,sizeof(int),1,f);
2029  fwrite(&(n->tpc), sizeof(int),1,f);
2030  fwrite(n->tp, sizeof(trackpoint),n->tpc,f);
2031  }
2032  n = n->next;
2033  }
2034  }
2035  /*Rekursionsaufruf*/
2036  save_cross(k->l,f,c, minlat, maxlat, minlon, maxlon);
2037  save_cross(k->r,f,c, minlat, maxlat, minlon, maxlon);
2038  }
2039 }
2041  if(k != NULL){
2042  if(k->status == 10)
2043  k->status = 2;
2044  /*rekursiver Aufruf*/
2045  reset_KOO_status(k->l);
2046  reset_KOO_status(k->r);
2047  }
2048 }
2049 void OSM::load(char* filename){
2050  FILE* f;
2051  f = fopen(filename,"rb");
2052  if(f != NULL){
2053  double minlat, maxlat, minlon, maxlon;
2054  fread(&minlat,sizeof(double),1,f);
2055  fread(&maxlat,sizeof(double),1,f);
2056  fread(&minlon,sizeof(double),1,f);
2057  fread(&maxlon,sizeof(double),1,f);
2058 
2059  if(minlat < this->minlat) this->minlat = minlat;
2060  if(maxlat > this->maxlat) this->maxlat = maxlat;
2061  if(minlon < this->minlon) this->minlon = minlon;
2062  if(maxlon > this->maxlon) this->maxlon = maxlon;
2063  load_lines(motorWay ,f);
2064  load_lines(highway ,f);
2065  load_lines(primary ,f);
2066  load_lines(secondary,f);
2067  load_lines(track ,f);
2068  load_lines(track2 ,f);
2069  load_lines(river ,f);
2070  load_lines(creek ,f);
2071  load_lines(wood ,f);
2072  load_lines(water ,f);
2073  load_points(metropolis, f);
2074  load_points(city, f);
2075  load_points(town, f);
2076  load_points(village, f);
2077  load_points(locality, f);
2078  load_points(col, f);
2079  load_points(peak, f);
2080  int c;
2081  fread(&c,sizeof(int),1,f);
2082  for(int i = 0; i < c; i++)
2083  load_cross(f);
2084  fclose(f);
2085  //QMessageBox(QMessageBox::NoIcon,"OSMende","equal heights follow...").exec();
2086 
2088  //QMessageBox(QMessageBox::NoIcon,"OSMende","equal heights finished.").exec();
2089  status = 3;
2090  }
2091 }
2093  qint64 id;
2094  fread(&id,sizeof(qint64),1,f);
2095  KOO* k = insert_AVL(id,D.nodes);
2096  if(k->lat == 200){
2097  fread(&(k->lon),sizeof(double),1,f);
2098  fread(&(k->lat),sizeof(double),1,f);
2099  k->status = 0;
2100  return k;
2101  }
2102  else{
2103  fseek(f,2*sizeof(double),SEEK_CUR);
2104  return k;
2105  }
2106 }
2107 Way* OSM::load_Way(FILE* f){
2108  qint64 id;
2109  int length,i;
2110  char type;
2111  Way* w;
2112  fread(&id,sizeof(qint64),1,f);
2113  fread(&type,sizeof(char),1,f);
2114  fread(&length,sizeof(int),1,f);
2115  w = insert_AVL(id,D.waysavl);
2116  if(w->type == -1 || w->nodec < length){
2117  /*lesen und fuellen, da noch nicht vorhanden oder kürzer*/
2118  KOO** newKOO = new KOO*[length];
2119  for(i = 0; i < length; i++)
2120  newKOO[i] = load_node(f);
2121 
2122  if(w->type != -1){
2123  replace_Way_KOO(w,newKOO,length);
2124  w = NULL; //Der Weg war schon vorhanden, wurde
2125  //nur geaendert, deshalb return NULL
2126  //da OSM::load_lines damit arbeitet
2127  }
2128  else{
2129  w->type = type;
2130  w->nodec = length;
2131  w->node = newKOO;
2132  w->maxlat = -90;
2133  w->minlat = 90;
2134  w->maxlon =-180;
2135  w->minlon = 180;
2136  for(i = 0; i < length; i++){
2137  if(w->node[i]->lat > w->maxlat) w->maxlat = float(w->node[i]->lat);
2138  if(w->node[i]->lat < w->minlat) w->minlat = float(w->node[i]->lat);
2139  if(w->node[i]->lon > w->maxlon) w->maxlon = float(w->node[i]->lon);
2140  if(w->node[i]->lon < w->minlon) w->minlon = float(w->node[i]->lon);
2141  }
2142  }
2143  }
2144  else{
2145  fseek(f,length*(2*sizeof(double)+sizeof(qint64)),SEEK_CUR);
2146  w = NULL; //auf keinen Fall neues Line
2147  }
2148  return w;
2149 }
2150 void OSM::load_cross(FILE* f){
2151  readdirection rd;
2152  float d,hm;
2153  qint64 id, nid, wid;
2154  int j,tpc,nodec;
2155  short c;
2156  Neighbour *n1, *n2;
2157  trackpoint *tp;
2158  fread(&id, sizeof(qint64),1,f);
2159  fread(&c,sizeof(short),1,f);
2160  Way* w;
2161  KOO* k = search(id,*D.nodes), *kn;
2162  if(k != NULL){
2163  if(k->cd == NULL){
2164  /*Kreuzungsdaten anlegen, falls noch nicht vorhanden*/
2165  k->cd = new crossdata;
2166  k->cd->neighbours = NULL;
2167  k->cd->s = new STRONG[2];
2168  k->cd->s->from = NULL;
2169  k->cd->s->via = NULL;
2170  }
2171 
2172  /*Alle Kreuzungsabgänge bearbeiten*/
2173  for(short i = 0; i < c; i++){
2174  /*einlesen*/
2175 
2176  fread(&(rd), sizeof(readdirection),1,f);
2177  fread(&(d), sizeof(float),1,f);
2178  fread(&(hm), sizeof(float),1,f);
2179  fread(&(nid), sizeof(qint64),1,f);
2180  fread(&(wid), sizeof(qint64),1,f);
2181  fread(&(nodec), sizeof(int),1,f);
2182  fread(&j, sizeof(int),1,f);
2183  fread(&(tpc), sizeof(int),1,f);
2184 
2185  kn = search(nid,*D.nodes);
2186  w = search(wid,*D.waysavl);
2187 
2188  if(kn != NULL && w != NULL && j+(nodec-1) < w->nodec){
2189  /*Achtung: bei verschieden alte OSM-DAtensätze gleichen sich
2190  die Wege nicht unbedingt aufgrund der Gleichheit ihrer ID.
2191  Im Falle der verschiedenheit muss wenigstens gewährleistet,
2192  dass Neighbour nicht über das nodearray hinausliest*/
2193  if(kn->cd == NULL){
2194  /*Kreuzungsdaten anlegen, falls noch nicht vorhanden*/
2195  kn->cd = new crossdata;
2196  kn->cd->neighbours = NULL;
2197  kn->cd->s = new STRONG[2];
2198  kn->cd->s->from = NULL;
2199  kn->cd->s->via = NULL;
2200  }
2201  n1 = add_Neighbour(k ,&(w->node[j]),kn,w,d,nodec,fw);
2202  n2 = add_Neighbour(kn,&(w->node[j]),k ,w,d,nodec,bw);
2203  if(n1 != NULL && n2 != NULL){
2204  /*Normalfalll: hin und rückweg existieren noch nicht*/
2205  tp = new trackpoint[tpc];
2206  fread(tp,sizeof(trackpoint),tpc,f);
2207  n1->tp = tp;
2208  n1->tpc = tpc;
2209  n1->brthr = n2;
2210  n1->hm = hm;
2211  n2->tp = tp;
2212  n2->tpc = tpc;
2213  n2->brthr = n1;
2214  n2->hm = qMax(float(0),hm - (tp[tpc-1].h - tp[0].h));
2215  //n2->hm = (n1->hm+n2->hm)/2.;
2216  //n1->hm = n2->hm;
2217  }
2218  else
2219  if(n1 != NULL){
2220  /*Ringstrasse bspw.*/
2221  tp = new trackpoint[tpc];
2222  fread(tp,sizeof(trackpoint),tpc,f);
2223  n1->tp = tp;
2224  n1->tpc = tpc;
2225  n1->brthr = n1;
2226  n1->hm = hm;
2227  }
2228  else{
2229  /*Straßen existieren bereits, seek setzen statt
2230  weiter auslesen*/
2231  del_Neighbour(k,n1);
2232  del_Neighbour(kn,n2);
2233  fseek(f,tpc*sizeof(trackpoint),SEEK_CUR);
2234  }
2235  }
2236  else{
2237  fseek(f,tpc*sizeof(trackpoint),SEEK_CUR);
2238  }
2239  }
2240  }
2241  else
2242  /*sonst kann die Kreuzung nicht angelegt werden, sollte aber nicht
2243  passieren*/
2244  for(short i = 0; i < c; i++){
2245  fseek(f, ( sizeof(readdirection)
2246  +2*sizeof(float)
2247  +2*sizeof(qint64)
2248  +2*sizeof(int)),SEEK_CUR);
2249  fread(&(tpc), sizeof(int),1,f);
2250  fseek(f,tpc*sizeof(trackpoint),SEEK_CUR);
2251  }
2252 }
2253 void OSM::load_lines(lines** l, FILE* f){
2254  int c;
2255  int len;
2256  Way* w;
2257  char name[1000];
2258  fread(&c,sizeof(int),1,f);
2259  for(int i = 0; i < c; i++){
2260  w = load_Way(f);
2261  fread(&len,sizeof(int),1,f);
2262  if(len > 0 && w != NULL){
2263  /*Way noch nicht vorhanden und besitzt Namen*/
2264  fread(name,sizeof(char),len,f);
2265  name[len]='\0';
2266  add_line(l,w,name);
2267  }
2268  else
2269  if(w != NULL)
2270  /*Way noch nicht vorhanden, aber kein Name*/
2271  add_line(l,w,NULL);
2272  else
2273  /*weg bereits vorhanden*/
2274  fseek(f,len*sizeof(char),SEEK_CUR);
2275  }
2276 }
2277 void OSM::load_points(points** p, FILE* f){
2278  int c;
2279  int len;
2280  float index;
2281  KOO* k;
2282  char name[1000];
2283  fread(&c,sizeof(int),1,f);
2284  for(int i = 0; i < c; i++){
2285  k = load_node(f);
2286  fread(&index,sizeof(float),1,f);
2287  fread(&len,sizeof(int),1,f);
2288  fread(name,sizeof(char),len,f);
2289  if(len > 0 && k->status == 0){
2290  name[len] = '\0';
2291  add_points(p,k,name,index);
2292  }
2293  else
2294  if(k->status == 0)
2295  add_points(p,k,NULL,index);
2296  }
2297 }
2307  check_lines_rek(wood );
2309 }
2311  lines dummy, *t = &dummy, *b;
2312  dummy.next = *l;
2313  while(t->next != NULL){
2314  if(t->next->way->type >= 98){
2315  /*Element loeschen*/
2316  b = t->next;
2317  t->next = t->next->next;
2318  delete(b);
2319  }
2320  else
2321  t = t->next;
2322  }
2323  *l = dummy.next;
2324 }
2326  int i = 0;
2327  while(a[i] != '\0'){
2328  if(a[i] == '\"')
2329  a[i] = '\'';
2330  i++;
2331  }
2332 }
2333 void OSM::htmlreplace(char* c){
2334  if(c != NULL){
2335  char html[2][6] = {{'&','#','3','9',';','\0'},{'&','#','3','4',';','\0'}};
2336  char newchar[2] = {39,34};
2337  for(int i = 0; i < 2; i++){
2338  while(strstr(c,html[i]) != NULL){
2339  char* ct = strstr(c,html[i]);
2340  ct[0] = newchar[i];
2341  strcpy(&ct[1],&ct[strlen(html[i])]);
2342  }
2343  }
2344  }
2345 }
2346 void OSM::select_cross(double lat, double lon, KOO** kdest, float* d,KOO* ksrc){
2347  if(ksrc != NULL){
2348  if(ksrc->status == 2){
2349  float d2 = distance(lat,lon,ksrc->lat,ksrc->lon);
2350  if(d2 < *d){
2351  *d = d2;
2352  *kdest = ksrc;
2353  }
2354  }
2355  select_cross(lat,lon,kdest,d,ksrc->l);
2356  select_cross(lat,lon,kdest,d,ksrc->r);
2357  }
2358 }
2359 Way* OSM::select_Way(double lat, double lon){
2360  KOO *k1 = get_first_KOO(), *k2 = NULL;
2361  Way k;
2362  k.minlat = float(lat - 0.0001);
2363  k.maxlat = float(lat + 0.0001);
2364  k.minlon = float(lon - 0.00015);
2365  k.maxlon = float(lon + 0.00015);
2366  lines dummy, *l;
2367  dummy.next = NULL;
2368  extract_Way(&dummy,get_first_Way(),&k,0,8);
2369 
2370  Way* wmin = NULL;
2371  float dmin = 10000, d1, d2;
2372  l = dummy.next;
2373  while(l != NULL){
2374  d1 = 1000;
2375  d2 = 1000;
2376  for(int i = 0; i < l->way->nodec; i++)
2377  if(distance(l->way->node[i]->lat,l->way->node[i]->lon,lat,lon) < d1){
2378  d2 = d1;
2379  d1 = distance(l->way->node[i]->lat,l->way->node[i]->lon,lat,lon);
2380  k2 = k1;
2381  k1 = l->way->node[i];
2382  }
2383  if((d1 + d2) - distance(k1->lat, k1->lon, k2->lat, k2->lon) < dmin){
2384  dmin = (d1 + d2) - distance(k1->lat, k1->lon, k2->lat, k2->lon);
2385  wmin = l->way;
2386  }
2387  l = l->next;
2388  }
2389 
2390 
2391 
2392  /*Liste löschen*/
2393  while(dummy.next != NULL){
2394  l = dummy.next;
2395  dummy.next = l->next;
2396  delete(l);
2397  }
2398 
2399  return wmin;
2400 }
2401 void OSM::extract_Way(lines* l, Way* w, Way* k, char mintype, char maxtype){
2402  if(w != NULL){
2403  if(w->type <= maxtype && w->type >= mintype
2404  && isin(w,k->minlat,k->maxlat,k->minlon,k->maxlon)){
2405  lines* tl = new lines;
2406  tl->way = w;
2407  tl->next = l->next;
2408  l->next = tl;
2409  }
2410  extract_Way(l,w->l,k,mintype,maxtype);
2411  extract_Way(l,w->r,k,mintype,maxtype);
2412  }
2413 }
2414 void OSM::change_Waytype(Way* w, char newtype){
2415  lines** l = NULL;
2416  switch(w->type){
2417  case 0: l = motorWay; break;
2418  case 1: l = highway; break;
2419  case 2: l = primary; break;
2420  case 3: l = secondary; break;
2421  case 4: l = track; break;
2422  case 5: l = track2; break;
2423  case 6: l = wood; break;
2424  case 7: l = water; break;
2425  case 8: l = river; break;
2426  case 9: l = creek; break;
2427  }
2428  if(l != NULL){
2429  char* name = NULL;
2430  del_lines(w,l,name);
2431  switch(newtype){
2432  case 0: l = motorWay; break;
2433  case 1: l = highway; break;
2434  case 2: l = primary; break;
2435  case 3: l = secondary; break;
2436  case 4: l = track; break;
2437  case 5: l = track2; break;
2438  case 6: l = wood; break;
2439  case 7: l = water; break;
2440  case 8: l = river; break;
2441  case 9: l = creek; break;
2442  }
2443  add_line(l,w,name);
2444  }
2445  w->type = newtype;
2446 }
2447 void OSM::del_lines(Way* w, lines** l, char* keepname){
2448  if(*l != NULL){
2449  lines* tl = *l, *tlbuffer;
2450  while(tl ->next != NULL && tl->next->way != w)
2451  tl = tl->next; //Weg raussuchen
2452  if(tl->next != NULL){
2453  /*falls gefunden, dann aus der Liste entfernen*/
2454  tlbuffer = tl->next;
2455  tl->next = tl->next->next;
2456  keepname = tlbuffer->name;
2457  delete(tlbuffer);
2458  }
2459  else{
2460  /*falls es das erste Listenelement ist*/
2461  if((*l)->way == w){
2462  tlbuffer = (*l);
2463  *l = tlbuffer->next;
2464  keepname = tlbuffer->name;
2465  delete(tlbuffer);
2466  }
2467  }
2468  }
2469 }
2470 void OSM::del_Way(Way* w){
2471  lines** l = NULL;
2472  switch(w->type){
2473  case 0: l = motorWay; break;
2474  case 1: l = highway; break;
2475  case 2: l = primary; break;
2476  case 3: l = secondary; break;
2477  case 4: l = track; break;
2478  case 5: l = track2; break;
2479  case 6: l = wood; break;
2480  case 7: l = water; break;
2481  case 8: l = river; break;
2482  case 9: l = creek; break;
2483  default: l = creek; break;
2484  }
2485  char *name = NULL;
2486  del_lines(w,l,name);
2487  if(name != NULL)
2488  delete(name);
2489 
2490  for(int i = 0; i < w->nodec; i++){
2491  if(w->node[i]->cd != NULL){
2492  del_Neighbour(w->node[i],w);
2493  }
2494  }
2495  w->type = 99;
2496 }
2498  if(k->cd != NULL){
2499  Neighbour dummy, *n = &dummy, *nbuffer;
2500  dummy.next = k->cd->neighbours;
2501  while(n->next != NULL){
2502  if(n->next->way == w){
2503  /*Die Nachbarrelation n->next muss geloescht werden*/
2504  nbuffer = n->next;
2505  n->next = nbuffer->next;
2506  delete(nbuffer);
2507  }
2508  else
2509  n = n->next;
2510  }
2511  k->cd->neighbours = dummy.next;
2512  }
2513 }
2515  if(n != NULL && k != NULL && k->cd != NULL){
2516  Neighbour dummy, *tn = &dummy;
2517  char found = 0;
2518  dummy.next = k->cd->neighbours;
2519  while(tn->next != NULL){
2520  if(tn->next == n){
2521  tn->next = tn->next->next;
2522  found = 1;
2523  }
2524  else
2525  tn = tn->next;
2526  }
2527  if(found)
2528  delete(n);
2529  k->cd->neighbours = dummy.next;
2530  }
2531 }
2533  if(w != NULL){
2534  if(w->l != NULL && w->l->id > w->id)
2535  return 0;
2536  if(w->r != NULL && w->r->id < w->id)
2537  return 0;
2538  return check_AVL(w->l)*check_AVL(w->r);
2539  }
2540  else
2541  return 1;
2542 }
2543 void OSM::replace_Way_KOO(Way* w, KOO** newKOO, int newlength){
2544  KOO** KOObuffer = w->node;
2545  int lengthbuffer = w->nodec;
2546  w->node = newKOO;
2547  w->nodec = newlength;
2548  for(int i = 0; i < lengthbuffer; i++)
2549  /*alle Wegpunkte untersuchen, ob sie Kreuzungen sind*/
2550  if(KOObuffer[i]->cd != NULL){
2551  Neighbour* nb = KOObuffer[i]->cd->neighbours;
2552  short deletenow = 0;
2553  while(nb != NULL){
2554  /*alle Nachbarsschaftsbeziehung der Kreuzung untersuchen*/
2555  if(nb->way == w){
2556  /*die Nachbarschaftsbeziehung verläuft auf dem zu
2557  veraendernden Weg w*/
2558  int KOOcount = 0;
2559  short countnow = 0;
2560  for(int j = 0; j < newlength; j++){
2561  /*Pruefe, ob die alten KOO auf dem neuem Weg vorhanden
2562  sind*/
2563  if(countnow)
2564  KOOcount++;
2565  if(w->node[j] == KOObuffer[i]){
2566  if(!countnow){
2567  countnow = 1;
2568  nb->node = &(w->node[j]);
2569  nb->rd = fw;
2570  nb->brthr->node = &(w->node[j]);
2571  nb->brthr->rd = bw;
2572  }
2573  else{
2574  countnow = 0;
2575  nb->nodec = KOOcount + 1;
2576  nb->brthr->nodec = KOOcount + 1;
2577  }
2578  }
2579  if(w->node[j] == nb->nb){
2580  if(!countnow){
2581  countnow = 1;
2582  nb->node = &(w->node[j]);
2583  nb->rd = bw;
2584  nb->brthr->node = &(w->node[j]);
2585  nb->brthr->rd = fw;
2586  }
2587  else{
2588  countnow = 0;
2589  nb->nodec = KOOcount + 1;
2590  nb->brthr->nodec = KOOcount + 1;
2591  }
2592  }
2593  }
2594  if(countnow || !KOOcount)
2595  /*wenigstens einer der Kreuzungen ist im neuem Weg
2596  nicht vorhanden. Diese Nachbarschaftsbeziehung muss
2597  aufgegeben werden*/
2598  deletenow = 1;
2599 
2600  }
2601  if(deletenow){
2602  Neighbour* nbbuffer = nb;
2603  nb = nb->next;
2604  del_Neighbour(nbbuffer->nb,nbbuffer->brthr);
2605  del_Neighbour(KOObuffer[i],nbbuffer);
2606  deletenow = 0;
2607  }
2608  else
2609  nb = nb->next;
2610  }
2611  }
2612  delete(KOObuffer);
2613 }
2615  if(k != NULL){
2616  if(k->cd != NULL && k->cd->neighbours != NULL){
2617  Neighbour* n = k->cd->neighbours;
2618  short equal = 1;
2619  double h1,h2;
2620  if(n->rd == fw) h1 = n->tp[0 ].h;
2621  else h1 = n->tp[n->tpc-1].h;
2622  /*Gibt es überhaupt Diskrepanzen bezueglich der Kreuzungshoehe*/
2623  while(n->next != NULL && equal == 1){
2624  if(n->next->rd == fw) h2 = n->next->tp[0 ].h;
2625  else h2 = n->next->tp[n->next->tpc-1].h;
2626  if(h1 != h2) equal = 0;
2627  h1 = h2;
2628  n = n->next;
2629  }
2630  /*Falls ja, sollten die Diskrepanzen beseitigt werden*/
2631  if(!equal){
2632  double avh = 0; //Average height
2633  int nbc = 0; //Neighbour count
2634  n = k->cd->neighbours;
2635  /*Alle abgehenden Wege sollen die Duchschnittshoehe der
2636  Kreuzung an der Kreuzung aufzeigen*/
2637  while(n != NULL){
2638  if(n->rd == fw) avh = avh + n->tp[0 ].h;
2639  else avh = avh + n->tp[n->tpc-1].h;
2640  nbc++;
2641  n = n->next;
2642  }
2643  avh = 1.*avh/nbc;
2644  /*Korriere alle abgehenden Wege der Kreuzung linear*/
2645  double dh;
2646  n = k->cd->neighbours;
2647  while(n != NULL){
2648  if(n->d > 0){
2649  if(n->rd == fw){
2650  dh = n->tp[0].h - avh;
2651  for(int i = 0; i < n->tpc; i++){
2652  n->tp[i].h = float(n->tp[i].h
2653  - dh* (n->d - n->tp[i].d)/n->d);
2654  }
2655  }
2656  else{
2657  dh = n->tp[n->tpc-1].h - avh;
2658  for(int i = 0; i < n->tpc; i++){
2659  n->tp[i].h = float(n->tp[i].h - dh* (n->tp[i].d)/n->d);
2660  }
2661  }
2662  }
2663  else{
2664  if(n->rd == fw) n->tp[0].h = float(avh);
2665  else n->tp[n->tpc-1].h = float(avh);
2666  }
2667  n = n->next;
2668  }
2669  }
2670  }
2671  equal_crossheight(k->l);
2672  equal_crossheight(k->r);
2673  }
2674 }
2676  if(k != NULL){
2677  if(k->cd != NULL && k->cd->neighbours != NULL){
2678  Neighbour* n = k->cd->neighbours;
2679  while(n != NULL){
2680  if(n->rd == fw){
2681  n->hm = (n->hm + n->brthr->hm)/2.;
2682  n->brthr->hm = n->hm;
2683  }
2684  n = n->next;
2685  }
2686  }
2687  normalize_Hm(k->l);
2688  normalize_Hm(k->r);
2689  }
2690 }
2692  if(k != NULL){
2693  if(k->cd != NULL && k->cd->neighbours != NULL){
2694  Neighbour* n = k->cd->neighbours;
2695  float hmswap;
2696  while(n != NULL){
2697  if(n->rd == fw){
2698  hmswap = n->hm;
2699  n->hm = n->brthr->hm;
2700  n->brthr->hm = hmswap;
2701  }
2702  n = n->next;
2703  }
2704  }
2705  invert_Hm(k->l);
2706  invert_Hm(k->r);
2707  }
2708 
2709 }
2711  if(k != NULL){
2712  if(k->cd != NULL && k->cd->neighbours != NULL){
2713  Neighbour* n = k->cd->neighbours;
2714  while(n != NULL){
2715  n->brthr->hm = n->hm = 0;
2716  if(n->rd == fw){
2717  for(int i = 1; i < n->tpc; i++)
2718  if(n->tp[i].d > n->tp[i-1].d){
2719  if(n->tp[i].h > n->tp[i-1].h)
2720  n->hm += (n->tp[i].h - n->tp[i-1].h);
2721  else
2722  n->brthr->hm -= (n->tp[i].h - n->tp[i-1].h);
2723  }
2724  }
2725  n = n->next;
2726  }
2727  }
2728  reset_Hm(k->l);
2729  reset_Hm(k->r);
2730  }
2731 }
2732 
2734  if(k != NULL){
2735  if(k->cd != NULL && k->cd->neighbours != NULL){
2736  Neighbour* n = k->cd->neighbours;
2737  while(n != NULL){
2738  n->brthr->hm = n->hm = 0;
2739  if(n->rd == fw){
2740  for(int i = 1; i < n->tpc; i++)
2741  if(n->tp[i].d > n->tp[i-1].d){
2742  if(n->tp[i].h > n->tp[i-1].h)
2743  n->hm += (n->tp[i].h - n->tp[i-1].h)
2744  *(n->tp[i].h - n->tp[i-1].h)
2745  /(n->tp[i].d - n->tp[i-1].d)/1000;
2746  else
2747  n->brthr->hm += (n->tp[i].h - n->tp[i-1].h)
2748  *(n->tp[i].h - n->tp[i-1].h)
2749  /(n->tp[i].d - n->tp[i-1].d)/1000;
2750  }
2751  }
2752  n = n->next;
2753  }
2754  }
2755  points_Hm(k->l);
2756  points_Hm(k->r);
2757  }
2758 }
2759 
2760 void OSM::merge(KOO* knew, KOO* kold){
2761  if( knew != NULL && kold != NULL &&
2762  knew->cd != NULL && kold->cd != NULL &&
2763  knew->cd->neighbours != NULL && kold->cd->neighbours != NULL){
2764  double newh;
2765  if(knew->cd->neighbours->rd == fw)
2766  newh = knew->cd->neighbours->tp[0].h;
2767  else
2768  newh = knew->cd->neighbours->tp[knew->cd->neighbours->tpc-1].h;
2769  Neighbour* tn = kold->cd->neighbours;
2770  while(tn != NULL){
2771  KOO* klast;
2772  if(tn->rd == fw) klast = tn->node[0];
2773  else klast = tn->node[tn->nodec-1];
2774  double dd = distance(klast->lat,klast->lon,knew->lat,knew->lon)
2775  -distance(klast->lat,klast->lon,kold->lat,kold->lon);
2776  tn->d = tn->brthr->d = tn->d + dd;
2777  if(tn->rd == fw){
2778  for(int i = 1; i < tn->tpc; i++)
2779  tn->tp[i].d = tn->tp[i].d+dd;
2780  tn->node[0] = knew;
2781  tn->tp[0].h = newh;
2782  }
2783  else{
2784  tn->tp[tn->tpc-1].d = tn->tp[tn->tpc-1].d + dd;
2785  tn->node[tn->nodec-1] = knew;
2786  tn->tp[tn->tpc-1].h = newh;
2787  }
2788  tn->brthr->nb = knew;
2789  double hmfw= 0, hmbw = 0;
2790  for(int i = 1; i < tn->tpc; i++)
2791  if(tn->tp[i].h > tn->tp[i-1].h)
2792  hmfw = hmfw + tn->tp[i].h - tn->tp[i-1].h;
2793  else
2794  hmbw = hmbw - tn->tp[i].h + tn->tp[i-1].h;
2795 
2796  if(tn->rd == fw){
2797  tn->hm = hmfw;
2798  tn->brthr->hm = hmbw;
2799  }
2800  else{
2801  tn->hm = hmbw;
2802  tn->brthr->hm = hmfw;
2803  }
2804 
2805  if(tn->nb == knew && tn != tn->brthr){
2806  del_Neighbour(knew,tn->brthr);
2807  tn = tn->next;
2808  }
2809  else{
2810  Neighbour* tb = tn->next;
2811  tn->next = knew->cd->neighbours;
2812  knew->cd->neighbours = tn;
2813  tn = tb;
2814  }
2815 
2816  }
2817  kold->cd = NULL;
2818  kold->status = 0;
2819  }
2820 }
2821 void OSM::deleteRect(double minlat, double maxlat,
2822  double minlon, double maxlon){
2823  /*alle Wege löschen*/
2824  del_Way(get_first_Way(),minlat,maxlat,minlon,maxlon);
2825  /*alle Punkte löschen*/
2826  points **pt[7];
2827  pt[0] = metropolis;
2828  pt[1] = city;
2829  pt[2] = town;
2830  pt[3] = village;
2831  pt[4] = locality;
2832  pt[5] = col;
2833  pt[6] = peak;
2834  for(int i = 0; i < 7; i++){
2835  points* p = *pt[i];
2836  points pbuf; pbuf.next = p;
2837  if(p != NULL) p->prev = &pbuf;
2838  while(p != NULL){
2839  if(isin(p,minlat,maxlat,minlon,maxlon)){
2840  p->prev->next = p->next;
2841  if(p->next != NULL)
2842  p->next->prev = p->prev;
2843  }
2844  p = p->next;
2845  }
2846  if(pbuf.next != NULL)
2847  pbuf.next->prev = NULL;
2848  *pt[i] = pbuf.next;
2849  }
2850 }
2851 void OSM::del_Way(Way* w, double minlat, double maxlat,
2852  double minlon, double maxlon){
2853  if(w != NULL){
2854  if(iscompletein(w,minlat,maxlat,minlon,maxlon))
2855  del_Way(w);
2856  del_Way(w->l,minlat,maxlat,minlon,maxlon);
2857  del_Way(w->r,minlat,maxlat,minlon,maxlon);
2858  }
2859 }
2860 void OSM::delete_AVL(Way* l){
2861  if(l != NULL){
2862  if(l->node != NULL) delete l->node;
2863  if(l->name != NULL) delete l->name;
2864  delete_AVL(l->l);
2865  delete_AVL(l->r);
2866  delete l;
2867  }
2868 }
2869 
2870 void OSM::delete_AVL(KOO* l){
2871  if(l != NULL){
2872  if(l->cd != NULL){
2873  Neighbour *n = l->cd->neighbours, *nt;
2874  while(n != NULL){
2875  nt = n;
2876  n = n->next;
2877  if(nt->rd == fw)
2878  delete nt->tp;
2879  delete nt;
2880  }
2881  if(l->cd->s != NULL) delete l->cd->s;
2882  delete l->cd;
2883  }
2884  delete_AVL(l->l);
2885  delete_AVL(l->r);
2886  delete l;
2887  }
2888 }
2889 
2890 void OSM::delete_lines(lines* l){
2891  lines* lt;
2892  while(l != NULL){
2893  lt = l;
2894  l = l->next;
2895  delete lt;
2896  }
2897 }
2898 
2899 void OSM::delete_points(points* l){
2900  points* lt;
2901  while(l != NULL){
2902  lt = l;
2903  l = l->next;
2904  if(lt->name != NULL) delete lt->name;
2905  delete lt;
2906  }
2907 }
2908 
2909 void OSM::delete_relation(relation* l){
2910  relation* lt;
2911  while(l != NULL){
2912  lt = l;
2913  l = l->next;
2914  if(lt->members != NULL) delete l->members;
2915  delete lt;
2916  }
2917 }
points ** locality
&lt; 20 : tag hamlet, locality, isolated_dwelling
Definition: osm.h:72
void read_OSM()
read osm file
Definition: osm.cpp:59
void del_Neighbour(KOO *k, Way *w)
Definition: osm.cpp:2497
double extract_valuef(char *s, const char *a)
search for tag a in string s and extract to double
Definition: osm.cpp:46
void del_lines(Way *w, lines **l, char *keepname)
Definition: osm.cpp:2447
string filename
Definition: osm.h:147
Neighbour * via
connection to reach this STRONG
Definition: DataTyps.h:258
double height_t(double lon, double lat, void *hc, short mode)
returns height data operating at the precalculated data grid
Definition: HeightData.cpp:343
void save_node(KOO *k, FILE *f)
Definition: osm.cpp:1977
void load(char *filename)
load btp to dataset
Definition: osm.cpp:2049
void replace_Way_KOO(Way *w, KOO **newKOO, int newlength)
Definition: osm.cpp:2543
relation ** waterr
Definition: osm.h:79
char balance
AVL tree balance.
Definition: DataTyps.h:84
Way * way
Neighbour lives uses this Way.
Definition: DataTyps.h:53
short iscompletein(Way *w, double minlat, double maxlat, double minlon, double maxlon)
Definition: osm.cpp:714
short isin(lines *l, double minlat, double maxlat, double minlon, double maxlon)
Definition: osm.cpp:670
char * extract_valuec(char *s, const char *a)
search for tag a in string s and returns it
Definition: osm.cpp:620
double getmaxlat()
return lsat calced bounding rect
Definition: osm.cpp:1752
float maxlon
bounding rect, for rendering
Definition: DataTyps.h:126
float index
for summit ranking
Definition: DataTyps.h:139
void save_Way(Way *w, FILE *f)
Definition: osm.cpp:1985
KOO * get_first_KOO()
returns root of node-AVL tree
Definition: osm.cpp:1692
container struct to hold data of a coordinate
Definition: DataTyps.h:82
int count_STRONG(KOO *k)
counts STRONG data recursivly
Definition: osm.cpp:803
void equal_crossheight(KOO *k)
find common cross height if Neighbour relation indicates different
Definition: osm.cpp:2614
KOO ** node
reference to KOO (of way)
Definition: DataTyps.h:61
char status
state of the KOO when used by different classes
Definition: DataTyps.h:100
double lat
Definition: DataTyps.h:86
lines ** water
Definition: osm.h:70
void get_KOO_Waysavl()
links node IDs to nodes recursivly
Definition: osm.cpp:578
KOO * nb
Definition: DataTyps.h:54
lines ** creek
Definition: osm.h:70
void check_lines_rek(lines **l)
check recursivly completeness of KOO pointers
Definition: osm.cpp:2310
KOO * rotate(KOO **s, branch b)
AVL tree handling: subroutine of insert(), returns root element.
Definition: osm.cpp:180
void reset_KOO_status(KOO *k, char i)
Definition: osm.cpp:1637
void reset_Hm(KOO *k)
resets Neighbour Hm to ascenting vertical meters
Definition: osm.cpp:2710
routing container struct, connects cross via Way with each other
Definition: DataTyps.h:47
double minlat
bounding rect of the osm data set
Definition: osm.h:200
relation ** woodr
Definition: osm.h:79
points * add_points(points **l, KOO *KOO, char *name, float index)
add a KOO to a OSM_Data points element with a given name and index
Definition: osm.cpp:1411
lines ** track2
Definition: osm.h:70
lines ** primary
Definition: osm.h:70
void calc_brect()
refresh bounding rect of dataset
Definition: osm.cpp:1644
Neighbour * next
next Neighbour, set to NULL if last
Definition: DataTyps.h:63
void nodehandling(FILE *f, char *line, char *lineattr, char *linename)
$osm-file reading: dealing with node data lines in file
Definition: osm.cpp:814
void extract_bbox(char *s)
extrac bounding box specified in osm file
Definition: osm.cpp:630
void sort_peaks()
primitive sort algorithm
Definition: osm.cpp:1813
qint64 extract_valuei(char *s, const char *a)
search for tag a in string s and extract to qint64
Definition: osm.cpp:34
int nodec
count of used KOO in way
Definition: DataTyps.h:59
KOO * k
reference to KOO
Definition: DataTyps.h:138
void check_lines()
delete Way with unresolved nodes
Definition: osm.cpp:2298
lines ** secondary
Definition: osm.h:70
double getminlat()
return lsat calced bounding rect
Definition: osm.cpp:1746
void extract_Way(lines *l, Way *w, Way *k, char mintype, char maxtype)
Definition: osm.cpp:2401
void load_lines(lines **l, FILE *f)
Definition: osm.cpp:2253
STRONG * s
memory for routing algorithms
Definition: DataTyps.h:75
qint64 id
OSM way id
Definition: DataTyps.h:123
Neighbour * add_Neighbour(KOO *k, KOO **node, KOO *nb, Way *w, float d, int KOOc, readdirection rd)
add Neighbour cross to k
Definition: osm.cpp:1695
void paek_pro(double lon, double lat, qint64 **c, float *Ahigher, int cc, int ac, float d, float mperlon, float mperlat)
evaluates prominence of summits
Definition: HeightData.cpp:426
qint64 id
id inherited from OSM data
Definition: DataTyps.h:83
void points_Hm(KOO *k)
accumulates section difficulties instead of vertical meters in Neighbour relation ...
Definition: osm.cpp:2733
char * name
OSM name of point
Definition: DataTyps.h:140
short balance
AVL tree balance.
Definition: DataTyps.h:128
holds digital elevation model extracted from SRTM3 data
Definition: HeightData.h:26
readdirection rd
Definition: DataTyps.h:52
char type
classification
Definition: DataTyps.h:129
double dminlat
claimed bounding rect of the &amp;osm data file
Definition: osm.h:202
KOO * load_node(FILE *f)
Definition: osm.cpp:2092
container for line geodata
Definition: DataTyps.h:122
points ** col
mountain pass
Definition: osm.h:72
KOO * insert_AVL(qint64 id, KOO **s)
AVL tree handling: accurate insert of id into data subtree s.
Definition: osm.cpp:266
KOO * search(qint64 id, KOO *s)
Definition: osm.cpp:105
lines ** ExclCheck[8]
help array to find exclusive Way to merge relation participants
Definition: osm.h:81
OSM_Data D
Definition: osm.h:150
void htmlreplace(char *c)
Definition: osm.cpp:2333
void * from
&lt; pointer to STRONG or FibunacciHeap
Definition: DataTyps.h:257
void initiallists()
initial class&#39;s containers
Definition: osm.cpp:734
void add_line(lines **l, Way *Way, char *name)
add a Way to a OSM_Data liones element with a given name
Definition: osm.cpp:1398
void RelationstoFace(relation **l, lines **f)
collect all Way to one relation
Definition: osm.cpp:1469
osm data container list for relation data (multiple lakes and forrests)
Definition: DataTyps.h:149
void calc_peak_index_pro(HeightData *h)
summit ranking uses t-functions of heighdata
Definition: osm.cpp:1759
void save_points(points **p, FILE *f, double minlat, double maxlat, double minlon, double maxlon)
Definition: osm.cpp:1944
points ** peak
summit
Definition: osm.h:72
points ** city
10000
Definition: osm.h:72
void merge(KOO *knew, KOO *kold)
solves conflictiv KOO and crossdata when loading several btp datasets
Definition: osm.cpp:2760
KOO ** node
array KOO pointers
Definition: DataTyps.h:125
void relationhandling(FILE *f, char *line, char *lineattr, char *linename, qint64 *currentseek)
$osm-file reading: dealing with relation data lines in file
Definition: osm.cpp:1066
lines ** NoHeight
Definition: osm.h:70
float d
distance
Definition: DataTyps.h:58
void quotationreplace(char *a)
replaces " by &#39;
Definition: osm.cpp:2325
char * name
OSM name of line
Definition: DataTyps.h:146
int tpc
count of trackpoint
Definition: DataTyps.h:60
Neighbour * neighbours
neigbours to link to other cross
Definition: DataTyps.h:74
lines ** wood
Definition: osm.h:70
void load_cross(FILE *f)
Definition: osm.cpp:2150
lines ** highway
Definition: osm.h:70
points ** metropolis
100000 : tag city
Definition: osm.h:72
Way * prev
AVL tree struct.
Definition: DataTyps.h:127
void invert_points(points **l)
invert elements of a list
Definition: osm.cpp:1458
double getminlon()
return lsat calced bounding rect
Definition: osm.cpp:1749
void normalize_Hm(KOO *k)
removes total height differences from Neighbour relation
Definition: osm.cpp:2675
int status
osm usage status variable
Definition: osm.h:146
lines ** track
Definition: osm.h:70
container struct to hold data of a cross
Definition: DataTyps.h:73
void save_lines(lines **l, FILE *f, double minlat, double maxlat, double minlon, double maxlon)
Definition: osm.cpp:1912
void load_points(points **p, FILE *f)
Definition: osm.cpp:2277
container struct for Track to hold distance and height data
Definition: DataTyps.h:33
float hm
total height meter, for routing
Definition: DataTyps.h:57
KOO * insert(qint64 id, KOO *s)
AVL tree handling: naiv insert of id into data subtree s.
Definition: osm.cpp:112
KOO * prev
AVL tree pointers.
Definition: DataTyps.h:85
trackpoint * tp
heighdata of this Neighbour
Definition: DataTyps.h:62
int count_cross(KOO *k)
counts crossdata recursivly
Definition: osm.cpp:793
void save(char *filename, double minlat, double maxlat, double minlon, double maxlon)
save dataset as btp
Definition: osm.cpp:1855
char * name
name ref owned by lines
Definition: DataTyps.h:130
Way * load_Way(FILE *f)
Definition: osm.cpp:2107
osm data container list for line like data (roads, rivers)
Definition: DataTyps.h:143
osm data container list for point like data (summits, towns, ...)
Definition: DataTyps.h:137
void save_cross(KOO *k, FILE *f, int *c, double minlat, double maxlat, double minlon, double maxlon)
Definition: osm.cpp:1992
Way * get_first_Way()
returns root of Way-AVL tree
Definition: osm.cpp:1689
void add_relation(relation **l, relation *r)
add a relation to a OSM_Data relation element with a given name and index
Definition: osm.cpp:1454
int nodec
count of KOO
Definition: DataTyps.h:124
short check_AVL(Way *w)
Definition: osm.cpp:2532
void invert_Hm(KOO *k)
switches descenting and ascenting vertical meters in Neighbour relation
Definition: osm.cpp:2691
int get_status()
returns current class state
Definition: osm.cpp:790
points ** village
20 : tag village, suburban
Definition: osm.h:72
void Wayhandling(FILE *f, char *line, char *lineattr, char *linename, qint64 *currentseek)
$osm-file reading: dealing with way data lines in file
Definition: osm.cpp:1120
points ** town
3000 : tag town
Definition: osm.h:72
Way * way
reference element of this list
Definition: DataTyps.h:144
lines ** motorWay
Definition: osm.h:70
lines ** river
Definition: osm.h:70
double getmaxlon()
return lsat calced bounding rect
Definition: osm.cpp:1755
void deleteRect(double minlat, double maxlat, double minlon, double maxlon)
delete all data lying within the rectangular area
Definition: osm.cpp:2821
Neighbour * brthr
related Neighbour with opposite read direction supposed to store brthr
Definition: DataTyps.h:56
main struct for routing purpose
Definition: DataTyps.h:255