Line data Source code
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 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef TILEMATRIXSET_HPP_INCLUDED 14 : #define TILEMATRIXSET_HPP_INCLUDED 15 : 16 : #include "cpl_port.h" 17 : 18 : #include <memory> 19 : #include <limits> 20 : #include <set> 21 : #include <string> 22 : #include <vector> 23 : 24 : //! @cond Doxygen_Suppress 25 : 26 : namespace gdal 27 : { 28 : 29 : class CPL_DLL TileMatrixSet 30 : { 31 : static constexpr double NaN = std::numeric_limits<double>::quiet_NaN(); 32 : 33 : public: 34 1522 : const std::string &identifier() const 35 : { 36 1522 : return mIdentifier; 37 : } 38 : 39 2 : const std::string &title() const 40 : { 41 2 : return mTitle; 42 : } 43 : 44 : //! "abstract" in TMS v1 / "description" in TMS v2 45 2 : const std::string &abstract() const 46 : { 47 2 : return mAbstract; 48 : } 49 : 50 : struct CPL_DLL BoundingBox 51 : { 52 : std::string mCrs{}; //! Can be a URL, a URI, a WKT or PROJJSON string. 53 : double mLowerCornerX{NaN}; 54 : double mLowerCornerY{NaN}; 55 : double mUpperCornerX{NaN}; 56 : double mUpperCornerY{NaN}; 57 : }; 58 : 59 33 : const BoundingBox &bbox() const 60 : { 61 33 : return mBbox; 62 : } 63 : 64 : //! Can be a URL, a URI, a WKT or PROJJSON string. 65 1619 : const std::string &crs() const 66 : { 67 1619 : return mCrs; 68 : } 69 : 70 2 : const std::string &wellKnownScaleSet() const 71 : { 72 2 : return mWellKnownScaleSet; 73 : } 74 : 75 : struct CPL_DLL TileMatrix 76 : { 77 : std::string mId{}; 78 : double mScaleDenominator{NaN}; 79 : double mResX{ 80 : NaN}; // computed from mScaleDenominator and CRS definition 81 : double mResY{ 82 : NaN}; // computed from mScaleDenominator and CRS definition 83 : double mTopLeftX{NaN}; 84 : double mTopLeftY{NaN}; 85 : int mTileWidth{}; 86 : int mTileHeight{}; 87 : int mMatrixWidth{}; 88 : int mMatrixHeight{}; 89 : 90 : struct CPL_DLL VariableMatrixWidth 91 : { 92 : int mCoalesce{}; 93 : int mMinTileRow{}; 94 : int mMaxTileRow{}; 95 : }; 96 : 97 : std::vector<VariableMatrixWidth> mVariableMatrixWidthList{}; 98 : }; 99 : 100 122 : const std::vector<TileMatrix> &tileMatrixList() const 101 : { 102 122 : return mTileMatrixList; 103 : } 104 : 105 410 : std::vector<TileMatrix> &tileMatrixList() 106 : { 107 410 : return mTileMatrixList; 108 : } 109 : 110 : /** Parse a TileMatrixSet definition, passed inline or by filename, 111 : * corresponding to the JSON encoding of the OGC Two Dimensional Tile Matrix 112 : * Set: http://docs.opengeospatial.org/is/17-083r2/17-083r2.html */ 113 : static std::unique_ptr<TileMatrixSet> parse(const char *fileOrDef); 114 : 115 : /** Create a raster tiling scheme */ 116 : static std::unique_ptr<TileMatrixSet> 117 : createRaster(int width, int height, int tileSize, int zoomLevelCount, 118 : double dfTopLeftX = 0.0, double dfTopLeftY = 0.0, 119 : double dfResXFull = 1.0, double dfResYFull = 1.0, 120 : const std::string &mCRS = std::string()); 121 : 122 : /** Return hardcoded tile matrix set names (such as GoogleMapsCompatible), 123 : * as well as XXX for each tms_XXXX.json in GDAL data directory */ 124 : static std::vector<std::string> listPredefinedTileMatrixSets(); 125 : 126 : bool haveAllLevelsSameTopLeft() const; 127 : 128 : bool haveAllLevelsSameTileSize() const; 129 : 130 : bool hasOnlyPowerOfTwoVaryingScales() const; 131 : 132 : bool hasVariableMatrixWidth() const; 133 : 134 : std::string exportToTMSJsonV1() const; 135 : 136 : private: 137 5675 : TileMatrixSet() = default; 138 : 139 : std::string mIdentifier{}; 140 : std::string mTitle{}; 141 : std::string mAbstract{}; 142 : BoundingBox mBbox{}; 143 : std::string mCrs{}; 144 : std::string mWellKnownScaleSet{}; 145 : std::vector<TileMatrix> mTileMatrixList{}; 146 : }; 147 : 148 : } // namespace gdal 149 : 150 : //! @endcond 151 : 152 : #endif // TILEMATRIXSET_HPP_INCLUDED