source: trunk/demos/tile-renderer.c @ 144

Last change on this file since 144 was 144, checked in by simon, 5 years ago

create tiles folder if not available

File size: 2.6 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 "src/memphis.h"
21#include <stdlib.h>
22#include <glib.h>
23#include <glib/gstdio.h>
24
25#define RESOLUTION 256
26
27int main (int argc, char **argv) {
28  g_type_init ();
29 
30  MemphisRenderer *r;
31  MemphisRuleSet *rules;
32  MemphisMap *map;
33  cairo_surface_t *surface;
34  cairo_t *cr;
35  gint i, j, maxx, maxy;
36  gchar *path, *mapfile;
37  gint zoom_level;
38
39  if (argc > 1)
40    zoom_level = atoi(argv[1]);
41  else
42    zoom_level = 14;
43
44  if (argc > 2)
45    mapfile = argv[2];
46  else
47    mapfile = "map.osm";
48
49  g_mkdir ("tiles", 0755);
50
51  rules = memphis_rule_set_new ();
52  memphis_rule_set_load_from_file (rules, "rule.xml");
53  map = memphis_map_new ();
54  memphis_map_load_from_file (map, mapfile);
55
56  r = memphis_renderer_new_full (rules, map);
57  memphis_renderer_set_resolution (r, RESOLUTION);
58  memphis_renderer_set_debug_level (r, 1);
59  g_print ("Tile resolution: %u\n", memphis_renderer_get_resolution (r));
60
61  maxx = memphis_renderer_get_max_x_tile (r, zoom_level);
62  maxy = memphis_renderer_get_max_y_tile (r, zoom_level);
63  i = memphis_renderer_get_min_x_tile (r, zoom_level);
64 
65  for (; i <= maxx; i++)
66    {
67      j = memphis_renderer_get_min_y_tile (r, zoom_level);
68      for (; j <= maxy; j++)
69        {
70          surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
71              RESOLUTION, RESOLUTION);
72          cr =  cairo_create(surface);
73          path = g_strdup_printf ("tiles/%i_%i.png", i, j);
74
75          g_print ("Drawing tile: %i, %i\n", i, j);
76          memphis_renderer_draw_tile (r, cr, i, j, zoom_level);
77          cairo_surface_write_to_png(surface, path);
78         
79          g_free (path);
80          cairo_destroy(cr);
81          cairo_surface_destroy(surface);
82        }
83    }
84 
85  memphis_renderer_free (r);
86  memphis_map_free (map);
87  memphis_rule_set_free (rules);
88
89  return 0;
90}
Note: See TracBrowser for help on using the repository browser.