]> git.street.me.uk Git - andy/viking.git/blob - test/test_coord_conversion.c
Shell test should be '=' rather than '==' for maximum portability.
[andy/viking.git] / test / test_coord_conversion.c
1 #include <math.h>
2 #include <vikwmscmapsource.h>
3 #include <vikslippymapsource.h>
4
5 void test_coord_to_mapcoord(VikMapSource *source, gdouble lat, gdouble lon, gdouble zoom)
6 {
7   VikCoord vikCoord;
8   MapCoord mapCoord;
9   vikCoord.mode = VIK_COORD_LATLON;
10   vikCoord.east_west = lon;
11   vikCoord.north_south = lat;
12   printf("%s: %f %f %f => ", g_type_name(G_OBJECT_TYPE(source)), vikCoord.east_west, vikCoord.north_south, zoom);
13   vik_map_source_coord_to_mapcoord (source, &vikCoord, zoom, zoom, &mapCoord);
14   printf("x=%d y=%d\n", mapCoord.x, mapCoord.y);
15 }
16
17 void test_mapcoord_to_center_coord (VikMapSource *source, int x, int y, int scale)
18 {
19   VikCoord vikCoord;
20   MapCoord mapCoord;
21   mapCoord.x = x;
22   mapCoord.y = y;
23   mapCoord.scale = scale;
24   printf("%s: %d %d %d => ", g_type_name(G_OBJECT_TYPE(source)), mapCoord.x, mapCoord.y, scale);
25   vik_map_source_mapcoord_to_center_coord (source, &mapCoord, &vikCoord);
26   printf("lon=%f lat=%f\n", vikCoord.east_west, vikCoord.north_south);
27 }
28
29 int main(int argc, char *argv[])
30 {
31 #if ! GLIB_CHECK_VERSION (2, 36, 0)
32   g_type_init();
33 #endif
34
35   VikMapSource *spotmaps4osm_wmsc_type = 
36     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_WMSC_MAP_SOURCE,
37                                 "id", 202,
38                                 "label", "Spotmaps (WMS-C)",
39                                 "hostname", "spotmaps.youmapps.org",
40                                 "url", "/spotmaps4osm/?LAYERS=spotmaps4osm&SERVICE=SPOTMAPS4OSM&SRS=EPSG:4326&bbox=%s,%s,%s,%s&width=256&height=256",
41                                 NULL));
42
43   VikMapSource *osmarender_type = 
44     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
45                                 "id", 12,
46                                 "label", "OpenStreetMap (Osmarender)",
47                                 "hostname", "tah.openstreetmap.org",
48                                 "url", "/Tiles/tile/%d/%d/%d.png",
49                                 "check-file-server-time", TRUE,
50                                 NULL));
51     
52   gdouble lats[] = { 0, 90, 45, -45, -90 };
53   gdouble lons[] = { 0, 180, 90, 45, -45, -90, -180 };
54   int scale;
55   for (scale = 0 ; scale < 18 ; scale++)
56   {
57     int i;
58     for (i=0 ; i<sizeof(lats)/sizeof(lats[0]) ; i++)
59     {
60       int j;
61       for (j=0 ; j<sizeof(lons)/sizeof(lons[0]) ; j++)
62       {
63         test_coord_to_mapcoord (spotmaps4osm_wmsc_type, lats[i], lons[j], 2<<scale);
64         test_coord_to_mapcoord (osmarender_type, lats[i], lons[j], 2<<scale);
65       }
66     }
67   }
68
69   for (scale = 0 ; scale < 18 ; scale++)
70   {
71     test_mapcoord_to_center_coord (spotmaps4osm_wmsc_type, 0, 0, scale);
72     test_mapcoord_to_center_coord (osmarender_type, 0, 0, scale);
73   }
74
75   return 0;
76 }