Initial implementation of new proj7 APIs support

This commit is contained in:
Artem Pavlenko 2021-01-15 15:21:09 +00:00
parent bec509d5b8
commit 88241b32ee
20 changed files with 226 additions and 273 deletions

View file

@ -1,6 +1,6 @@
# This file is part of Mapnik (c++ mapping toolkit)
#
# Copyright (C) 2017 Artem Pavlenko
# Copyright (C) 2021 Artem Pavlenko
#
# Mapnik is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@ -79,7 +79,7 @@ SCONF_TEMP_DIR = '.sconf_temp'
BOOST_SEARCH_PREFIXES = ['/usr/local','/opt/local','/sw','/usr',]
BOOST_MIN_VERSION = '1.61'
#CAIRO_MIN_VERSION = '1.8.0'
PROJ_MIN_VERSION = (7, 2, 0)
HARFBUZZ_MIN_VERSION = (0, 9, 34)
HARFBUZZ_MIN_VERSION_STRING = "%s.%s.%s" % HARFBUZZ_MIN_VERSION
@ -92,7 +92,7 @@ pretty_dep_names = {
'gdal':'GDAL C++ library | configured using gdal-config program | try setting GDAL_CONFIG SCons option | more info: https://github.com/mapnik/mapnik/wiki/GDAL',
'ogr':'OGR-enabled GDAL C++ Library | configured using gdal-config program | try setting GDAL_CONFIG SCons option | more info: https://github.com/mapnik/mapnik/wiki/OGR',
'cairo':'Cairo C library | configured using pkg-config | try setting PKG_CONFIG_PATH SCons option',
'proj':'Proj.4 C Projections library | configure with PROJ_LIBS & PROJ_INCLUDES | more info: http://trac.osgeo.org/proj/',
'proj':'Proj C Projections library | configure with PROJ_LIBS & PROJ_INCLUDES | more info: http://trac.osgeo.org/proj/',
'pg':'Postgres C Library required for PostGIS plugin | configure with pg_config program or configure with PG_LIBS & PG_INCLUDES | more info: https://github.com/mapnik/mapnik/wiki/PostGIS',
'sqlite3':'SQLite3 C Library | configure with SQLITE_LIBS & SQLITE_INCLUDES | more info: https://github.com/mapnik/mapnik/wiki/SQLite',
'jpeg':'JPEG C library | configure with JPEG_LIBS & JPEG_INCLUDES',
@ -116,7 +116,7 @@ pretty_dep_names = {
'boost_regex_icu':'libboost_regex built with optional ICU unicode support is needed for unicode regex support in mapnik.',
'sqlite_rtree':'The SQLite plugin requires libsqlite3 built with RTREE support (-DSQLITE_ENABLE_RTREE=1)',
'pgsql2sqlite_rtree':'The pgsql2sqlite program requires libsqlite3 built with RTREE support (-DSQLITE_ENABLE_RTREE=1)',
'PROJ_LIB':'The directory where proj4 stores its data files. Must exist for proj4 to work correctly',
'PROJ_LIB':'The directory where proj stores its data files. Must exist for proj to work correctly',
'GDAL_DATA':'The directory where GDAL stores its data files. Must exist for GDAL to work correctly',
'ICU_DATA':'The directory where icu stores its data files. If ICU reports a path, it must exist. ICU can also be built without .dat files and in that case this path is empty'
}
@ -422,7 +422,7 @@ opts.AddVariables(
BoolVariable('WEBP', 'Build Mapnik with WEBP read', 'True'),
PathVariable('WEBP_INCLUDES', 'Search path for libwebp include files', '/usr/include', PathVariable.PathAccept),
PathVariable('WEBP_LIBS','Search path for libwebp library files','/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept),
BoolVariable('PROJ', 'Build Mapnik with proj4 support to enable transformations between many different projections', 'True'),
BoolVariable('PROJ', 'Build Mapnik with proj support to enable transformations between many different projections', 'True'),
PathVariable('PROJ_INCLUDES', 'Search path for PROJ.4 include files', '/usr/include', PathVariable.PathAccept),
PathVariable('PROJ_LIBS', 'Search path for PROJ.4 library files', '/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept),
('PG_INCLUDES', 'Search path for libpq (postgres client) include files', ''),
@ -940,51 +940,40 @@ def CheckProjData(context, silent=False):
context.Message('Checking for PROJ_LIB directory...')
ret, out = context.TryRun("""
// This is narly, could eventually be replaced using https://github.com/OSGeo/proj.4/pull/551]
#include <proj_api.h>
#include <proj.h>
#include <iostream>
#include <cstring>
#include <sstream>
#include <vector>
#include <string>
#include <fstream>
static void my_proj4_logger(void * user_data, int /*level*/, const char * msg)
std::vector<std::string> split_searchpath(std::string const& paths)
{
std::string* posMsg = static_cast<std::string*>(user_data);
*posMsg += msg;
std::vector<std::string> output;
std::stringstream ss(paths);
std::string path;
for( std::string path;std::getline(ss, path, ':');)
{
output.push_back(path);
}
return output;
}
// https://github.com/OSGeo/gdal/blob/ddbf6d39aa4b005a77ca4f27c2d61a3214f336f8/gdal/alg/gdalapplyverticalshiftgrid.cpp#L616-L633
std::string find_proj_path(const char * pszFilename) {
std::string osMsg;
std::string osFilename;
projCtx ctx = pj_ctx_alloc();
pj_ctx_set_app_data(ctx, &osMsg);
pj_ctx_set_debug(ctx, PJ_LOG_DEBUG_MAJOR);
pj_ctx_set_logger(ctx, my_proj4_logger);
PAFile f = pj_open_lib(ctx, pszFilename, "rb");
if( f )
int main()
{
PJ_INFO info = proj_info();
std::string result = info.searchpath;
for (auto path : split_searchpath(result))
{
pj_ctx_fclose(ctx, f);
std::ifstream file(path + "/proj.db");
if (file)
{
std::cout << path;
return 0;
}
}
size_t nPos = osMsg.find("fopen(");
if( nPos != std::string::npos )
{
osFilename = osMsg.substr(nPos + strlen("fopen("));
nPos = osFilename.find(")");
if( nPos != std::string::npos )
osFilename = osFilename.substr(0, nPos);
}
pj_ctx_free(ctx);
return osFilename;
}
int main() {
std::string result = find_proj_path(" ");
std::cout << result;
if (result.empty()) {
return -1;
}
return 0;
return -1;
}
""", '.cpp')
@ -992,7 +981,7 @@ int main() {
if silent:
context.did_show_result=1
if ret:
context.Result('pj_open_lib returned %s' % value)
context.Result('proj_info.searchpath returned %s' % value)
else:
context.Result('Failed to detect (mapnik-config will have null value)')
return value
@ -1565,7 +1554,7 @@ if not preconfigured:
env['SKIPPED_DEPS'].append('jpeg')
if env['PROJ']:
OPTIONAL_LIBSHEADERS.append(['proj', 'proj_api.h', False,'C','-DMAPNIK_USE_PROJ4'])
OPTIONAL_LIBSHEADERS.append(['proj', 'proj.h', False,'C','-DMAPNIK_USE_PROJ'])
inc_path = env['%s_INCLUDES' % 'PROJ']
lib_path = env['%s_LIBS' % 'PROJ']
env.AppendUnique(CPPPATH = fix_path(inc_path))

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]>
<Map
srs="+init=epsg:4326"
srs="epsg:4326"
background-color="#dfd8c9">
<Style name="style">
@ -10,7 +10,7 @@
</Rule>
</Style>
<Layer name="layer"
srs="+init=epsg:4326">
srs="epsg:4326">
<StyleName>style</StyleName>
<Datasource>
<Parameter name="file">./valid.geotiff.tif</Parameter>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]>
<Map
srs="+init=epsg:4326"
srs="epsg:4326"
background-color="#dfd8c9">
<Style name="style">
@ -10,7 +10,7 @@
</Rule>
</Style>
<Layer name="layer"
srs="+init=epsg:4326">
srs="epsg:4326">
<StyleName>style</StyleName>
<Datasource>
<Parameter name="file">./valid.geotiff.tif</Parameter>

View file

@ -11,7 +11,7 @@
#include <mapnik/feature_type_style.hpp>
#include <memory>
class test : public benchmark::test_case
{
public:
@ -24,7 +24,7 @@ public:
}
bool operator()() const
{
mapnik::Map m(256,256,"+init=epsg:3857");
mapnik::Map m(256,256,"epsg:3857");
mapnik::parameters params;
params["type"]="memory";

View file

@ -51,7 +51,7 @@ void render(mapnik::geometry::multi_polygon<double> const& geom,
agg::pixfmt_rgba32_plain pixf(buf);
ren_base renb(pixf);
renderer ren(renb);
mapnik::proj_transform prj_trans(mapnik::projection("+init=epsg:4326"),mapnik::projection("+init=epsg:4326"));
mapnik::proj_transform prj_trans(mapnik::projection("epsg:4326"),mapnik::projection("epsg:4326"));
ren.color(agg::rgba8(127,127,127,255));
agg::rasterizer_scanline_aa<> ras;
for (auto const& poly : geom)

View file

@ -56,13 +56,13 @@ public:
}
};
// echo -180 -60 | cs2cs -f "%.10f" +init=epsg:4326 +to +init=epsg:3857
// echo -180 -60 | cs2cs -f "%.10f" epsg:4326 +to epsg:3857
int main(int argc, char** argv)
{
mapnik::box2d<double> from(-180,-80,180,80);
mapnik::box2d<double> to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316);
std::string from_str("+init=epsg:4326");
std::string to_str("+init=epsg:3857");
std::string from_str("epsg:4326");
std::string to_str("epsg:3857");
std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over");
return benchmark::sequencer(argc, argv)

View file

@ -42,7 +42,7 @@ using datasource_ptr = std::shared_ptr<datasource>;
* @brief A Mapnik map layer.
*
* Create a layer with a named string and, optionally, an srs string either
* with a Proj.4 epsg code ('+init=epsg:<code>') or with a Proj.4 literal
* with a Proj.4 epsg code ('epsg:<code>') or with a Proj.4 literal
* ('+proj=<literal>'). If no srs is specified it will default to
* '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
*/

View file

@ -27,12 +27,12 @@
#include <mapnik/config.hpp>
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/geometry/point.hpp>
#include <mapnik/projection.hpp>
// stl
#include <vector>
namespace mapnik {
class projection;
template <typename T> class box2d;
class MAPNIK_DECL proj_transform : private util::noncopyable
@ -40,7 +40,7 @@ class MAPNIK_DECL proj_transform : private util::noncopyable
public:
proj_transform(projection const& source,
projection const& dest);
~proj_transform();
bool equal() const;
bool is_known() const;
bool forward (double& x, double& y , double& z) const;
@ -59,6 +59,8 @@ public:
mapnik::projection const& dest() const;
private:
PJ_CONTEXT* ctx_ = nullptr;
PJ* transform_ = nullptr;
projection const& source_;
projection const& dest_;
bool is_source_longlat_;

View file

@ -37,6 +37,13 @@ MAPNIK_DISABLE_WARNING_POP
#include <string>
#include <stdexcept>
// fwd decl
struct projCtx_t;
struct PJconsts;
using PJ_CONTEXT = struct projCtx_t;
using PJ = struct PJconsts;
namespace mapnik {
class proj_init_error : public std::runtime_error
@ -66,7 +73,7 @@ public:
void forward(double & x, double & y) const;
void inverse(double & x,double & y) const;
std::string expanded() const;
void init_proj4() const;
void init_proj() const;
private:
void swap (projection& rhs);
@ -75,8 +82,8 @@ private:
std::string params_;
bool defer_proj_init_;
mutable bool is_geographic_;
mutable void * proj_;
mutable void * proj_ctx_;
mutable PJ * proj_;
mutable PJ_CONTEXT * proj_ctx_;
};
template <typename charT, typename traits>

View file

@ -76,7 +76,7 @@ if '-DHAVE_PNG' in env['CPPDEFINES']:
lib_env['LIBS'].append('png')
enabled_imaging_libraries.append('png_reader.cpp')
if '-DMAPNIK_USE_PROJ4' in env['CPPDEFINES']:
if '-DMAPNIK_USE_PROJ' in env['CPPDEFINES']:
lib_env['LIBS'].append('proj')
if '-DHAVE_TIFF' in env['CPPDEFINES']:

View file

@ -32,9 +32,9 @@
// boost
#include <boost/geometry/algorithms/envelope.hpp>
#ifdef MAPNIK_USE_PROJ4
// proj4
#include <proj_api.h>
#ifdef MAPNIK_USE_PROJ
// proj
#include <proj.h>
#endif
// stl
@ -126,16 +126,44 @@ proj_transform::proj_transform(projection const& source,
}
if (!known_trans)
{
#ifdef MAPNIK_USE_PROJ4
source_.init_proj4();
dest_.init_proj4();
#ifdef MAPNIK_USE_PROJ
transform_ = proj_create_crs_to_crs(ctx_,
source_.params().c_str(),
dest_.params().c_str(), nullptr);
if (transform_ == nullptr)
{
throw std::runtime_error(std::string("Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ): '") + source_.params() + "'->'" + dest_.params() + "'");
}
PJ* transform_gis = proj_normalize_for_visualization(ctx_, transform_);
if (transform_gis == nullptr)
{
throw std::runtime_error(std::string("Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ): '") + source_.params() + "'->'" + dest_.params() + "'");
}
proj_destroy(transform_);
transform_ = transform_gis;
#else
throw std::runtime_error(std::string("Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ4): '") + source_.params() + "'->'" + dest_.params() + "'");
throw std::runtime_error(std::string("Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ): '") + source_.params() + "'->'" + dest_.params() + "'");
#endif
}
}
}
proj_transform::~proj_transform()
{
#ifdef MAPNIK_USE_PROJ
if (transform_)
{
proj_destroy(transform_);
transform_ = nullptr;
}
if (ctx_)
{
proj_context_destroy(ctx_);
ctx_ = nullptr;
}
#endif
}
bool proj_transform::equal() const
{
return is_source_equal_dest_;
@ -189,7 +217,6 @@ unsigned int proj_transform::forward (std::vector<geometry::point<double>> & ls)
bool proj_transform::forward (double * x, double * y , double * z, int point_count, int offset) const
{
if (is_source_equal_dest_)
return true;
@ -202,37 +229,14 @@ bool proj_transform::forward (double * x, double * y , double * z, int point_cou
return merc2lonlat(x, y, point_count, offset);
}
#ifdef MAPNIK_USE_PROJ4
if (is_source_longlat_)
{
int i;
for(i=0; i<point_count; i++) {
x[i*offset] *= DEG_TO_RAD;
y[i*offset] *= DEG_TO_RAD;
}
}
if (pj_transform( source_.proj_, dest_.proj_, point_count,
offset, x,y,z) != 0)
{
#ifdef MAPNIK_USE_PROJ
if (proj_trans_generic(transform_, PJ_FWD,
x, offset * sizeof(double), point_count,
y, offset * sizeof(double), point_count,
z, offset * sizeof(double), point_count,
0, 0, 0) != point_count)
return false;
}
for(int j=0; j<point_count; j++) {
if (x[j] == HUGE_VAL || y[j] == HUGE_VAL)
{
return false;
}
}
if (is_dest_longlat_)
{
int i;
for(i=0; i<point_count; i++) {
x[i*offset] *= RAD_TO_DEG;
y[i*offset] *= RAD_TO_DEG;
}
}
#endif
return true;
}
@ -251,38 +255,13 @@ bool proj_transform::backward (double * x, double * y , double * z, int point_co
return lonlat2merc(x, y, point_count, offset);
}
#ifdef MAPNIK_USE_PROJ4
if (is_dest_longlat_)
{
for (int i = 0; i < point_count; ++i)
{
x[i * offset] *= DEG_TO_RAD;
y[i * offset] *= DEG_TO_RAD;
}
}
if (pj_transform(dest_.proj_, source_.proj_, point_count,
offset, x, y, z) != 0)
{
#ifdef MAPNIK_USE_PROJ
if (proj_trans_generic(transform_, PJ_INV,
x, offset * sizeof(double), point_count,
y, offset * sizeof(double), point_count,
z, offset * sizeof(double), point_count,
0, 0, 0) != point_count)
return false;
}
for (int j = 0; j < point_count; ++j)
{
if (x[j] == HUGE_VAL || y[j] == HUGE_VAL)
{
return false;
}
}
if (is_source_longlat_)
{
for (int i = 0; i < point_count; ++i)
{
x[i * offset] *= RAD_TO_DEG;
y[i * offset] *= RAD_TO_DEG;
}
}
#endif
return true;
}

View file

@ -28,23 +28,13 @@
// stl
#include <stdexcept>
#ifdef MAPNIK_USE_PROJ4
// proj4
#include <proj_api.h>
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
#include <mutex>
static std::mutex mutex_;
#ifdef _MSC_VER
#pragma NOTE(mapnik is building against < proj 4.8, reprojection will be faster if you use >= 4.8)
#else
#warning mapnik is building against < proj 4.8, reprojection will be faster if you use >= 4.8
#endif
#endif
#ifdef MAPNIK_USE_PROJ
// proj
#include <proj.h>
#endif
namespace mapnik {
projection::projection(std::string const& params, bool defer_proj_init)
: params_(params),
defer_proj_init_(defer_proj_init),
@ -58,13 +48,13 @@ projection::projection(std::string const& params, bool defer_proj_init)
}
else
{
#ifdef MAPNIK_USE_PROJ4
init_proj4();
#ifdef MAPNIK_USE_PROJ
init_proj();
#else
throw std::runtime_error(std::string("Cannot initialize projection '") + params_ + " ' without proj4 support (-DMAPNIK_USE_PROJ4)");
throw std::runtime_error(std::string("Cannot initialize projection '") + params_ + " ' without proj support (-DMAPNIK_USE_PROJ)");
#endif
}
if (!defer_proj_init_) init_proj4();
if (!defer_proj_init_) init_proj();
}
projection::projection(projection const& rhs)
@ -74,7 +64,7 @@ projection::projection(projection const& rhs)
proj_(nullptr),
proj_ctx_(nullptr)
{
if (!defer_proj_init_) init_proj4();
if (!defer_proj_init_) init_proj();
}
projection& projection::operator=(projection const& rhs)
@ -83,7 +73,7 @@ projection& projection::operator=(projection const& rhs)
swap(tmp);
proj_ctx_ = nullptr;
proj_ = nullptr;
if (!defer_proj_init_) init_proj4();
if (!defer_proj_init_) init_proj();
return *this;
}
@ -97,34 +87,35 @@ bool projection::operator!=(const projection& other) const
return !(*this == other);
}
void projection::init_proj4() const
void projection::init_proj() const
{
#ifdef MAPNIK_USE_PROJ4
#ifdef MAPNIK_USE_PROJ
if (!proj_)
{
#if PJ_VERSION >= 480
proj_ctx_ = pj_ctx_alloc();
proj_ = pj_init_plus_ctx(proj_ctx_, params_.c_str());
proj_ctx_ = proj_context_create();
proj_ = proj_create_crs_to_crs(proj_ctx_, "epsg:4326", params_.c_str(), nullptr);
if (!proj_ || !proj_ctx_)
{
if (proj_ctx_) {
pj_ctx_free(proj_ctx_);
proj_context_destroy(proj_ctx_);
proj_ctx_ = nullptr;
}
if (proj_) {
pj_free(proj_);
proj_destroy(proj_);
proj_ = nullptr;
}
throw proj_init_error(params_);
}
#else
#if defined(MAPNIK_THREADSAFE)
std::lock_guard<std::mutex> lock(mutex_);
#endif
proj_ = pj_init_plus(params_.c_str());
if (!proj_) throw proj_init_error(params_);
#endif
is_geographic_ = pj_is_latlong(proj_) ? true : false;
// determine the type of CRS
PJ* crs = proj_create(proj_ctx_, params_.c_str());
if (crs)
{
PJ_TYPE type = proj_get_type(crs);
is_geographic_ = (type == PJ_TYPE_GEOGRAPHIC_2D_CRS
||
type == PJ_TYPE_GEOGRAPHIC_3D_CRS) ? true : false;
}
proj_destroy(crs);
}
#endif
}
@ -151,82 +142,68 @@ std::string const& projection::params() const
void projection::forward(double & x, double &y ) const
{
#ifdef MAPNIK_USE_PROJ4
#ifdef MAPNIK_USE_PROJ
if (!proj_)
{
throw std::runtime_error("projection::forward not supported unless proj4 is initialized");
}
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
std::lock_guard<std::mutex> lock(mutex_);
#endif
projUV p;
p.u = x * DEG_TO_RAD;
p.v = y * DEG_TO_RAD;
p = pj_fwd(p,proj_);
x = p.u;
y = p.v;
if (is_geographic_)
{
x *=RAD_TO_DEG;
y *=RAD_TO_DEG;
throw std::runtime_error("projection::forward not supported unless proj is initialized");
}
PJ_COORD coord;
coord.lpzt.z = 0.0;
coord.lpzt.t = HUGE_VAL;
coord.lpzt.lam = x;
coord.lpzt.phi = y;
PJ_COORD coord_out = proj_trans(proj_, PJ_FWD, coord);
x = coord_out.xy.x;
y = coord_out.xy.y;
#else
throw std::runtime_error("projection::forward not supported without proj4 support (-DMAPNIK_USE_PROJ4)");
throw std::runtime_error("projection::forward not supported without proj support (-DMAPNIK_USE_PROJ)");
#endif
}
void projection::inverse(double & x,double & y) const
{
#ifdef MAPNIK_USE_PROJ4
#ifdef MAPNIK_USE_PROJ
if (!proj_)
{
throw std::runtime_error("projection::inverse not supported unless proj4 is initialized");
throw std::runtime_error("projection::forward not supported unless proj is initialized");
}
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
std::lock_guard<std::mutex> lock(mutex_);
#endif
if (is_geographic_)
{
x *=DEG_TO_RAD;
y *=DEG_TO_RAD;
}
projUV p;
p.u = x;
p.v = y;
p = pj_inv(p,proj_);
x = RAD_TO_DEG * p.u;
y = RAD_TO_DEG * p.v;
PJ_COORD coord;
coord.xyzt.z = 0.0;
coord.xyzt.t = HUGE_VAL;
coord.xyzt.x = x;
coord.xyzt.y = y;
PJ_COORD coord_out = proj_trans(proj_, PJ_INV, coord);
x = coord_out.xy.x;
y = coord_out.xy.y;
#else
throw std::runtime_error("projection::inverse not supported without proj4 support (-DMAPNIK_USE_PROJ4)");
throw std::runtime_error("projection::inverse not supported without proj support (-DMAPNIK_USE_PROJ)");
#endif
}
projection::~projection()
{
#ifdef MAPNIK_USE_PROJ4
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
std::lock_guard<std::mutex> lock(mutex_);
#endif
#ifdef MAPNIK_USE_PROJ
if (proj_)
{
pj_free(proj_);
proj_destroy(proj_);
proj_ = nullptr;
}
#if PJ_VERSION >= 480
if (proj_ctx_)
{
pj_ctx_free(proj_ctx_);
proj_context_destroy(proj_ctx_);
proj_ctx_ = nullptr;
}
#endif
#endif
}
std::string projection::expanded() const
{
#ifdef MAPNIK_USE_PROJ4
if (proj_) return mapnik::util::trim_copy(pj_get_def( proj_, 0 ));
#ifdef MAPNIK_USE_PROJ
if (proj_)
{
PJ_PROJ_INFO info = proj_pj_info(proj_);
return mapnik::util::trim_copy(info.definition);
}
#endif
return params_;
}

