LCOV - code coverage report
Current view: top level - autotest/cpp - test_osr_proj4.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 26 26 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 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             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "gdal_unit_test.h"
      15             : 
      16             : #include "cpl_error.h"
      17             : #include "ogr_api.h"
      18             : #include "ogr_srs_api.h"
      19             : 
      20             : #include <algorithm>
      21             : #include <cmath>
      22             : #include <string>
      23             : 
      24             : #include "gtest_include.h"
      25             : 
      26             : namespace
      27             : {
      28             : 
      29             : // Common fixture with test data
      30             : struct test_osr_proj4 : public ::testing::Test
      31             : {
      32             :     OGRErr err_ = OGRERR_NONE;
      33             :     OGRSpatialReferenceH srs_ = nullptr;
      34             : 
      35           2 :     void SetUp() override
      36             :     {
      37           2 :         srs_ = OSRNewSpatialReference(nullptr);
      38           2 :         ASSERT_TRUE(nullptr != srs_);
      39           2 :         OSRSetAxisMappingStrategy(srs_, OAMS_TRADITIONAL_GIS_ORDER);
      40             :     }
      41             : 
      42           2 :     void TearDown() override
      43             :     {
      44           2 :         OSRDestroySpatialReference(srs_);
      45           2 :         srs_ = nullptr;
      46           2 :     }
      47             : };
      48             : 
      49             : // Test the +k_0 flag works as well as +k when
      50             : // consuming PROJ.4 format
      51           4 : TEST_F(test_osr_proj4, k_0)
      52             : {
      53             :     std::string wkt(
      54             :         "+proj=tmerc +lat_0=53.5000000000 +lon_0=-8.0000000000 "
      55             :         "+k_0=1.0000350000 +x_0=200000.0000000000 +y_0=250000.0000000000 "
      56             :         "+a=6377340.189000 +rf=299.324965 +towgs84=482.530,"
      57           1 :         "-130.596,564.557,-1.042,-0.214,-0.631,8.15");
      58             : 
      59           1 :     err_ = OSRImportFromProj4(srs_, wkt.c_str());
      60           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      61             : 
      62             :     // TODO: Check max error value
      63           1 :     const double maxError = 0.00005;  // 0.0000005
      64           1 :     double val = 0;
      65             : 
      66           1 :     val = OSRGetProjParm(srs_, SRS_PP_SCALE_FACTOR, -1111, &err_);
      67           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      68             : 
      69           1 :     EXPECT_NEAR(val, 1.000035, maxError);
      70             : }
      71             : 
      72             : // Verify that we can import strings with parameter values
      73             : // that are exponents and contain a plus sign
      74           4 : TEST_F(test_osr_proj4, proj_strings_with_exponents)
      75             : {
      76             :     std::string wkt(
      77             :         "+proj=lcc +x_0=0.6096012192024384e+06 +y_0=0 "
      78             :         "+lon_0=90dw +lat_0=42dn +lat_1=44d4'n +lat_2=42d44'n "
      79           1 :         "+a=6378206.400000 +rf=294.978698 +nadgrids=conus,ntv1_can.dat");
      80             : 
      81           1 :     err_ = OSRImportFromProj4(srs_, wkt.c_str());
      82           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      83             : 
      84           1 :     const double maxError = 0.0005;
      85           1 :     double val = 0;
      86             : 
      87           1 :     val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_);
      88           1 :     ASSERT_EQ(err_, OGRERR_NONE);
      89             : 
      90           1 :     EXPECT_NEAR(val, 609601.219, maxError);
      91             : }
      92             : 
      93             : }  // namespace

Generated by: LCOV version 1.14