]> git.street.me.uk Git - andy/viking.git/blame - test/test_coord_conversion.c
A Mapnik Rendering layer
[andy/viking.git] / test / test_coord_conversion.c
CommitLineData
90f15672
GB
1#include <math.h>
2#include <vikwmscmapsource.h>
3#include <vikslippymapsource.h>
4
5void 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
17void 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
29int main(int argc, char *argv[])
30{
05c5785a 31#if ! GLIB_CHECK_VERSION (2, 36, 0)
90f15672 32 g_type_init();
05c5785a
RN
33#endif
34
90f15672
GB
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}