source: trunk/demos/tile-renderer.c

Last change on this file was 228, checked in by simon, 4 years ago

Install the default rules set to share it with other packages

File size: 2.7 KB
Line 
1/*
2 * Memphis - Cairo Rederer for OSM in C
3 * Copyright (C) 2009  Simon Wenner <simon@wenner.ch>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20#include <memphis/memphis.h>
21#include <stdlib.h>
22#include <glib/gstdio.h>
23
24#define RESOLUTION 256
25
26int main (int argc, char **argv) {
27  g_type_init ();
28 
29  MemphisRenderer *r;
30  MemphisRuleSet *rules;
31  MemphisMap *map;
32  cairo_surface_t *surface;
33  cairo_t *cr;
34  gint i, j, maxx, maxy;
35  gchar *path, *mapfile;
36  gint zoom_level;
37
38  if (argc > 1)
39    zoom_level = atoi(argv[1]);
40  else
41    zoom_level = 14;
42
43  if (argc > 2)
44    mapfile = argv[2];
45  else
46    mapfile = "map.osm";
47
48  g_mkdir ("tiles", 0755);
49
50  memphis_debug_set_print_progress (TRUE);
51
52  rules = memphis_rule_set_new ();
53  memphis_rule_set_load_from_file (rules, "default-rules.xml", NULL);
54
55  map = memphis_map_new ();
56  GError *err = NULL;
57  memphis_map_load_from_file (map, mapfile, &err);
58  if (err != NULL) {
59    g_print ("Error: %s\n", err->message);
60    return -1;
61  }
62
63  r = memphis_renderer_new_full (rules, map);
64  memphis_renderer_set_resolution (r, RESOLUTION);
65  g_print ("Tile resolution: %u\n", memphis_renderer_get_resolution (r));
66
67  maxx = memphis_renderer_get_max_x_tile (r, zoom_level);
68  maxy = memphis_renderer_get_max_y_tile (r, zoom_level);
69  i = memphis_renderer_get_min_x_tile (r, zoom_level);
70 
71  for (; i <= maxx; i++)
72    {
73      j = memphis_renderer_get_min_y_tile (r, zoom_level);
74      for (; j <= maxy; j++)
75        {
76          surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
77              RESOLUTION, RESOLUTION);
78          cr =  cairo_create(surface);
79          path = g_strdup_printf ("tiles/%i_%i.png", i, j);
80
81          g_print ("Drawing tile: %i, %i\n", i, j);
82          memphis_renderer_draw_tile (r, cr, i, j, zoom_level);
83          cairo_surface_write_to_png(surface, path);
84         
85          g_free (path);
86          cairo_destroy(cr);
87          cairo_surface_destroy(surface);
88        }
89    }
90 
91  memphis_renderer_free (r);
92  memphis_map_free (map);
93  memphis_rule_set_free (rules);
94
95  return 0;
96}
Note: See TracBrowser for help on using the repository browser.