| 1 | /********************************************************************** |
| 2 | Egcs.h: Conversions from and to european grid coding system |
| 3 | Author(s): [email protected] |
| 4 | Copyright (C) 2016-2020 European Union (Joint Research Centre) |
| 5 | |
| 6 | This file is part of jiplib. |
| 7 | |
| 8 | jiplib is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | jiplib is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with jiplib. If not, see <https://www.gnu.org/licenses/>. |
| 20 | ***********************************************************************/ |
| 21 | /* #include <math.h> */ |
| 22 | #include <cmath> |
| 23 | #include <string> |
| 24 | |
| 25 | #ifndef _EGCS_H_ |
| 26 | #define _EGCS_H_ |
| 27 | |
| 28 | class Egcs |
| 29 | { |
| 30 | public: |
| 31 | Egcs(); |
| 32 | Egcs(unsigned short level); |
| 33 | /* Egcs(unsigned short level); */ |
| 34 | ~Egcs(); |
| 35 | unsigned short cell2level(const std::string& cellCode) const; |
| 36 | std::string geo2cell(double x, double y) const; |
| 37 | double getSize() const {return getBaseSize()*pow(2.0,(m_level-19)%3);}; |
| 38 | void setLevel(unsigned short level){m_level=level;}; |
| 39 | unsigned short getLevel() const{return m_level;}; |
| 40 | unsigned short res2level(double resolution) const; |
| 41 | double getResolution() const; |
| 42 | void force2grid(double& ulx, double& uly, double& lrx, double &lry) const; |
| 43 | void cell2bb(const std::string& cellCode, int &ulx, int &uly, int &lrx, int &lry) const; |
| 44 | void cell2mid(const std::string& cellCode, double& midX, double& midY) const; |
| 45 | private: |
| 46 | int getBaseSize() const {return pow(10.0,(m_level+1)/3);}; |
| 47 | unsigned short m_level; |
| 48 | // level square scheme example |
| 49 | // 19 1000km xy 32 |
| 50 | // 18 500km xy-q 32-A |
| 51 | // 17 250km xy-qq 32-AB |
| 52 | // 16 100km xxyy 3320 |
| 53 | // 5 25m xxxxxyyyyy-qq 3346720658-DC |
| 54 | // 1 1m xxxxxxxyyyyyyy 33467652065889 |
| 55 | }; |
| 56 | #endif // _EGCS_H_ |
| 57 |