/[zanavi_public1]/navit/navit/maptool/osm_relations.c
ZANavi

Diff of /navit/navit/maptool/osm_relations.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 36 Revision 37
1/**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
1/** 20/**
2 * Navit, a modular navigation system. 21 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2011 Navit Team 22 * Copyright (C) 2005-2011 Navit Team
4 * 23 *
5 * This program is free software; you can redistribute it and/or 24 * This program is free software; you can redistribute it and/or
15 * along with this program; if not, write to the 34 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 36 * Boston, MA 02110-1301, USA.
18 */ 37 */
19#include <stdio.h> 38#include <stdio.h>
39#include <time.h>
20#include <string.h> 40#include <string.h>
21#include "maptool.h" 41#include "maptool.h"
22#include "attr.h" 42#include "attr.h"
23 43
24struct relations { 44struct relations
45{
25 GHashTable *member_hash[3]; 46 GHashTable *member_hash[3];
26}; 47};
27 48
28struct relations_func { 49struct relations_func
50{
29 void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv); 51 void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv);
30 void *func_priv; 52 void *func_priv;
31}; 53};
32 54
33struct relations_member { 55struct relations_member
56{
34 osmid memberid; 57 osmid memberid;
35 void *relation_priv,*member_priv; 58 void *relation_priv, *member_priv;
36 struct relations_func *func; 59 struct relations_func *func;
37}; 60};
38 61
39static guint
40relations_member_hash(gconstpointer key) 62static guint relations_member_hash(gconstpointer key)
41{ 63{
42 const struct relations_member *memb=key; 64 const struct relations_member *memb = key;
43 return (memb->memberid >> 32)^(memb->memberid & 0xffffffff); 65 return (memb->memberid >> 32) ^ (memb->memberid & 0xffffffff);
44} 66}
45 67
46static gboolean
47relations_member_equal(gconstpointer a, gconstpointer b) 68static gboolean relations_member_equal(gconstpointer a, gconstpointer b)
48{ 69{
49 const struct relations_member *memba=a; 70 const struct relations_member *memba = a;
50 const struct relations_member *membb=b; 71 const struct relations_member *membb = b;
51 return (memba->memberid == membb->memberid); 72 return (memba->memberid == membb->memberid);
52} 73}
53 74
54struct relations * 75struct relations *
55relations_new(void) 76relations_new(void)
56{ 77{
57 struct relations *ret=g_new(struct relations, 1); 78 struct relations *ret=g_new(struct relations, 1);
58 int i; 79 int i;
59 80
60 for (i = 0 ; i < 3 ; i++) 81 for (i = 0; i < 3; i++)
82 {
61 ret->member_hash[i]=g_hash_table_new_full(relations_member_hash, relations_member_equal, NULL, NULL); 83 ret->member_hash[i] = g_hash_table_new_full(relations_member_hash, relations_member_equal, NULL, NULL);
84 }
62 return ret; 85 return ret;
63} 86}
64 87
65struct relations_func * 88struct relations_func *
66relations_func_new(void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv), void *func_priv) 89relations_func_new(void(*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv), void *func_priv)
67{ 90{
68 struct relations_func *relations_func=g_new(struct relations_func, 1); 91 struct relations_func *relations_func=g_new(struct relations_func, 1);
69 relations_func->func=func; 92 relations_func->func = func;
70 relations_func->func_priv=func_priv; 93 relations_func->func_priv = func_priv;
71 return relations_func; 94 return relations_func;
72} 95}
73 96
74void
75relations_add_func(struct relations *rel, struct relations_func *func, void *relation_priv, void *member_priv, int type, osmid id) 97void relations_add_func(struct relations *rel, struct relations_func *func, void *relation_priv, void *member_priv, int type, osmid id)
76{ 98{
99 //fprintf(stderr,"relations_add_func:001\n");
100
77 GHashTable *member_hash=rel->member_hash[type-1]; 101 GHashTable *member_hash = rel->member_hash[type - 1];
78 struct relations_member *memb=g_new(struct relations_member, 1); 102 struct relations_member *memb=g_new(struct relations_member, 1);
79 103
80 memb->memberid=id; 104 memb->memberid = id;
81 memb->relation_priv=relation_priv; 105 memb->relation_priv = relation_priv;
82 memb->member_priv=member_priv; 106 memb->member_priv = member_priv;
83 memb->func=func; 107 memb->func = func;
84 g_hash_table_insert(member_hash, memb, g_list_append(g_hash_table_lookup(member_hash, memb), memb)); 108 g_hash_table_insert(member_hash, memb, g_list_append(g_hash_table_lookup(member_hash, memb), memb));
85} 109}
86 110
87void
88relations_process(struct relations *rel, FILE *nodes, FILE *ways, FILE *relations) 111void relations_process(struct relations *rel, FILE *nodes, FILE *ways, FILE *relations)
89{ 112{
90 char buffer[128]; 113 char buffer[128];
91 struct item_bin *ib=(struct item_bin *)buffer; 114 struct item_bin *ib = (struct item_bin *) buffer;
92 long long *id; 115 long long *id;
93 struct coord *c=(struct coord *)(ib+1),cn={0,0}; 116 struct coord *c = (struct coord *) (ib + 1), cn =
117 { 0, 0 };
94 struct node_item *ni; 118 struct node_item *ni;
95 GList *l; 119 GList *l;
96 120
121 time_t start_tt, end_tt;
122 double diff_tt;
123 double diff2_tt;
124 long long size_in;
125 long long pos_in;
126 int _c = 0;
127 int _e = 8000000;
128
129 //fprintf(stderr,"relations_process:001\n");
130
97 if (nodes) { 131 if (nodes)
132 {
133 //fprintf(stderr,"relations_process:002 nodes\n");
134
135 long long pos_now = (long long)ftello(nodes); // 64bit
136 fseeko(nodes, 0, SEEK_END);
137 size_in = (long long)ftello(nodes); // 64bit
138 fprintf(stderr, "relations_process: pos nodes file=%lld\n", pos_now);
139 fprintf(stderr, "relations_process:size nodes file=%lld\n", size_in);
140 // seek to start of file
141 fseeko(nodes, 0, SEEK_SET);
142 // reset timer
143 diff2_tt = 0;
144 _c = 0;
145 time(&start_tt);
146
98 item_bin_init(ib, type_point_unkn); 147 item_bin_init(ib, type_point_unkn);
99 item_bin_add_coord(ib, &cn, 1); 148 item_bin_add_coord(ib, &cn, 1);
100 item_bin_add_attr_longlong(ib, attr_osm_nodeid, 0); 149 item_bin_add_attr_longlong(ib, attr_osm_nodeid, 0);
101 id=item_bin_get_attr(ib, attr_osm_nodeid, NULL); 150 id = item_bin_get_attr(ib, attr_osm_nodeid, NULL);
102 while ((ni=read_node_item(nodes))) { 151 while ((ni = read_node_item(nodes, 0)))
152 {
153 _c++;
154
103 *id=ni->id; 155 *id = ni->id;
104 *c=ni->c; 156 *c = ni->c;
105 l=g_hash_table_lookup(rel->member_hash[0], id); 157 l = g_hash_table_lookup(rel->member_hash[0], id);
106 while (l) { 158 while (l)
159 {
107 struct relations_member *memb=l->data; 160 struct relations_member *memb = l->data;
108 memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv); 161 memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
109 l=g_list_next(l); 162 l = g_list_next(l);
163 }
164
165 if (_c > _e)
166 {
167 _c = 0;
168
169 pos_in = ftello(nodes); // 64bit
170 time(&end_tt);
171 diff_tt = difftime(end_tt,start_tt);
172 char outstring[200];
173 char outstring2[200];
174 char outstring3[200];
175 convert_to_human_time(diff_tt, outstring);
176 convert_to_human_bytes(pos_in, outstring2);
177 convert_to_human_bytes(size_in, outstring3);
178 fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-NODES: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3);
179 if (pos_in > 0)
180 {
181 double eta_time = (diff_tt / pos_in) * (size_in - pos_in);
182 convert_to_human_time(eta_time, outstring);
183 fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-NODES: %s left\n", outstring);
184 }
110 } 185 }
111 } 186 }
112 } 187 }
188
189 //fprintf(stderr,"relations_process:002.9\n");
190
113 if (ways) { 191 if (ways)
192 {
193 //fprintf(stderr,"relations_process:003 ways\n");
194
195 long long pos_now = (long long)ftello(ways); // 64bit
196 fseeko(ways, 0, SEEK_END);
197 size_in = (long long)ftello(ways); // 64bit
198 fprintf(stderr, "relations_process: pos ways file=%lld\n", pos_now);
199 fprintf(stderr, "relations_process:size ways file=%lld\n", size_in);
200 // seek to start of file
201 fseeko(ways, 0, SEEK_SET);
202 // reset timer
203 diff2_tt = 0;
204 _c = 0;
205 time(&start_tt);
206
114 while ((ib=read_item(ways))) { 207 while ((ib = read_item(ways, 0)))
208 {
209 _c++;
210
211 //fprintf(stderr,"relations_process:003.1\n");
212
115 id=item_bin_get_attr(ib, attr_osm_wayid, NULL); 213 id = item_bin_get_attr(ib, attr_osm_wayid, NULL);
214
215 //fprintf(stderr,"********DUMP relw***********\n");
216 //dump_itembin(ib);
217 //fprintf(stderr,"********DUMP relw***********\n");
218
219 //char *labelxx=item_bin_get_attr(ib, attr_name, NULL);
220 //fprintf(stderr,"relations_process:003.2 %s\n", labelxx);
221 //labelxx=item_bin_get_attr(ib, attr_label, NULL);
222 //fprintf(stderr,"relations_process:003.3 %s\n", labelxx);
223
116 if (id) { 224 if (id)
225 {
226 //fprintf(stderr,"relations_process:004 wayid:"LONGLONG_FMT"\n", id);
227
117 l=g_hash_table_lookup(rel->member_hash[1], id); 228 l = g_hash_table_lookup(rel->member_hash[1], id);
118 while (l) { 229 while (l)
230 {
231 //fprintf(stderr,"relations_process:005\n");
119 struct relations_member *memb=l->data; 232 struct relations_member *memb = l->data;
233 //fprintf(stderr,"relations_process:005.1 %d\n", memb->memberid);
120 memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv); 234 memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
121 l=g_list_next(l); 235 l = g_list_next(l);
236 }
237 }
238
239 if (_c > _e)
240 {
241 _c = 0;
242
243 pos_in = ftello(ways); // 64bit
244 time(&end_tt);
245 diff_tt = difftime(end_tt,start_tt);
246 char outstring[200];
247 char outstring2[200];
248 char outstring3[200];
249 convert_to_human_time(diff_tt, outstring);
250 convert_to_human_bytes(pos_in, outstring2);
251 convert_to_human_bytes(size_in, outstring3);
252 fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-WAYS: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3);
253 if (pos_in > 0)
254 {
255 double eta_time = (diff_tt / pos_in) * (size_in - pos_in);
256 convert_to_human_time(eta_time, outstring);
257 fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-WAYS: %s left\n", outstring);
122 } 258 }
123 } 259 }
124 } 260 }
125 } 261 }
126} 262}
263

Legend:
Removed from v.36  
changed lines
  Added in v.37

   
Visit the ZANavi Wiki