View file

@ -51,11 +51,11 @@ static const char * well_known_srs_strings[] = {
boost::optional<well_known_srs_e> is_well_known_srs(std::string const& srs)
{
if (srs == "+init=epsg:4326" || srs == MAPNIK_LONGLAT_PROJ)
if (srs == "epsg:4326" || srs == MAPNIK_LONGLAT_PROJ)
{
return boost::optional<well_known_srs_e>(mapnik::WGS_84);
}
else if (srs == "+init=epsg:3857" || srs == MAPNIK_GMERC_PROJ)
else if (srs == "epsg:3857" || srs == MAPNIK_GMERC_PROJ)
{
return boost::optional<well_known_srs_e>(mapnik::G_MERC);
}
@ -65,11 +65,11 @@ boost::optional<well_known_srs_e> is_well_known_srs(std::string const& srs)
boost::optional<bool> is_known_geographic(std::string const& srs)
{
std::string trimmed = util::trim_copy(srs);
if (trimmed == "+init=epsg:3857")
if (trimmed == "epsg:3857")
{
return boost::optional<bool>(false);
}
else if (trimmed == "+init=epsg:4326")
else if (trimmed == "epsg:4326")
{
return boost::optional<bool>(true);
}

@ -1 +1 @@
Subproject commit c67cf11850d65e963e6103b6141f1eca67667aa2
Subproject commit 004b170698a826de599e42678a27868e861e595e

@ -1 +1 @@
Subproject commit bacfd251da550fa82ea56f6710dc6f85431480c2
Subproject commit d0072a38390375794be2804b65e36982b4e50711

View file

@ -1,4 +1,3 @@
#include "catch.hpp"
#include <iostream>
@ -25,7 +24,7 @@ TEST_CASE("exceptions") {
SECTION("handling") {
try {
mapnik::projection srs("foo");
mapnik::projection srs("FAIL");
// to avoid unused variable warning
srs.params();
REQUIRE(false);
@ -38,7 +37,7 @@ SECTION("handling") {
mapnik::projection srs("+proj=longlat foo",true);
REQUIRE(srs.is_geographic());
REQUIRE(true);
srs.init_proj4();
srs.init_proj();
// oddly init_proj4 does not throw with old proj/ubuntu precise
//REQUIRE(false);
} catch (...) {

View file

@ -11,8 +11,8 @@ TEST_CASE("geometry reprojection") {
SECTION("test_projection_4326_3857 - Empty Geometry Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans(source, dest);
{
geometry_empty geom;
@ -37,8 +37,8 @@ SECTION("test_projection_4326_3857 - Empty Geometry Object") {
SECTION("test_projection_4326_3857 - Empty Geometry in Geometry Variant") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans(source, dest);
{
geometry<double> geom = geometry_empty();
@ -66,8 +66,8 @@ SECTION("test_projection_4326_3857 - Empty Geometry in Geometry Variant") {
SECTION("test_projection_4326_3857 - Point Geometry Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
point<double> geom1(-97.552175, 35.522895);
@ -119,8 +119,8 @@ SECTION("test_projection_4326_3857 - Point Geometry Object") {
SECTION("test_projection_4326_3857 - Point Geometry Variant Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
double x1 = -97.552175;
@ -176,8 +176,8 @@ SECTION("test_projection_4326_3857 - Point Geometry Variant Object") {
SECTION("test_projection_4326_3857 - Line_String Geometry Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
line_string<double> geom1;
@ -241,8 +241,8 @@ SECTION("test_projection_4326_3857 - Line_String Geometry Object") {
SECTION("test_projection_4326_3857 - Line_String Geometry Variant Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
line_string<double> geom1_;
@ -316,8 +316,8 @@ SECTION("test_projection_4326_3857 - Line_String Geometry Variant Object") {
SECTION("test_projection_4326_3857 - Polygon Geometry Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1;
@ -411,8 +411,8 @@ SECTION("test_projection_4326_3857 - Polygon Geometry Object") {
SECTION("test_projection_4326_3857 - Polygon Geometry Variant Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1_;
@ -503,8 +503,8 @@ SECTION("test_projection_4326_3857 - Polygon Geometry Variant Object") {
SECTION("test_projection_4326_3857 - Multi_Point Geometry Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
multi_point<double> geom1;
@ -568,8 +568,8 @@ SECTION("test_projection_4326_3857 - Multi_Point Geometry Object") {
SECTION("test_projection_4326_3857 - Multi_Point Geometry Variant Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
multi_point<double> geom1_;
@ -643,8 +643,8 @@ SECTION("test_projection_4326_3857 - Multi_Point Geometry Variant Object") {
SECTION("test_projection_4326_3857 - Multi_Line_String Geometry Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
line_string<double> geom1a;
@ -720,8 +720,8 @@ SECTION("test_projection_4326_3857 - Multi_Line_String Geometry Object") {
SECTION("test_projection_4326_3857 - Multi_Line_String Geometry Variant Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
line_string<double> geom1a_;
@ -799,8 +799,8 @@ SECTION("test_projection_4326_3857 - Multi_Line_String Geometry Variant Object")
SECTION("test_projection_4326_3857 - Multi_Polygon Geometry Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1a;
@ -898,8 +898,8 @@ SECTION("test_projection_4326_3857 - Multi_Polygon Geometry Object") {
SECTION("test_projection_4326_3857 - Multi_Polygon Geometry Variant Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1a_;
@ -993,8 +993,8 @@ SECTION("test_projection_4326_3857 - Multi_Polygon Geometry Variant Object") {
SECTION("test_projection_4326_3857 - Geometry Collection Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1a;
@ -1092,8 +1092,8 @@ SECTION("test_projection_4326_3857 - Geometry Collection Object") {
SECTION("test_projection_4326_3857 - Geometry Collection Variant Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
polygon<double> geom1a_;
@ -1187,8 +1187,8 @@ SECTION("test_projection_4326_3857 - Geometry Collection Variant Object") {
SECTION("test_projection_4269_3857 - Line_String Geometry Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4269");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4269");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
line_string<double> geom1;
@ -1252,8 +1252,8 @@ SECTION("test_projection_4269_3857 - Line_String Geometry Object") {
SECTION("test_projection_4269_3857 - Point Geometry Object") {
using namespace mapnik::geometry;
mapnik::projection source("+init=epsg:4269");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4269");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans1(source, dest);
mapnik::proj_transform proj_trans2(dest, source);
point<double> geom1(-97.552175, 35.522895);

View file

@ -18,8 +18,8 @@ SECTION("proj and view strategy") {
mapnik::view_transform vt(256, 256, e);
mapnik::view_strategy vs(vt);
mapnik::unview_strategy uvs(vt);
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::projection source("epsg:4326");
mapnik::projection dest("epsg:3857");
mapnik::proj_transform proj_trans(source, dest);
mapnik::proj_transform proj_trans_rev(dest, source);
mapnik::proj_strategy ps(proj_trans);

View file

@ -15,8 +15,8 @@ TEST_CASE("projection transform")
SECTION("Test bounding box transforms - 4326 to 3857")
{
mapnik::projection proj_4326("+init=epsg:4326");
mapnik::projection proj_3857("+init=epsg:3857");
mapnik::projection proj_4326("epsg:4326");
mapnik::projection proj_3857("epsg:3857");
mapnik::proj_transform prj_trans(proj_4326, proj_3857);
double minx = -45.0;
@ -48,8 +48,8 @@ SECTION("Test bounding box transforms - 4326 to 3857")
#if defined(MAPNIK_USE_PROJ4) && PJ_VERSION >= 480
SECTION("test pj_transform failure behavior")
{
mapnik::projection proj_4269("+init=epsg:4269");
mapnik::projection proj_3857("+init=epsg:3857");
mapnik::projection proj_4269("epsg:4269");
mapnik::projection proj_3857("epsg:3857");
mapnik::proj_transform prj_trans(proj_4269, proj_3857);
mapnik::proj_transform prj_trans2(proj_3857, proj_4269);
@ -125,8 +125,8 @@ SECTION("test pj_transform failure behavior")
// Github Issue https://github.com/mapnik/mapnik/issues/2648
SECTION("Test proj antimeridian bbox")
{
mapnik::projection prj_geog("+init=epsg:4326");
mapnik::projection prj_proj("+init=epsg:2193");
mapnik::projection prj_geog("epsg:4326");
mapnik::projection prj_proj("epsg:2193");
mapnik::proj_transform prj_trans_fwd(prj_proj, prj_geog);
mapnik::proj_transform prj_trans_rev(prj_geog, prj_proj);
@ -134,7 +134,7 @@ SECTION("Test proj antimeridian bbox")
// reference values taken from proj4 command line tool:
// (non-corner points assume PROJ_ENVELOPE_POINTS == 20)
//
// cs2cs -Ef %.10f +init=epsg:2193 +to +init=epsg:4326 <<END
// cs2cs -Ef %.10f epsg:2193 +to epsg:4326 <<END
// 2105800 3087000 # left-most
// 1495200 3087000 # bottom-most
// 2105800 7173000 # right-most
@ -171,7 +171,7 @@ SECTION("Test proj antimeridian bbox")
// reference values taken from proj4 command line tool:
//
// cs2cs -Ef %.10f +init=epsg:2193 +to +init=epsg:4326 <<END
// cs2cs -Ef %.10f epsg:2193 +to epsg:4326 <<END
// 274000 3087000 # left-most
// 276000 3087000 # bottom-most
// 276000 7173000 # right-most
@ -208,13 +208,13 @@ SECTION("Test proj antimeridian bbox")
SECTION("proj_transform of coordinate arrays with stride > 1")
{
mapnik::projection const proj_4326("+init=epsg:4326");
mapnik::projection const proj_3857("+init=epsg:3857");
mapnik::projection const proj_2193("+init=epsg:2193");
mapnik::projection const proj_4326("epsg:4326");
mapnik::projection const proj_3857("epsg:3857");
mapnik::projection const proj_2193("epsg:2193");
SECTION("lonlat <-> Web Mercator")
{
// cs2cs -Ef %.10f +init=epsg:4326 +to +init=epsg:3857 <<END
// cs2cs -Ef %.10f epsg:4326 +to epsg:3857 <<END
// 170.142139 -43.595056
// 175.566667 -39.283333
// END
@ -245,7 +245,7 @@ SECTION("proj_transform of coordinate arrays with stride > 1")
#ifdef MAPNIK_USE_PROJ4
SECTION("lonlat <-> New Zealand Transverse Mercator 2000")
{
// cs2cs -Ef %.10f +init=epsg:4326 +to +init=epsg:2193 <<END
// cs2cs -Ef %.10f epsg:4326 +to epsg:2193 <<END
// 170.142139 -43.595056
// 175.566667 -39.283333
// END

View file

@ -26,8 +26,8 @@ SECTION("polygon closing - epsg 2330") {
va_type va(g);
mapnik::box2d<double> extent(16310607, 7704513, 16310621, 7704527);
mapnik::view_transform tr(512, 512, extent);
mapnik::projection proj1("+init=epsg:2330");
mapnik::projection proj2("+init=epsg:4326");
mapnik::projection proj1("epsg:2330");
mapnik::projection proj2("epsg:4326");
mapnik::proj_transform prj_trans(proj1, proj2);
path_type path(tr, va, prj_trans);
@ -78,8 +78,8 @@ SECTION("polygon closing - epsg 32633") {
va_type va(g);
mapnik::box2d<double> extent(166022, 0, 833978, 9329005);
mapnik::view_transform tr(512, 512, extent);
mapnik::projection proj1("+init=epsg:32633");
mapnik::projection proj2("+init=epsg:4326");
mapnik::projection proj1("epsg:32633");
mapnik::projection proj2("epsg:4326");
mapnik::proj_transform prj_trans(proj1, proj2);
path_type path(tr, va, prj_trans);