]> git.street.me.uk Git - andy/viking.git/blob - test/test_metatile.c
Merge branch 'MapsExtendedConfiguration'
[andy/viking.git] / test / test_metatile.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4  *
5  * Copyright (C) 2014, Rob Norris <rw_norris@hotmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <limits.h>
26 #include <string.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <errno.h>
30 #include <fcntl.h>
31
32 #include <metatile.h>
33
34 int main ( int argc, char *argv[] )
35 {
36     const int tile_max = METATILE_MAX_SIZE;
37     char err_msg[PATH_MAX];
38     char id[PATH_MAX];
39     char *buf;
40     int len;
41     int compressed;
42
43     // Could extend to get values from the command-line.
44     int x = 4051;
45     int y = 2753;
46     int z = 13;
47     //char dir[] = "/var/lib/mod_tile/default";
48     char dir[] = "metatile_example";
49     // Example defaults to a metatile that was pre generated using mod_tile
50     // Equates to 'metatile_example/13/0/0/250/220/0.meta'
51     //  which is Brownsea Island, Dorset, UK (50.69N, 1.96W)
52
53     buf = malloc(tile_max);
54     if (!buf) {
55         return 1;
56     }
57
58     err_msg[0] = 0;
59
60     len = metatile_read(dir, x, y, z, buf, tile_max, &compressed, err_msg);
61
62     if (len > 0) {
63         // Do something with buf
64         // Just dump to a file
65         FILE *fp;
66         if (compressed)
67           fp = fopen( "tilefrommeta.gz" , "w" );
68         else
69           fp = fopen( "tilefrommeta.png" , "w" );
70
71         if ( fp ) {
72           fwrite(buf, 1 , len, fp);
73           fclose(fp);
74         }
75         else
76           fprintf(stderr, "Failed to open file because: \n", strerror(errno));
77
78         free(buf);
79         return 0;
80     }
81     else
82         fprintf(stderr, "FAILED: %s\n", err_msg);
83
84     free(buf);
85     return 3;
86 }