1 /** 2 * SPDX-License-Identifier: GPL-2.0-or-later 3 * 4 * This file is part of osm2pgsql (https://osm2pgsql.org/). 5 * 6 * Copyright (C) 2006-2021 by the osm2pgsql developer community. 7 * For a full list of authors see the git log. 8 */ 9 10 #include <catch.hpp> 11 12 #include <vector> 13 14 #include "common-import.hpp" 15 #include "config.h" 16 #include "reprojection.hpp" 17 18 static testing::db::import_t db; 19 20 TEST_CASE("Projection setup") 21 { 22 char const* const style_file = OSM2PGSQLDATA_DIR "default.style"; 23 24 std::vector<char const *> option_params = {"osm2pgsql", "-S", style_file, 25 "--number-processes", "1"}; 26 27 std::string proj_name; 28 char const *srid = ""; 29 30 SECTION("No options") 31 { 32 proj_name = "Spherical Mercator"; 33 srid = "3857"; 34 } 35 36 SECTION("Latlong option") 37 { 38 option_params.push_back("-l"); 39 proj_name = "Latlong"; 40 srid = "4326"; 41 } 42 43 SECTION("Mercator option") 44 { 45 option_params.push_back("-m"); 46 proj_name = "Spherical Mercator"; 47 srid = "3857"; 48 } 49 50 #ifdef HAVE_GENERIC_PROJ 51 SECTION("Latlong with -E option") 52 { 53 proj_name = "Latlong"; 54 srid = "4326"; 55 option_params.push_back("-E"); 56 option_params.push_back(srid); 57 } 58 59 SECTION("Mercator with -E option") 60 { 61 proj_name = "Spherical Mercator"; 62 srid = "3857"; 63 option_params.push_back("-E"); 64 option_params.push_back(srid); 65 } 66 67 SECTION("Arbitrary projection with -E option") 68 { 69 srid = "32632"; 70 option_params.push_back("-E"); 71 option_params.push_back(srid); 72 } 73 #endif 74 75 option_params.push_back("foo"); 76 77 options_t options{(int)option_params.size(), (char **)option_params.data()}; 78 79 if (!proj_name.empty()) { 80 CHECK(options.projection->target_desc() == proj_name); 81 } 82 83 db.run_import(options, "n1 Tamenity=bar x0 y0"); 84 85 auto conn = db.connect(); 86 87 CHECK(conn.result_as_string( 88 "SELECT Find_SRID('public', 'planet_osm_roads', 'way')") == srid); 89 } 90