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

Contents of /navit/navit/maptool/osm_relations.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 57 - (show annotations) (download)
Sun Mar 19 16:46:08 2017 UTC (7 years, 1 month ago) by zoff99
File MIME type: text/plain
File size: 8487 byte(s)
updates
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
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2011 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38 #include <stdio.h>
39 #include <time.h>
40 #include <string.h>
41 #include "maptool.h"
42 #include "attr.h"
43
44 struct relations
45 {
46 GHashTable *member_hash[3];
47 };
48
49 struct relations_func
50 {
51 void (*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv);
52 void *func_priv;
53 };
54
55 struct relations_member
56 {
57 osmid memberid;
58 void *relation_priv, *member_priv;
59 struct relations_func *func;
60 };
61
62 static guint relations_member_hash(gconstpointer key)
63 {
64 const struct relations_member *memb = key;
65 return (memb->memberid >> 32) ^ (memb->memberid & 0xffffffff);
66 }
67
68 static gboolean relations_member_equal(gconstpointer a, gconstpointer b)
69 {
70 const struct relations_member *memba = a;
71 const struct relations_member *membb = b;
72 return (memba->memberid == membb->memberid);
73 }
74
75 struct relations *
76 relations_new(void)
77 {
78 struct relations *ret=g_new(struct relations, 1);
79 int i;
80
81 for (i = 0; i < 3; i++)
82 {
83 ret->member_hash[i] = g_hash_table_new_full(relations_member_hash, relations_member_equal, NULL, NULL);
84 }
85 return ret;
86 }
87
88 struct relations_func *
89 relations_func_new(void(*func)(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv), void *func_priv)
90 {
91 struct relations_func *relations_func=g_new(struct relations_func, 1);
92 relations_func->func = func;
93 relations_func->func_priv = func_priv;
94 return relations_func;
95 }
96
97 void relations_add_func(struct relations *rel, struct relations_func *func, void *relation_priv, void *member_priv, int type, osmid id)
98 {
99 //fprintf(stderr,"relations_add_func:001\n");
100
101 GHashTable *member_hash = rel->member_hash[type - 1];
102 struct relations_member *memb=g_new(struct relations_member, 1);
103
104 memb->memberid = id;
105 memb->relation_priv = relation_priv;
106 memb->member_priv = member_priv;
107 memb->func = func;
108 g_hash_table_insert(member_hash, memb, g_list_append(g_hash_table_lookup(member_hash, memb), memb));
109 }
110
111 void relations_process(struct relations *rel, FILE *nodes, FILE *ways, FILE *relations)
112 {
113 // char buffer_rel1[128];
114 char *buffer_rel1 = g_malloc0(MAX_ITEMBIN_BYTES_);
115 struct item_bin *ib = (struct item_bin *) buffer_rel1;
116 long long *id;
117 struct coord *c = (struct coord *) (ib + 1), cn = { 0, 0 };
118 struct node_item *ni;
119 GList *l;
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
131 if (nodes)
132 {
133 long long pos_now = (long long)ftello(nodes); // 64bit
134 fseeko(nodes, 0, SEEK_END);
135 size_in = (long long)ftello(nodes); // 64bit
136 fprintf_(stderr, "relations_process: pos nodes file=%lld\n", pos_now);
137 fprintf_(stderr, "relations_process:size nodes file=%lld\n", size_in);
138 // seek to start of file
139 fseeko(nodes, 0, SEEK_SET);
140 // reset timer
141 diff2_tt = 0;
142 _c = 0;
143 time(&start_tt);
144
145 item_bin_init(ib, type_point_unkn);
146 item_bin_add_coord(ib, &cn, 1);
147 item_bin_add_attr_longlong(ib, attr_osm_nodeid, 0);
148 id = item_bin_get_attr(ib, attr_osm_nodeid, NULL);
149
150 while ((ni = read_node_item(nodes, 0)))
151 {
152 _c++;
153
154 *id = ni->id;
155 *c = ni->c;
156
157 l = g_hash_table_lookup(rel->member_hash[0], id);
158 while (l)
159 {
160 struct relations_member *memb = l->data;
161 memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
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 }
185 }
186 }
187 }
188
189 // fprintf_(stderr,"relations_process:002.9\n");
190
191
192 // dont need the buffer here -------
193 g_free(buffer_rel1);
194 ib = NULL;
195
196 if (ways)
197 {
198 // fprintf_(stderr,"relations_process:003 ways\n");
199
200 long long pos_now = (long long)ftello(ways); // 64bit
201 fseeko(ways, 0, SEEK_END);
202 size_in = (long long)ftello(ways); // 64bit
203 fprintf_(stderr, "relations_process: pos ways file=%lld\n", pos_now);
204 fprintf_(stderr, "relations_process:size ways file=%lld\n", size_in);
205 // seek to start of file
206 fseeko(ways, 0, SEEK_SET);
207 // reset timer
208 diff2_tt = 0;
209 _c = 0;
210 time(&start_tt);
211
212 // fprintf_(stderr,"relations_process:004 ways\n");
213
214 // zero out buffer ------------------
215 // bzero(ib_buffer_array[0], MAX_ITEMBIN_BYTES_);
216 // zero out buffer ------------------
217
218
219 while ((ib = read_item(ways, 0)))
220 {
221 _c++;
222
223 // fprintf_(stderr,"relations_process:003.1\n");
224
225 if (ib)
226 {
227
228 id = item_bin_get_attr(ib, attr_osm_wayid, NULL);
229
230 //fprintf(stderr,"********DUMP relw***********\n");
231 //dump_itembin(ib);
232 //fprintf(stderr,"********DUMP relw***********\n");
233
234 //char *labelxx=item_bin_get_attr(ib, attr_name, NULL);
235 //fprintf(stderr,"relations_process:003.2 %s\n", labelxx);
236 //labelxx=item_bin_get_attr(ib, attr_label, NULL);
237 //fprintf(stderr,"relations_process:003.3 %s\n", labelxx);
238
239 if (id)
240 {
241 // fprintf_(stderr,"relations_process:004 wayid:"LONGLONG_FMT"\n", id);
242
243 l = g_hash_table_lookup(rel->member_hash[1], id);
244 while (l)
245 {
246 // fprintf_(stderr,"relations_process:005\n");
247 struct relations_member *memb = l->data;
248 // fprintf_(stderr,"relations_process:005.1 %d\n", memb->memberid);
249 memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
250 l = g_list_next(l);
251 }
252 }
253
254 if (_c > _e)
255 {
256 _c = 0;
257
258 pos_in = ftello(ways); // 64bit
259 time(&end_tt);
260 diff_tt = difftime(end_tt,start_tt);
261 char outstring[200];
262 char outstring2[200];
263 char outstring3[200];
264 convert_to_human_time(diff_tt, outstring);
265 convert_to_human_bytes(pos_in, outstring2);
266 convert_to_human_bytes(size_in, outstring3);
267 fprintf_(stderr, "-RUNTIME-LOOP-REL-PROC-WAYS: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3);
268 if (pos_in > 0)
269 {
270 double eta_time = (diff_tt / pos_in) * (size_in - pos_in);
271 convert_to_human_time(eta_time, outstring);
272 fprintf_(stderr, "-RUNTIME-LOOP-REL-PROC-WAYS: %s left\n", outstring);
273 }
274 }
275
276 }
277
278 }
279 }
280
281 // fprintf_(stderr,"relations_process:099\n");
282 }
283
284 void relations_destroy_func(void *key, GList *l, void *data)
285 {
286 while (l)
287 {
288 g_free(l->data);
289 l=g_list_next(l);
290 }
291 }
292
293 void relations_destroy(struct relations *relations)
294 {
295 int i;
296
297 for (i = 0 ; i < 3 ; i++)
298 {
299 g_hash_table_foreach(relations->member_hash[i], (GHFunc)relations_destroy_func, NULL);
300 g_hash_table_destroy(relations->member_hash[i]);
301 }
302 }
303
304
305

   
Visit the ZANavi Wiki