1 /******************************************************************************
2  *
3  * Project:  WMS Client Driver
4  * Purpose:  Implementation of Dataset and RasterBand classes for WMS
5  *           and other similar services.
6  * Author:   Adam Nowacki, nowak@xpam.de
7  *
8  ******************************************************************************
9  * Copyright (c) 2007, Adam Nowacki
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #include "wmsdriver.h"
31 #include "minidriver_worldwind.h"
32 
33 CPL_CVSID("$Id: minidriver_worldwind.cpp 3b0bbf7a8a012d69a783ee1f9cfeb5c52b370021 2017-06-27 20:57:02Z Even Rouault $")
34 
WMSMiniDriver_WorldWind()35 WMSMiniDriver_WorldWind::WMSMiniDriver_WorldWind() {}
36 
~WMSMiniDriver_WorldWind()37 WMSMiniDriver_WorldWind::~WMSMiniDriver_WorldWind() {}
38 
Initialize(CPLXMLNode * config,CPL_UNUSED char ** papszOpenOptions)39 CPLErr WMSMiniDriver_WorldWind::Initialize(CPLXMLNode *config, CPL_UNUSED char **papszOpenOptions) {
40     CPLErr ret = CE_None;
41 
42     // Try both spellings
43     m_base_url = CPLGetXMLValue(config, "ServerURL",
44         CPLGetXMLValue(config, "ServerUrl", ""));
45 
46     if (m_base_url.empty()) {
47         CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS, TileService mini-driver: ServerURL missing.");
48         ret = CE_Failure;
49     }
50     else { // Prepare the url, leave it ready for extra arguments
51         const char *dataset = CPLGetXMLValue(config, "Layer", "");
52         URLPrepare(m_base_url);
53         m_base_url += CPLOPrintf("T=%s", dataset);
54     }
55 
56     m_projection_wkt = ProjToWKT("EPSG:4326");
57     return ret;
58 }
59 
TiledImageRequest(WMSHTTPRequest & request,const GDALWMSImageRequestInfo & iri,const GDALWMSTiledImageRequestInfo & tiri)60 CPLErr WMSMiniDriver_WorldWind::TiledImageRequest(WMSHTTPRequest &request,
61                                                     const GDALWMSImageRequestInfo &iri,
62                                                     const GDALWMSTiledImageRequestInfo &tiri)
63 {
64     CPLString &url = request.URL;
65     const GDALWMSDataWindow *data_window = m_parent_dataset->WMSGetDataWindow();
66     int worldwind_y = static_cast<int>(floor(((data_window->m_y1 - data_window->m_y0) / (iri.m_y1 - iri.m_y0)) + 0.5)) - tiri.m_y - 1;
67     // http://worldwind25.arc.nasa.gov/tile/tile.aspx?T=geocover2000&L=0&X=86&Y=39
68     url = m_base_url + CPLOPrintf("L=%d&X=%d&Y=%d", tiri.m_level, tiri.m_x, worldwind_y);
69     return CE_None;
70 }
71