-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathObliqueMercatorProjection.cc
More file actions
104 lines (87 loc) · 3.58 KB
/
ObliqueMercatorProjection.cc
File metadata and controls
104 lines (87 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Fimex, ObliqueMercatorProjection.cc
*
* (C) Copyright 2017, SMHI
*
* Project Info: https://wiki.met.no/fimex/start
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* Created on: May 12, 2017
* Author: Martin Raspaud
*/
#include "fimex/coordSys/ObliqueMercatorProjection.h"
#include <boost/regex.hpp>
#include <proj_api.h>
#include "fimex/Utils.h"
#include "fimex/Logger.h"
namespace MetNoFimex
{
using namespace std;
static LoggerPtr logger = getLogger("fimex.ObliqueMercatorProjection");
ObliqueMercatorProjection::ObliqueMercatorProjection()
: ProjectionImpl("oblique_mercator", false)
{}
ObliqueMercatorProjection::~ObliqueMercatorProjection()
{}
bool ObliqueMercatorProjection::acceptsProj4(const std::string& proj4Str)
{
return proj4ProjectionMatchesName(proj4Str, "omerc");
}
std::vector<CDMAttribute> ObliqueMercatorProjection::parametersFromProj4(const std::string& proj4Str)
{
vector<CDMAttribute> attrs;
if (!acceptsProj4(proj4Str)) return attrs;
attrs.push_back(CDMAttribute("grid_mapping_name", "oblique_mercator"));
// longitude at origin
double longOfProjOrigin = 0.;
boost::smatch what;
if (boost::regex_search(proj4Str, what, boost::regex("\\+lonc=(\\S+)"))) {
longOfProjOrigin = string2type<double>(what[1].str());
}
attrs.push_back(CDMAttribute("longitude_of_projection_origin", longOfProjOrigin));
// standard_parallel or scale_factor
if (boost::regex_search(proj4Str, what, boost::regex("\\+lat_0=(\\S+)"))) {
double latOfProjOrigin = string2type<double>(what[1].str());
attrs.push_back(CDMAttribute("latitude_of_projection_origin", latOfProjOrigin));
}
// azimuth of central line
double azimuthOfCentralLine = 0.;
if (boost::regex_search(proj4Str, what, boost::regex("\\+alpha=(\\S+)"))) {
azimuthOfCentralLine = string2type<double>(what[1].str());
}
attrs.push_back(CDMAttribute("azimuth_of_central_line", azimuthOfCentralLine));
if (boost::regex_search(proj4Str, what, boost::regex("\\+k=(\\S+)"))) {
attrs.push_back(CDMAttribute("scale_factor_at_projection_origin", string2type<double>(what[1].str())));
}
if (boost::regex_search(proj4Str, what, boost::regex("\\+no_rot"))) {
attrs.push_back(CDMAttribute("no_rotation", ""));
}
proj4GetEarthAttributes(proj4Str, attrs);
attrs.push_back(CDMAttribute("proj4", proj4Str));
return attrs;
}
std::ostream& ObliqueMercatorProjection::getProj4ProjectionPart(std::ostream& oproj) const
{
oproj << "+proj=omerc";
addParameterToStream(oproj, "longitude_of_projection_origin", " +lonc=");
addParameterToStream(oproj, "latitude_of_projection_origin", " +lat_0=");
addParameterToStream(oproj, "azimuth_of_central_line", " +alpha=");
addParameterToStream(oproj, "scale_factor_at_projection_origin", " +k_0=");
addParameterToStream(oproj, "no_rotation", " +no_rot");
return oproj;
}
}