2 * Copyright (C) 2009-2010 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. #GisWms integrates closely with #GisTile. 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&
79 static gchar *_make_uri(GisWms *wms, GisTile *tile)
81 return g_strdup_printf(
106 * @wms: the #GisWms to fetch the data from
107 * @tile: a #GisTile representing the area to be fetched
108 * @mode: the update type to use when fetching data
109 * @callback: callback to call when a chunk of data is received
110 * @user_data: user data to pass to the callback
112 * Fetch a image coresponding to a #GisTile from a WMS server.
114 * Returns: the path to the local file.
116 gchar *gis_wms_fetch(GisWms *wms, GisTile *tile, GisCacheType mode,
117 GisChunkCallback callback, gpointer user_data)
119 gchar *uri = _make_uri(wms, tile);
120 gchar *tilep = gis_tile_get_path(tile);
121 gchar *local = g_strdup_printf("%s%s", tilep, wms->extension);
123 gchar *path = gis_http_fetch(wms->http, uri, local,
124 mode, callback, user_data);
133 * @uri_prefix: the base URL for the WMS server
134 * @uri_layer: the layer the images should be fetched from (wms LAYERS)
135 * @uri_format: the format the images should be fetch in (wms FORMAT)
136 * @prefix: prefix to use for local files
137 * @extension: file extension for local files, should correspond to @uri_format
138 * @width: width in pixels for downloaded images (wms WIDTH)
139 * @height: height in pixels for downloaded images (wms HEIGHT)
141 * Creates a #GisWms for some layer on a WMS server. The returned #GisWms
142 * stores information about the images so it does not need to be entered each
143 * time a images is fetched.
145 * Returns: the new #GisWms
148 const gchar *uri_prefix, const gchar *uri_layer,
149 const gchar *uri_format, const gchar *prefix,
150 const gchar *extension, gint width, gint height)
152 g_debug("GisWms: new - %s", uri_prefix);
153 GisWms *wms = g_new0(GisWms, 1);
154 wms->http = gis_http_new(prefix);
155 wms->uri_prefix = g_strdup(uri_prefix);
156 wms->uri_layer = g_strdup(uri_layer);
157 wms->uri_format = g_strdup(uri_format);
158 wms->extension = g_strdup(extension);
160 wms->height = height;
166 * @wms: the #GisWms to free
168 * Free resources used by @wms and cancel any pending requests.
170 void gis_wms_free(GisWms *wms)
172 g_debug("GisWms: free - %s", wms->uri_prefix);
173 gis_http_free(wms->http);
174 g_free(wms->uri_prefix);
175 g_free(wms->uri_layer);
176 g_free(wms->uri_format);
177 g_free(wms->extension);