LCOV - code coverage report
Current view: top level - autotest/cpp - test_osr_pci.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 51 51 100.0 %
Date: 2024-11-21 22:18:42 Functions: 10 10 100.0 %

          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             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "gdal_unit_test.h"
      15             : 
      16             : #include "cpl_error.h"
      17             : #include "cpl_string.h"
      18             : #include "ogr_api.h"
      19             : #include "ogr_srs_api.h"
      20             : 
      21             : #include <algorithm>
      22             : #include <cmath>
      23             : #include <string>
      24             : 
      25             : #include "gtest_include.h"
      26             : 
      27             : namespace
      28             : {
      29             : 
      30             : // Common fixture with test data
      31             : struct test_osr_pci : public ::testing::Test
      32             : {
      33             :     OGRErr err_ = OGRERR_NONE;
      34             :     OGRSpatialReferenceH srs_ = nullptr;
      35             : 
      36           2 :     void SetUp() override
      37             :     {
      38           2 :         srs_ = OSRNewSpatialReference(nullptr);
      39           2 :         ASSERT_TRUE(nullptr != srs_);
      40             :     }
      41             : 
      42           2 :     void TearDown() override
      43             :     {
      44           2 :         OSRDestroySpatialReference(srs_);
      45           2 :         srs_ = nullptr;
      46           2 :     }
      47             : };
      48             : 
      49             : // Test the OGRSpatialReference::importFromPCI() and OSRImportFromPCI()
      50           4 : TEST_F(test_osr_pci, importFromPCI)
      51             : {
      52           1 :     const int size = 17;
      53           1 :     double params[size] = {0.0, 0.0, 45.0, 54.5, 47.0, 62.0, 0.0, 0.0, 0.0,
      54             :                            0.0, 0.0, 0.0,  0.0,  0.0,  0.0,  0.0, 0.0};
      55             : 
      56           1 :     err_ = OSRImportFromPCI(srs_, "EC          E015", "METRE", params);
      57           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      58             : 
      59           1 :     const double maxError = 0.0000005;
      60           1 :     double val = 0;
      61             : 
      62           1 :     val = OSRGetProjParm(srs_, SRS_PP_STANDARD_PARALLEL_1, -1111, &err_);
      63           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      64           1 :     EXPECT_NEAR(val, 47.0, maxError);
      65             : 
      66           1 :     val = OSRGetProjParm(srs_, SRS_PP_STANDARD_PARALLEL_2, -1111, &err_);
      67           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      68           1 :     EXPECT_NEAR(val, 62.0, maxError);
      69             : 
      70           1 :     val = OSRGetProjParm(srs_, SRS_PP_LATITUDE_OF_CENTER, -1111, &err_);
      71           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      72           1 :     EXPECT_NEAR(val, 54.5, maxError);
      73             : 
      74           1 :     val = OSRGetProjParm(srs_, SRS_PP_LONGITUDE_OF_CENTER, -1111, &err_);
      75           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      76           1 :     EXPECT_NEAR(val, 45.0, maxError);
      77             : 
      78           1 :     val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_);
      79           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      80           1 :     EXPECT_NEAR(val, 0.0, maxError);
      81             : 
      82           1 :     val = OSRGetProjParm(srs_, SRS_PP_FALSE_NORTHING, -1111, &err_);
      83           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      84           1 :     EXPECT_NEAR(val, 0.0, maxError);
      85             : }
      86             : 
      87             : // Test the OGRSpatialReference::exportToPCI() and OSRExportToPCI()
      88           4 : TEST_F(test_osr_pci, exportToPCI)
      89             : {
      90           1 :     const char *wkt =
      91             :         "PROJCS[\"unnamed\",GEOGCS[\"NAD27\","
      92             :         "DATUM[\"North_American_Datum_1927\","
      93             :         "SPHEROID[\"Clarke 1866\",6378206.4,294.9786982139006,"
      94             :         "AUTHORITY[\"EPSG\",\"7008\"]],AUTHORITY[\"EPSG\",\"6267\"]],"
      95             :         "PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433],"
      96             :         "AUTHORITY[\"EPSG\",\"4267\"]],PROJECTION[\"Lambert_Conformal_Conic_"
      97             :         "2SP\"],"
      98             :         "PARAMETER[\"standard_parallel_1\",33.90363402777778],"
      99             :         "PARAMETER[\"standard_parallel_2\",33.62529002777778],"
     100             :         "PARAMETER[\"latitude_of_origin\",33.76446202777777],"
     101             :         "PARAMETER[\"central_meridian\",-117.4745428888889],"
     102             :         "PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],"
     103             :         "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]]]";
     104             : 
     105           1 :     err_ = OSRImportFromWkt(srs_, (char **)&wkt);
     106           1 :     ASSERT_EQ(err_, OGRERR_NONE);
     107             : 
     108           1 :     char *proj = nullptr;
     109           1 :     char *units = nullptr;
     110           1 :     double *params = nullptr;
     111             : 
     112           1 :     err_ = OSRExportToPCI(srs_, &proj, &units, &params);
     113           1 :     EXPECT_EQ(err_, OGRERR_NONE);
     114             : 
     115           1 :     EXPECT_STREQ(proj, "LCC         D-01");
     116             : 
     117           1 :     EXPECT_STREQ(units, "METRE");
     118             : 
     119           1 :     const double maxError = 0.0000005;
     120             : 
     121           1 :     EXPECT_NEAR(params[2], -117.47454290, maxError);
     122             : 
     123           1 :     EXPECT_NEAR(params[3], 33.76446203, maxError);
     124             : 
     125           1 :     EXPECT_NEAR(params[4], 33.90363403, maxError);
     126             : 
     127           1 :     EXPECT_NEAR(params[5], 33.62529003, maxError);
     128             : 
     129           1 :     CPLFree(proj);
     130           1 :     CPLFree(units);
     131           1 :     CPLFree(params);
     132             : }
     133             : 
     134             : }  // namespace

Generated by: LCOV version 1.14