Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: gdal "crs info" command 5 : * Author: Alessandro Pasotti <elpaso at itopen dot it> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2026, Alessandro Pasotti <elpaso at itopen dot it> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef GDALALG_CRSINFO_INCLUDED 14 : #define GDALALG_CRSINFO_INCLUDED 15 : 16 : //! @cond Doxygen_Suppress 17 : 18 : #include "gdalalgorithm.h" 19 : 20 : /************************************************************************/ 21 : /* GDALCRSInfoAlgorithm */ 22 : /************************************************************************/ 23 : 24 : class GDALCRSInfoAlgorithm final : public GDALAlgorithm 25 : { 26 : public: 27 : static constexpr const char *NAME = "info"; 28 : static constexpr const char *DESCRIPTION = 29 : "Return information on a coordinate reference system (CRS)."; 30 : static constexpr const char *HELP_URL = "/programs/gdal_crs_info.html"; 31 : 32 : GDALCRSInfoAlgorithm(); 33 108 : ~GDALCRSInfoAlgorithm() override = default; 34 : 35 : private: 36 : bool RunImpl(GDALProgressFunc, void *) override; 37 : 38 : void Print(const char *str) const; 39 : 40 : mutable std::string m_output{}; 41 : bool m_stdout{false}; 42 : std::string m_crs{}; 43 : bool m_validate{false}; 44 : bool m_singleLineOutput{false}; 45 : bool m_identifyCRS{false}; 46 : std::string m_outputTypeStr; 47 : 48 : // Flags to control the output type. The default is OUTPUT_TYPE_DEFAULT 49 : // that means "proj4" and "wkt2" 50 : enum class OutputType : uint32_t 51 : { 52 : OUTPUT_TYPE_PROJJSON = 1 << 0, 53 : OUTPUT_TYPE_PROJ4 = 1 << 1, 54 : OUTPUT_TYPE_WKT1 = 1 << 2, 55 : OUTPUT_TYPE_WKT2 = 1 << 3, 56 : OUTPUT_TYPE_WKT_ESRI = 1 << 4, 57 : OUTPUT_TYPE_MAPINFO = 1 << 5, 58 : OUTPUT_TYPE_XML = 1 << 6, 59 : 60 : // This flag is used to indicate the last output type. It is not used for output but for internal purposes only. 61 : OUTPUT_TYPE_LAST = 1 << 6, 62 : 63 : // Combinations of flags 64 : OUTPUT_TYPE_WKT_ALL = 65 : OUTPUT_TYPE_WKT1 | OUTPUT_TYPE_WKT2 | OUTPUT_TYPE_WKT_ESRI, 66 : OUTPUT_TYPE_DEFAULT = OUTPUT_TYPE_PROJ4 | OUTPUT_TYPE_WKT2, 67 : OUTPUT_TYPE_ALL = 0xFFFFFFFF, 68 : }; 69 : 70 : OutputType m_outputType{OutputType::OUTPUT_TYPE_DEFAULT}; 71 : 72 : // Combined and alias output types 73 : static constexpr const char *OUTPUT_TYPE_DEFAULT_STR = "default"; 74 : static constexpr const char *OUTPUT_TYPE_ALL_STR = "all"; 75 : // Latest WKT available. 76 : static constexpr const char *OUTPUT_TYPE_WKT_LATEST_STR = "wkt"; 77 : static constexpr const char *OUTPUT_TYPE_WKT_ALL_STR = "wkt_all"; 78 : 79 : // Individual output types 80 : static constexpr const char *OUTPUT_TYPE_PROJJSON_STR = "projjson"; 81 : static constexpr const char *OUTPUT_TYPE_PROJ4_STR = "proj4"; 82 : static constexpr const char *OUTPUT_TYPE_WKT1_STR = "wkt1"; 83 : static constexpr const char *OUTPUT_TYPE_WKT2_STR = "wkt2"; 84 : static constexpr const char *OUTPUT_TYPE_WKT_ESRI_STR = "wkt_esri"; 85 : static constexpr const char *OUTPUT_TYPE_MAPINFO_STR = "mapinfo"; 86 : static constexpr const char *OUTPUT_TYPE_XML_STR = "xml"; 87 : 88 : CPLErr PrintCRSInfo(const OGRSpatialReference *crs, OutputType outputType, 89 : bool prettyPrint, bool printSeparator) const; 90 : 91 : CPLErr PrintCRSOutputTypes(const OGRSpatialReference *crs, 92 : OutputType outputTypes, bool prettyPrint) const; 93 : }; 94 : 95 : //! @endcond 96 : 97 : #endif