1 /****************************************************************************** 2 * 3 * Project: GDAL 4 * Purpose: Class to handle TileMatrixSet 5 * Author: Even Rouault, <even dot rouault at spatialys.com> 6 * 7 ****************************************************************************** 8 * Copyright (c) 2020, Even Rouault <even dot rouault at spatialys.com> 9 * 10 * Permission is hereby granted, free of charge, to any person obtaining a 11 * copy of this software and associated documentation files (the "Software"), 12 * to deal in the Software without restriction, including without limitation 13 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 * and/or sell copies of the Software, and to permit persons to whom the 15 * Software is furnished to do so, subject to the following conditions: 16 * 17 * The above copyright notice and this permission notice shall be included 18 * in all copies or substantial portions of the Software. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 * DEALINGS IN THE SOFTWARE. 27 ****************************************************************************/ 28 29 #ifndef TILEMATRIXSET_HPP_INCLUDED 30 #define TILEMATRIXSET_HPP_INCLUDED 31 32 #include "cpl_port.h" 33 34 #include <memory> 35 #include <limits> 36 #include <set> 37 #include <string> 38 #include <vector> 39 40 //! @cond Doxygen_Suppress 41 42 namespace gdal 43 { 44 45 class CPL_DLL TileMatrixSet 46 { 47 static constexpr double NaN = std::numeric_limits<double>::quiet_NaN(); 48 49 public: identifier() const50 const std::string& identifier() const { return mIdentifier; } title() const51 const std::string& title() const { return mTitle; } abstract() const52 const std::string& abstract() const { return mAbstract; } 53 54 struct CPL_DLL BoundingBox 55 { 56 std::string mCrs{}; 57 double mLowerCornerX{NaN}; 58 double mLowerCornerY{NaN}; 59 double mUpperCornerX{NaN}; 60 double mUpperCornerY{NaN}; 61 }; bbox() const62 const BoundingBox& bbox() const { return mBbox; } crs() const63 const std::string& crs() const { return mCrs; } wellKnownScaleSet() const64 const std::string& wellKnownScaleSet() const { return mWellKnownScaleSet; } 65 66 struct CPL_DLL TileMatrix 67 { 68 std::string mId{}; 69 double mScaleDenominator{NaN}; 70 double mResX{NaN}; // computed from mScaleDenominator and CRS definition 71 double mResY{NaN}; // computed from mScaleDenominator and CRS definition 72 double mTopLeftX{NaN}; 73 double mTopLeftY{NaN}; 74 int mTileWidth{}; 75 int mTileHeight{}; 76 int mMatrixWidth{}; 77 int mMatrixHeight{}; 78 79 struct CPL_DLL VariableMatrixWidth 80 { 81 int mCoalesce{}; 82 int mMinTileRow{}; 83 int mMaxTileRow{}; 84 }; 85 std::vector<VariableMatrixWidth> mVariableMatrixWidthList{}; 86 }; tileMatrixList() const87 const std::vector<TileMatrix>& tileMatrixList() const { return mTileMatrixList; } 88 89 /** Parse a TileMatrixSet definition, passed inline or by filename, 90 * corresponding to the JSON encoding of the OGC Two Dimensional Tile Matrix Set: 91 * http://docs.opengeospatial.org/is/17-083r2/17-083r2.html */ 92 static std::unique_ptr<TileMatrixSet> parse(const char* fileOrDef); 93 94 /** Return hardcoded tile matrix set names (such as GoogleMapsCompatible), as 95 * well as XXX for each tms_XXXX.json in GDAL data directory */ 96 static std::set<std::string> listPredefinedTileMatrixSets(); 97 98 bool haveAllLevelsSameTopLeft() const; 99 100 bool haveAllLevelsSameTileSize() const; 101 102 bool hasOnlyPowerOfTwoVaryingScales() const; 103 104 bool hasVariableMatrixWidth() const; 105 106 private: 107 TileMatrixSet() = default; 108 109 std::string mIdentifier{}; 110 std::string mTitle{}; 111 std::string mAbstract{}; 112 BoundingBox mBbox{}; 113 std::string mCrs{}; 114 std::string mWellKnownScaleSet{}; 115 std::vector<TileMatrix> mTileMatrixList{}; 116 }; 117 118 } // namespace gdal 119 120 //! @endcond 121 122 #endif // TILEMATRIXSET_HPP_INCLUDED 123