PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
projection.hh
Go to the documentation of this file.
1 /* Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2023 PISM Authors
2  *
3  * This file is part of PISM.
4  *
5  * PISM is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 3 of the License, or (at your option) any later
8  * version.
9  *
10  * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with PISM; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef PISM_PROJECTION_H
21 #define PISM_PROJECTION_H
22 
23 #include <string>
24 #include <array>
25 
26 #include "pism/util/Units.hh"
27 #include "pism/util/VariableMetadata.hh"
28 
29 namespace pism {
30 
31 class File;
32 namespace array {
33 class Array3D;
34 class Scalar;
35 }
36 
37 /*! @brief Convert a proj string with an EPSG code to a set of CF attributes. */
38 /*!
39  * Fails if `proj_string` does not contain an EPSG code.
40  */
41 VariableMetadata epsg_to_cf(units::System::Ptr system, const std::string &proj_string);
42 
43 class MappingInfo {
44 public:
45  MappingInfo(const std::string &mapping_name, units::System::Ptr unit_system);
47  std::string proj;
48 };
49 
50 /*! @brief Check consistency of the "mapping" variable with the EPSG code in the proj string. */
51 /*!
52  * If the consistency check fails, throws RuntimeError explaining the failure. Fails if `info.proj`
53  * does not use an EPSG code.
54  */
55 void check_consistency_epsg(const MappingInfo &info);
56 
57 /*! @brief Get projection info from a file. */
58 MappingInfo get_projection_info(const File &input_file, const std::string &mapping_name,
59  units::System::Ptr unit_system);
60 
61 void compute_longitude(const std::string &projection, array::Scalar &result);
62 void compute_latitude(const std::string &projection, array::Scalar &result);
63 
64 void compute_lon_bounds(const std::string &projection, array::Array3D &result);
65 void compute_lat_bounds(const std::string &projection, array::Array3D &result);
66 
67 /*!
68  * Utility class converting `x,y` coordinates in a projection to a `lon,lat` pair.
69  *
70  * Requires the `PROJ` library.
71  */
73 public:
74  LonLatCalculator(const std::string &proj_string);
76 
77  double lon(double x, double y) const;
78  double lat(double x, double y) const;
79  std::array<double, 2> lonlat(double x, double y) const;
80 private:
81  struct Impl;
83 };
84 
85 } // end of namespace pism
86 
87 #endif /* PISM_PROJECTION_H */
High-level PISM I/O class.
Definition: File.hh:56
std::array< double, 2 > lonlat(double x, double y) const
Definition: projection.cc:462
LonLatCalculator(const std::string &proj_string)
Definition: projection.cc:447
double lat(double x, double y) const
Definition: projection.cc:458
double lon(double x, double y) const
Definition: projection.cc:454
std::string proj
Definition: projection.hh:47
VariableMetadata mapping
Definition: projection.hh:46
MappingInfo(const std::string &mapping_name, units::System::Ptr unit_system)
Definition: projection.cc:40
A virtual class collecting methods common to ice and bedrock 3D fields.
Definition: Array3D.hh:33
std::shared_ptr< System > Ptr
Definition: Units.hh:47
void compute_latitude(const std::string &projection, array::Scalar &result)
Definition: projection.cc:422
void compute_longitude(const std::string &projection, array::Scalar &result)
Definition: projection.cc:419
VariableMetadata epsg_to_cf(units::System::Ptr system, const std::string &proj_string)
Return CF-Convention "mapping" variable corresponding to an EPSG code specified in a PROJ string.
Definition: projection.cc:47
void check_consistency_epsg(const MappingInfo &info)
Check consistency of the "mapping" variable with the EPSG code in the proj string.
Definition: projection.cc:136
MappingInfo get_projection_info(const File &input_file, const std::string &mapping_name, units::System::Ptr unit_system)
Get projection info from a file.
Definition: projection.cc:198
void compute_lat_bounds(const std::string &projection, array::Array3D &result)
Definition: projection.cc:430
void compute_lon_bounds(const std::string &projection, array::Array3D &result)
Definition: projection.cc:426