summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--navit/maptool/buffer.c11
-rw-r--r--navit/maptool/maptool.c44
-rw-r--r--navit/maptool/maptool.h3
-rw-r--r--navit/maptool/osm.c34
-rw-r--r--navit/maptool/tile.c41
5 files changed, 129 insertions, 4 deletions
diff --git a/navit/maptool/buffer.c b/navit/maptool/buffer.c
index 85206537e..5f7c39505 100644
--- a/navit/maptool/buffer.c
+++ b/navit/maptool/buffer.c
@@ -60,3 +60,14 @@ load_buffer(char *filename, struct buffer *b, long long offset, long long size)
fread(b->base, b->size, 1, f);
fclose(f);
}
+
+long long
+sizeof_buffer(char *filename)
+{
+ long long ret;
+ FILE *f=fopen(filename,"rb");
+ fseek(f, 0, SEEK_END);
+ ret=ftell(f);
+ fclose(f);
+ return ret;
+}
diff --git a/navit/maptool/maptool.c b/navit/maptool/maptool.c
index 0fdeb0fbc..60335718c 100644
--- a/navit/maptool/maptool.c
+++ b/navit/maptool/maptool.c
@@ -174,6 +174,9 @@ struct maptool_params {
char *timestamp;
char *result;
char *dbstr;
+ int node_table_loaded;
+ int countries_loaded;
+ int tilesdir_loaded;
};
static int
@@ -661,6 +664,35 @@ maptool_assemble_map(struct maptool_params *p, char *suffix, char **filenames, c
}
}
+static void
+maptool_load_node_table(struct maptool_params *p, int next_to_last)
+{
+ if (!p->node_table_loaded) {
+ load_buffer("coords.tmp",&node_buffer,0, slice_size);
+ p->node_table_loaded=1;
+ slices=1;
+ }
+}
+
+static void
+maptool_load_countries(struct maptool_params *p)
+{
+ if (!p->countries_loaded) {
+ load_countries();
+ p->countries_loaded=1;
+ }
+}
+
+static void
+maptool_load_tilesdir(struct maptool_params *p, char *suffix)
+{
+ if (!p->tilesdir_loaded) {
+ FILE *tilesdir=tempfile(suffix,"tilesdir",0);
+ load_tilesdir(tilesdir);
+ p->tilesdir_loaded=1;
+ }
+}
+
int main(int argc, char **argv)
{
#if 0
@@ -730,9 +762,11 @@ int main(int argc, char **argv)
if (p.start <= phase && p.end >= phase) {
fprintf(stderr,"PROGRESS: Phase %d: collecting data\n",phase);
osm_collect_data(&p, suffix);
+ p.node_table_loaded=1;
}
phase++;
if (p.start <= phase && p.end >= phase) {
+ maptool_load_node_table(&p,1);
fprintf(stderr,"PROGRESS: Phase %d: counting references and resolving ways\n",phase);
osm_count_references(&p, suffix);
}
@@ -742,12 +776,10 @@ int main(int argc, char **argv)
osm_process_way2poi(&p, suffix);
}
phase++;
- if (0) {
- load_buffer("coords.tmp",&node_buffer,0, slice_size);
- }
if (p.start <= phase && p.end >= phase) {
if (p.process_ways) {
fprintf(stderr,"PROGRESS: Phase %d: finding intersections\n",phase);
+ maptool_load_node_table(&p,0);
osm_find_intersections(&p, suffix);
} else
fprintf(stderr,"PROGRESS: Skipping Phase %d\n",phase);
@@ -757,6 +789,7 @@ int main(int argc, char **argv)
node_buffer.base=NULL;
node_buffer.malloced=0;
node_buffer.size=0;
+ p.node_table_loaded=0;
} else {
fprintf(stderr,"PROGRESS: Phase %d: Reading data\n",phase);
FILE *ways_split=tempfile(suffix,"ways_split",0);
@@ -773,6 +806,7 @@ int main(int argc, char **argv)
if (p.start <= phase && p.end >= phase) {
fprintf(stderr,"PROGRESS: Phase %d: sorting countries\n",phase);
sort_countries(p.keep_tmpfiles);
+ p.countries_loaded=1;
}
phase++;
if (p.start <= phase && p.end >= phase) {
@@ -811,11 +845,15 @@ int main(int argc, char **argv)
suffix=suffixes[i];
if (p.start <= phase && p.end >= phase) {
fprintf(stderr,"PROGRESS: Phase %d: generating tiles\n",phase);
+ maptool_load_countries(&p);
maptool_generate_tiles(&p, suffix, filenames, filename_count, i == suffix_start, suffixes[0]);
+ p.tilesdir_loaded=1;
}
phase++;
if (p.start <= phase && p.end >= phase) {
fprintf(stderr,"PROGRESS: Phase %d: assembling map\n",phase);
+ maptool_load_countries(&p);
+ maptool_load_tilesdir(&p, suffix);
maptool_assemble_map(&p, suffix, filenames, referencenames, filename_count, i == suffix_start, i == suffix_count-1, suffixes[0]);
}
phase--;
diff --git a/navit/maptool/maptool.h b/navit/maptool/maptool.h
index 8c8001b9c..4a2c2316d 100644
--- a/navit/maptool/maptool.h
+++ b/navit/maptool/maptool.h
@@ -116,6 +116,7 @@ struct buffer {
void save_buffer(char *filename, struct buffer *b, long long offset);
void load_buffer(char *filename, struct buffer *b, long long offset, long long size);
+long long sizeof_buffer(char *filename);
/* ch.c */
@@ -261,6 +262,7 @@ FILE *resolve_ways_file(FILE *in, char *suffix, char *filename);
void process_way2poi(FILE *in, FILE *out, int type);
int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final);
void write_countrydir(struct zip_info *zip_info);
+void load_countries(void);
void remove_countryfiles(void);
void osm_init(FILE*);
@@ -317,6 +319,7 @@ extern GList *aux_tile_list;
int tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr);
void tile_bbox(char *tile, struct rect *r, int overlap);
int tile_len(char *tile);
+void load_tilesdir(FILE *in);
void tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name);
void tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max);
int add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size);
diff --git a/navit/maptool/osm.c b/navit/maptool/osm.c
index b64f0a0cc..e8713d074 100644
--- a/navit/maptool/osm.c
+++ b/navit/maptool/osm.c
@@ -2282,6 +2282,40 @@ write_countrydir(struct zip_info *zip_info)
}
void
+load_countries(void)
+{
+ char filename[32];
+ FILE *f;
+ int i;
+ struct country_table *co;
+
+ for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
+ co=&country_table[i];
+ sprintf(filename,"country_%d.bin", co->countryid);
+ f=fopen(filename,"rb");
+ if (f) {
+ int i,first=1;
+ struct item_bin *ib;
+ while ((ib=read_item(f))) {
+ struct coord *c=(struct coord *)(ib+1);
+ co->size+=ib->len*4+4;
+ for (i = 0 ; i < ib->clen/2 ; i++) {
+ if (first) {
+ co->r.l=c[i];
+ co->r.h=c[i];
+ first=0;
+ } else
+ bbox_extend(&c[i], &co->r);
+ }
+ }
+ fseek(f, 0, SEEK_END);
+ co->size=ftell(f);
+ fclose(f);
+ }
+ }
+}
+
+void
remove_countryfiles(void)
{
int i;
diff --git a/navit/maptool/tile.c b/navit/maptool/tile.c
index 6d7886923..1817ba6d5 100644
--- a/navit/maptool/tile.c
+++ b/navit/maptool/tile.c
@@ -460,6 +460,45 @@ create_tile_hash_list(GList *list)
}
void
+load_tilesdir(FILE *in)
+{
+ char tile[32],subtile[32],c;
+ int size,zipnum=0;
+ create_tile_hash();
+ tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ struct tile_head **last=&tile_head_root;
+ while (fscanf(in,"%[^:]:%d",tile,&size) == 2) {
+ struct tile_head *th=malloc(sizeof(struct tile_head));
+ if (!strcmp(tile,"index"))
+ tile[0]='\0';
+ th->num_subtiles=0;
+ th->total_size=size;
+ th->total_size_used=0;
+ th->zipnum=zipnum++;
+ th->zip_data=NULL;
+ th->name=string_hash_lookup(tile);
+#if 0
+ printf("tile '%s' %d\n",tile,size);
+#endif
+ while (fscanf(in,":%[^:\n]",subtile) == 1) {
+#if 0
+ printf("subtile '%s'\n",subtile);
+#endif
+ th=realloc(th, sizeof(struct tile_head)+(th->num_subtiles+1)*sizeof(char*));
+ *th_get_subtile( th, th->num_subtiles ) = string_hash_lookup(subtile);
+ th->num_subtiles++;
+ }
+ *last=th;
+ last=&th->next;
+ add_tile_hash(th);
+ g_hash_table_insert(tile_hash, th->name, th);
+ if (fread(&c, 1, 1, in) != 1 || c != '\n') {
+ printf("syntax error\n");
+ }
+ }
+}
+
+void
write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out)
{
int idx,len,maxlen;
@@ -495,7 +534,7 @@ write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out)
last=&th->next;
th->next=NULL;
th->zipnum=zip_get_zipnum(zip_info);
- fprintf(out,"%s:%d",(char *)next->data,th->total_size);
+ fprintf(out,"%s:%d",strlen((char *)next->data)?(char *)next->data:"index",th->total_size);
for ( idx = 0; idx< th->num_subtiles; idx++ ){
data= th_get_subtile( th, idx );