Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: WMS Client Driver 4 : * Purpose: Implementation of Dataset and RasterBand classes for WMS 5 : * and other similar services. 6 : * Author: Even Rouault 7 : * 8 : ****************************************************************************** 9 : * Copyright (c) 2011, Even Rouault <even dot rouault at spatialys.com> 10 : * 11 : * SPDX-License-Identifier: MIT 12 : ****************************************************************************/ 13 : 14 : #include "wmsdriver.h" 15 : #include "minidriver_virtualearth.h" 16 : 17 : #include <algorithm> 18 : 19 : // These should be global, they are used all over the place 20 : const double SPHERICAL_RADIUS = 6378137.0; 21 : const double MAX_GM = SPHERICAL_RADIUS * M_PI; // 20037508.342789244 22 : 23 1 : WMSMiniDriver_VirtualEarth::WMSMiniDriver_VirtualEarth() 24 : { 25 1 : } 26 : 27 2 : WMSMiniDriver_VirtualEarth::~WMSMiniDriver_VirtualEarth() 28 : { 29 2 : } 30 : 31 : CPLErr 32 1 : WMSMiniDriver_VirtualEarth::Initialize(CPLXMLNode *config, 33 : CPL_UNUSED char **papszOpenOptions) 34 : { 35 1 : m_base_url = CPLGetXMLValue(config, "ServerURL", ""); 36 1 : if (m_base_url.empty()) 37 : { 38 0 : CPLError(CE_Failure, CPLE_AppDefined, 39 : "GDALWMS, VirtualEarth mini-driver: ServerURL missing."); 40 0 : return CE_Failure; 41 : } 42 : 43 1 : if (m_base_url.find("${quadkey}") == std::string::npos) 44 : { 45 0 : CPLError(CE_Failure, CPLE_AppDefined, 46 : "GDALWMS, VirtualEarth mini-driver: ${quadkey} missing in " 47 : "ServerURL."); 48 0 : return CE_Failure; 49 : } 50 : 51 1 : m_parent_dataset->WMSSetDefaultBlockSize(256, 256); 52 1 : m_parent_dataset->WMSSetDefaultDataWindowCoordinates(-MAX_GM, MAX_GM, 53 : MAX_GM, -MAX_GM); 54 1 : m_parent_dataset->WMSSetDefaultTileLevel(21); 55 1 : m_parent_dataset->WMSSetDefaultOverviewCount(20); 56 1 : m_parent_dataset->WMSSetNeedsDataWindow(FALSE); 57 1 : m_oSRS.importFromEPSG(3857); 58 1 : return CE_None; 59 : } 60 : 61 0 : CPLErr WMSMiniDriver_VirtualEarth::TiledImageRequest( 62 : WMSHTTPRequest &request, CPL_UNUSED const GDALWMSImageRequestInfo &iri, 63 : const GDALWMSTiledImageRequestInfo &tiri) 64 : { 65 0 : CPLString &url = request.URL; 66 0 : url = m_base_url; 67 : 68 : char szTileNumber[64]; 69 0 : int x = tiri.m_x; 70 0 : int y = tiri.m_y; 71 0 : int z = std::min(32, tiri.m_level); 72 : 73 0 : for (int i = 0; i < z; i++) 74 : { 75 0 : int row = (y & 1); 76 0 : int col = (x & 1); 77 : 78 0 : szTileNumber[z - 1 - i] = (char)('0' + (col | (row << 1))); 79 : 80 0 : x = x >> 1; 81 0 : y = y >> 1; 82 : } 83 0 : szTileNumber[z] = 0; 84 : 85 0 : URLSearchAndReplace(&url, "${quadkey}", "%s", szTileNumber); 86 : // Sounds like this should be random 87 0 : URLSearchAndReplace(&url, "${server_num}", "%d", 88 0 : (tiri.m_x + tiri.m_y + z) % 4); 89 0 : return CE_None; 90 : }