3 OSM::OSM(
string fileName){
11 delete_AVL(*(
D.nodes));
12 delete_AVL(*(
D.waysavl));
23 delete_lines(*
water);
31 delete_relation(*
woodr);
37 x1 = strstr(s,a)+strlen(a)+2*
sizeof(char);
39 QMessageBox(QMessageBox::NoIcon,
"Error",QString(
"Could not extract integer value from '%1'").arg(s)).exec();
42 qint64 result = QString(x1).toLongLong();
49 x1 = strstr(s,a)+strlen(a)+2*
sizeof(char);
51 QMessageBox(QMessageBox::NoIcon,
"Error",QString(
"Could not extract double value from '%1'").arg(s)).exec();
55 double result = atof(x1);
64 printf(
"Fehler beim öffnen der Datei ");
68 char line[10000],lineattr[10000],linename[10000];
78 currentseek = _ftelli64(f);
81 if(strstr(line,
"bbox=") != NULL
82 || strstr(line,
"<bound box=") != NULL)
84 if(strstr(line,
"<bounds ") != NULL){
90 if (strstr(line,
"<node ") != NULL)
92 if (strstr(line,
"<way ") != NULL)
94 if (strstr(line,
"<relation ") != NULL)
102 printf(
"Initialisieren korrekten Dateinamen mit OSM(fileName)!\n");
106 while (s != NULL && s->
id !=
id){
107 if(s->
id >
id) s = s->l;
116 while (s != NULL && s->
id !=
id){
183 case l:
switch((*s)->balance){
184 case +1:
switch((*s)->r->balance){
185 case -1:(*s)->balance = 0;
186 (*s)->r->balance = -2;
188 case 0: (*s)->balance = 0;
189 (*s)->r->balance = -1;
191 case 1: (*s)->balance = -1;
192 (*s)->r->balance = -1;
196 case +2:
switch((*s)->r->balance){
197 case -1:(*s)->balance = 1;
198 (*s)->r->balance = -2;
200 case 0: (*s)->balance = 1;
201 (*s)->r->balance = -1;
203 case 1: (*s)->balance = 0;
204 (*s)->r->balance = 0;
206 case 2: (*s)->balance = -1;
207 (*s)->r->balance = 0;
213 case r:
switch((*s)->balance){
214 case -1:
switch((*s)->l->balance){
215 case -1:(*s)->balance = 1;
216 (*s)->l->balance = 1;
218 case 0: (*s)->balance = 0;
219 (*s)->l->balance = 1;
221 case 1: (*s)->balance = 0;
222 (*s)->l->balance = 2;
226 case -2:
switch((*s)->l->balance){
227 case -2:(*s)->balance = 1;
228 (*s)->l->balance = 0;
230 case -1:(*s)->balance = 0;
231 (*s)->l->balance = 0;
233 case 0: (*s)->balance = -1;
234 (*s)->l->balance = 1;
236 case 1: (*s)->balance = -1;
237 (*s)->l->balance = 2;
251 (*s)->l->
prev = (*s);
252 if (k != NULL) k->
prev = (*s)->l;
261 (*s)->r->
prev = (*s);
262 if (k != NULL) k->
prev = (*s)->r;
281 case -1: i =
rotate(&i,r);
283 case 1:
rotate(&(i->l),l);
295 case-1:
if(i->
prev == NULL) fertig = 1;
307 case -1:
rotate(&(i->r),r);
319 case 1:
if(i->
prev == NULL) fertig = 1;
326 if (i->
prev == NULL){
349 while (s != NULL && s->
id !=
id){
350 if(s->
id >
id) s = s->l;
359 while (s != NULL && s->
id !=
id){
417 case l:
switch((*s)->balance){
418 case +1:
switch((*s)->r->balance){
419 case -1:(*s)->balance = 0;
420 (*s)->r->balance = -2;
422 case 0: (*s)->balance = 0;
423 (*s)->r->balance = -1;
425 case 1: (*s)->balance = -1;
426 (*s)->r->balance = -1;
430 case +2:
switch((*s)->r->balance){
431 case -1:(*s)->balance = 1;
432 (*s)->r->balance = -2;
434 case 0: (*s)->balance = 1;
435 (*s)->r->balance = -1;
437 case 1: (*s)->balance = 0;
438 (*s)->r->balance = 0;
440 case 2: (*s)->balance = -1;
441 (*s)->r->balance = 0;
447 case r:
switch((*s)->balance){
448 case -1:
switch((*s)->l->balance){
449 case -1:(*s)->balance = 1;
450 (*s)->l->balance = 1;
452 case 0: (*s)->balance = 0;
453 (*s)->l->balance = 1;
455 case 1: (*s)->balance = 0;
456 (*s)->l->balance = 2;
460 case -2:
switch((*s)->l->balance){
461 case -2:(*s)->balance = 1;
462 (*s)->l->balance = 0;
464 case -1:(*s)->balance = 0;
465 (*s)->l->balance = 0;
467 case 0: (*s)->balance = -1;
468 (*s)->l->balance = 1;
470 case 1: (*s)->balance = -1;
471 (*s)->l->balance = 2;
485 (*s)->l->
prev = (*s);
486 if (k != NULL) k->
prev = (*s)->l;
495 (*s)->r->
prev = (*s);
496 if (k != NULL) k->
prev = (*s)->r;
513 case -1: i =
rotate(&i,r);
515 case 1:
rotate(&(i->l),l);
527 case-1:
if(i->
prev == NULL) fertig = 1;
539 case -1:
rotate(&(i->r),r);
551 case 1:
if(i->
prev == NULL) fertig = 1;
558 if (i->
prev == NULL){
591 for(
int j = 0; j < l->
nodec; j++){
595 if(l->
node[j] == NULL){
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);
607 if(l->
node[j]->lon < l->minlon )
608 l->minlon = float(l->
node[j]->lon);
617 printf(
"Zuerst Datei einlesen mittels read_OSM_all()\n");
623 x1 = strstr(s,a)+strlen(a)+2*
sizeof(char);
625 QMessageBox(QMessageBox::NoIcon,
"Error",QString(
"Could not char value from '%1'").arg(s)).exec();
626 x2 = strchr(x1,
'\'');
631 if(strstr(s,
"bbox=") != NULL){
632 char* t = strstr(s,
"bbox=");
634 char* t2 = strstr(t,
",");
651 char* t = strstr(s,
"box=");
653 char* t2 = strstr(t,
",");
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)
677 ( (l->
way->minlon >= minlon && l->
way->minlon <= maxlon)
679 ||(l->
way->minlon <= minlon && l->
way->
maxlon >= maxlon)
686 double minlon,
double maxlon){
687 return isin(l->
k,minlat,maxlat,minlon,maxlon);
690 double minlon,
double maxlon){
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)
706 ( (w->minlon >= minlon && w->minlon <= maxlon)
708 ||(w->minlon <= minlon && w->
maxlon >= maxlon)
715 double minlon,
double maxlon){
716 if( w->minlat > minlat
717 && w->maxlat < maxlat
718 && w->minlon > minlon
724 void OSM::setfilename(
string fileName){
725 if(fileName.compare(fileName.size()-4,4,
".osm") == 0){
730 printf(
"%s ist keien .osm-Datei!\n",fileName.c_str());
745 D.waysavl =
new Way*;
805 if(k->cd != NULL && k->cd->
s != NULL)
815 char* attr = &line[0];
817 short foundplace = 0,foundpeak = 0, foundpopulation = 0, foundname = 0, foundcol = 0;
828 while(strstr(line,
"</node>") == NULL &&
829 !(strstr(line,
"<node ")!=NULL && strstr(line,
"/>") != NULL)){
832 if(strstr(line,
"<tag k='place' v='") != NULL){
833 strcpy(lineattr,line);
837 if(strstr(line,
"<tag k='tourism' v='alpine_hut'/>") != NULL){
841 if(strstr(line,
"<tag k='natural' v='peak'/>") != NULL){
844 if(strstr(line,
"<tag k='natural' v='saddle'/>") != NULL ||
845 strstr(line,
"<tag k='mountain_pass' v='yes'/>") != NULL){
848 if(strstr(line,
"<tag k='name' v='") != NULL){
850 strcpy(linename,line);
856 strstr(line,
"<tag k='openGeoDB:name' v='")!=NULL){
858 strcpy(linename,line);
864 strstr(line,
"<tag k='name:")!=NULL){
866 strcpy(linename,line);
870 if(strstr(line,
"tag k='population' v='") != NULL){
877 foundplace = foundpeak = 0;
881 if(foundpopulation && foundplace && !foundcol)
885 if(population>100000)
891 if(population>3000 || !strcmp(attr,
"town"))
902 if(foundplace && !foundpopulation && !foundcol){
904 if(!strcmp(attr,
"city"))
907 if(!strcmp(attr,
"town"))
910 if( !strcmp(attr,
"suburb")
911 ||!strcmp(attr,
"village"))
914 if( !strcmp(attr,
"hamlet")
915 ||!strcmp(attr,
"locality")
916 ||!strcmp(attr,
"alpine_hut")
917 ||!strcmp(attr,
"isolated_dwelling"))
922 if(foundcol && foundname){
925 if(foundpeak && foundname && !foundcol)
1067 qint64* currentseek){
1069 int relationlength = 0;
1070 int iswood = 0, iswater = 0;
1073 while(strstr(line,
"</relation>") == NULL){
1074 if(strstr(line,
"<member type='way'") != NULL){
1077 tw =
search(tID,*(
D.waysavl));
1078 if(tw != NULL && tw->
type == 6)
1081 if(strstr(line,
"<tag k='landuse' v='forest'/>") != NULL
1082 || strstr(line,
"<tag k='natural' v='wood'/>") != NULL)
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)
1092 if ((iswood || iswater) && relationlength > 0){
1094 r->memberscount = relationlength;
1095 r->members =
new Way*[relationlength];
1096 _fseeki64(f,*currentseek,SEEK_SET);
1100 relationlength = -1;
1101 while(strstr(line,
"</relation>") == NULL){
1104 if(strstr(line,
"<member type='way'") != NULL){
1106 r->members[relationlength] =
new Way;
1121 qint64* currentseek){
1122 char* attr = &line[0];
1125 while(strstr(line,
"</way>") == NULL){
1126 if(strstr(line,
"<nd ref=") != NULL) Waylength++;
1129 if(name == NULL && strstr(line,
"<tag k='name' v='") != NULL){
1131 strcpy(linename,line);
1135 if(strstr(line,
"<tag k='ref' v='") != NULL){
1137 strcpy(linename,line);
1144 _fseeki64(f,*currentseek,SEEK_SET);
1148 k->
nodec = Waylength;
1149 k->
node =
new KOO*[Waylength];
1155 while(strstr(line,
"</way>") == NULL){
1158 if(strstr(line,
"<nd ref=") != NULL){
1163 if(strstr(line,
"<tag k='highway' v='") != NULL){
1164 strcpy(lineattr,line);
1166 if(!strcmp(attr,
"motorway")||
1167 !strcmp(attr,
"motorway_link")||
1168 !strcmp(attr,
"trunk")||
1169 !strcmp(attr,
"trunk_link"))
1171 if(!strcmp(attr,
"primary")||
1172 !strcmp(attr,
"primary_link"))
1174 if((!strcmp(attr,
"secondary")
1175 ||!strcmp(attr,
"secondary_link")))
1177 if(!strcmp(attr,
"tertiary"))
1179 if(!strcmp(attr,
"residential")
1180 ||!strcmp(attr,
"unclassified")
1181 ||!strcmp(attr,
"road")
1182 ||!strcmp(attr,
"service"))
1184 if( !strcmp(attr,
"cycleway")||
1185 !strcmp(attr,
"track")||
1186 !strcmp(attr,
"footway"))
1189 if(strstr(line,
"<tag k='surface' v='") != NULL){
1190 strcpy(lineattr,line);
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"))
1199 if(!strcmp(attr,
"compacted")||
1200 !strcmp(attr,
"fine_gravel ")||
1201 !strcmp(attr,
"sett"))
1203 if(!strcmp(attr,
"cobblestone:flattened"))
1205 if(!strcmp(attr,
"cobblestone"))
1208 if(strstr(line,
"<tag k='tracktype' v='") != NULL){
1209 strcpy(lineattr,line);
1211 if(!strcmp(attr,
"grade1"))
1213 if(!strcmp(attr,
"grade2"))
1215 if(!strcmp(attr,
"grade3")||
1216 !strcmp(attr,
"grade4")||
1217 !strcmp(attr,
"grade5"))
1220 if(strstr(line,
"<tag k='tunnel' v='yes'/>") != NULL
1221 || strstr(line,
"<tag k='bridge' v='") != NULL){
1224 if((strstr(line,
"<tag k='landuse' v='forest'/>") != NULL
1225 || strstr(line,
"<tag k='natural' v='wood'/>") != NULL))
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))
1231 if(strstr(line,
"<tag k='waterway' v='river'/>") != NULL)
1233 if(strstr(line,
"<tag k='waterway' v='stream'/>") != NULL)
1401 if(*l == NULL) a->next = NULL;
1405 Way->
name = a->
name =
new char[strlen(name)+1];
1406 strcpy(a->
name,name);
1416 a->
name =
new char[strlen(name)+1];
1417 strcpy(a->
name,name);
1425 if((*l)->index < index){
1435 while(p->next != NULL && p->
index >= index)
1437 if(p->
index >= index){
1471 short *used, exists,foundneighbourmember;
1482 used =
new short[r->memberscount];
1483 for(i = 0; i < r->memberscount; i++){
1485 tempWay =
search(r->members[i]->
id,*(
D.waysavl));
1486 if(tempWay != NULL && tempWay->
type != 99){
1488 r->members[i] = tempWay;
1494 for(i = 0; i < r->memberscount; i++)
1496 if(r->members[i]->
node[0 ]->
id ==
1504 if(cf->
way->
id == r->members[i]->
id){
1511 if(!exists && r->members[i]->
type > 8){
1522 Ways =
new Way*[r->memberscount];
1524 e = r->members[i]->
node[0];
1525 s = r->members[i]->
node[r->members[i]->
nodec-1];
1526 Ways[cm]=r->members[i];
1529 foundneighbourmember = 0;
1530 for(j = 0; j < r->memberscount; j++){
1532 &&( s->
id == r->members[j]->
node[0]->
id
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];
1541 s = r->members[j]->
node[0];
1543 j = r->memberscount;
1544 foundneighbourmember = 1;
1547 }
while( foundneighbourmember
1548 && (e->
id != Ways[cm]->
node[0] ->
id)
1553 if(foundneighbourmember){
1556 int FoundExclusive = 1;
1557 int CheckMax = 6;
if(l ==
woodr) CheckMax = 8;
1558 for(j = 0; j <= cm; j++){
1560 for(
int k = 0; k < CheckMax; k++){
1563 if(Ways[j]->
id == cf->
way->
id){
1564 FoundExclusive = -1;
1572 if(FoundExclusive == 1){
1577 if(FoundExclusive > -1){
1581 for(j = 0; j <= cm; j++)
1582 nodecount = nodecount + Ways[j]->nodec;
1583 nodecount = nodecount - cm;
1588 grandWay->
id = Ways[FoundExclusive]->
id;
1589 grandWay->
nodec = nodecount;
1590 grandWay->
node =
new KOO*[nodecount];
1591 grandWay->
type = r->type;
1594 s = r->members[i]->
node[0];
1596 grandWay->maxlat = -90;
1597 grandWay->minlat = 90;
1599 grandWay->minlon = 180;
1600 for(j = 0; j <= cm; j++){
1601 if(Ways[j]->node[0]->
id == s->
id){
1603 for(k = 0; k < Ways[j]->
nodec-1; k++){
1604 grandWay->
node[cn] = Ways[j]->
node[k];
1611 for(k = Ways[j]->nodec-1; k > 0; k--){
1612 grandWay->
node[cn] = Ways[j]->
node[k];
1615 s = Ways[j]->
node[0];
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 )
1624 if(Ways[j]->minlon < grandWay->minlon )
1625 grandWay->minlon = Ways[j]->minlon;
1670 if(p->
k->
lat > maxlat) maxlat = p->
k->
lat;
1672 if(p->
k->lon > maxlon) maxlon = p->
k->lon;
1673 if(p->
k->lon < minlon) minlon = p->
k->lon;
1680 for(
int i = 0; i < p->
way->
nodec; i++){
1690 return *(
D.waysavl);
1696 int KOOc, readdirection rd){
1705 while(n->
next != NULL && (n->
nb != nb || n->
way != w))
1710 if(n->
nb != nb || n->
way != w){
1761 int wc = 50, j, i, ac = 10;
1763 float d = float(0.2);
1765 float* index =
new float[ac];
1766 float* index2 =
new float[ac];
1769 qint64**c =
new qint64*[ac];
1770 for(i = 0; i < ac; i++)
1771 c[i] =
new qint64[wc];
1772 float mperlon, mperlat;
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;
1777 h->
paek_pro(p->
k->lon,p->
k->
lat,c,&Ahigher,wc,ac,d,mperlon,mperlat);
1778 for(i = 0; i < ac; i++){
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]);
1789 for(j = 0; j < wc; 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));
1797 for(j = 0; j < ac; j++){
1798 is = is + sqrt(index[j]);
1799 is2 = is2 + index2[j];
1801 p->
index = sqrt(is*is*is2/ac);
1802 p->
index = float(p->
index * max(1.,1+(0.002-Ahigher)*500));
1807 for(i = 0; i < ac; i++)
1820 f = fopen(
"pointssortiert.txt",
"w");
1824 while(l->next != NULL){
1827 l->prev->next = l->next;
1828 l->next->prev = l->prev;
1830 if(l->next->next != NULL){
1831 l->next->next->prev = l;
1832 l->next = l->next->next;
1845 fprintf(f,
"%f - %s - %f N %f E\n",l->
index,l->
name,l->
k->
lat,l->
k->lon);
1851 p.next->prev = NULL;
1855 void OSM::save(
char* filename,
double minlat,
double maxlat,
1856 double minlon,
double maxlon){
1858 f = fopen(filename,
"wb");
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);
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);
1913 double minlon,
double maxlon){
1917 fwrite(&c,
sizeof(
int),1,f);
1921 if(
isin(k->
way,minlat,maxlat,minlon,maxlon))
1925 fwrite(&c,
sizeof(
int),1,f);
1928 if(
isin(k->
way,minlat,maxlat,minlon,maxlon)){
1931 if(k->
name == NULL){
1932 fwrite(&len,
sizeof(
int),1,f);
1935 len = strlen(k->
name);
1936 fwrite(&len,
sizeof(
int),1,f);
1937 fwrite(k->
name,
sizeof(
char),len,f);
1945 double minlon,
double maxlon){
1949 fwrite(&c,
sizeof(
int),1,f);
1953 if(
isin(k->
k,minlat,maxlat,minlon,maxlon))
1957 fwrite(&c,
sizeof(
int),1,f);
1960 if(
isin(k->
k,minlat,maxlat,minlon,maxlon)){
1962 fwrite(&(k->
index),
sizeof(
float),1,f);
1964 if(k->
name == NULL){
1965 fwrite(&len,
sizeof(
int),1,f);
1968 len = strlen(k->
name);
1969 fwrite(&len,
sizeof(
int),1,f);
1970 fwrite(k->
name,
sizeof(
char),len,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);
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++)
1993 double maxlat,
double minlon,
double maxlon){
1998 fwrite(&(k->
id),
sizeof(qint64),1,f);
2011 fwrite(&i,
sizeof(
short),1,f);
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);
2024 for(
int l = n->
way->
nodec-1; l >=0; l--){
2028 fwrite(&j,
sizeof(
int),1,f);
2029 fwrite(&(n->
tpc),
sizeof(
int),1,f);
2036 save_cross(k->l,f,c, minlat, maxlat, minlon, maxlon);
2037 save_cross(k->r,f,c, minlat, maxlat, minlon, maxlon);
2051 f = fopen(filename,
"rb");
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);
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;
2081 fread(&c,
sizeof(
int),1,f);
2082 for(
int i = 0; i < c; i++)
2094 fread(&
id,
sizeof(qint64),1,f);
2097 fread(&(k->lon),
sizeof(
double),1,f);
2098 fread(&(k->
lat),
sizeof(
double),1,f);
2103 fseek(f,2*
sizeof(
double),SEEK_CUR);
2112 fread(&
id,
sizeof(qint64),1,f);
2113 fread(&type,
sizeof(
char),1,f);
2114 fread(&length,
sizeof(
int),1,f);
2118 KOO** newKOO =
new KOO*[length];
2119 for(i = 0; i < length; i++)
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);
2140 if(w->
node[i]->lon < w->minlon) w->minlon = float(w->
node[i]->lon);
2145 fseek(f,length*(2*
sizeof(
double)+
sizeof(qint64)),SEEK_CUR);
2153 qint64 id, nid, wid;
2158 fread(&
id,
sizeof(qint64),1,f);
2159 fread(&c,
sizeof(
short),1,f);
2168 k->cd->
s->
from = NULL;
2169 k->cd->
s->
via = NULL;
2173 for(
short i = 0; i < c; i++){
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);
2188 if(kn != NULL && w != NULL && j+(nodec-1) < w->
nodec){
2197 kn->cd->s =
new STRONG[2];
2198 kn->cd->s->
from = NULL;
2199 kn->cd->s->via = NULL;
2203 if(n1 != NULL && n2 != NULL){
2214 n2->
hm = qMax(
float(0),hm - (tp[tpc-1].h - tp[0].h));
2244 for(
short i = 0; i < c; i++){
2245 fseek(f, (
sizeof(readdirection)
2248 +2*
sizeof(
int)),SEEK_CUR);
2249 fread(&(tpc),
sizeof(
int),1,f);
2258 fread(&c,
sizeof(
int),1,f);
2259 for(
int i = 0; i < c; i++){
2261 fread(&len,
sizeof(
int),1,f);
2262 if(len > 0 && w != NULL){
2264 fread(name,
sizeof(
char),len,f);
2274 fseek(f,len*
sizeof(
char),SEEK_CUR);
2283 fread(&c,
sizeof(
int),1,f);
2284 for(
int i = 0; i < c; i++){
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){
2311 lines dummy, *t = &dummy, *b;
2313 while(t->next != NULL){
2317 t->next = t->next->next;
2327 while(a[i] !=
'\0'){
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]);
2341 strcpy(&ct[1],&ct[strlen(html[i])]);
2346 void OSM::select_cross(
double lat,
double lon,
KOO** kdest,
float* d,
KOO* ksrc){
2349 float d2 = distance(lat,lon,ksrc->
lat,ksrc->lon);
2355 select_cross(lat,lon,kdest,d,ksrc->l);
2356 select_cross(lat,lon,kdest,d,ksrc->r);
2359 Way* OSM::select_Way(
double lat,
double lon){
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);
2371 float dmin = 10000, d1, d2;
2376 for(
int i = 0; i < l->
way->
nodec; i++)
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);
2393 while(dummy.next != NULL){
2395 dummy.next = l->next;
2403 if(w->
type <= maxtype && w->
type >= mintype
2404 &&
isin(w,k->minlat,k->maxlat,k->minlon,k->
maxlon)){
2414 void OSM::change_Waytype(
Way* w,
char newtype){
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;
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;
2449 lines* tl = *l, *tlbuffer;
2450 while(tl ->next != NULL && tl->next->
way != w)
2452 if(tl->next != NULL){
2454 tlbuffer = tl->next;
2455 tl->next = tl->next->next;
2456 keepname = tlbuffer->
name;
2463 *l = tlbuffer->next;
2464 keepname = tlbuffer->
name;
2470 void OSM::del_Way(
Way* w){
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;
2490 for(
int i = 0; i < w->
nodec; i++){
2491 if(w->
node[i]->cd != NULL){
2501 while(n->
next != NULL){
2515 if(n != NULL && k != NULL && k->cd != NULL){
2519 while(tn->
next != NULL){
2534 if(w->l != NULL && w->l->
id > w->
id)
2536 if(w->r != NULL && w->r->
id < w->
id)
2545 int lengthbuffer = w->
nodec;
2547 w->
nodec = newlength;
2548 for(
int i = 0; i < lengthbuffer; i++)
2550 if(KOObuffer[i]->cd != NULL){
2552 short deletenow = 0;
2560 for(
int j = 0; j < newlength; j++){
2565 if(w->
node[j] == KOObuffer[i]){
2575 nb->
nodec = KOOcount + 1;
2579 if(w->
node[j] == nb->
nb){
2589 nb->
nodec = KOOcount + 1;
2594 if(countnow || !KOOcount)
2616 if(k->cd != NULL && k->cd->
neighbours != NULL){
2620 if(n->
rd == fw) h1 = n->
tp[0 ].h;
2621 else h1 = n->
tp[n->
tpc-1].h;
2623 while(n->
next != NULL && equal == 1){
2626 if(h1 != h2) equal = 0;
2638 if(n->
rd == fw) avh = avh + n->
tp[0 ].h;
2639 else avh = avh + n->
tp[n->
tpc-1].h;
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);
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);
2664 if(n->
rd == fw) n->
tp[0].h = float(avh);
2665 else n->
tp[n->
tpc-1].h = float(avh);
2677 if(k->cd != NULL && k->cd->
neighbours != NULL){
2693 if(k->cd != NULL && k->cd->
neighbours != NULL){
2712 if(k->cd != NULL && k->cd->
neighbours != NULL){
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);
2735 if(k->cd != NULL && k->cd->
neighbours != NULL){
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;
2748 *(n->
tp[i].h - n->
tp[i-1].h)
2749 /(n->
tp[i].d - n->
tp[i-1].d)/1000;
2761 if( knew != NULL && kold != NULL &&
2762 knew->cd != NULL && kold->cd != NULL &&
2772 if(tn->
rd == fw) klast = tn->
node[0];
2774 double dd = distance(klast->
lat,klast->lon,knew->
lat,knew->lon)
2775 -distance(klast->
lat,klast->lon,kold->
lat,kold->lon);
2778 for(
int i = 1; i < tn->
tpc; i++)
2779 tn->
tp[i].d = tn->
tp[i].d+dd;
2784 tn->
tp[tn->
tpc-1].d = tn->
tp[tn->
tpc-1].d + dd;
2786 tn->
tp[tn->
tpc-1].h = newh;
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;
2794 hmbw = hmbw - tn->
tp[i].h + tn->
tp[i-1].h;
2805 if(tn->
nb == knew && tn != tn->
brthr){
2822 double minlon,
double maxlon){
2834 for(
int i = 0; i < 7; i++){
2836 points pbuf; pbuf.next = p;
2837 if(p != NULL) p->prev = &pbuf;
2839 if(
isin(p,minlat,maxlat,minlon,maxlon)){
2840 p->prev->next = p->next;
2842 p->next->prev = p->prev;
2846 if(pbuf.next != NULL)
2847 pbuf.next->prev = NULL;
2851 void OSM::del_Way(
Way* w,
double minlat,
double maxlat,
2852 double minlon,
double maxlon){
2856 del_Way(w->l,minlat,maxlat,minlon,maxlon);
2857 del_Way(w->r,minlat,maxlat,minlon,maxlon);
2860 void OSM::delete_AVL(
Way* l){
2862 if(l->
node != NULL)
delete l->
node;
2863 if(l->
name != NULL)
delete l->
name;
2870 void OSM::delete_AVL(
KOO* l){
2881 if(l->cd->
s != NULL)
delete l->cd->
s;
2890 void OSM::delete_lines(
lines* l){
2899 void OSM::delete_points(
points* l){
2904 if(lt->
name != NULL)
delete lt->
name;
2909 void OSM::delete_relation(
relation* l){
2914 if(lt->members != NULL)
delete l->members;
points ** locality
< 20 : tag hamlet, locality, isolated_dwelling
void read_OSM()
read osm file
void del_Neighbour(KOO *k, Way *w)
double extract_valuef(char *s, const char *a)
search for tag a in string s and extract to double
void del_lines(Way *w, lines **l, char *keepname)
Neighbour * via
connection to reach this STRONG
double height_t(double lon, double lat, void *hc, short mode)
returns height data operating at the precalculated data grid
void save_node(KOO *k, FILE *f)
void load(char *filename)
load btp to dataset
void replace_Way_KOO(Way *w, KOO **newKOO, int newlength)
char balance
AVL tree balance.
Way * way
Neighbour lives uses this Way.
short iscompletein(Way *w, double minlat, double maxlat, double minlon, double maxlon)
short isin(lines *l, double minlat, double maxlat, double minlon, double maxlon)
char * extract_valuec(char *s, const char *a)
search for tag a in string s and returns it
double getmaxlat()
return lsat calced bounding rect
float maxlon
bounding rect, for rendering
float index
for summit ranking
void save_Way(Way *w, FILE *f)
KOO * get_first_KOO()
returns root of node-AVL tree
container struct to hold data of a coordinate
int count_STRONG(KOO *k)
counts STRONG data recursivly
void equal_crossheight(KOO *k)
find common cross height if Neighbour relation indicates different
KOO ** node
reference to KOO (of way)
char status
state of the KOO when used by different classes
void get_KOO_Waysavl()
links node IDs to nodes recursivly
void check_lines_rek(lines **l)
check recursivly completeness of KOO pointers
KOO * rotate(KOO **s, branch b)
AVL tree handling: subroutine of insert(), returns root element.
void reset_KOO_status(KOO *k, char i)
void reset_Hm(KOO *k)
resets Neighbour Hm to ascenting vertical meters
routing container struct, connects cross via Way with each other
double minlat
bounding rect of the osm data set
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
void calc_brect()
refresh bounding rect of dataset
Neighbour * next
next Neighbour, set to NULL if last
void nodehandling(FILE *f, char *line, char *lineattr, char *linename)
$osm-file reading: dealing with node data lines in file
void extract_bbox(char *s)
extrac bounding box specified in osm file
void sort_peaks()
primitive sort algorithm
qint64 extract_valuei(char *s, const char *a)
search for tag a in string s and extract to qint64
int nodec
count of used KOO in way
void check_lines()
delete Way with unresolved nodes
double getminlat()
return lsat calced bounding rect
void extract_Way(lines *l, Way *w, Way *k, char mintype, char maxtype)
void load_lines(lines **l, FILE *f)
STRONG * s
memory for routing algorithms
Neighbour * add_Neighbour(KOO *k, KOO **node, KOO *nb, Way *w, float d, int KOOc, readdirection rd)
add Neighbour cross to k
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
qint64 id
id inherited from OSM data
void points_Hm(KOO *k)
accumulates section difficulties instead of vertical meters in Neighbour relation ...
char * name
OSM name of point
short balance
AVL tree balance.
holds digital elevation model extracted from SRTM3 data
double dminlat
claimed bounding rect of the &osm data file
container for line geodata
points ** col
mountain pass
KOO * insert_AVL(qint64 id, KOO **s)
AVL tree handling: accurate insert of id into data subtree s.
KOO * search(qint64 id, KOO *s)
lines ** ExclCheck[8]
help array to find exclusive Way to merge relation participants
void htmlreplace(char *c)
void * from
< pointer to STRONG or FibunacciHeap
void initiallists()
initial class's containers
void add_line(lines **l, Way *Way, char *name)
add a Way to a OSM_Data liones element with a given name
void RelationstoFace(relation **l, lines **f)
collect all Way to one relation
osm data container list for relation data (multiple lakes and forrests)
void calc_peak_index_pro(HeightData *h)
summit ranking uses t-functions of heighdata
void save_points(points **p, FILE *f, double minlat, double maxlat, double minlon, double maxlon)
void merge(KOO *knew, KOO *kold)
solves conflictiv KOO and crossdata when loading several btp datasets
KOO ** node
array KOO pointers
void relationhandling(FILE *f, char *line, char *lineattr, char *linename, qint64 *currentseek)
$osm-file reading: dealing with relation data lines in file
void quotationreplace(char *a)
replaces " by '
char * name
OSM name of line
int tpc
count of trackpoint
Neighbour * neighbours
neigbours to link to other cross
points ** metropolis
100000 : tag city
Way * prev
AVL tree struct.
void invert_points(points **l)
invert elements of a list
double getminlon()
return lsat calced bounding rect
void normalize_Hm(KOO *k)
removes total height differences from Neighbour relation
int status
osm usage status variable
container struct to hold data of a cross
void save_lines(lines **l, FILE *f, double minlat, double maxlat, double minlon, double maxlon)
void load_points(points **p, FILE *f)
container struct for Track to hold distance and height data
float hm
total height meter, for routing
KOO * insert(qint64 id, KOO *s)
AVL tree handling: naiv insert of id into data subtree s.
KOO * prev
AVL tree pointers.
trackpoint * tp
heighdata of this Neighbour
int count_cross(KOO *k)
counts crossdata recursivly
void save(char *filename, double minlat, double maxlat, double minlon, double maxlon)
save dataset as btp
char * name
name ref owned by lines
osm data container list for line like data (roads, rivers)
osm data container list for point like data (summits, towns, ...)
void save_cross(KOO *k, FILE *f, int *c, double minlat, double maxlat, double minlon, double maxlon)
Way * get_first_Way()
returns root of Way-AVL tree
void add_relation(relation **l, relation *r)
add a relation to a OSM_Data relation element with a given name and index
void invert_Hm(KOO *k)
switches descenting and ascenting vertical meters in Neighbour relation
int get_status()
returns current class state
points ** village
20 : tag village, suburban
void Wayhandling(FILE *f, char *line, char *lineattr, char *linename, qint64 *currentseek)
$osm-file reading: dealing with way data lines in file
points ** town
3000 : tag town
Way * way
reference element of this list
double getmaxlon()
return lsat calced bounding rect
void deleteRect(double minlat, double maxlat, double minlon, double maxlon)
delete all data lying within the rectangular area
Neighbour * brthr
related Neighbour with opposite read direction supposed to store brthr
main struct for routing purpose