Line data Source code
1 : ///////////////////////////////////////////////////////////////////////////////
2 : //
3 : // Project: C++ Test Suite for GDAL/OGR
4 : // Purpose: Test some PROJ.4 specific translation issues.
5 : // Ported from osr/osr_proj4.py.
6 : // Author: Mateusz Loskot <mateusz@loskot.net>
7 : //
8 : ///////////////////////////////////////////////////////////////////////////////
9 : // Copyright (c) 2006, Mateusz Loskot <mateusz@loskot.net>
10 : /*
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #include "gdal_unit_test.h"
31 :
32 : #include "cpl_error.h"
33 : #include "ogr_api.h"
34 : #include "ogr_srs_api.h"
35 :
36 : #include <algorithm>
37 : #include <cmath>
38 : #include <string>
39 :
40 : #include "gtest_include.h"
41 :
42 : namespace
43 : {
44 :
45 : // Common fixture with test data
46 : struct test_osr_proj4 : public ::testing::Test
47 : {
48 : OGRErr err_ = OGRERR_NONE;
49 : OGRSpatialReferenceH srs_ = nullptr;
50 :
51 2 : void SetUp() override
52 : {
53 2 : srs_ = OSRNewSpatialReference(nullptr);
54 2 : ASSERT_TRUE(nullptr != srs_);
55 2 : OSRSetAxisMappingStrategy(srs_, OAMS_TRADITIONAL_GIS_ORDER);
56 : }
57 :
58 2 : void TearDown() override
59 : {
60 2 : OSRDestroySpatialReference(srs_);
61 2 : srs_ = nullptr;
62 2 : }
63 : };
64 :
65 : // Test the +k_0 flag works as well as +k when
66 : // consuming PROJ.4 format
67 4 : TEST_F(test_osr_proj4, k_0)
68 : {
69 : std::string wkt(
70 : "+proj=tmerc +lat_0=53.5000000000 +lon_0=-8.0000000000 "
71 : "+k_0=1.0000350000 +x_0=200000.0000000000 +y_0=250000.0000000000 "
72 : "+a=6377340.189000 +rf=299.324965 +towgs84=482.530,"
73 1 : "-130.596,564.557,-1.042,-0.214,-0.631,8.15");
74 :
75 1 : err_ = OSRImportFromProj4(srs_, wkt.c_str());
76 1 : ASSERT_EQ(err_, OGRERR_NONE);
77 :
78 : // TODO: Check max error value
79 1 : const double maxError = 0.00005; // 0.0000005
80 1 : double val = 0;
81 :
82 1 : val = OSRGetProjParm(srs_, SRS_PP_SCALE_FACTOR, -1111, &err_);
83 1 : ASSERT_EQ(err_, OGRERR_NONE);
84 :
85 1 : EXPECT_NEAR(val, 1.000035, maxError);
86 : }
87 :
88 : // Verify that we can import strings with parameter values
89 : // that are exponents and contain a plus sign
90 4 : TEST_F(test_osr_proj4, proj_strings_with_exponents)
91 : {
92 : std::string wkt(
93 : "+proj=lcc +x_0=0.6096012192024384e+06 +y_0=0 "
94 : "+lon_0=90dw +lat_0=42dn +lat_1=44d4'n +lat_2=42d44'n "
95 1 : "+a=6378206.400000 +rf=294.978698 +nadgrids=conus,ntv1_can.dat");
96 :
97 1 : err_ = OSRImportFromProj4(srs_, wkt.c_str());
98 1 : ASSERT_EQ(err_, OGRERR_NONE);
99 :
100 1 : const double maxError = 0.0005;
101 1 : double val = 0;
102 :
103 1 : val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_);
104 1 : ASSERT_EQ(err_, OGRERR_NONE);
105 :
106 1 : EXPECT_NEAR(val, 609601.219, maxError);
107 : }
108 :
109 : } // namespace
|