2 * Copyright (C) 2009-2011 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @short_description: Web Map Service
22 * Provides an API for accessing image tiles form a Web Map Service (WMS)
23 * server. #GritsWms integrates closely with #GritsTile. The remote server must
24 * support the EPSG:4326 cartographic projection.
31 * Metacarte Open Street Map:
32 * http://labs.metacarta.com/wms/vmap0?
38 * EXCEPTIONS=application/vnd.ogc.se_inimage&
45 * NASA Blue Marble Next Generation:
46 * http://www.nasa.network.com/elev?
53 * BBOX=-180,-90,180,90&
58 * NASA Shuttle Radar Topography Mission:
59 * http://www.nasa.network.com/elev?
66 * BBOX=-180,-90,180,90&
67 * FORMAT=application/bil32&
77 #include "grits-wms.h"
78 #include "grits-http.h"
80 static gchar *g_strdup_printf_safe(char *fmt, ...)
84 setlocale(LC_ALL, "POSIX.UTF-8");
85 char *str = g_strdup_vprintf(fmt, ap);
86 setlocale(LC_ALL, "");
91 static gchar *_make_uri(GritsWms *wms, GritsTile *tile)
93 return g_strdup_printf_safe(
118 * @wms: the #GritsWms to fetch the data from
119 * @tile: a #GritsTile representing the area to be fetched
120 * @mode: the update type to use when fetching data
121 * @callback: callback to call when a chunk of data is received
122 * @user_data: user data to pass to the callback
124 * Fetch a image coresponding to a #GritsTile from a WMS server.
126 * Returns: the path to the local file.
128 gchar *grits_wms_fetch(GritsWms *wms, GritsTile *tile, GritsCacheType mode,
129 GritsChunkCallback callback, gpointer user_data)
131 gchar *uri = _make_uri(wms, tile);
132 gchar *tilep = grits_tile_get_path(tile);
133 gchar *local = g_strdup_printf("%s%s", tilep, wms->extension);
134 gchar *path = grits_http_fetch(wms->http, uri, local,
135 mode, callback, user_data);
144 * @uri_prefix: the base URL for the WMS server
145 * @uri_layer: the layer the images should be fetched from (wms LAYERS)
146 * @uri_format: the format the images should be fetch in (wms FORMAT)
147 * @prefix: prefix to use for local files
148 * @extension: file extension for local files, should correspond to @uri_format
149 * @width: width in pixels for downloaded images (wms WIDTH)
150 * @height: height in pixels for downloaded images (wms HEIGHT)
152 * Creates a #GritsWms for some layer on a WMS server. The returned #GritsWms
153 * stores information about the images so it does not need to be entered each
154 * time a images is fetched.
156 * Returns: the new #GritsWms
158 GritsWms *grits_wms_new(
159 const gchar *uri_prefix, const gchar *uri_layer,
160 const gchar *uri_format, const gchar *prefix,
161 const gchar *extension, gint width, gint height)
163 g_debug("GritsWms: new - %s", uri_prefix);
164 GritsWms *wms = g_new0(GritsWms, 1);
165 wms->http = grits_http_new(prefix);
166 wms->uri_prefix = g_strdup(uri_prefix);
167 wms->uri_layer = g_strdup(uri_layer);
168 wms->uri_format = g_strdup(uri_format);
169 wms->extension = g_strdup(extension);
171 wms->height = height;
177 * @wms: the #GritsWms to free
179 * Free resources used by @wms and cancel any pending requests.
181 void grits_wms_free(GritsWms *wms)
183 g_debug("GritsWms: free - %s", wms->uri_prefix);
184 grits_http_free(wms->http);
185 g_free(wms->uri_prefix);
186 g_free(wms->uri_layer);
187 g_free(wms->uri_format);
188 g_free(wms->extension);