Line data Source code
1 : ///////////////////////////////////////////////////////////////////////////////
2 : //
3 : // Project: C++ Test Suite for GDAL/OGR
4 : // Purpose: Test some PCI specific translation issues.
5 : // Ported from osr/osr_pci.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 "cpl_string.h"
34 : #include "ogr_api.h"
35 : #include "ogr_srs_api.h"
36 :
37 : #include <algorithm>
38 : #include <cmath>
39 : #include <string>
40 :
41 : #include "gtest_include.h"
42 :
43 : namespace
44 : {
45 :
46 : // Common fixture with test data
47 : struct test_osr_pci : public ::testing::Test
48 : {
49 : OGRErr err_ = OGRERR_NONE;
50 : OGRSpatialReferenceH srs_ = nullptr;
51 :
52 2 : void SetUp() override
53 : {
54 2 : srs_ = OSRNewSpatialReference(nullptr);
55 2 : ASSERT_TRUE(nullptr != srs_);
56 : }
57 :
58 2 : void TearDown() override
59 : {
60 2 : OSRDestroySpatialReference(srs_);
61 2 : srs_ = nullptr;
62 2 : }
63 : };
64 :
65 : // Test the OGRSpatialReference::importFromPCI() and OSRImportFromPCI()
66 4 : TEST_F(test_osr_pci, importFromPCI)
67 : {
68 1 : const int size = 17;
69 1 : double params[size] = {0.0, 0.0, 45.0, 54.5, 47.0, 62.0, 0.0, 0.0, 0.0,
70 : 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
71 :
72 1 : err_ = OSRImportFromPCI(srs_, "EC E015", "METRE", params);
73 1 : ASSERT_EQ(err_, OGRERR_NONE);
74 :
75 1 : const double maxError = 0.0000005;
76 1 : double val = 0;
77 :
78 1 : val = OSRGetProjParm(srs_, SRS_PP_STANDARD_PARALLEL_1, -1111, &err_);
79 1 : ASSERT_EQ(err_, OGRERR_NONE);
80 1 : EXPECT_NEAR(val, 47.0, maxError);
81 :
82 1 : val = OSRGetProjParm(srs_, SRS_PP_STANDARD_PARALLEL_2, -1111, &err_);
83 1 : ASSERT_EQ(err_, OGRERR_NONE);
84 1 : EXPECT_NEAR(val, 62.0, maxError);
85 :
86 1 : val = OSRGetProjParm(srs_, SRS_PP_LATITUDE_OF_CENTER, -1111, &err_);
87 1 : ASSERT_EQ(err_, OGRERR_NONE);
88 1 : EXPECT_NEAR(val, 54.5, maxError);
89 :
90 1 : val = OSRGetProjParm(srs_, SRS_PP_LONGITUDE_OF_CENTER, -1111, &err_);
91 1 : ASSERT_EQ(err_, OGRERR_NONE);
92 1 : EXPECT_NEAR(val, 45.0, maxError);
93 :
94 1 : val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_);
95 1 : ASSERT_EQ(err_, OGRERR_NONE);
96 1 : EXPECT_NEAR(val, 0.0, maxError);
97 :
98 1 : val = OSRGetProjParm(srs_, SRS_PP_FALSE_NORTHING, -1111, &err_);
99 1 : ASSERT_EQ(err_, OGRERR_NONE);
100 1 : EXPECT_NEAR(val, 0.0, maxError);
101 : }
102 :
103 : // Test the OGRSpatialReference::exportToPCI() and OSRExportToPCI()
104 4 : TEST_F(test_osr_pci, exportToPCI)
105 : {
106 1 : const char *wkt =
107 : "PROJCS[\"unnamed\",GEOGCS[\"NAD27\","
108 : "DATUM[\"North_American_Datum_1927\","
109 : "SPHEROID[\"Clarke 1866\",6378206.4,294.9786982139006,"
110 : "AUTHORITY[\"EPSG\",\"7008\"]],AUTHORITY[\"EPSG\",\"6267\"]],"
111 : "PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433],"
112 : "AUTHORITY[\"EPSG\",\"4267\"]],PROJECTION[\"Lambert_Conformal_Conic_"
113 : "2SP\"],"
114 : "PARAMETER[\"standard_parallel_1\",33.90363402777778],"
115 : "PARAMETER[\"standard_parallel_2\",33.62529002777778],"
116 : "PARAMETER[\"latitude_of_origin\",33.76446202777777],"
117 : "PARAMETER[\"central_meridian\",-117.4745428888889],"
118 : "PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],"
119 : "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]]]";
120 :
121 1 : err_ = OSRImportFromWkt(srs_, (char **)&wkt);
122 1 : ASSERT_EQ(err_, OGRERR_NONE);
123 :
124 1 : char *proj = nullptr;
125 1 : char *units = nullptr;
126 1 : double *params = nullptr;
127 :
128 1 : err_ = OSRExportToPCI(srs_, &proj, &units, ¶ms);
129 1 : EXPECT_EQ(err_, OGRERR_NONE);
130 :
131 1 : EXPECT_STREQ(proj, "LCC D-01");
132 :
133 1 : EXPECT_STREQ(units, "METRE");
134 :
135 1 : const double maxError = 0.0000005;
136 :
137 1 : EXPECT_NEAR(params[2], -117.47454290, maxError);
138 :
139 1 : EXPECT_NEAR(params[3], 33.76446203, maxError);
140 :
141 1 : EXPECT_NEAR(params[4], 33.90363403, maxError);
142 :
143 1 : EXPECT_NEAR(params[5], 33.62529003, maxError);
144 :
145 1 : CPLFree(proj);
146 1 : CPLFree(units);
147 1 : CPLFree(params);
148 : }
149 :
150 : } // namespace
|