/[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 31 - (hide annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 2 months ago) by zoff99
File MIME type: text/plain
File size: 7342 byte(s)
new map version, lots of fixes and experimental new features
1 zoff99 31 /**
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[128];
114     struct item_bin *ib = (struct item_bin *) buffer;
115     long long *id;
116     struct coord *c = (struct coord *) (ib + 1), cn =
117     { 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     //fprintf(stderr,"relations_process:002 nodes\n");
134    
135     long long pos_now = ftello(nodes); // 64bit
136     fseeko(nodes, 0, SEEK_END);
137     size_in = ftello(nodes); // 64bit
138     fseeko(nodes, pos_now, SEEK_SET);
139     // reset timer
140     diff2_tt = 0;
141     _c = 0;
142     time(&start_tt);
143    
144     item_bin_init(ib, type_point_unkn);
145     item_bin_add_coord(ib, &cn, 1);
146     item_bin_add_attr_longlong(ib, attr_osm_nodeid, 0);
147     id = item_bin_get_attr(ib, attr_osm_nodeid, NULL);
148     while ((ni = read_node_item(nodes, 0)))
149     {
150     _c++;
151    
152     *id = ni->id;
153     *c = ni->c;
154     l = g_hash_table_lookup(rel->member_hash[0], id);
155     while (l)
156     {
157     struct relations_member *memb = l->data;
158     memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
159     l = g_list_next(l);
160     }
161    
162     if (_c > _e)
163     {
164     _c = 0;
165    
166     pos_in = ftello(nodes); // 64bit
167     time(&end_tt);
168     diff_tt = difftime(end_tt,start_tt);
169     char outstring[200];
170     char outstring2[200];
171     char outstring3[200];
172     convert_to_human_time(diff_tt, outstring);
173     convert_to_human_bytes(pos_in, outstring2);
174     convert_to_human_bytes(size_in, outstring3);
175     fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-NODES: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3);
176     if (pos_in > 0)
177     {
178     double eta_time = (diff_tt / pos_in) * (size_in - pos_in);
179     convert_to_human_time(eta_time, outstring);
180     fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-NODES: %s left\n", outstring);
181     }
182     }
183     }
184     }
185    
186     //fprintf(stderr,"relations_process:002.9\n");
187    
188     if (ways)
189     {
190     //fprintf(stderr,"relations_process:003 ways\n");
191    
192     long long pos_now = ftello(ways); // 64bit
193     fseeko(ways, 0, SEEK_END);
194     size_in = ftello(ways); // 64bit
195     fseeko(ways, pos_now, SEEK_SET);
196     // reset timer
197     diff2_tt = 0;
198     _c = 0;
199     time(&start_tt);
200    
201     while ((ib = read_item(ways, 0)))
202     {
203     _c++;
204    
205     //fprintf(stderr,"relations_process:003.1\n");
206    
207     id = item_bin_get_attr(ib, attr_osm_wayid, NULL);
208    
209     //fprintf(stderr,"********DUMP relw***********\n");
210     //dump_itembin(ib);
211     //fprintf(stderr,"********DUMP relw***********\n");
212    
213     //char *labelxx=item_bin_get_attr(ib, attr_name, NULL);
214     //fprintf(stderr,"relations_process:003.2 %s\n", labelxx);
215     //labelxx=item_bin_get_attr(ib, attr_label, NULL);
216     //fprintf(stderr,"relations_process:003.3 %s\n", labelxx);
217    
218     if (id)
219     {
220     //fprintf(stderr,"relations_process:004 wayid:"LONGLONG_FMT"\n", id);
221    
222     l = g_hash_table_lookup(rel->member_hash[1], id);
223     while (l)
224     {
225     //fprintf(stderr,"relations_process:005\n");
226     struct relations_member *memb = l->data;
227     //fprintf(stderr,"relations_process:005.1 %d\n", memb->memberid);
228     memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv);
229     l = g_list_next(l);
230     }
231     }
232    
233     if (_c > _e)
234     {
235     _c = 0;
236    
237     pos_in = ftello(ways); // 64bit
238     time(&end_tt);
239     diff_tt = difftime(end_tt,start_tt);
240     char outstring[200];
241     char outstring2[200];
242     char outstring3[200];
243     convert_to_human_time(diff_tt, outstring);
244     convert_to_human_bytes(pos_in, outstring2);
245     convert_to_human_bytes(size_in, outstring3);
246     fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-WAYS: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3);
247     if (pos_in > 0)
248     {
249     double eta_time = (diff_tt / pos_in) * (size_in - pos_in);
250     convert_to_human_time(eta_time, outstring);
251     fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-WAYS: %s left\n", outstring);
252     }
253     }
254     }
255     }
256     }
257    

   
Visit the ZANavi Wiki