| 1 | // Copyright (c) 2018, 2026, Oracle and/or its affiliates. |
| 2 | // |
| 3 | // This program is free software; you can redistribute it and/or modify |
| 4 | // it under the terms of the GNU General Public License, version 2.0, |
| 5 | // as published by the Free Software Foundation. |
| 6 | // |
| 7 | // This program is designed to work with certain software (including |
| 8 | // but not limited to OpenSSL) that is licensed under separate terms, |
| 9 | // as designated in a particular file or component or in included license |
| 10 | // documentation. The authors of MySQL hereby grant you an additional |
| 11 | // permission to link the program and your derivative works with the |
| 12 | // separately licensed software that they have either included with |
| 13 | // the program or referenced in the documentation. |
| 14 | // |
| 15 | // This program is distributed in the hope that it will be useful, |
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | // GNU General Public License, version 2.0, for more details. |
| 19 | // |
| 20 | // You should have received a copy of the GNU General Public License |
| 21 | // along with this program; if not, write to the Free Software |
| 22 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | |
| 24 | #include "my_config.h" |
| 25 | |
| 26 | #include <gtest/gtest.h> |
| 27 | #include <memory> // unique_ptr |
| 28 | |
| 29 | #include "sql/dd/dd.h" |
| 30 | #include "sql/dd/impl/types/spatial_reference_system_impl.h" |
| 31 | #include "sql/dd/properties.h" |
| 32 | #include "sql/dd/types/spatial_reference_system.h" |
| 33 | #include "sql/gis/geometries.h" |
| 34 | #include "sql/gis/geometries_cs.h" |
| 35 | #include "sql/gis/relops.h" |
| 36 | |
| 37 | namespace gis_srs_unittest { |
| 38 | |
| 39 | TEST(SrsTest, GeogcsProj4Parameters) { |
| 40 | dd::Spatial_reference_system_impl *srs; |
| 41 | srs = dynamic_cast<dd::Spatial_reference_system_impl *>( |
| 42 | dd::create_object<dd::Spatial_reference_system>()); |
| 43 | srs->set_id(1000000); |
| 44 | srs->set_name("Test"); |
| 45 | srs->set_created(0UL); |
| 46 | srs->set_last_altered(0UL); |
| 47 | |
| 48 | // Ellipsoid without TOWGS84. |
| 49 | srs->set_definition( |
| 50 | "GEOGCS[\"WGS 84\",DATUM[\"World Geodetic System 1984\",SPHEROID[\"WGS " |
| 51 | "84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0." |
| 52 | "017453292519943278],AXIS[\"Lat\",NORTH],AXIS[\"Lon\",EAST]]"); |
| 53 | srs->parse_definition(); |
| 54 | EXPECT_STREQ(srs->proj4_parameters().c_str(), |
| 55 | "+proj=lonlat +a=6378137 +rf=298.257223563 " |
| 56 | "+towgs84=0,0,0,0,0,0,0 +no_defs"); |
| 57 | |
| 58 | // Ellipsoid recognized as WGS 84 (authority clause on GEOGCS). |
| 59 | srs->set_definition( |
| 60 | "GEOGCS[\"WGS 84\",DATUM[\"World Geodetic System 1984\",SPHEROID[\"WGS " |
| 61 | "84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0." |
| 62 | "017453292519943278],AXIS[\"Lat\",NORTH],AXIS[\"Lon\",EAST],AUTHORITY[" |
| 63 | "\"EPSG\",\"4326\"]]"); |
| 64 | srs->parse_definition(); |
| 65 | EXPECT_STREQ(srs->proj4_parameters().c_str(), |
| 66 | "+proj=lonlat +a=6378137 +rf=298.257223563 " |
| 67 | "+towgs84=0,0,0,0,0,0,0 +no_defs"); |
| 68 | |
| 69 | // Ellipsoid with TOWGS84. |
| 70 | srs->set_definition( |
| 71 | "GEOGCS[\"WGS 84\",DATUM[\"World Geodetic System 1984\",SPHEROID[\"WGS " |
| 72 | "84\",6378137,298.257223563],TOWGS84[1,2,3,4,5,6,7]],PRIMEM[" |
| 73 | "\"Greenwich\",0],UNIT[\"degree\",0.017453292519943278],AXIS[\"Lat\"," |
| 74 | "NORTH],AXIS[\"Lon\",EAST]]"); |
| 75 | srs->parse_definition(); |
| 76 | EXPECT_STREQ(srs->proj4_parameters().c_str(), |
| 77 | "+proj=lonlat +a=6378137 +rf=298.257223563 " |
| 78 | "+towgs84=1,2,3,4,5,6,7 +no_defs"); |
| 79 | |
| 80 | // Sphere without TOWGS84. |
| 81 | srs->set_definition( |
| 82 | "GEOGCS[\"Sphere\",DATUM[\"Sphere\",SPHEROID[\"Sphere\",6378137,0]]," |
| 83 | "PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.017453292519943278],AXIS[" |
| 84 | "\"Lat\",NORTH],AXIS[\"Lon\",EAST]]"); |
| 85 | srs->parse_definition(); |
| 86 | EXPECT_STREQ( |
| 87 | srs->proj4_parameters().c_str(), |
| 88 | "+proj=lonlat +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +no_defs"); |
| 89 | |
| 90 | // Sphere with TOWGS84. |
| 91 | srs->set_definition( |
| 92 | "GEOGCS[\"Sphere\",DATUM[\"Sphere\",SPHEROID[\"Sphere\",6378137,0]," |
| 93 | "TOWGS84[1,2,3,4,5,6,7]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0." |
| 94 | "017453292519943278],AXIS[\"Lat\",NORTH],AXIS[\"Lon\",EAST]]"); |
| 95 | srs->parse_definition(); |
| 96 | EXPECT_STREQ( |
| 97 | srs->proj4_parameters().c_str(), |
| 98 | "+proj=lonlat +a=6378137 +b=6378137 +towgs84=1,2,3,4,5,6,7 +no_defs"); |
| 99 | |
| 100 | delete srs; |
| 101 | } |
| 102 | |
| 103 | TEST(SrsTest, ProjcsProj4Parameters) { |
| 104 | dd::Spatial_reference_system_impl *srs; |
| 105 | srs = dynamic_cast<dd::Spatial_reference_system_impl *>( |
| 106 | dd::create_object<dd::Spatial_reference_system>()); |
| 107 | srs->set_id(1000000); |
| 108 | srs->set_name("Test"); |
| 109 | srs->set_created(0UL); |
| 110 | srs->set_last_altered(0UL); |
| 111 | |
| 112 | // Projection. |
| 113 | srs->set_definition( |
| 114 | "PROJCS[\"WGS 84 / Pseudo-Mercator\",GEOGCS[\"WGS 84\",DATUM[\"World " |
| 115 | "Geodetic System 1984\",SPHEROID[\"WGS " |
| 116 | "84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0." |
| 117 | "017453292519943278],AXIS[\"Lat\",NORTH],AXIS[\"Lon\",EAST]],PROJECTION[" |
| 118 | "\"Popular Visualisation Pseudo " |
| 119 | "Mercator\",AUTHORITY[\"EPSG\",\"1024\"]],PARAMETER[\"Latitude of " |
| 120 | "natural origin\",0,AUTHORITY[\"EPSG\",\"8801\"]],PARAMETER[\"Longitude " |
| 121 | "of natural origin\",0,AUTHORITY[\"EPSG\",\"8802\"]],PARAMETER[\"False " |
| 122 | "easting\",0,AUTHORITY[\"EPSG\",\"8806\"]],PARAMETER[\"False " |
| 123 | "northing\",0,AUTHORITY[\"EPSG\",\"8807\"]],UNIT[\"metre\",1],AXIS[\"X\"," |
| 124 | "EAST],AXIS[\"Y\",NORTH]]"); |
| 125 | srs->parse_definition(); |
| 126 | EXPECT_STREQ( |
| 127 | srs->proj4_parameters().c_str(), |
| 128 | "+proj=webmerc +a=6378137 +rf=298.257223563 +towgs84=0,0,0,0,0,0,0 " |
| 129 | "+no_defs +to_meter=1.000000 +lon_0=0 +x_0=0 +y_0=0"); |
| 130 | |
| 131 | delete srs; |
| 132 | } |
| 133 | |
| 134 | } // namespace gis_srs_unittest |