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;
+}
char *timestamp;
char *result;
char *dbstr;
+ int node_table_loaded;
+ int countries_loaded;
+ int tilesdir_loaded;
};
static int
}
}
+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
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);
}
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);
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);
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) {
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--;
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 */
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*);
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);
}
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;
}
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;
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 );