aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2020-11-26 20:58:01 +0100
committerGitHub <noreply@github.com>2020-11-26 20:58:01 +0100
commit3cb26a406a7e1a964f5f3b5caf3c624222664fb2 (patch)
tree414dad90bd94170f6e619197b9a47bfca096d322
parentf5b3616bb03f8e52a5e5a23704d645492a662393 (diff)
parentd9205b9245388f23b65917a21ec72d6bec15d035 (diff)
downloadPROJ-3cb26a406a7e1a964f5f3b5caf3c624222664fb2.tar.gz
PROJ-3cb26a406a7e1a964f5f3b5caf3c624222664fb2.zip
Merge pull request #2403 from kbevers/remove-proj_api.h
Remove proj_api.h
-rw-r--r--docs/source/development/index.rst5
-rw-r--r--docs/source/development/reference/deprecated.rst270
-rw-r--r--docs/source/development/reference/index.rst1
-rwxr-xr-xscripts/cppcheck.sh2
-rw-r--r--scripts/reference_exported_symbols.txt127
-rw-r--r--src/4D_api.cpp48
-rw-r--r--src/Makefile.am8
-rw-r--r--src/aasincos.cpp8
-rw-r--r--src/apps/cct.cpp6
-rw-r--r--src/apps/cs2cs.cpp17
-rw-r--r--src/apps/emess.cpp6
-rw-r--r--src/apps/geod_set.cpp2
-rw-r--r--src/apps/gie.cpp8
-rw-r--r--src/apps/proj.cpp10
-rw-r--r--src/auth.cpp2
-rw-r--r--src/conversions/axisswap.cpp2
-rw-r--r--src/conversions/set.cpp2
-rw-r--r--src/conversions/unitconvert.cpp2
-rw-r--r--src/ctx.cpp163
-rw-r--r--src/datum_set.cpp8
-rw-r--r--src/dmstor.cpp6
-rw-r--r--src/ell_set.cpp46
-rw-r--r--src/errno.cpp18
-rw-r--r--src/fileapi.cpp240
-rw-r--r--src/filemanager.cpp145
-rw-r--r--src/gauss.cpp6
-rw-r--r--src/generic_inverse.cpp2
-rw-r--r--src/grids.cpp120
-rw-r--r--src/init.cpp70
-rw-r--r--src/initcache.cpp20
-rw-r--r--src/internal.cpp13
-rw-r--r--src/iso19111/c_api.cpp24
-rw-r--r--src/iso19111/datum.cpp5
-rw-r--r--src/iso19111/factory.cpp1
-rw-r--r--src/iso19111/io.cpp5
-rw-r--r--src/lib_proj.cmake5
-rw-r--r--src/log.cpp6
-rw-r--r--src/malloc.cpp138
-rw-r--r--src/mlfn.cpp4
-rw-r--r--src/mlfn.hpp4
-rw-r--r--src/mutex.cpp5
-rw-r--r--src/networkfilemanager.cpp6
-rw-r--r--src/param.cpp8
-rw-r--r--src/phi2.cpp6
-rw-r--r--src/pipeline.cpp12
-rw-r--r--src/pr_list.cpp8
-rw-r--r--src/proj.h10
-rw-r--r--src/proj_api.h227
-rw-r--r--src/proj_internal.h126
-rw-r--r--src/proj_mdist.cpp4
-rw-r--r--src/projections/adams.cpp2
-rw-r--r--src/projections/aea.cpp6
-rw-r--r--src/projections/aeqd.cpp4
-rw-r--r--src/projections/airy.cpp2
-rw-r--r--src/projections/aitoff.cpp6
-rw-r--r--src/projections/bacon.cpp6
-rw-r--r--src/projections/bertin1953.cpp2
-rw-r--r--src/projections/bipc.cpp2
-rw-r--r--src/projections/bonne.cpp4
-rw-r--r--src/projections/calcofi.cpp1
-rw-r--r--src/projections/cass.cpp4
-rw-r--r--src/projections/ccon.cpp4
-rw-r--r--src/projections/cea.cpp4
-rw-r--r--src/projections/chamb.cpp6
-rw-r--r--src/projections/col_urban.cpp2
-rw-r--r--src/projections/comill.cpp2
-rw-r--r--src/projections/eck3.cpp8
-rw-r--r--src/projections/eqc.cpp2
-rw-r--r--src/projections/eqdc.cpp4
-rw-r--r--src/projections/eqearth.cpp6
-rw-r--r--src/projections/fouc_s.cpp2
-rw-r--r--src/projections/geos.cpp2
-rw-r--r--src/projections/gn_sinu.cpp10
-rw-r--r--src/projections/gnom.cpp2
-rw-r--r--src/projections/goode.cpp6
-rw-r--r--src/projections/gstmerc.cpp2
-rw-r--r--src/projections/hammer.cpp2
-rw-r--r--src/projections/healpix.cpp14
-rw-r--r--src/projections/igh.cpp2
-rw-r--r--src/projections/igh_o.cpp2
-rw-r--r--src/projections/imw_p.cpp4
-rw-r--r--src/projections/isea.cpp2
-rw-r--r--src/projections/krovak.cpp4
-rw-r--r--src/projections/labrd.cpp2
-rw-r--r--src/projections/laea.cpp4
-rw-r--r--src/projections/lagrng.cpp2
-rw-r--r--src/projections/lcc.cpp2
-rw-r--r--src/projections/lcca.cpp4
-rw-r--r--src/projections/loxim.cpp2
-rw-r--r--src/projections/lsat.cpp2
-rw-r--r--src/projections/misrsom.cpp2
-rw-r--r--src/projections/mod_ster.cpp10
-rw-r--r--src/projections/moll.cpp6
-rw-r--r--src/projections/natearth.cpp2
-rw-r--r--src/projections/natearth2.cpp2
-rw-r--r--src/projections/nsper.cpp4
-rw-r--r--src/projections/ob_tran.cpp8
-rw-r--r--src/projections/ocea.cpp2
-rw-r--r--src/projections/oea.cpp2
-rw-r--r--src/projections/omerc.cpp2
-rw-r--r--src/projections/ortho.cpp4
-rw-r--r--src/projections/patterson.cpp2
-rw-r--r--src/projections/poly.cpp4
-rw-r--r--src/projections/putp3.cpp4
-rw-r--r--src/projections/putp4p.cpp4
-rw-r--r--src/projections/putp5.cpp4
-rw-r--r--src/projections/putp6.cpp4
-rw-r--r--src/projections/qsc.cpp2
-rw-r--r--src/projections/robin.cpp2
-rw-r--r--src/projections/rouss.cpp4
-rw-r--r--src/projections/rpoly.cpp2
-rw-r--r--src/projections/sch.cpp2
-rw-r--r--src/projections/sconics.cpp2
-rw-r--r--src/projections/somerc.cpp2
-rw-r--r--src/projections/stere.cpp4
-rw-r--r--src/projections/sterea.cpp4
-rw-r--r--src/projections/sts.cpp8
-rw-r--r--src/projections/tmerc.cpp10
-rw-r--r--src/projections/tpeqd.cpp2
-rw-r--r--src/projections/urm5.cpp2
-rw-r--r--src/projections/urmfps.cpp4
-rw-r--r--src/projections/vandg2.cpp4
-rw-r--r--src/projections/wag3.cpp2
-rw-r--r--src/projections/wink1.cpp2
-rw-r--r--src/projections/wink2.cpp2
-rw-r--r--src/strerrno.cpp13
-rw-r--r--src/tests/multistresstest.cpp172
-rw-r--r--src/tests/test228.cpp12
-rw-r--r--src/transform.cpp1850
-rw-r--r--src/transformations/affine.cpp2
-rw-r--r--src/transformations/helmert.cpp2
-rw-r--r--src/transformations/horner.cpp10
-rw-r--r--src/transformations/molodensky.cpp2
-rw-r--r--src/utils.cpp182
-rw-r--r--test/fuzzers/standard_fuzzer.cpp7
-rw-r--r--test/unit/CMakeLists.txt11
-rw-r--r--test/unit/Makefile.am10
-rw-r--r--test/unit/gie_self_tests.cpp2
-rw-r--r--test/unit/pj_phi2_test.cpp2
-rw-r--r--test/unit/pj_transform_test.cpp740
140 files changed, 669 insertions, 4610 deletions
diff --git a/docs/source/development/index.rst b/docs/source/development/index.rst
index 85c10c6d..f985279f 100644
--- a/docs/source/development/index.rst
+++ b/docs/source/development/index.rst
@@ -39,9 +39,8 @@ are maintained in a `separate git repository <https://github.com/OSGeo/proj-datu
.. attention::
The ``proj_api.h`` header and the functions related to it is
- considered deprecated from version 5.0.0 and onwards. The header will be
- removed from PROJ in version 7.0.0 scheduled for release March 1st
- 2020.
+ considered deprecated from version 5.0.0 and onwards. The header has been
+ removed in version 8.0.0 released March 1st 2021.
.. attention::
diff --git a/docs/source/development/reference/deprecated.rst b/docs/source/development/reference/deprecated.rst
deleted file mode 100644
index 19f43b41..00000000
--- a/docs/source/development/reference/deprecated.rst
+++ /dev/null
@@ -1,270 +0,0 @@
-.. _api:
-
-********************************************************************************
-Deprecated API
-********************************************************************************
-
-.. contents:: Contents
- :depth: 3
- :backlinks: none
-
-Introduction
-------------
-
-Procedure ``pj_init()`` selects and initializes a cartographic
-projection with its argument control parameters. ``argc`` is the number
-of elements in the array of control strings argv that each contain
-individual cartographic control keyword assignments (+ proj arguments).
-The list must contain at least the proj=projection and Earth’s radius or
-elliptical parameters. If the initialization of the projection is
-successful a valid address is returned otherwise a NULL value.
-
-The ``pj_init_plus()`` function operates similarly to ``pj_init()`` but
-takes a single string containing the definition, with each parameter
-prefixed with a plus sign. For example
-``+proj=utm +zone=11 +ellps=WGS84``.
-
-Once initialization is performed either forward or inverse projections
-can be performed with the returned value of ``pj_init()`` used as the
-argument proj. The argument structure projUV values u and v contain
-respective longitude and latitude or x and y. Latitude and longitude are
-in radians. If a projection operation fails, both elements of projUV are
-set to ``HUGE_VAL`` (defined in ``math.h``).
-
-Note: all projections have a forward mode, but some do not have an
-inverse projection. If the projection does not have an inverse the
-projPJ structure element inv will be ``NULL``.
-
-The ``pj_transform`` function may be used to transform points between
-the two provided coordinate systems. In addition to converting between
-cartographic projection coordinates and geographic coordinates, this
-function also takes care of datum shifts if possible between the source
-and destination coordinate system. Unlike ``pj_fwd()`` and ``pj_inv()``
-it is also allowable for the coordinate system definitions
-``(projPJ *)`` to be geographic coordinate systems (defined as
-``+proj=latlong``).
-The x, y and z arrays contain the input values of the points, and are replaced with the output values.
-The function returns zero on success, or the error number (also in ``pj_errno``)
-on failure.
-
-Memory associated with the projection may be freed with ``pj_free()``.
-
-Example
--------
-
-The following program reads latitude and longitude values in decimal
-degrees, performs Mercator projection with a Clarke 1866 ellipsoid and a
-33° latitude of true scale and prints the projected cartesian values in
-meters:
-
-.. code::
-
- #include <proj_api.h>
-
- main(int argc, char **argv) {
- projPJ pj_merc, pj_latlong;
- double x, y;
-
- if (!(pj_merc = pj_init_plus("+proj=merc +ellps=clrk66 +lat_ts=33")) )
- exit(1);
- if (!(pj_latlong = pj_init_plus("+proj=latlong +ellps=clrk66")) )
- exit(1);
- while (scanf("%lf %lf", &x, &y) == 2) {
- x *= DEG_TO_RAD;
- y *= DEG_TO_RAD;
- p = pj_transform(pj_latlong, pj_merc, 1, 1, &x, &y, NULL );
- printf("%.2f\t%.2f\n", x, y);
- }
- exit(0);
- }
-
-
-For this program, an input of ``-16 20.25`` would give a result of
-``-1495284.21 1920596.79``.
-
-API Functions
--------------
-
-pj_transform
-============
-
-::
-
- int pj_transform( projPJ srcdefn,
- projPJ dstdefn,
- long point_count,
- int point_offset,
- double *x,
- double *y,
- double *z );
-
-
-Transform the x/y/z points from the source coordinate system to the
-destination coordinate system.
-
-``srcdefn``: source (input) coordinate system.
-
-``dstdefn``: destination (output) coordinate system.
-
-``point_count``: the number of points to be processed (the size of the
-x/y/z arrays).
-
-``point_offset``: the step size from value to value (measured in
-doubles) within the x/y/z arrays - normally 1 for a packed array. May be
-used to operate on xyz interleaved point arrays.
-
-``x``/``y``/``z``: The array of X, Y and Z coordinate values passed as
-input, and modified in place for output. The Z may optionally be NULL.
-
-``return``: The return is zero on success, or a PROJ.4 error code.
-
-The ``pj_transform()`` function transforms the passed in list of points
-from the source coordinate system to the destination coordinate system.
-Note that geographic locations need to be passed in radians, not decimal
-degrees, and will be returned similarly. The ``z`` array may be passed
-as NULL if Z values are not available.
-
-If there is an overall failure, an error code will be returned from the
-function. If individual points fail to transform - for instance due to
-being over the horizon - then those x/y/z values will be set to
-``HUGE_VAL`` on return. Input values that are ``HUGE_VAL`` will not be
-transformed.
-
-
-pj_init_plus
-============
-
-::
-
- projPJ pj_init_plus(const char *definition);
-
-This function converts a string representation of a coordinate system
-definition into a projPJ object suitable for use with other API
-functions. On failure the function will return NULL and set pj_errno.
-The definition should be of the general form
-``+proj=tmerc +lon_0 +datum=WGS84``. Refer to PROJ.4 documentation and
-the :ref:`transformation` notes for additional detail.
-
-Coordinate system objects allocated with ``pj_init_plus()`` should be
-deallocated with ``pj_free()``.
-
-
-pj_free
-=======
-
-::
-
- void pj_free( projPJ pj );
-
-Frees all resources associated with pj.
-
-
-pj_is_latlong
-=============
-
-::
-
- int pj_is_latlong( projPJ pj );
-
-Returns TRUE if the passed coordinate system is geographic
-(``proj=latlong``).
-
-
-pj_is_geocent
-=============
-
-::
-
- int pj_is_geocent( projPJ pj );``
-
-Returns TRUE if the coordinate system is geocentric (``proj=geocent``).
-
-pj_get_def
-==========
-
-::
-
- char *pj_get_def( projPJ pj, int options);``
-
-Returns the PROJ.4 initialization string suitable for use with
-``pj_init_plus()`` that would produce this coordinate system, but with
-the definition expanded as much as possible (for instance ``+init=`` and
-``+datum=`` definitions).
-
-pj_latlong_from_proj
-====================
-
-::
-
- projPJ pj_latlong_from_proj( projPJ pj_in );``
-
-Returns a new coordinate system definition which is the geographic
-coordinate (lat/long) system underlying ``pj_in``.
-
-pj_set_finder
-==============
-
-::
-
- void pj_set_finder( const char *(*new_finder)(const char *) );``
-
-Install a custom function for finding init and grid shift files.
-
-pj_set_searchpath
-=================
-
-::
-
- void pj_set_searchpath ( int count, const char **path );``
-
-Set a list of directories to search for init and grid shift files.
-
-
-pj_deallocate_grids
-===================
-
-::
-
- void pj_deallocate_grids( void );``
-
-Frees all resources associated with loaded and cached datum shift grids.
-
-
-pj_strerrno
-===========
-
-::
-
- char *pj_strerrno( int );``
-
-Returns the error text associated with the passed in error code.
-
-pj_get_errno_ref
-================
-
-::
-
- int *pj_get_errno_ref( void );``
-
-Returns a pointer to the global pj\_errno error variable.
-
-pj_get_release
-==============
-
-::
-
- const char *pj_get_release( void );``
-
-Returns an internal string describing the release version.
-
-Obsolete Functions
-~~~~~~~~~~~~~~~~~~
-
-``XY pj_fwd( LP lp, PJ *P );``
-
-``LP pj_inv( XY xy, PJ *P );``
-
-``projPJ pj_init(int argc, char **argv);``
-
-.. _more info: pj_transform
-
diff --git a/docs/source/development/reference/index.rst b/docs/source/development/reference/index.rst
index 1d39b1d0..caa893c3 100644
--- a/docs/source/development/reference/index.rst
+++ b/docs/source/development/reference/index.rst
@@ -10,4 +10,3 @@ Reference
datatypes
functions
cpp/index.rst
- deprecated
diff --git a/scripts/cppcheck.sh b/scripts/cppcheck.sh
index 1cfd61b5..4e76db94 100755
--- a/scripts/cppcheck.sh
+++ b/scripts/cppcheck.sh
@@ -22,7 +22,7 @@ for dirname in ${TOPDIR}/src; do
echo "Running cppcheck on $dirname... (can be long)"
if ! cppcheck --inline-suppr --template='{file}:{line},{severity},{id},{message}' \
--enable=all --inconclusive --std=posix \
- -DCPPCHECK -D__cplusplus=201103L -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H -DNAN \
+ -DCPPCHECK -D__cplusplus=201103L -DNAN \
-I${TOPDIR}/src -I${TOPDIR}/include \
"$dirname" \
-j 8 >>${LOG_FILE} 2>&1 ; then
diff --git a/scripts/reference_exported_symbols.txt b/scripts/reference_exported_symbols.txt
index 8db49a95..8ea2c231 100644
--- a/scripts/reference_exported_symbols.txt
+++ b/scripts/reference_exported_symbols.txt
@@ -284,8 +284,8 @@ osgeo::proj::datum::VerticalReferenceFrame::create(osgeo::proj::util::PropertyMa
osgeo::proj::datum::VerticalReferenceFrame::realizationMethod() const
osgeo::proj::datum::VerticalReferenceFrame::~VerticalReferenceFrame()
osgeo::proj::File::~File()
-osgeo::proj::FileManager::exists(projCtx_t*, char const*)
-osgeo::proj::FileManager::open(projCtx_t*, char const*, osgeo::proj::FileAccess)
+osgeo::proj::FileManager::exists(pj_ctx*, char const*)
+osgeo::proj::FileManager::open(pj_ctx*, char const*, osgeo::proj::FileAccess)
osgeo::proj::File::read_line(unsigned long, bool&, bool&)
osgeo::proj::GenericShiftGrid::~GenericShiftGrid()
osgeo::proj::GenericShiftGrid::GenericShiftGrid(std::string const&, int, int, osgeo::proj::ExtentAndRes const&)
@@ -293,9 +293,9 @@ osgeo::proj::GenericShiftGrid::gridAt(double, double) const
osgeo::proj::GenericShiftGridSet::~GenericShiftGridSet()
osgeo::proj::GenericShiftGridSet::GenericShiftGridSet()
osgeo::proj::GenericShiftGridSet::gridAt(double, double) const
-osgeo::proj::GenericShiftGridSet::open(projCtx_t*, std::string const&)
-osgeo::proj::GenericShiftGridSet::reassign_context(projCtx_t*)
-osgeo::proj::GenericShiftGridSet::reopen(projCtx_t*)
+osgeo::proj::GenericShiftGridSet::open(pj_ctx*, std::string const&)
+osgeo::proj::GenericShiftGridSet::reassign_context(pj_ctx*)
+osgeo::proj::GenericShiftGridSet::reopen(pj_ctx*)
osgeo::proj::Grid::~Grid()
osgeo::proj::Grid::Grid(std::string const&, int, int, osgeo::proj::ExtentAndRes const&)
osgeo::proj::HorizontalShiftGrid::gridAt(double, double) const
@@ -304,9 +304,9 @@ osgeo::proj::HorizontalShiftGrid::HorizontalShiftGrid(std::string const&, int, i
osgeo::proj::HorizontalShiftGridSet::gridAt(double, double) const
osgeo::proj::HorizontalShiftGridSet::~HorizontalShiftGridSet()
osgeo::proj::HorizontalShiftGridSet::HorizontalShiftGridSet()
-osgeo::proj::HorizontalShiftGridSet::open(projCtx_t*, std::string const&)
-osgeo::proj::HorizontalShiftGridSet::reassign_context(projCtx_t*)
-osgeo::proj::HorizontalShiftGridSet::reopen(projCtx_t*)
+osgeo::proj::HorizontalShiftGridSet::open(pj_ctx*, std::string const&)
+osgeo::proj::HorizontalShiftGridSet::reassign_context(pj_ctx*)
+osgeo::proj::HorizontalShiftGridSet::reopen(pj_ctx*)
osgeo::proj::internal::ci_equal(std::string const&, char const*)
osgeo::proj::internal::ci_equal(std::string const&, std::string const&)
osgeo::proj::internal::ci_find(std::string const&, char const*)
@@ -351,9 +351,9 @@ osgeo::proj::io::AuthorityFactory::getUnitList() const
osgeo::proj::io::AuthorityFactory::identifyBodyFromSemiMajorAxis(double, double) const
osgeo::proj::io::AuthorityFactory::listAreaOfUseFromName(std::string const&, bool) const
osgeo::proj::io::AuthorityFactory::UnitInfo::UnitInfo()
-osgeo::proj::io::createFromUserInput(std::string const&, projCtx_t*)
+osgeo::proj::io::createFromUserInput(std::string const&, pj_ctx*)
osgeo::proj::io::createFromUserInput(std::string const&, std::shared_ptr<osgeo::proj::io::DatabaseContext> const&, bool)
-osgeo::proj::io::DatabaseContext::create(std::string const&, std::vector<std::string, std::allocator<std::string> > const&, projCtx_t*)
+osgeo::proj::io::DatabaseContext::create(std::string const&, std::vector<std::string, std::allocator<std::string> > const&, pj_ctx*)
osgeo::proj::io::DatabaseContext::create(void*)
osgeo::proj::io::DatabaseContext::~DatabaseContext()
osgeo::proj::io::DatabaseContext::getAuthorities() const
@@ -413,7 +413,7 @@ osgeo::proj::io::PROJStringFormatter::setUseApproxTMerc(bool)
osgeo::proj::io::PROJStringFormatter::startInversion()
osgeo::proj::io::PROJStringFormatter::stopInversion()
osgeo::proj::io::PROJStringFormatter::toString() const
-osgeo::proj::io::PROJStringParser::attachContext(projCtx_t*)
+osgeo::proj::io::PROJStringParser::attachContext(pj_ctx*)
osgeo::proj::io::PROJStringParser::attachDatabaseContext(std::shared_ptr<osgeo::proj::io::DatabaseContext> const&)
osgeo::proj::io::PROJStringParser::createFromPROJString(std::string const&)
osgeo::proj::io::PROJStringParser::~PROJStringParser()
@@ -734,90 +734,51 @@ osgeo::proj::util::UnsupportedOperationException::~UnsupportedOperationException
osgeo::proj::util::UnsupportedOperationException::UnsupportedOperationException(osgeo::proj::util::UnsupportedOperationException const&)
osgeo::proj::VerticalShiftGrid::gridAt(double, double) const
osgeo::proj::VerticalShiftGridSet::gridAt(double, double) const
-osgeo::proj::VerticalShiftGridSet::open(projCtx_t*, std::string const&)
-osgeo::proj::VerticalShiftGridSet::reassign_context(projCtx_t*)
-osgeo::proj::VerticalShiftGridSet::reopen(projCtx_t*)
+osgeo::proj::VerticalShiftGridSet::open(pj_ctx*, std::string const&)
+osgeo::proj::VerticalShiftGridSet::reassign_context(pj_ctx*)
+osgeo::proj::VerticalShiftGridSet::reopen(pj_ctx*)
osgeo::proj::VerticalShiftGridSet::~VerticalShiftGridSet()
osgeo::proj::VerticalShiftGridSet::VerticalShiftGridSet()
osgeo::proj::VerticalShiftGrid::~VerticalShiftGrid()
osgeo::proj::VerticalShiftGrid::VerticalShiftGrid(std::string const&, int, int, osgeo::proj::ExtentAndRes const&)
-pj_acquire_lock
+pj_acquire_lock()
pj_add_type_crs_if_needed(std::string const&)
-pj_apply_gridshift
pj_approx_2D_trans(PJconsts*, PJ_DIRECTION, PJ_COORD)
pj_approx_3D_trans(PJconsts*, PJ_DIRECTION, PJ_COORD)
pj_atof(char const*)
-pj_calloc
pj_chomp(char*)
-pj_cleanup_lock
-pj_clear_initcache
-pj_compare_datums
-pj_context_get_grid_cache_filename(projCtx_t*)
-pj_context_set_user_writable_directory(projCtx_t*, std::string const&)
-pj_ctx_alloc
-pj_ctx_fclose
-pj_ctx_fgets
-pj_ctx_fopen
-pj_ctx_fread
-pj_ctx_free
-pj_ctx_fseek
-pj_ctx_ftell
-pj_ctx_get_app_data
-pj_ctx_get_errno
-pj_ctx_get_fileapi
-pj_ctx_set_app_data
-pj_ctx_set_debug
-pj_ctx_set_errno
-pj_ctx_set_fileapi
-pj_ctx_set_logger
-pj_dalloc
-pj_datum_transform
-pj_dealloc
-pj_deallocate_grids
-pj_ell_set(projCtx_t*, ARG_list*, double*, double*)
-pj_find_file
-pj_free
-pj_fwd
-pj_fwd3d
-pj_geocentric_to_geodetic
-pj_geodetic_to_geocentric
-pj_get_ctx
+pj_cleanup_lock()
+pj_clear_initcache()
+pj_context_get_grid_cache_filename(pj_ctx*)
+pj_context_set_user_writable_directory(pj_ctx*, std::string const&)
+pj_ell_set(pj_ctx*, ARG_list*, double*, double*)
+pj_find_file(pj_ctx*, char const*, char*, unsigned long)
+pj_fwd3d(PJ_LPZ, PJconsts*)
+pj_fwd(PJ_LP, PJconsts*)
+pj_get_ctx(PJconsts*)
pj_get_datums_ref()
-pj_get_def
-pj_get_default_ctx
-pj_get_default_fileapi
-pj_get_default_searchpaths(projCtx_t*)
-pj_get_errno_ref
-pj_get_relative_share_proj(projCtx_t*)
-pj_get_release
-pj_get_spheroid_defn
-pj_has_inverse
-pj_init
-pj_init_ctx
-pj_init_plus
-pj_init_plus_ctx
-pj_inv
-pj_inv3d
-pj_is_geocent
-pj_is_latlong
-pj_latlong_from_proj
-pj_log
-pj_malloc
+pj_get_default_ctx()
+pj_get_default_searchpaths(pj_ctx*)
+pj_get_def(PJconsts*, int)
+pj_get_relative_share_proj(pj_ctx*)
+pj_get_release()
+pj_has_inverse(PJconsts*)
+pj_init_ctx(pj_ctx*, int, char**)
+pj_init(int, char**)
+pj_init_plus(char const*)
+pj_init_plus_ctx(pj_ctx*, char const*)
+pj_inv3d(PJ_XYZ, PJconsts*)
+pj_inv(PJ_XY, PJconsts*)
+pj_log(pj_ctx*, int, char const*, ...)
pj_mkparam(char const*)
-pj_open_lib
pj_param_exists(ARG_list*, char const*)
-pj_param(projCtx_t*, ARG_list*, char const*)
-pj_phi2(projCtx_t*, double, double)
-pj_pr_list
-pj_release_lock
-pj_set_ctx
-pj_set_finder
-pj_set_searchpath
+pj_param(pj_ctx*, ARG_list*, char const*)
+pj_phi2(pj_ctx*, double, double)
+pj_pr_list(PJconsts*)
+pj_release_lock()
pj_shrink(char*)
-pj_stderr_logger
-pj_strdup
-pj_strerrno
-pj_transform
+pj_stderr_logger(void*, int, char const*)
+pj_strdup(char const*)
proj_alter_id
proj_alter_name
proj_angular_input
@@ -852,7 +813,7 @@ proj_context_set_enable_network
proj_context_set_fileapi
proj_context_set_file_finder
proj_context_set_network_callbacks
-proj_context_set(PJconsts*, projCtx_t*)
+proj_context_set(PJconsts*, pj_ctx*)
proj_context_set_search_paths
proj_context_set_sqlite3_vfs_name
proj_context_set_url_endpoint
diff --git a/src/4D_api.cpp b/src/4D_api.cpp
index 86c0e071..15bc73c8 100644
--- a/src/4D_api.cpp
+++ b/src/4D_api.cpp
@@ -778,14 +778,14 @@ PJ *pj_create_internal (PJ_CONTEXT *ctx, const char *definition) {
argc = pj_trim_argc (args);
if (argc==0) {
- pj_dealloc (args);
+ free (args);
proj_context_errno_set(ctx, PJD_ERR_NO_ARGS);
return nullptr;
}
argv = pj_trim_argv (argc, args);
if (!argv) {
- pj_dealloc(args);
+ free(args);
proj_context_errno_set(ctx, ENOMEM);
return nullptr;
}
@@ -795,8 +795,8 @@ PJ *pj_create_internal (PJ_CONTEXT *ctx, const char *definition) {
allow_init_epsg = proj_context_get_use_proj4_init_rules(ctx, FALSE);
P = pj_init_ctx_with_allow_init_epsg (ctx, (int) argc, argv, allow_init_epsg);
- pj_dealloc (argv);
- pj_dealloc (args);
+ free (argv);
+ free (args);
/* Support cs2cs-style modifiers */
ret = cs2cs_emulation_setup (P);
@@ -834,7 +834,7 @@ indicator, as in {"+proj=utm", "+zone=32"}, or leave it out, as in {"proj=utm",
P = proj_create (ctx, c);
- pj_dealloc ((char *) c);
+ free ((char *) c);
return P;
}
@@ -862,13 +862,13 @@ Same as proj_create_argv() but calls pj_create_internal() instead of proj_create
P = pj_create_internal (ctx, c);
- pj_dealloc ((char *) c);
+ free ((char *) c);
return P;
}
/** Create an area of use */
PJ_AREA * proj_area_create(void) {
- return static_cast<PJ_AREA*>(pj_calloc(1, sizeof(PJ_AREA)));
+ return static_cast<PJ_AREA*>(calloc(1, sizeof(PJ_AREA)));
}
/** Assign a bounding box to an area of use. */
@@ -886,7 +886,7 @@ void proj_area_set_bbox(PJ_AREA *area,
/** Free an area of use */
void proj_area_destroy(PJ_AREA* area) {
- pj_dealloc(area);
+ free(area);
}
/************************************************************************/
@@ -1353,17 +1353,13 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons
return P;
}
-PJ *proj_destroy (PJ *P) {
- pj_free (P);
- return nullptr;
-}
/*****************************************************************************/
int proj_errno (const PJ *P) {
/******************************************************************************
Read an error level from the context of a PJ.
******************************************************************************/
- return pj_ctx_get_errno (pj_get_ctx ((PJ *) P));
+ return proj_context_errno (pj_get_ctx ((PJ *) P));
}
/*****************************************************************************/
@@ -1374,7 +1370,7 @@ int proj_context_errno (PJ_CONTEXT *ctx) {
******************************************************************************/
if (nullptr==ctx)
ctx = pj_get_default_ctx();
- return pj_ctx_get_errno (ctx);
+ return ctx->last_errno;
}
/*****************************************************************************/
@@ -1389,6 +1385,7 @@ int proj_errno_set (const PJ *P, int err) {
/* For P==0 err goes to the default context */
proj_context_errno_set (pj_get_ctx ((PJ *) P), err);
errno = err;
+
return err;
}
@@ -1439,16 +1436,15 @@ int proj_errno_reset (const PJ *P) {
int last_errno;
last_errno = proj_errno (P);
- pj_ctx_set_errno (pj_get_ctx ((PJ *) P), 0);
+ proj_context_errno_set (pj_get_ctx ((PJ *) P), 0);
errno = 0;
- pj_errno = 0;
return last_errno;
}
/* Create a new context based on the default context */
PJ_CONTEXT *proj_context_create (void) {
- return pj_ctx_alloc ();
+ return new (std::nothrow) pj_ctx(*pj_get_default_ctx());
}
@@ -1460,7 +1456,7 @@ PJ_CONTEXT *proj_context_destroy (PJ_CONTEXT *ctx) {
if (pj_get_default_ctx ()==ctx)
return nullptr;
- pj_ctx_free (ctx);
+ delete ctx;
return nullptr;
}
@@ -1499,15 +1495,15 @@ static char *path_append (char *buf, const char *app, size_t *buf_size) {
/* "pj_realloc", so to speak */
if (*buf_size < len) {
- p = static_cast<char*>(pj_calloc (2 * len, sizeof (char)));
+ p = static_cast<char*>(calloc (2 * len, sizeof (char)));
if (nullptr==p) {
- pj_dealloc (buf);
+ free (buf);
return nullptr;
}
*buf_size = 2 * len;
if (buf != nullptr)
strcpy (p, buf);
- pj_dealloc (buf);
+ free (buf);
buf = p;
}
assert(buf);
@@ -1560,7 +1556,7 @@ PJ_INFO proj_info (void) {
}
}
- pj_dalloc(const_cast<char*>(info.searchpath));
+ free(const_cast<char*>(info.searchpath));
info.searchpath = buf ? buf : empty;
info.paths = ctx ? ctx->c_compat_paths : nullptr;
@@ -1635,7 +1631,7 @@ PJ_PROJ_INFO proj_pj_info(PJ *P) {
pjinfo.definition = empty;
else
pjinfo.definition = pj_shrink (def);
- /* Make pj_free clean this up eventually */
+ /* Make proj_destroy clean this up eventually */
P->def_full = def;
pjinfo.has_inverse = pj_has_inverse(P);
@@ -1746,7 +1742,7 @@ PJ_INIT_INFO proj_init_info(const char *initname){
if( strcmp(initname, "epsg") == 0 || strcmp(initname, "EPSG") == 0 ) {
const char* val;
- pj_ctx_set_errno( ctx, 0 );
+ proj_context_errno_set( ctx, 0 );
strncpy (ininfo.name, initname, sizeof(ininfo.name) - 1);
strcpy(ininfo.origin, "EPSG");
@@ -1764,7 +1760,7 @@ PJ_INIT_INFO proj_init_info(const char *initname){
if( strcmp(initname, "IGNF") == 0 ) {
const char* val;
- pj_ctx_set_errno( ctx, 0 );
+ proj_context_errno_set( ctx, 0 );
strncpy (ininfo.name, initname, sizeof(ininfo.name) - 1);
strcpy(ininfo.origin, "IGNF");
@@ -1809,7 +1805,7 @@ PJ_INIT_INFO proj_init_info(const char *initname){
for ( ; start; start = next) {
next = start->next;
- pj_dalloc(start);
+ free(start);
}
return ininfo;
diff --git a/src/Makefile.am b/src/Makefile.am
index 5b36c8bd..4f3db3ed 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,7 +9,7 @@ AM_CPPFLAGS = -DPROJ_LIB=\"$(pkgdatadir)\" \
-DMUTEX_@MUTEX_SETTING@ -I$(top_srcdir)/include @SQLITE3_CFLAGS@ @TIFF_CFLAGS@ @TIFF_ENABLED_FLAGS@ @CURL_CFLAGS@ @CURL_ENABLED_FLAGS@
AM_CXXFLAGS = @CXX_WFLAGS@ @FLTO_FLAG@
-include_HEADERS = proj.h proj_experimental.h proj_constants.h proj_api.h geodesic.h \
+include_HEADERS = proj.h proj_experimental.h proj_constants.h geodesic.h \
proj_symbol_rename.h
EXTRA_DIST = bin_cct.cmake bin_gie.cmake bin_cs2cs.cmake \
@@ -209,19 +209,17 @@ libproj_la_SOURCES = \
\
aasincos.cpp adjlon.cpp \
dmstor.cpp auth.cpp \
- deriv.cpp ell_set.cpp ellps.cpp errno.cpp \
+ deriv.cpp ell_set.cpp ellps.cpp \
factors.cpp fwd.cpp init.cpp inv.cpp \
list.cpp malloc.cpp mlfn.cpp mlfn.hpp msfn.cpp proj_mdist.cpp \
param.cpp phi2.cpp pr_list.cpp \
qsfn.cpp strerrno.cpp \
tsfn.cpp units.cpp ctx.cpp log.cpp zpoly1.cpp rtodms.cpp \
release.cpp gauss.cpp \
- fileapi.cpp \
generic_inverse.cpp \
quadtree.hpp \
\
- datums.cpp datum_set.cpp transform.cpp \
- utils.cpp \
+ datums.cpp datum_set.cpp \
mutex.cpp initcache.cpp geodesic.c \
strtod.cpp \
\
diff --git a/src/aasincos.cpp b/src/aasincos.cpp
index 398a8cfc..c4314c67 100644
--- a/src/aasincos.cpp
+++ b/src/aasincos.cpp
@@ -9,24 +9,24 @@
#define ATOL 1e-50
double
-aasin(projCtx ctx,double v) {
+aasin(PJ_CONTEXT *ctx,double v) {
double av;
if ((av = fabs(v)) >= 1.) {
if (av > ONE_TOL)
- pj_ctx_set_errno( ctx, PJD_ERR_ACOS_ASIN_ARG_TOO_LARGE );
+ proj_context_errno_set( ctx, PJD_ERR_ACOS_ASIN_ARG_TOO_LARGE );
return (v < 0. ? -M_HALFPI : M_HALFPI);
}
return asin(v);
}
double
-aacos(projCtx ctx, double v) {
+aacos(PJ_CONTEXT *ctx, double v) {
double av;
if ((av = fabs(v)) >= 1.) {
if (av > ONE_TOL)
- pj_ctx_set_errno( ctx, PJD_ERR_ACOS_ASIN_ARG_TOO_LARGE );
+ proj_context_errno_set( ctx, PJD_ERR_ACOS_ASIN_ARG_TOO_LARGE );
return (v < 0. ? M_PI : 0.);
}
return acos(v);
diff --git a/src/apps/cct.cpp b/src/apps/cct.cpp
index b0e15e62..ebfa6a23 100644
--- a/src/apps/cct.cpp
+++ b/src/apps/cct.cpp
@@ -360,7 +360,7 @@ int main(int argc, char **argv) {
if (nullptr==P) {
print (PJ_LOG_ERROR, "%s: Bad transformation arguments - (%s)\n '%s -h' for help",
- o->progname, pj_strerrno (proj_errno(P)), o->progname);
+ o->progname, proj_errno_string (proj_errno(P)), o->progname);
free (o);
if (stdout != fout)
fclose (fout);
@@ -387,7 +387,7 @@ int main(int argc, char **argv) {
buf = static_cast<char*>(calloc (1, 10000));
if (nullptr==buf) {
print (PJ_LOG_ERROR, "%s: Out of memory", o->progname);
- pj_free (P);
+ proj_destroy (P);
free (o);
if (stdout != fout)
fclose (fout);
@@ -435,7 +435,7 @@ int main(int argc, char **argv) {
if (HUGE_VAL==point.xyzt.x) {
/* transformation error */
print (PJ_LOG_NONE, "# Record %d TRANSFORMATION ERROR: %s (%s)",
- (int) o->record_index, buf, pj_strerrno (proj_errno(P)));
+ (int) o->record_index, buf, proj_errno_string (proj_errno(P)));
proj_errno_restore (P, err);
continue;
}
diff --git a/src/apps/cs2cs.cpp b/src/apps/cs2cs.cpp
index 1a33d444..12e045bb 100644
--- a/src/apps/cs2cs.cpp
+++ b/src/apps/cs2cs.cpp
@@ -468,10 +468,23 @@ int main(int argc, char **argv) {
reverseout = 1;
continue;
case 'D': /* set debug level */
+ {
if (--argc <= 0)
goto noargument;
- pj_ctx_set_debug(pj_get_default_ctx(), atoi(*++argv));
+ int log_level = atoi(*++argv);
+ if (log_level <= 0) {
+ proj_log_level(pj_get_default_ctx(), PJ_LOG_NONE);
+ } else if (log_level == 1) {
+ proj_log_level(pj_get_default_ctx(), PJ_LOG_ERROR);
+ } else if (log_level == 2) {
+ proj_log_level(pj_get_default_ctx(), PJ_LOG_DEBUG);
+ } else if (log_level == 3) {
+ proj_log_level(pj_get_default_ctx(), PJ_LOG_TRACE);
+ } else {
+ proj_log_level(pj_get_default_ctx(), PJ_LOG_TELL);
+ }
continue;
+ }
case 'd':
if (--argc <= 0)
goto noargument;
@@ -611,7 +624,7 @@ int main(int argc, char **argv) {
if (!transformation) {
emess(3, "cannot initialize transformation\ncause: %s",
- pj_strerrno(pj_errno));
+ proj_errno_string(proj_context_errno(nullptr)));
}
if (use_env_locale) {
diff --git a/src/apps/emess.cpp b/src/apps/emess.cpp
index 53018ba8..5a50cd25 100644
--- a/src/apps/emess.cpp
+++ b/src/apps/emess.cpp
@@ -9,17 +9,13 @@
# endif
#endif
-#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#endif
-
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "proj_api.h"
+#include "proj_internal.h"
#include "proj_config.h"
#define EMESS_ROUTINE
#include "emess.h"
diff --git a/src/apps/geod_set.cpp b/src/apps/geod_set.cpp
index 603f0d95..d6516f22 100644
--- a/src/apps/geod_set.cpp
+++ b/src/apps/geod_set.cpp
@@ -75,6 +75,6 @@ geod_set(int argc, char **argv) {
/* free up linked list */
for ( ; start; start = curr) {
curr = start->next;
- pj_dalloc(start);
+ free(start);
}
}
diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp
index 2fe854fa..b504b922 100644
--- a/src/apps/gie.cpp
+++ b/src/apps/gie.cpp
@@ -880,8 +880,8 @@ static int expect_failure_with_errno_message (int expected, int got) {
banner (T.operation);
fprintf (T.fout, "%s", T.op_ko? " -----\n": delim);
fprintf (T.fout, " FAILURE in %s(%d):\n", opt_strip_path (T.curr_file), (int) F->lineno);
- fprintf (T.fout, " got errno %s (%d): %s\n", err_const_from_errno(got), got, pj_strerrno (got));
- fprintf (T.fout, " expected %s (%d): %s", err_const_from_errno(expected), expected, pj_strerrno (expected));
+ fprintf (T.fout, " got errno %s (%d): %s\n", err_const_from_errno(got), got, proj_errno_string (got));
+ fprintf (T.fout, " expected %s (%d): %s", err_const_from_errno(expected), expected, proj_errno_string (expected));
fprintf (T.fout, "\n");
return 1;
}
@@ -934,7 +934,7 @@ Tell GIE what to expect, when transforming the ACCEPTed input
/* Otherwise, it's a true failure */
banner (T.operation);
errmsg (3, "%sInvalid operation definition in line no. %d:\n %s (errno=%s/%d)\n",
- delim, (int) T.operation_lineno, pj_strerrno(proj_errno(T.P)),
+ delim, (int) T.operation_lineno, proj_errno_string (proj_errno(T.P)),
err_const_from_errno (proj_errno(T.P)), proj_errno(T.P)
);
return another_failing_failure ();
@@ -1186,7 +1186,7 @@ static int list_err_codes (void) {
if (9999==lookup[i].the_errno)
break;
fprintf (T.fout, "%25s (%2.2d): %s\n", lookup[i].the_err_const + 8,
- lookup[i].the_errno, pj_strerrno(lookup[i].the_errno));
+ lookup[i].the_errno, proj_errno_string (lookup[i].the_errno));
}
return 0;
}
diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp
index c9bd8950..a5c917f6 100644
--- a/src/apps/proj.cpp
+++ b/src/apps/proj.cpp
@@ -250,10 +250,8 @@ static void vprocess(FILE *fid) {
if (postscale) { dat_xy.x *= fscale; dat_xy.y *= fscale; }
}
- /* For some reason pj_errno does not work as expected in some */
- /* versions of Visual Studio, so using pj_get_errno_ref instead */
- if (*pj_get_errno_ref()) {
- emess(-1, pj_strerrno(*pj_get_errno_ref()));
+ if (proj_context_errno(nullptr)) {
+ emess(-1, proj_errno_string(proj_context_errno(nullptr)));
continue;
}
@@ -477,7 +475,7 @@ int main(int argc, char **argv) {
}
if (!(Proj = pj_init(pargc, pargv)))
emess(3,"projection initialization failure\ncause: %s",
- pj_strerrno(pj_errno));
+ proj_errno_string(proj_context_errno(nullptr)));
if (!proj_angular_input(Proj, PJ_FWD)) {
emess(3, "can't initialize operations that take non-angular input coordinates");
@@ -562,7 +560,7 @@ int main(int argc, char **argv) {
}
if( Proj )
- pj_free(Proj);
+ proj_destroy(Proj);
exit(0); /* normal completion */
}
diff --git a/src/auth.cpp b/src/auth.cpp
index a8ee262a..ced02fb4 100644
--- a/src/auth.cpp
+++ b/src/auth.cpp
@@ -18,7 +18,7 @@
pj_authset(double es) {
double t, *APA;
- if ((APA = (double *)pj_malloc(APA_SIZE * sizeof(double))) != nullptr) {
+ if ((APA = (double *)malloc(APA_SIZE * sizeof(double))) != nullptr) {
APA[0] = es * P00;
t = es * es;
APA[0] += t * P01;
diff --git a/src/conversions/axisswap.cpp b/src/conversions/axisswap.cpp
index 4ae2b4e4..1aa339c3 100644
--- a/src/conversions/axisswap.cpp
+++ b/src/conversions/axisswap.cpp
@@ -169,7 +169,7 @@ static PJ_COORD reverse_4d(PJ_COORD coo, PJ *P) {
/***********************************************************************/
PJ *CONVERSION(axisswap,0) {
/***********************************************************************/
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
char *s;
unsigned int i, j, n = 0;
diff --git a/src/conversions/set.cpp b/src/conversions/set.cpp
index 7628bf4f..2f30bda8 100644
--- a/src/conversions/set.cpp
+++ b/src/conversions/set.cpp
@@ -39,7 +39,7 @@ PJ *OPERATION(set, 0) {
P->inv4d = set_fwd_inv;
P->fwd4d = set_fwd_inv;
- auto set = static_cast<struct Set*>(pj_calloc (1, sizeof(struct Set)));
+ auto set = static_cast<struct Set*>(calloc (1, sizeof(struct Set)));
P->opaque = set;
if (nullptr==P->opaque)
return pj_default_destructor(P, ENOMEM);
diff --git a/src/conversions/unitconvert.cpp b/src/conversions/unitconvert.cpp
index 172e2c48..61bccbf1 100644
--- a/src/conversions/unitconvert.cpp
+++ b/src/conversions/unitconvert.cpp
@@ -433,7 +433,7 @@ static double get_unit_conversion_factor(const char* name,
/***********************************************************************/
PJ *CONVERSION(unitconvert,0) {
/***********************************************************************/
- struct pj_opaque_unitconvert *Q = static_cast<struct pj_opaque_unitconvert*>(pj_calloc (1, sizeof (struct pj_opaque_unitconvert)));
+ struct pj_opaque_unitconvert *Q = static_cast<struct pj_opaque_unitconvert*>(calloc (1, sizeof (struct pj_opaque_unitconvert)));
const char *s, *name;
int i;
double f;
diff --git a/src/ctx.cpp b/src/ctx.cpp
index 6dbe0de5..2093950b 100644
--- a/src/ctx.cpp
+++ b/src/ctx.cpp
@@ -1,6 +1,6 @@
/******************************************************************************
* Project: PROJ.4
- * Purpose: Implementation of the projCtx thread context object.
+ * Purpose: Implementation of the PJ_CONTEXT thread context object.
* Author: Frank Warmerdam, warmerdam@pobox.com
*
******************************************************************************
@@ -43,7 +43,7 @@
/* pj_get_ctx() */
/************************************************************************/
-projCtx pj_get_ctx( projPJ pj )
+PJ_CONTEXT* pj_get_ctx( PJ *pj )
{
if (nullptr==pj)
@@ -54,13 +54,17 @@ projCtx pj_get_ctx( projPJ pj )
}
/************************************************************************/
-/* pj_set_ctx() */
-/* */
-/* Note we do not deallocate the old context! */
+/* proj_assign_context() */
/************************************************************************/
-void pj_set_ctx( projPJ pj, projCtx ctx )
-
+/** \brief Re-assign a context to a PJ* object.
+ *
+ * This may be useful if the PJ* has been created with a context that is
+ * thread-specific, and is later used in another thread. In that case,
+ * the user may want to assign another thread-specific context to the
+ * object.
+ */
+void proj_assign_context( PJ* pj, PJ_CONTEXT *ctx )
{
if (pj==nullptr)
return;
@@ -71,36 +75,20 @@ void pj_set_ctx( projPJ pj, projCtx ctx )
}
for( const auto &alt: pj->alternativeCoordinateOperations )
{
- pj_set_ctx(alt.pj, ctx);
+ proj_assign_context(alt.pj, ctx);
}
-}
-
-/************************************************************************/
-/* proj_assign_context() */
-/************************************************************************/
-/** \brief Re-assign a context to a PJ* object.
- *
- * This may be useful if the PJ* has been created with a context that is
- * thread-specific, and is later used in another thread. In that case,
- * the user may want to assign another thread-specific context to the
- * object.
- */
-void proj_assign_context( PJ* pj, PJ_CONTEXT* ctx )
-{
- pj_set_ctx( pj, ctx );
}
/************************************************************************/
/* createDefault() */
/************************************************************************/
-projCtx_t projCtx_t::createDefault()
+pj_ctx pj_ctx::createDefault()
{
- projCtx_t ctx;
+ pj_ctx ctx;
ctx.debug_level = PJ_LOG_NONE;
ctx.logger = pj_stderr_logger;
- ctx.fileapi_legacy = pj_get_default_fileapi();
NS_PROJ::FileManager::fillDefaultNetworkInterface(&ctx);
if( getenv("PROJ_DEBUG") != nullptr )
@@ -117,7 +105,7 @@ projCtx_t projCtx_t::createDefault()
/* get_cpp_context() */
/**************************************************************************/
-projCppContext* projCtx_t::get_cpp_context()
+projCppContext* pj_ctx::get_cpp_context()
{
if (cpp_context == nullptr) {
cpp_context = new projCppContext(this);
@@ -125,12 +113,11 @@ projCppContext* projCtx_t::get_cpp_context()
return cpp_context;
}
-
/**************************************************************************/
/* safeAutoCloseDbIfNeeded() */
/**************************************************************************/
-void projCtx_t::safeAutoCloseDbIfNeeded()
+void pj_ctx::safeAutoCloseDbIfNeeded()
{
if (cpp_context) {
cpp_context->autoCloseDbIfNeeded();
@@ -141,7 +128,7 @@ void projCtx_t::safeAutoCloseDbIfNeeded()
/* set_search_paths() */
/************************************************************************/
-void projCtx_t::set_search_paths(const std::vector<std::string>& search_paths_in )
+void pj_ctx::set_search_paths(const std::vector<std::string>& search_paths_in )
{
search_paths = search_paths_in;
delete[] c_compat_paths;
@@ -158,26 +145,24 @@ void projCtx_t::set_search_paths(const std::vector<std::string>& search_paths_in
/* set_ca_bundle_path() */
/**************************************************************************/
-void projCtx_t::set_ca_bundle_path(const std::string& ca_bundle_path_in)
+void pj_ctx::set_ca_bundle_path(const std::string& ca_bundle_path_in)
{
ca_bundle_path = ca_bundle_path_in;
}
/************************************************************************/
-/* projCtx_t(const projCtx_t& other) */
+/* pj_ctx(const pj_ctx& other) */
/************************************************************************/
-projCtx_t::projCtx_t(const projCtx_t& other) :
+pj_ctx::pj_ctx(const pj_ctx& other) :
debug_level(other.debug_level),
logger(other.logger),
logger_app_data(other.logger_app_data),
- fileapi_legacy(other.fileapi_legacy),
cpp_context(other.cpp_context ? other.cpp_context->clone(this) : nullptr),
use_proj4_init_rules(other.use_proj4_init_rules),
epsg_file_exists(other.epsg_file_exists),
ca_bundle_path(other.ca_bundle_path),
env_var_proj_lib(other.env_var_proj_lib),
- file_finder_legacy(other.file_finder_legacy),
file_finder(other.file_finder),
file_finder_user_data(other.file_finder_user_data),
custom_sqlite3_vfs_name(other.custom_sqlite3_vfs_name),
@@ -197,129 +182,35 @@ projCtx_t::projCtx_t(const projCtx_t& other) :
/* pj_get_default_ctx() */
/************************************************************************/
-projCtx pj_get_default_ctx()
+PJ_CONTEXT* pj_get_default_ctx()
{
// C++11 rules guarantee a thread-safe instantiation.
- static projCtx_t default_context(projCtx_t::createDefault());
+ static pj_ctx default_context(pj_ctx::createDefault());
return &default_context;
}
/************************************************************************/
-/* ~projCtx_t() */
+/* ~pj_ctx() */
/************************************************************************/
-projCtx_t::~projCtx_t()
+pj_ctx::~pj_ctx()
{
delete[] c_compat_paths;
proj_context_delete_cpp_context(cpp_context);
}
/************************************************************************/
-/* pj_ctx_alloc() */
-/************************************************************************/
-
-projCtx pj_ctx_alloc()
-
-{
- return new (std::nothrow) projCtx_t(*pj_get_default_ctx());
-}
-
-/************************************************************************/
/* proj_context_clone() */
/* Create a new context based on a custom context */
/************************************************************************/
-PJ_CONTEXT *proj_context_clone (PJ_CONTEXT *ctx)
-{
- if (nullptr==ctx)
- return pj_ctx_alloc ();
-
- return new (std::nothrow) projCtx_t(*ctx);
-}
-
-/************************************************************************/
-/* pj_ctx_free() */
-/************************************************************************/
-
-void pj_ctx_free( projCtx ctx )
-
-{
- delete ctx;
-}
-
-/************************************************************************/
-/* pj_ctx_get_errno() */
-/************************************************************************/
-
-int pj_ctx_get_errno( projCtx ctx )
-
+PJ_CONTEXT* proj_context_clone (PJ_CONTEXT *ctx)
{
if (nullptr==ctx)
- return pj_get_default_ctx ()->last_errno;
- return ctx->last_errno;
-}
-
-/************************************************************************/
-/* pj_ctx_set_errno() */
-/* */
-/* Also sets the global errno */
-/************************************************************************/
-
-void pj_ctx_set_errno( projCtx ctx, int new_errno )
-
-{
- ctx->last_errno = new_errno;
- if( new_errno == 0 )
- return;
- errno = new_errno;
- pj_errno = new_errno;
-}
-
-/************************************************************************/
-/* pj_ctx_set_debug() */
-/************************************************************************/
-
-void pj_ctx_set_debug( projCtx ctx, int new_debug )
+ return proj_context_create();
-{
- if (nullptr==ctx)
- return;
- ctx->debug_level = new_debug;
+ return new (std::nothrow) pj_ctx(*ctx);
}
-/************************************************************************/
-/* pj_ctx_set_logger() */
-/************************************************************************/
-
-void pj_ctx_set_logger( projCtx ctx, void (*new_logger)(void*,int,const char*) )
-{
- if (nullptr==ctx)
- return;
- ctx->logger = new_logger;
-}
-
-/************************************************************************/
-/* pj_ctx_set_app_data() */
-/************************************************************************/
-
-void pj_ctx_set_app_data( projCtx ctx, void *new_app_data )
-
-{
- if (nullptr==ctx)
- return;
- ctx->logger_app_data = new_app_data;
-}
-
-/************************************************************************/
-/* pj_ctx_get_app_data() */
-/************************************************************************/
-
-void *pj_ctx_get_app_data( projCtx ctx )
-
-{
- if (nullptr==ctx)
- return nullptr;
- return ctx->logger_app_data;
-}
diff --git a/src/datum_set.cpp b/src/datum_set.cpp
index 15d51613..398d85cd 100644
--- a/src/datum_set.cpp
+++ b/src/datum_set.cpp
@@ -38,7 +38,7 @@
/* pj_datum_set() */
/************************************************************************/
-int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef)
+int pj_datum_set(PJ_CONTEXT *ctx, paralist *pl, PJ *projdef)
{
const char *name, *towgs84, *nadgrids;
@@ -71,7 +71,7 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef)
for (i = 0; (s = pj_datums[i].id) && strcmp(name, s) ; ++i) {}
if (!s) {
- pj_ctx_set_errno(ctx, PJD_ERR_UNKNOWN_ELLP_PARAM);
+ proj_context_errno_set(ctx, PJD_ERR_UNKNOWN_ELLP_PARAM);
return 1;
}
@@ -87,7 +87,7 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef)
curr = curr->next = pj_mkparam(entry);
if (nullptr == curr)
{
- pj_ctx_set_errno(ctx, ENOMEM);
+ proj_context_errno_set(ctx, ENOMEM);
return 1;
}
}
@@ -97,7 +97,7 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef)
curr = curr->next = pj_mkparam(pj_datums[i].defn);
if (nullptr == curr)
{
- pj_ctx_set_errno(ctx, ENOMEM);
+ proj_context_errno_set(ctx, ENOMEM);
return 1;
}
}
diff --git a/src/dmstor.cpp b/src/dmstor.cpp
index 3ba66030..24887a11 100644
--- a/src/dmstor.cpp
+++ b/src/dmstor.cpp
@@ -26,7 +26,7 @@ dmstor(const char *is, char **rs) {
}
double
-dmstor_ctx(projCtx ctx, const char *is, char **rs) {
+dmstor_ctx(PJ_CONTEXT *ctx, const char *is, char **rs) {
int sign, n, nl;
char *s, work[MAX_WORK];
const char* p;
@@ -61,7 +61,7 @@ dmstor_ctx(projCtx ctx, const char *is, char **rs) {
n = 2; break;
case 'r': case 'R':
if (nl) {
- pj_ctx_set_errno( ctx, PJD_ERR_WRONG_FORMAT_DMS_VALUE );
+ proj_context_errno_set( ctx, PJD_ERR_WRONG_FORMAT_DMS_VALUE );
return HUGE_VAL;
}
++s;
@@ -73,7 +73,7 @@ dmstor_ctx(projCtx ctx, const char *is, char **rs) {
continue;
}
if (n < nl) {
- pj_ctx_set_errno( ctx, PJD_ERR_WRONG_FORMAT_DMS_VALUE );
+ proj_context_errno_set( ctx, PJD_ERR_WRONG_FORMAT_DMS_VALUE );
return HUGE_VAL;
}
v += tv * vm[n];
diff --git a/src/ell_set.cpp b/src/ell_set.cpp
index ddd507ac..176fc553 100644
--- a/src/ell_set.cpp
+++ b/src/ell_set.cpp
@@ -77,13 +77,13 @@ int pj_ellipsoid (PJ *P) {
int err = proj_errno_reset (P);
const char *empty = {""};
- pj_dealloc(P->def_size);
+ free(P->def_size);
P->def_size = nullptr;
- pj_dealloc(P->def_shape);
+ free(P->def_shape);
P->def_shape = nullptr;
- pj_dealloc(P->def_spherification);
+ free(P->def_spherification);
P->def_spherification = nullptr;
- pj_dealloc(P->def_ellps);
+ free(P->def_ellps);
P->def_ellps = nullptr;
/* Specifying R overrules everything */
@@ -162,7 +162,7 @@ static int ellps_ellps (PJ *P) {
new_params->next = pj_mkparam (ellps->ell);
if (nullptr == new_params->next)
{
- pj_dealloc(new_params);
+ free(new_params);
return proj_errno_set (P, ENOMEM);
}
paralist* old_params = P->params;
@@ -176,8 +176,8 @@ static int ellps_ellps (PJ *P) {
ellps_shape (P);
P->params = old_params;
- pj_dealloc (new_params->next);
- pj_dealloc (new_params);
+ free (new_params->next);
+ free (new_params);
if (proj_errno (P))
return proj_errno (P);
@@ -195,7 +195,7 @@ static int ellps_size (PJ *P) {
paralist *par = nullptr;
int a_was_set = 0;
- pj_dealloc(P->def_size);
+ free(P->def_size);
P->def_size = nullptr;
/* A size parameter *must* be given, but may have been given as ellps prior */
@@ -235,7 +235,7 @@ static int ellps_shape (PJ *P) {
par = nullptr;
len = sizeof (keys) / sizeof (char *);
- pj_dealloc(P->def_shape);
+ free(P->def_shape);
P->def_shape = nullptr;
/* Check which shape key is specified */
@@ -552,7 +552,7 @@ int pj_calc_ellipsoid_params (PJ *P, double a, double es) {
if (0==P->f)
P->f = 1 - cos (P->alpha); /* = 1 - sqrt (1 - PIN->es); */
if (P->f == 1.0) {
- pj_ctx_set_errno( P->ctx, PJD_ERR_INVALID_ECCENTRICITY);
+ proj_context_errno_set( P->ctx, PJD_ERR_INVALID_ECCENTRICITY);
return PJD_ERR_INVALID_ECCENTRICITY;
}
P->rf = P->f != 0.0 ? 1.0/P->f: HUGE_VAL;
@@ -573,7 +573,7 @@ int pj_calc_ellipsoid_params (PJ *P, double a, double es) {
P->one_es = 1. - P->es;
if (P->one_es == 0.) {
- pj_ctx_set_errno( P->ctx, PJD_ERR_INVALID_ECCENTRICITY);
+ proj_context_errno_set( P->ctx, PJD_ERR_INVALID_ECCENTRICITY);
return PJD_ERR_INVALID_ECCENTRICITY;
}
@@ -609,7 +609,7 @@ int pj_ell_set (PJ_CONTEXT *ctx, paralist *pl, double *a, double *es) {
/**************************************************************************************/
-int pj_ell_set (projCtx ctx, paralist *pl, double *a, double *es) {
+int pj_ell_set (PJ_CONTEXT *ctx, paralist *pl, double *a, double *es) {
/***************************************************************************************
Initialize ellipsoidal parameters: This is the original ellipsoid setup
function by Gerald Evenden - significantly more compact than pj_ellipsoid and
@@ -630,7 +630,7 @@ int pj_ell_set (projCtx ctx, paralist *pl, double *a, double *es) {
paralist *start = 0;
/* clear any previous error */
- pj_ctx_set_errno(ctx,0);
+ proj_context_errno_set(ctx,0);
/* check for varying forms of ellipsoid input */
*a = *es = 0.;
@@ -648,7 +648,7 @@ int pj_ell_set (projCtx ctx, paralist *pl, double *a, double *es) {
for (start = pl; start && start->next ; start = start->next) ;
for (i = 0; (s = pj_ellps[i].id) && strcmp(name, s) ; ++i) ;
if (!s) {
- pj_ctx_set_errno( ctx, PJD_ERR_UNKNOWN_ELLP_PARAM);
+ proj_context_errno_set( ctx, PJD_ERR_UNKNOWN_ELLP_PARAM);
return 1;
}
start->next = pj_mkparam(pj_ellps[i].major);
@@ -662,14 +662,14 @@ int pj_ell_set (projCtx ctx, paralist *pl, double *a, double *es) {
else if (pj_param(ctx,pl, "te").i) { /* eccentricity */
e = pj_param(ctx,pl, "de").f;
if (e < 0) {
- pj_ctx_set_errno(ctx, PJD_ERR_INVALID_ECCENTRICITY);
+ proj_context_errno_set(ctx, PJD_ERR_INVALID_ECCENTRICITY);
return 1;
}
*es = e * e;
} else if (pj_param(ctx,pl, "trf").i) { /* recip flattening */
*es = pj_param(ctx,pl, "drf").f;
if (*es == 0.0) {
- pj_ctx_set_errno(ctx, PJD_ERR_REV_FLATTENING_IS_ZERO);
+ proj_context_errno_set(ctx, PJD_ERR_REV_FLATTENING_IS_ZERO);
goto bomb;
}
*es = 1./ *es;
@@ -700,7 +700,7 @@ int pj_ell_set (projCtx ctx, paralist *pl, double *a, double *es) {
*es = 0.;
} else if (pj_param(ctx,pl, "bR_h").i) { /* sphere--harmonic mean */
if ( (*a + b) == 0.0) {
- pj_ctx_set_errno(ctx, PJD_ERR_TOLERANCE_CONDITION);
+ proj_context_errno_set(ctx, PJD_ERR_TOLERANCE_CONDITION);
goto bomb;
}
*a = 2. * *a * b / (*a + b);
@@ -711,7 +711,7 @@ int pj_ell_set (projCtx ctx, paralist *pl, double *a, double *es) {
tmp = sin(pj_param(ctx,pl, i ? "rR_lat_a" : "rR_lat_g").f);
if (fabs(tmp) > M_HALFPI) {
- pj_ctx_set_errno(ctx, PJD_ERR_REF_RAD_LARGER_THAN_90);
+ proj_context_errno_set(ctx, PJD_ERR_REF_RAD_LARGER_THAN_90);
goto bomb;
}
tmp = 1. - *es * tmp * tmp;
@@ -721,8 +721,8 @@ int pj_ell_set (projCtx ctx, paralist *pl, double *a, double *es) {
}
bomb:
if (start) { /* clean up temporary extension of list */
- pj_dalloc(start->next->next);
- pj_dalloc(start->next);
+ free(start->next->next);
+ free(start->next);
start->next = 0;
}
if (ctx->last_errno)
@@ -730,15 +730,15 @@ bomb:
}
/* some remaining checks */
if (*es < 0.) {
- pj_ctx_set_errno(ctx, PJD_ERR_ES_LESS_THAN_ZERO);
+ proj_context_errno_set(ctx, PJD_ERR_ES_LESS_THAN_ZERO);
return 1;
}
if (*es >= 1.) {
- pj_ctx_set_errno(ctx, PJD_ERR_INVALID_ECCENTRICITY);
+ proj_context_errno_set(ctx, PJD_ERR_INVALID_ECCENTRICITY);
return 1;
}
if (*a <= 0.) {
- pj_ctx_set_errno(ctx, PJD_ERR_MAJOR_AXIS_NOT_GIVEN);
+ proj_context_errno_set(ctx, PJD_ERR_MAJOR_AXIS_NOT_GIVEN);
return 1;
}
return 0;
diff --git a/src/errno.cpp b/src/errno.cpp
deleted file mode 100644
index 4f3119b3..00000000
--- a/src/errno.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-/* For full ANSI compliance of global variable */
-
-#include "proj.h"
-#include "proj_internal.h"
-
-int pj_errno = 0;
-
-/************************************************************************/
-/* pj_get_errno_ref() */
-/************************************************************************/
-
-int *pj_get_errno_ref()
-
-{
- return &pj_errno;
-}
-
-/* end */
diff --git a/src/fileapi.cpp b/src/fileapi.cpp
deleted file mode 100644
index 70be2502..00000000
--- a/src/fileapi.cpp
+++ /dev/null
@@ -1,240 +0,0 @@
-/******************************************************************************
- * Project: PROJ.4
- * Purpose: Implementation of the pj_ctx_* file api, and the default stdio
- * based implementation.
- * Author: Frank Warmerdam, warmerdam@pobox.com
- *
- ******************************************************************************
- * Copyright (c) 2013, Frank Warmerdam
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *****************************************************************************/
-
-#include <errno.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "proj.h"
-#include "proj_internal.h"
-#include "filemanager.hpp"
-
-static PAFile stdio_fopen(projCtx ctx, const char *filename,
- const char *access);
-static size_t stdio_fread(void *buffer, size_t size, size_t nmemb,
- PAFile file);
-static int stdio_fseek(PAFile file, long offset, int whence);
-static long stdio_ftell(PAFile file);
-static void stdio_fclose(PAFile file);
-
-static projFileAPI default_fileapi = {
- stdio_fopen,
- stdio_fread,
- stdio_fseek,
- stdio_ftell,
- stdio_fclose
-};
-
-typedef struct {
- projCtx ctx;
- FILE *fp;
-} stdio_pafile;
-
-/************************************************************************/
-/* pj_get_default_fileapi() */
-/************************************************************************/
-
-projFileAPI *pj_get_default_fileapi(void)
-{
- return &default_fileapi;
-}
-
-/************************************************************************/
-/* stdio_fopen() */
-/************************************************************************/
-
-static PAFile stdio_fopen(projCtx ctx, const char *filename,
- const char *access)
-{
- stdio_pafile *pafile;
- FILE *fp;
-
- fp = fopen(filename, access);
- if (fp == nullptr)
- {
- return nullptr;
- }
-
- pafile = (stdio_pafile *) malloc(sizeof(stdio_pafile));
- if (!pafile)
- {
- pj_ctx_set_errno(ctx, ENOMEM);
- fclose(fp);
- return nullptr;
- }
-
- pafile->fp = fp;
- pafile->ctx = ctx;
- return (PAFile) pafile;
-}
-
-/************************************************************************/
-/* stdio_fread() */
-/************************************************************************/
-
-static size_t stdio_fread(void *buffer, size_t size, size_t nmemb,
- PAFile file)
-{
- stdio_pafile *pafile = (stdio_pafile *) file;
- return fread(buffer, size, nmemb, pafile->fp);
-}
-
-/************************************************************************/
-/* stdio_fseek() */
-/************************************************************************/
-static int stdio_fseek(PAFile file, long offset, int whence)
-{
- stdio_pafile *pafile = (stdio_pafile *) file;
- return fseek(pafile->fp, offset, whence);
-}
-
-/************************************************************************/
-/* stdio_ftell() */
-/************************************************************************/
-static long stdio_ftell(PAFile file)
-{
- stdio_pafile *pafile = (stdio_pafile *) file;
- return ftell(pafile->fp);
-}
-
-/************************************************************************/
-/* stdio_fclose() */
-/************************************************************************/
-static void stdio_fclose(PAFile file)
-{
- stdio_pafile *pafile = (stdio_pafile *) file;
- fclose(pafile->fp);
- free(pafile);
-}
-
-/************************************************************************/
-/* pj_ctx_fopen() */
-/* */
-/* Open a file using the provided file io hooks. */
-/************************************************************************/
-
-PAFile pj_ctx_fopen(projCtx ctx, const char *filename, const char *access)
-{
- return ctx->fileapi_legacy->FOpen(ctx, filename, access);
-}
-
-/************************************************************************/
-/* pj_ctx_fread() */
-/************************************************************************/
-size_t pj_ctx_fread(projCtx ctx, void *buffer, size_t size, size_t nmemb, PAFile file)
-{
- return ctx->fileapi_legacy->FRead(buffer, size, nmemb, file);
-}
-
-/************************************************************************/
-/* pj_ctx_fseek() */
-/************************************************************************/
-int pj_ctx_fseek(projCtx ctx, PAFile file, long offset, int whence)
-{
- return ctx->fileapi_legacy->FSeek(file, offset, whence);
-}
-
-/************************************************************************/
-/* pj_ctx_ftell() */
-/************************************************************************/
-long pj_ctx_ftell(projCtx ctx, PAFile file)
-{
- return ctx->fileapi_legacy->FTell(file);
-}
-
-/************************************************************************/
-/* pj_ctx_fclose() */
-/************************************************************************/
-void pj_ctx_fclose(projCtx ctx, PAFile file)
-{
- ctx->fileapi_legacy->FClose(file);
-}
-
-/************************************************************************/
-/* pj_ctx_fgets() */
-/* */
-/* A not very optimal implementation of fgets on top of */
-/* fread(). If we end up using this a lot more care should be */
-/* taken. */
-/************************************************************************/
-
-char *pj_ctx_fgets(projCtx ctx, char *line, int size, PAFile file)
-{
- long start = pj_ctx_ftell(ctx, file);
- size_t bytes_read;
- int i;
- int max_size;
-
- line[size-1] = '\0';
- bytes_read = pj_ctx_fread(ctx, line, 1, size-1, file);
- if(bytes_read == 0)
- return nullptr;
- if(bytes_read < (size_t)size)
- {
- line[bytes_read] = '\0';
- }
-
- max_size = (int)MIN(bytes_read, (size_t)(size > 2 ? size - 2 : 0));
- for( i = 0; i < max_size; i++)
- {
- if (line[i] == '\n')
- {
- line[i+1] = '\0';
- pj_ctx_fseek(ctx, file, start + i + 1, SEEK_SET);
- break;
- }
- }
- return line;
-}
-
-/************************************************************************/
-/* pj_ctx_set_fileapi() */
-/************************************************************************/
-
-void pj_ctx_set_fileapi( projCtx ctx, projFileAPI *fileapi )
-
-{
- if (nullptr==ctx)
- return;
- ctx->fileapi_legacy = fileapi;
-}
-
-/************************************************************************/
-/* pj_ctx_get_fileapi() */
-/************************************************************************/
-
-projFileAPI *pj_ctx_get_fileapi( projCtx ctx )
-
-{
- if (nullptr==ctx)
- return nullptr;
- return ctx->fileapi_legacy;
-}
-
diff --git a/src/filemanager.cpp b/src/filemanager.cpp
index e6a9ed95..b3b074a2 100644
--- a/src/filemanager.cpp
+++ b/src/filemanager.cpp
@@ -786,75 +786,6 @@ std::unique_ptr<File> FileStdio::open(PJ_CONTEXT *ctx, const char *filename,
// ---------------------------------------------------------------------------
-#ifndef REMOVE_LEGACY_SUPPORT
-
-class FileLegacyAdapter : public File {
- PJ_CONTEXT *m_ctx;
- PAFile m_fp;
-
- FileLegacyAdapter(const FileLegacyAdapter &) = delete;
- FileLegacyAdapter &operator=(const FileLegacyAdapter &) = delete;
-
- protected:
- FileLegacyAdapter(const std::string &filename, PJ_CONTEXT *ctx, PAFile fp)
- : File(filename), m_ctx(ctx), m_fp(fp) {}
-
- public:
- ~FileLegacyAdapter() override;
-
- size_t read(void *buffer, size_t sizeBytes) override;
- size_t write(const void *, size_t) override { return 0; }
- bool seek(unsigned long long offset, int whence = SEEK_SET) override;
- unsigned long long tell() override;
- void reassign_context(PJ_CONTEXT *ctx) override { m_ctx = ctx; }
-
- // We may lie, but the real use case is only for network files
- bool hasChanged() const override { return false; }
-
- static std::unique_ptr<File> open(PJ_CONTEXT *ctx, const char *filename,
- FileAccess access);
-};
-
-// ---------------------------------------------------------------------------
-
-FileLegacyAdapter::~FileLegacyAdapter() { pj_ctx_fclose(m_ctx, m_fp); }
-
-// ---------------------------------------------------------------------------
-
-size_t FileLegacyAdapter::read(void *buffer, size_t sizeBytes) {
- return pj_ctx_fread(m_ctx, buffer, 1, sizeBytes, m_fp);
-}
-
-// ---------------------------------------------------------------------------
-
-bool FileLegacyAdapter::seek(unsigned long long offset, int whence) {
- if (offset != static_cast<unsigned long long>(static_cast<long>(offset))) {
- pj_log(m_ctx, PJ_LOG_ERROR,
- "Attempt at seeking to a 64 bit offset. Not supported yet");
- return false;
- }
- return pj_ctx_fseek(m_ctx, m_fp, static_cast<long>(offset), whence) == 0;
-}
-
-// ---------------------------------------------------------------------------
-
-unsigned long long FileLegacyAdapter::tell() {
- return pj_ctx_ftell(m_ctx, m_fp);
-}
-
-// ---------------------------------------------------------------------------
-
-std::unique_ptr<File>
-FileLegacyAdapter::open(PJ_CONTEXT *ctx, const char *filename, FileAccess) {
- auto fid = pj_ctx_fopen(ctx, filename, "rb");
- return std::unique_ptr<File>(fid ? new FileLegacyAdapter(filename, ctx, fid)
- : nullptr);
-}
-
-#endif // REMOVE_LEGACY_SUPPORT
-
-// ---------------------------------------------------------------------------
-
class FileApiAdapter : public File {
PJ_CONTEXT *m_ctx;
PROJ_FILE_HANDLE *m_fp;
@@ -954,12 +885,6 @@ std::unique_ptr<File> FileManager::open(PJ_CONTEXT *ctx, const char *filename,
}
return pj_network_file_open(ctx, filename);
}
-#ifndef REMOVE_LEGACY_SUPPORT
- // If the user has specified a legacy fileapi, use it
- if (ctx->fileapi_legacy != pj_get_default_fileapi()) {
- return FileLegacyAdapter::open(ctx, filename, access);
- }
-#endif
if (ctx->fileApi.open_cbk != nullptr) {
return FileApiAdapter::open(ctx, filename, access);
}
@@ -1445,8 +1370,8 @@ static bool dontReadUserWritableDirectory() {
}
static void *
-pj_open_lib_internal(projCtx ctx, const char *name, const char *mode,
- void *(*open_file)(projCtx, const char *, const char *),
+pj_open_lib_internal(PJ_CONTEXT *ctx, const char *name, const char *mode,
+ void *(*open_file)(PJ_CONTEXT *, const char *, const char *),
char *out_full_filename, size_t out_full_filename_size) {
try {
std::string fname;
@@ -1493,10 +1418,6 @@ pj_open_lib_internal(projCtx ctx, const char *name, const char *mode,
ctx, name, ctx->file_finder_user_data)) != nullptr)
;
- else if (ctx->file_finder_legacy != nullptr &&
- (sysname = ctx->file_finder_legacy(name)) != nullptr)
- ;
-
/* The user has search paths set */
else if (!ctx->search_paths.empty()) {
for (const auto &path : ctx->search_paths) {
@@ -1566,7 +1487,7 @@ pj_open_lib_internal(projCtx ctx, const char *name, const char *mode,
}
if (ctx->last_errno == 0 && errno != 0)
- pj_ctx_set_errno(ctx, errno);
+ proj_context_errno_set(ctx, errno);
pj_log(ctx, PJ_LOG_DEBUG_MAJOR, "pj_open_lib(%s): call fopen(%s) - %s",
name, sysname, fid == nullptr ? "failed" : "succeeded");
@@ -1617,7 +1538,7 @@ std::vector<std::string> pj_get_default_searchpaths(PJ_CONTEXT *ctx) {
/* pj_open_file_with_manager() */
/************************************************************************/
-static void *pj_open_file_with_manager(projCtx ctx, const char *name,
+static void *pj_open_file_with_manager(PJ_CONTEXT *ctx, const char *name,
const char * /* mode */) {
return NS_PROJ::FileManager::open(ctx, name, NS_PROJ::FileAccess::READ_ONLY)
.release();
@@ -1639,7 +1560,7 @@ static NS_PROJ::io::DatabaseContextPtr getDBcontext(PJ_CONTEXT *ctx) {
/************************************************************************/
std::unique_ptr<NS_PROJ::File>
-NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) {
+NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name) {
if (ctx == nullptr) {
ctx = pj_get_default_ctx();
@@ -1666,7 +1587,7 @@ NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) {
pj_open_file_with_manager, nullptr,
0)));
if (file) {
- pj_ctx_set_errno(ctx, 0);
+ proj_context_errno_set(ctx, 0);
} else {
// For final network access attempt, use the new
// name.
@@ -1696,7 +1617,7 @@ NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) {
pj_open_file_with_manager, nullptr,
0)));
if (file) {
- pj_ctx_set_errno(ctx, 0);
+ proj_context_errno_set(ctx, 0);
}
}
} catch (const std::exception &e) {
@@ -1721,7 +1642,7 @@ NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) {
if (file) {
pj_log(ctx, PJ_LOG_DEBUG_MAJOR, "Using %s",
remote_file.c_str());
- pj_ctx_set_errno(ctx, 0);
+ proj_context_errno_set(ctx, 0);
}
}
}
@@ -1729,26 +1650,6 @@ NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) {
}
/************************************************************************/
-/* pj_open_lib() */
-/************************************************************************/
-
-#ifndef REMOVE_LEGACY_SUPPORT
-
-// Used by following legacy function
-static void *pj_ctx_fopen_adapter(projCtx ctx, const char *name,
- const char *mode) {
- return pj_ctx_fopen(ctx, name, mode);
-}
-
-// Legacy function
-PAFile pj_open_lib(projCtx ctx, const char *name, const char *mode) {
- return (PAFile)pj_open_lib_internal(ctx, name, mode, pj_ctx_fopen_adapter,
- nullptr, 0);
-}
-
-#endif // REMOVE_LEGACY_SUPPORT
-
-/************************************************************************/
/* pj_find_file() */
/************************************************************************/
@@ -1764,7 +1665,7 @@ PAFile pj_open_lib(projCtx ctx, const char *name, const char *mode) {
* @param out_full_filename_size size of out_full_filename.
* @return 1 if the file was found, 0 otherwise.
*/
-int pj_find_file(projCtx ctx, const char *short_filename,
+int pj_find_file(PJ_CONTEXT *ctx, const char *short_filename,
char *out_full_filename, size_t out_full_filename_size) {
auto file = std::unique_ptr<NS_PROJ::File>(
reinterpret_cast<NS_PROJ::File *>(pj_open_lib_internal(
@@ -1812,7 +1713,7 @@ static std::string trim(const std::string &s) {
/* pj_load_ini() */
/************************************************************************/
-void pj_load_ini(projCtx ctx) {
+void pj_load_ini(PJ_CONTEXT *ctx) {
if (ctx->iniFileLoaded)
return;
@@ -1891,19 +1792,6 @@ void pj_load_ini(projCtx ctx) {
//! @endcond
/************************************************************************/
-/* pj_set_finder() */
-/************************************************************************/
-
-void pj_set_finder(const char *(*new_finder)(const char *))
-
-{
- auto ctx = pj_get_default_ctx();
- if (ctx) {
- ctx->file_finder_legacy = new_finder;
- }
-}
-
-/************************************************************************/
/* proj_context_set_file_finder() */
/************************************************************************/
@@ -1974,19 +1862,6 @@ void proj_context_set_search_paths(PJ_CONTEXT *ctx, int count_paths,
}
/************************************************************************/
-/* pj_set_searchpath() */
-/* */
-/* Path control for callers that can't practically provide */
-/* pj_set_finder() style callbacks. Call with (0,NULL) as args */
-/* to clear the searchpath set. */
-/************************************************************************/
-
-void pj_set_searchpath(int count, const char **path) {
- proj_context_set_search_paths(nullptr, count,
- const_cast<const char *const *>(path));
-}
-
-/************************************************************************/
/* proj_context_set_ca_bundle_path() */
/************************************************************************/
diff --git a/src/gauss.cpp b/src/gauss.cpp
index a34a8f5b..96bd5166 100644
--- a/src/gauss.cpp
+++ b/src/gauss.cpp
@@ -81,7 +81,7 @@ void *pj_gauss_ini(double e, double phi0, double *chi, double *rc) {
return ((void *)en);
}
-PJ_LP pj_gauss(projCtx ctx, PJ_LP elp, const void *data) {
+PJ_LP pj_gauss(PJ_CONTEXT *ctx, PJ_LP elp, const void *data) {
const struct GAUSS *en = (const struct GAUSS *)data;
PJ_LP slp;
(void) ctx;
@@ -93,7 +93,7 @@ PJ_LP pj_gauss(projCtx ctx, PJ_LP elp, const void *data) {
return(slp);
}
-PJ_LP pj_inv_gauss(projCtx ctx, PJ_LP slp, const void *data) {
+PJ_LP pj_inv_gauss(PJ_CONTEXT *ctx, PJ_LP slp, const void *data) {
const struct GAUSS *en = (const struct GAUSS *)data;
PJ_LP elp;
double num;
@@ -109,6 +109,6 @@ PJ_LP pj_inv_gauss(projCtx ctx, PJ_LP slp, const void *data) {
}
/* convergence failed */
if (!i)
- pj_ctx_set_errno(ctx, PJD_ERR_NON_CONV_INV_MERI_DIST);
+ proj_context_errno_set(ctx, PJD_ERR_NON_CONV_INV_MERI_DIST);
return (elp);
}
diff --git a/src/generic_inverse.cpp b/src/generic_inverse.cpp
index a15cfae1..ddd5060b 100644
--- a/src/generic_inverse.cpp
+++ b/src/generic_inverse.cpp
@@ -109,6 +109,6 @@ PJ_LP pj_generic_inverse_2d(PJ_XY xy, PJ *P, PJ_LP lpInitial) {
lp.phi = M_HALFPI;
}
}
- pj_ctx_set_errno(P->ctx, PJD_ERR_NON_CONVERGENT);
+ proj_context_errno_set(P->ctx, PJD_ERR_NON_CONVERGENT);
return lp;
}
diff --git a/src/grids.cpp b/src/grids.cpp
index 8065813a..8bb865d8 100644
--- a/src/grids.cpp
+++ b/src/grids.cpp
@@ -197,7 +197,7 @@ GTXVerticalShiftGrid *GTXVerticalShiftGrid::open(PJ_CONTEXT *ctx,
/* Read the header. */
/* -------------------------------------------------------------------- */
if (fp->read(header, sizeof(header)) != sizeof(header)) {
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
@@ -223,7 +223,7 @@ GTXVerticalShiftGrid *GTXVerticalShiftGrid::open(PJ_CONTEXT *ctx,
if (xorigin < -360 || xorigin > 360 || yorigin < -90 || yorigin > 90) {
pj_log(ctx, PJ_LOG_ERROR,
"gtx file header has invalid extents, corrupt?");
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
@@ -258,7 +258,7 @@ bool GTXVerticalShiftGrid::valueAt(int x, int y, float &out) const {
m_fp->seek(40 + sizeof(float) * (y * m_width + x));
if (m_fp->read(&out, sizeof(out)) != sizeof(out)) {
- pj_ctx_set_errno(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return false;
}
if (IS_LSB) {
@@ -1389,7 +1389,7 @@ VerticalShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) {
auto set = std::unique_ptr<VerticalShiftGridSet>(
GTiffVGridShiftSet::open(ctx, std::move(fp), actualName));
if (!set)
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return set;
#else
pj_log(ctx, PJ_LOG_ERROR,
@@ -1570,7 +1570,7 @@ NTv1Grid *NTv1Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
/* Read the header. */
/* -------------------------------------------------------------------- */
if (fp->read(header, sizeof(header)) != sizeof(header)) {
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
@@ -1590,7 +1590,7 @@ NTv1Grid *NTv1Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
if (*((int *)(header + 8)) != 12) {
pj_log(ctx, PJ_LOG_ERROR,
"NTv1 grid shift file has wrong record count, corrupt?");
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
@@ -1609,7 +1609,7 @@ NTv1Grid *NTv1Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
extent.resY > 1e-10)) {
pj_log(ctx, PJ_LOG_ERROR, "Inconsistent georeferencing for %s",
filename.c_str());
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
const int columns = static_cast<int>(
@@ -1631,7 +1631,7 @@ bool NTv1Grid::valueAt(int x, int y, bool compensateNTConvention,
m_fp->seek(192 + 2 * sizeof(double) * (y * m_width + m_width - 1 - x));
if (m_fp->read(&two_doubles[0], sizeof(two_doubles)) !=
sizeof(two_doubles)) {
- pj_ctx_set_errno(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return false;
}
if (IS_LSB) {
@@ -1692,7 +1692,7 @@ CTable2Grid *CTable2Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
/* Read the header. */
/* -------------------------------------------------------------------- */
if (fp->read(header, sizeof(header)) != sizeof(header)) {
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
@@ -1718,7 +1718,7 @@ CTable2Grid *CTable2Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
extent.resX > 1e-10 && extent.resY > 1e-10)) {
pj_log(ctx, PJ_LOG_ERROR, "Inconsistent georeferencing for %s",
filename.c_str());
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
int width;
@@ -1726,7 +1726,7 @@ CTable2Grid *CTable2Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
memcpy(&width, header + 128, 4);
memcpy(&height, header + 132, 4);
if (width <= 0 || height <= 0) {
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
extent.east = extent.west + (width - 1) * extent.resX;
@@ -1744,7 +1744,7 @@ bool CTable2Grid::valueAt(int x, int y, bool compensateNTConvention,
float two_floats[2];
m_fp->seek(160 + 2 * sizeof(float) * (y * m_width + x));
if (m_fp->read(&two_floats[0], sizeof(two_floats)) != sizeof(two_floats)) {
- pj_ctx_set_errno(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return false;
}
if (!IS_LSB) {
@@ -1828,7 +1828,7 @@ bool NTv2Grid::valueAt(int x, int y, bool compensateNTConvention,
4 * sizeof(float) *
(static_cast<unsigned long long>(y) * m_width + m_width - 1 - x));
if (m_fp->read(&two_float[0], sizeof(two_float)) != sizeof(two_float)) {
- pj_ctx_set_errno(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return false;
}
if (m_mustSwap) {
@@ -1862,14 +1862,14 @@ std::unique_ptr<NTv2GridSet> NTv2GridSet::open(PJ_CONTEXT *ctx,
/* Read the header. */
/* -------------------------------------------------------------------- */
if (fpRaw->read(header, sizeof(header)) != sizeof(header)) {
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
constexpr int OFFSET_GS_TYPE = 56;
if (memcmp(header + OFFSET_GS_TYPE, "SECONDS", 7) != 0) {
pj_log(ctx, PJ_LOG_ERROR, "Only GS_TYPE=SECONDS is supported");
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
@@ -1899,12 +1899,12 @@ std::unique_ptr<NTv2GridSet> NTv2GridSet::open(PJ_CONTEXT *ctx,
for (unsigned subfile = 0; subfile < num_subfiles; subfile++) {
// Read header
if (fpRaw->read(header, sizeof(header)) != sizeof(header)) {
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
if (strncmp(header, "SUB_NAME", 8) != 0) {
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
@@ -1946,7 +1946,7 @@ std::unique_ptr<NTv2GridSet> NTv2GridSet::open(PJ_CONTEXT *ctx,
extent.resY > 1e-10)) {
pj_log(ctx, PJ_LOG_ERROR, "Inconsistent georeferencing for %s",
filename.c_str());
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
const int columns = static_cast<int>(
@@ -1966,7 +1966,7 @@ std::unique_ptr<NTv2GridSet> NTv2GridSet::open(PJ_CONTEXT *ctx,
pj_log(ctx, PJ_LOG_ERROR,
"GS_COUNT(%u) does not match expected cells (%dx%d)",
gs_count, columns, rows);
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return nullptr;
}
@@ -2367,7 +2367,7 @@ HorizontalShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) {
auto set = std::unique_ptr<HorizontalShiftGridSet>(
GTiffHGridShiftSet::open(ctx, std::move(fp), actualName));
if (!set)
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return set;
#else
pj_log(ctx, PJ_LOG_ERROR,
@@ -2703,7 +2703,7 @@ GenericShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) {
auto set = std::unique_ptr<GenericShiftGridSet>(
GTiffGenericGridShiftSet::open(ctx, std::move(fp), actualName));
if (!set)
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return set;
#else
pj_log(ctx, PJ_LOG_ERROR,
@@ -2786,11 +2786,11 @@ ListOfGenericGrids pj_generic_grid_init(PJ *P, const char *gridkey) {
if (!gridSet) {
if (!canFail) {
if (proj_context_errno(P->ctx) != PJD_ERR_NETWORK_ERROR) {
- pj_ctx_set_errno(P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
}
return {};
}
- pj_ctx_set_errno(P->ctx, 0); // don't treat as a persistent error
+ proj_context_errno_set(P->ctx, 0); // don't treat as a persistent error
} else {
grids.emplace_back(std::move(gridSet));
}
@@ -2830,11 +2830,11 @@ static ListOfHGrids getListOfGridSets(PJ_CONTEXT *ctx, const char *grids) {
if (!gridSet) {
if (!canFail) {
if (proj_context_errno(ctx) != PJD_ERR_NETWORK_ERROR) {
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
}
return {};
}
- pj_ctx_set_errno(ctx, 0); // don't treat as a persistent error
+ proj_context_errno_set(ctx, 0); // don't treat as a persistent error
} else {
list.emplace_back(std::move(gridSet));
}
@@ -2948,7 +2948,7 @@ static PJ_LP pj_hgrid_interpolate(PJ_LP t, const HorizontalShiftGrid *grid,
#define MAX_ITERATIONS 10
#define TOL 1e-12
-static PJ_LP pj_hgrid_apply_internal(projCtx ctx, PJ_LP in,
+static PJ_LP pj_hgrid_apply_internal(PJ_CONTEXT *ctx, PJ_LP in,
PJ_DIRECTION direction,
const HorizontalShiftGrid *grid,
HorizontalShiftGridSet *gridset,
@@ -3066,7 +3066,7 @@ PJ_LP pj_hgrid_apply(PJ_CONTEXT *ctx, const ListOfHGrids &grids, PJ_LP lp,
HorizontalShiftGridSet *gridset = nullptr;
const auto grid = findGrid(grids, lp, gridset);
if (!grid) {
- pj_ctx_set_errno(ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(ctx, PJD_ERR_GRID_AREA);
return out;
}
if (grid->isNullGrid()) {
@@ -3082,7 +3082,7 @@ PJ_LP pj_hgrid_apply(PJ_CONTEXT *ctx, const ListOfHGrids &grids, PJ_LP lp,
}
if (out.lam == HUGE_VAL || out.phi == HUGE_VAL)
- pj_ctx_set_errno(ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(ctx, PJD_ERR_GRID_AREA);
return out;
}
@@ -3098,7 +3098,7 @@ PJ_LP pj_hgrid_value(PJ *P, const ListOfHGrids &grids, PJ_LP lp) {
HorizontalShiftGridSet *gridset = nullptr;
const auto grid = findGrid(grids, lp, gridset);
if (!grid) {
- pj_ctx_set_errno(P->ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(P->ctx, PJD_ERR_GRID_AREA);
return out;
}
@@ -3107,7 +3107,7 @@ PJ_LP pj_hgrid_value(PJ *P, const ListOfHGrids &grids, PJ_LP lp) {
if (!extent.isGeographic) {
pj_log(P->ctx, PJ_LOG_ERROR,
"Can only handle grids referenced in a geographic CRS");
- pj_ctx_set_errno(P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return out;
}
@@ -3130,7 +3130,7 @@ PJ_LP pj_hgrid_value(PJ *P, const ListOfHGrids &grids, PJ_LP lp) {
}
if (out.lam == HUGE_VAL || out.phi == HUGE_VAL) {
- pj_ctx_set_errno(P->ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(P->ctx, PJD_ERR_GRID_AREA);
}
return out;
@@ -3157,7 +3157,7 @@ static double read_vgrid_value(PJ_CONTEXT *ctx, const ListOfVGrids &grids,
}
}
if (!grid) {
- pj_ctx_set_errno(ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(ctx, PJD_ERR_GRID_AREA);
return HUGE_VAL;
}
if (grid->isNullGrid()) {
@@ -3168,7 +3168,7 @@ static double read_vgrid_value(PJ_CONTEXT *ctx, const ListOfVGrids &grids,
if (!extent.isGeographic) {
pj_log(ctx, PJ_LOG_ERROR,
"Can only handle grids referenced in a geographic CRS");
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return HUGE_VAL;
}
@@ -3200,7 +3200,7 @@ static double read_vgrid_value(PJ_CONTEXT *ctx, const ListOfVGrids &grids,
if (!(grid_ix >= 0 && grid_ix < grid->width())) {
// in the unlikely case we end up here...
pj_log(ctx, PJ_LOG_ERROR, "grid_ix not in grid");
- pj_ctx_set_errno(ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(ctx, PJD_ERR_GRID_AREA);
return HUGE_VAL;
}
int grid_iy = static_cast<int>(lround(floor(grid_y)));
@@ -3309,11 +3309,11 @@ ListOfVGrids pj_vgrid_init(PJ *P, const char *gridkey) {
if (!gridSet) {
if (!canFail) {
if (proj_context_errno(P->ctx) != PJD_ERR_NETWORK_ERROR) {
- pj_ctx_set_errno(P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
}
return {};
}
- pj_ctx_set_errno(P->ctx, 0); // don't treat as a persistent error
+ proj_context_errno_set(P->ctx, 0); // don't treat as a persistent error
} else {
grids.emplace_back(std::move(gridSet));
}
@@ -3377,7 +3377,7 @@ bool pj_bilinear_interpolation_three_samples(
if (!extent.isGeographic) {
pj_log(ctx, PJ_LOG_ERROR,
"Can only handle grids referenced in a geographic CRS");
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return false;
}
@@ -3443,49 +3443,3 @@ bool pj_bilinear_interpolation_three_samples(
NS_PROJ_END
-/************************************************************************/
-/* pj_apply_gridshift() */
-/* */
-/* This is the externally callable interface - part of the */
-/* public API - though it is not used internally any more and I */
-/* doubt it is used by any other applications. But we preserve */
-/* it to honour our public api. */
-/************************************************************************/
-
-int pj_apply_gridshift(projCtx ctx, const char *nadgrids, int inverse,
- long point_count, int point_offset, double *x, double *y,
- double * /*z */)
-
-{
- auto hgrids = NS_PROJ::getListOfGridSets(ctx, nadgrids);
- if (hgrids.empty()) {
- pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
- return 1;
- }
-
- for (long i = 0; i < point_count; i++) {
- PJ_LP input;
-
- long io = i * point_offset;
- input.phi = y[io];
- input.lam = x[io];
-
- auto output =
- pj_hgrid_apply(ctx, hgrids, input, inverse ? PJ_INV : PJ_FWD);
-
- if (output.lam != HUGE_VAL) {
- y[io] = output.phi;
- x[io] = output.lam;
- } else {
- if (ctx->debug_level >= PJ_LOG_DEBUG_MAJOR) {
- pj_log(ctx, PJ_LOG_DEBUG_MAJOR,
- "pj_apply_gridshift(): failed to find a grid shift "
- "table for\n"
- " location (%.7fdW,%.7fdN)",
- x[io] * RAD_TO_DEG, y[io] * RAD_TO_DEG);
- }
- }
- }
-
- return 0;
-}
diff --git a/src/init.cpp b/src/init.cpp
index 101fc8ad..7b614c5f 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1,7 +1,7 @@
/******************************************************************************
* Project: PROJ.4
* Purpose: Initialize projection object from string definition. Includes
- * pj_init(), pj_init_plus() and pj_free() function.
+ * pj_init(), and pj_init_plus() function.
* Author: Gerald Evenden, Frank Warmerdam <warmerdam@pobox.com>
*
******************************************************************************
@@ -55,7 +55,7 @@ static paralist *string_to_paralist (PJ_CONTEXT *ctx, char *definition) {
/* Keep a handle to the start of the list, so we have something to return */
auto param = pj_mkparam_ws (c, &c);
if (nullptr==param) {
- pj_dealloc_params (ctx, first, ENOMEM);
+ free_params (ctx, first, ENOMEM);
return nullptr;
}
if (nullptr==last) {
@@ -84,7 +84,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
char *buffer = nullptr;
size_t n;
- fname = static_cast<char*>(pj_malloc (MAX_PATH_FILENAME+ID_TAG_MAX+3));
+ fname = static_cast<char*>(malloc (MAX_PATH_FILENAME+ID_TAG_MAX+3));
if (nullptr==fname) {
return nullptr;
}
@@ -96,7 +96,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
else
key += 5;
if (MAX_PATH_FILENAME + ID_TAG_MAX + 2 < strlen (key)) {
- pj_dealloc (fname);
+ free (fname);
return nullptr;
}
memmove (fname, key, strlen (key) + 1);
@@ -105,7 +105,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
section = strrchr(fname, ':');
if (nullptr==section) {
proj_context_errno_set (ctx, PJD_ERR_NO_COLON_IN_INIT_STRING);
- pj_dealloc (fname);
+ free (fname);
return nullptr;
}
*section = 0;
@@ -117,7 +117,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
auto file = NS_PROJ::FileManager::open_resource_file(ctx, fname);
if (nullptr==file) {
- pj_dealloc (fname);
+ free (fname);
proj_context_errno_set (ctx, PJD_ERR_NO_OPTION_IN_INIT_FILE);
return nullptr;
}
@@ -131,7 +131,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
line = file->read_line(MAX_LINE_LENGTH, maxLenReached, eofReached);
/* End of file? */
if (maxLenReached || eofReached) {
- pj_dealloc (fname);
+ free (fname);
proj_context_errno_set (ctx, PJD_ERR_NO_OPTION_IN_INIT_FILE);
return nullptr;
}
@@ -149,9 +149,9 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
}
/* We're at the first line of the right section - copy line to buffer */
- buffer = static_cast<char*>(pj_malloc (current_buffer_size));
+ buffer = static_cast<char*>(malloc (current_buffer_size));
if (nullptr==buffer) {
- pj_dealloc (fname);
+ free (fname);
return nullptr;
}
@@ -183,22 +183,22 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
pj_chomp (&line[0]); /* Remove '#' style comments */
next_length = strlen (line.data()) + buffer_length + 2;
if (next_length > current_buffer_size) {
- char *b = static_cast<char*>(pj_malloc (2 * current_buffer_size));
+ char *b = static_cast<char*>(malloc (2 * current_buffer_size));
if (nullptr==b) {
- pj_dealloc (buffer);
+ free (buffer);
buffer = nullptr;
break;
}
strcpy (b, buffer);
current_buffer_size *= 2;
- pj_dealloc (buffer);
+ free (buffer);
buffer = b;
}
buffer[buffer_length] = ' ';
strcpy (buffer + buffer_length + 1, line.data());
}
- pj_dealloc (fname);
+ free (fname);
if (nullptr==buffer)
return nullptr;
pj_shrink (buffer);
@@ -257,7 +257,7 @@ Expand key from buffer or (if not in buffer) from init file
PJ* src;
const char* proj_string;
- pj_ctx_set_errno( ctx, 0 );
+ proj_context_errno_set( ctx, 0 );
if( !allow_init_epsg ) {
pj_log (ctx, PJ_LOG_TRACE, "%s expansion disallowed", xkey);
@@ -306,7 +306,7 @@ Expand key from buffer or (if not in buffer) from init file
definition,
init_items->param,
init_items->next ? init_items->next->param : "(empty)");
- pj_dealloc (definition);
+ free (definition);
if (nullptr==init_items)
return nullptr;
@@ -415,7 +415,7 @@ pj_init_plus( const char *definition )
}
PJ *
-pj_init_plus_ctx( projCtx ctx, const char *definition )
+pj_init_plus_ctx( PJ_CONTEXT *ctx, const char *definition )
{
#define MAX_ARG 200
char *argv[MAX_ARG];
@@ -424,7 +424,7 @@ pj_init_plus_ctx( projCtx ctx, const char *definition )
PJ *result = nullptr;
/* make a copy that we can manipulate */
- defn_copy = (char *) pj_malloc( strlen(definition)+1 );
+ defn_copy = (char *) malloc( strlen(definition)+1 );
if (!defn_copy)
return nullptr;
strcpy( defn_copy, definition );
@@ -447,8 +447,8 @@ pj_init_plus_ctx( projCtx ctx, const char *definition )
if( argc+1 == MAX_ARG )
{
- pj_dalloc( defn_copy );
- pj_ctx_set_errno( ctx, PJD_ERR_UNPARSEABLE_CS_DEF );
+ free( defn_copy );
+ proj_context_errno_set( ctx, PJD_ERR_UNPARSEABLE_CS_DEF );
return nullptr;
}
@@ -477,7 +477,7 @@ pj_init_plus_ctx( projCtx ctx, const char *definition )
/* perform actual initialization */
result = pj_init_ctx( ctx, argc, argv );
- pj_dalloc( defn_copy );
+ free( defn_copy );
return result;
}
@@ -511,7 +511,7 @@ static PJ_CONSTRUCTOR locate_constructor (const char *name) {
PJ *
-pj_init_ctx(projCtx ctx, int argc, char **argv) {
+pj_init_ctx(PJ_CONTEXT *ctx, int argc, char **argv) {
/* Legacy interface: allow init=epsg:XXXX syntax by default */
int allow_init_epsg = proj_context_get_use_proj4_init_rules(ctx, TRUE);
return pj_init_ctx_with_allow_init_epsg(ctx, argc, argv, allow_init_epsg);
@@ -519,7 +519,7 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) {
PJ *
-pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_init_epsg) {
+pj_init_ctx_with_allow_init_epsg(PJ_CONTEXT *ctx, int argc, char **argv, int allow_init_epsg) {
const char *s;
char *name;
PJ_CONSTRUCTOR proj;
@@ -538,7 +538,7 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
ctx->last_errno = 0;
if (argc <= 0) {
- pj_ctx_set_errno (ctx, PJD_ERR_NO_ARGS);
+ proj_context_errno_set (ctx, PJD_ERR_NO_ARGS);
return nullptr;
}
@@ -552,13 +552,13 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
/* can't have nested pipelines directly */
if (n_pipelines > 1) {
- pj_ctx_set_errno (ctx, PJD_ERR_MALFORMED_PIPELINE);
+ proj_context_errno_set (ctx, PJD_ERR_MALFORMED_PIPELINE);
return nullptr;
}
/* don't allow more than one +init in non-pipeline operations */
if (n_pipelines == 0 && n_inits > 1) {
- pj_ctx_set_errno (ctx, PJD_ERR_TOO_MANY_INITS);
+ proj_context_errno_set (ctx, PJD_ERR_TOO_MANY_INITS);
return nullptr;
}
@@ -566,14 +566,14 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
/* put arguments into internal linked list */
start = curr = pj_mkparam(argv[0]);
if (!curr) {
- pj_dealloc_params (ctx, start, ENOMEM);
+ free_params (ctx, start, ENOMEM);
return nullptr;
}
for (i = 1; i < argc; ++i) {
curr->next = pj_mkparam(argv[i]);
if (!curr->next) {
- pj_dealloc_params (ctx, start, ENOMEM);
+ free_params (ctx, start, ENOMEM);
return nullptr;
}
curr = curr->next;
@@ -588,31 +588,31 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
if (init && n_pipelines == 0) {
init = pj_expand_init_internal (ctx, init, allow_init_epsg);
if (!init) {
- pj_dealloc_params (ctx, start, PJD_ERR_NO_ARGS);
+ free_params (ctx, start, PJD_ERR_NO_ARGS);
return nullptr;
}
}
if (ctx->last_errno) {
- pj_dealloc_params (ctx, start, ctx->last_errno);
+ free_params (ctx, start, ctx->last_errno);
return nullptr;
}
/* Find projection selection */
curr = pj_param_exists (start, "proj");
if (nullptr==curr) {
- pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
+ free_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
return nullptr;
}
name = curr->param;
if (strlen (name) < 6) {
- pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
+ free_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
return nullptr;
}
name += 5;
proj = locate_constructor (name);
if (nullptr==proj) {
- pj_dealloc_params (ctx, start, PJD_ERR_UNKNOWN_PROJECTION_ID);
+ free_params (ctx, start, PJD_ERR_UNKNOWN_PROJECTION_ID);
return nullptr;
}
@@ -621,7 +621,7 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
/* Allocate projection structure */
PIN = proj(nullptr);
if (nullptr==PIN) {
- pj_dealloc_params (ctx, start, ENOMEM);
+ free_params (ctx, start, ENOMEM);
return nullptr;
}
@@ -820,7 +820,7 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
PIN->from_greenwich = 0.0;
/* Private object for the geodesic functions */
- PIN->geod = static_cast<struct geod_geodesic*>(pj_calloc (1, sizeof (struct geod_geodesic)));
+ PIN->geod = static_cast<struct geod_geodesic*>(calloc (1, sizeof (struct geod_geodesic)));
if (nullptr==PIN->geod)
return pj_default_destructor (PIN, ENOMEM);
geod_init(PIN->geod, PIN->a, (1 - sqrt (1 - PIN->es)));
@@ -829,7 +829,7 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
err = proj_errno_reset (PIN);
PIN = proj(PIN);
if (proj_errno (PIN)) {
- pj_free(PIN);
+ proj_destroy(PIN);
return nullptr;
}
proj_errno_restore (PIN, err);
diff --git a/src/initcache.cpp b/src/initcache.cpp
index af20fb82..cf9460ab 100644
--- a/src/initcache.cpp
+++ b/src/initcache.cpp
@@ -48,7 +48,7 @@ paralist *pj_clone_paralist( const paralist *list)
for( ; list != nullptr; list = list->next )
{
paralist *newitem = (paralist *)
- pj_malloc(sizeof(paralist) + strlen(list->param));
+ malloc(sizeof(paralist) + strlen(list->param));
newitem->used = 0;
newitem->next = nullptr;
@@ -83,17 +83,17 @@ void pj_clear_initcache()
{
paralist *n, *t = cache_paralist[i];
- pj_dalloc( cache_key[i] );
+ free( cache_key[i] );
/* free parameter list elements */
for (; t != nullptr; t = n) {
n = t->next;
- pj_dalloc(t);
+ free(t);
}
}
- pj_dalloc( cache_key );
- pj_dalloc( cache_paralist );
+ free( cache_key );
+ free( cache_paralist );
cache_count = 0;
cache_alloc= 0;
cache_key = nullptr;
@@ -151,29 +151,29 @@ void pj_insert_initcache( const char *filekey, const paralist *list )
cache_alloc = cache_alloc * 2 + 15;
- cache_key_new = (char **) pj_malloc(sizeof(char*) * cache_alloc);
+ cache_key_new = (char **) malloc(sizeof(char*) * cache_alloc);
if( cache_key && cache_count )
{
memcpy( cache_key_new, cache_key, sizeof(char*) * cache_count);
}
- pj_dalloc( cache_key );
+ free( cache_key );
cache_key = cache_key_new;
cache_paralist_new = (paralist **)
- pj_malloc(sizeof(paralist*) * cache_alloc);
+ malloc(sizeof(paralist*) * cache_alloc);
if( cache_paralist && cache_count )
{
memcpy( cache_paralist_new, cache_paralist,
sizeof(paralist*) * cache_count );
}
- pj_dalloc( cache_paralist );
+ free( cache_paralist );
cache_paralist = cache_paralist_new;
}
/*
** Duplicate the filekey and paralist, and insert in cache.
*/
- cache_key[cache_count] = (char *) pj_malloc(strlen(filekey)+1);
+ cache_key[cache_count] = (char *) malloc(strlen(filekey)+1);
strcpy( cache_key[cache_count], filekey );
cache_paralist[cache_count] = pj_clone_paralist( list );
diff --git a/src/internal.cpp b/src/internal.cpp
index 91994077..175ffa9b 100644
--- a/src/internal.cpp
+++ b/src/internal.cpp
@@ -141,15 +141,15 @@ Check if a a PJ has an inverse.
void proj_context_set (PJ *P, PJ_CONTEXT *ctx) {
if (nullptr==ctx)
ctx = pj_get_default_ctx ();
- pj_set_ctx (P, ctx);
+ proj_assign_context (P, ctx);
}
void proj_context_inherit (PJ *parent, PJ *child) {
if (nullptr==parent)
- pj_set_ctx (child, pj_get_default_ctx());
+ proj_assign_context (child, pj_get_default_ctx());
else
- pj_set_ctx (child, pj_get_ctx(parent));
+ proj_assign_context (child, pj_get_ctx(parent));
}
@@ -411,13 +411,16 @@ to that context.
******************************************************************************/
if (nullptr==ctx)
ctx = pj_get_default_ctx();
- pj_ctx_set_errno (ctx, err);
+ ctx->last_errno = err;
+ if( err == 0 )
+ return;
+ errno = err;
}
/* logging */
/* pj_vlog resides in pj_log.c and relates to pj_log as vsprintf relates to sprintf */
-void pj_vlog( projCtx ctx, int level, const char *fmt, va_list args );
+void pj_vlog( PJ_CONTEXT *ctx, int level, const char *fmt, va_list args );
/***************************************************************************************/
diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp
index cbbdcaa8..8fdebcbd 100644
--- a/src/iso19111/c_api.cpp
+++ b/src/iso19111/c_api.cpp
@@ -79,10 +79,10 @@ static void PROJ_NO_INLINE proj_log_error(PJ_CONTEXT *ctx, const char *function,
msg += ": ";
msg += text;
ctx->logger(ctx->logger_app_data, PJ_LOG_ERROR, msg.c_str());
- auto previous_errno = pj_ctx_get_errno(ctx);
+ auto previous_errno = proj_context_errno(ctx);
if (previous_errno == 0) {
// only set errno if it wasn't set deeper down the call stack
- pj_ctx_set_errno(ctx, PJD_ERR_GENERIC_ERROR);
+ proj_context_errno_set(ctx, PJD_ERR_GENERIC_ERROR);
}
}
@@ -2690,11 +2690,11 @@ proj_get_crs_info_list_from_database(PJ_CONTEXT *ctx, const char *auth_name,
void proj_crs_info_list_destroy(PROJ_CRS_INFO **list) {
if (list) {
for (int i = 0; list[i] != nullptr; i++) {
- pj_dalloc(list[i]->auth_name);
- pj_dalloc(list[i]->code);
- pj_dalloc(list[i]->name);
- pj_dalloc(list[i]->area_name);
- pj_dalloc(list[i]->projection_method_name);
+ free(list[i]->auth_name);
+ free(list[i]->code);
+ free(list[i]->name);
+ free(list[i]->area_name);
+ free(list[i]->projection_method_name);
delete list[i];
}
delete[] list;
@@ -2784,11 +2784,11 @@ PROJ_UNIT_INFO **proj_get_units_from_database(PJ_CONTEXT *ctx,
void proj_unit_list_destroy(PROJ_UNIT_INFO **list) {
if (list) {
for (int i = 0; list[i] != nullptr; i++) {
- pj_dalloc(list[i]->auth_name);
- pj_dalloc(list[i]->code);
- pj_dalloc(list[i]->name);
- pj_dalloc(list[i]->category);
- pj_dalloc(list[i]->proj_short_name);
+ free(list[i]->auth_name);
+ free(list[i]->code);
+ free(list[i]->name);
+ free(list[i]->category);
+ free(list[i]->proj_short_name);
delete list[i];
}
delete[] list;
diff --git a/src/iso19111/datum.cpp b/src/iso19111/datum.cpp
index e29f6319..60244779 100644
--- a/src/iso19111/datum.cpp
+++ b/src/iso19111/datum.cpp
@@ -43,7 +43,6 @@
// clang-format off
#include "proj.h"
#include "proj_internal.h"
-#include "proj_api.h"
// clang-format on
#include "proj_json_streaming_writer.hpp"
@@ -418,7 +417,7 @@ std::string
PrimeMeridian::getPROJStringWellKnownName(const common::Angle &angle) {
const double valRad = angle.getSIValue();
std::string projPMName;
- projCtx ctxt = pj_ctx_alloc();
+ PJ_CONTEXT *ctxt = proj_context_create();
auto proj_pm = proj_list_prime_meridians();
for (int i = 0; proj_pm[i].id != nullptr; ++i) {
double valRefRad = dmstor_ctx(ctxt, proj_pm[i].defn, nullptr);
@@ -427,7 +426,7 @@ PrimeMeridian::getPROJStringWellKnownName(const common::Angle &angle) {
break;
}
}
- pj_ctx_free(ctxt);
+ proj_context_destroy(ctxt);
return projPMName;
}
//! @endcond
diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp
index 0ccfefc1..03fd5267 100644
--- a/src/iso19111/factory.cpp
+++ b/src/iso19111/factory.cpp
@@ -65,7 +65,6 @@
// clang-format off
#include "proj.h"
#include "proj_internal.h"
-#include "proj_api.h"
// clang-format on
#include <sqlite3.h>
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp
index 713a471d..867a0d53 100644
--- a/src/iso19111/io.cpp
+++ b/src/iso19111/io.cpp
@@ -70,7 +70,6 @@
// clang-format off
#include "proj.h"
#include "proj_internal.h"
-#include "proj_api.h"
// clang-format on
using namespace NS_PROJ::common;
@@ -9820,7 +9819,7 @@ PROJStringParser::createFromPROJString(const std::string &projString) {
paralist *list = pj_expand_init(ctx, init);
ctx->projStringParserCreateFromPROJStringRecursionCounter--;
if (!list) {
- pj_dealloc(init);
+ free(init);
throw ParsingException("cannot expand " + projString);
}
std::string expanded;
@@ -9843,7 +9842,7 @@ PROJStringParser::createFromPROJString(const std::string &projString) {
}
auto n = t->next;
- pj_dealloc(t);
+ free(t);
t = n;
}
for (const auto &pair : d->steps_[0].paramValues) {
diff --git a/src/lib_proj.cmake b/src/lib_proj.cmake
index 67bc1f4e..7ca7f3a4 100644
--- a/src/lib_proj.cmake
+++ b/src/lib_proj.cmake
@@ -217,9 +217,7 @@ set(SRC_LIBPROJ_CORE
dmstor.cpp
ell_set.cpp
ellps.cpp
- errno.cpp
factors.cpp
- fileapi.cpp
fwd.cpp
gauss.cpp
generic_inverse.cpp
@@ -246,10 +244,8 @@ set(SRC_LIBPROJ_CORE
rtodms.cpp
strerrno.cpp
strtod.cpp
- transform.cpp
tsfn.cpp
units.cpp
- utils.cpp
wkt1_generated_parser.c
wkt1_generated_parser.h
wkt1_parser.cpp
@@ -275,7 +271,6 @@ set(SRC_LIBPROJ_CORE
)
set(HEADERS_LIBPROJ
- proj_api.h
proj.h
proj_experimental.h
proj_constants.h
diff --git a/src/log.cpp b/src/log.cpp
index 3cc10cfd..c343e65b 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -48,9 +48,9 @@ void pj_stderr_logger( void *app_data, int level, const char *msg )
/************************************************************************/
/* pj_vlog() */
/************************************************************************/
-void pj_vlog( projCtx ctx, int level, const char *fmt, va_list args );
+void pj_vlog( PJ_CONTEXT *ctx, int level, const char *fmt, va_list args );
/* Workhorse for the log functions - relates to pj_log as vsprintf relates to sprintf */
-void pj_vlog( projCtx ctx, int level, const char *fmt, va_list args )
+void pj_vlog( PJ_CONTEXT *ctx, int level, const char *fmt, va_list args )
{
char *msg_buf;
@@ -84,7 +84,7 @@ void pj_vlog( projCtx ctx, int level, const char *fmt, va_list args )
/* pj_log() */
/************************************************************************/
-void pj_log( projCtx ctx, int level, const char *fmt, ... )
+void pj_log( PJ_CONTEXT *ctx, int level, const char *fmt, ... )
{
va_list args;
diff --git a/src/malloc.cpp b/src/malloc.cpp
index c8de6630..6b7fbf26 100644
--- a/src/malloc.cpp
+++ b/src/malloc.cpp
@@ -53,99 +53,13 @@
using namespace NS_PROJ;
-/**********************************************************************/
-void *pj_malloc(size_t size) {
-/***********************************************************************
-Currently, pj_malloc is a hack to solve an errno problem.
-The problem is described in more details at
-https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=86420.
-It seems, that pj_init and similar functions incorrectly
-(under debian/glibs-2.3.2) assume that pj_malloc resets
-errno after success. pj_malloc tries to mimic this.
-
-NOTE (2017-09-29): The problem described at the bugzilla page
-referred to above, is most likely a case of someone not
-understanding the proper usage of errno. We should review
-whether "the problem is actually a problem" in PROJ.4 code.
-
-Library specific allocators can be useful, and improve
-interoperability, if properly used. That is, by making them
-run/initialization time switchable, somewhat like the file i/o
-interface.
-
-But as things stand, we are more likely to get benefit
-from reviewing the code for proper errno usage, which is hard,
-due to the presence of context local and global pj_errnos.
-
-Probably, these were introduced in order to support incomplete
-implementations of thread local errnos at an early phase of the
-implementation of multithreading support in PROJ.4).
-
-It is likely too late to get rid of contexts, but we can still
-benefit from a better usage of errno.
-***********************************************************************/
- int old_errno = errno;
- void *res = malloc(size);
- if ( res && !old_errno )
- errno = 0;
- return res;
-}
-
-
-/**********************************************************************/
-void *pj_calloc (size_t n, size_t size) {
-/***********************************************************************
-pj_calloc is the pj-equivalent of calloc().
-
-It allocates space for an array of <n> elements of size <size>.
-The array is initialized to zeros.
-***********************************************************************/
- void *res = pj_malloc (n*size);
- if (nullptr==res)
- return nullptr;
- memset (res, 0, n*size);
- return res;
-}
-
-
-/**********************************************************************/
-void pj_dalloc(void *ptr) {
-/**********************************************************************/
- free(ptr);
-}
-
-
-/**********************************************************************/
-void *pj_dealloc (void *ptr) {
-/***********************************************************************
-pj_dealloc supports the common use case of "clean up and return a null
-pointer" to signal an error in a multi level allocation:
-
- struct foo { int bar; int *baz; };
-
- struct foo *p = pj_calloc (1, sizeof (struct foo));
- if (0==p)
- return 0;
-
- p->baz = pj_calloc (10, sizeof(int));
- if (0==p->baz)
- return pj_dealloc (p); // clean up + signal error by 0-return
-
- return p; // success
-
-***********************************************************************/
- if (nullptr==ptr)
- return nullptr;
- pj_dalloc (ptr);
- return nullptr;
-}
/**********************************************************************/
char *pj_strdup(const char *str)
/**********************************************************************/
{
size_t len = strlen(str) + 1;
- char *dup = static_cast<char*>(pj_malloc(len));
+ char *dup = static_cast<char*>(malloc(len));
if (dup)
memcpy(dup, str, len);
return dup;
@@ -153,7 +67,7 @@ char *pj_strdup(const char *str)
/*****************************************************************************/
-void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) {
+void *free_params (PJ_CONTEXT *ctx, paralist *start, int errlev) {
/*****************************************************************************
Companion to pj_default_destructor (below). Deallocates a linked list
of "+proj=xxx" initialization parameters.
@@ -164,9 +78,9 @@ void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) {
paralist *t, *n;
for (t = start; t; t = n) {
n = t->next;
- pj_dealloc(t);
+ free(t);
}
- pj_ctx_set_errno (ctx, errlev);
+ proj_context_errno_set (ctx, errlev);
return (void *) nullptr;
}
@@ -174,7 +88,7 @@ void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) {
/************************************************************************/
-/* pj_free() */
+/* proj_destroy() */
/* */
/* This is the application callable entry point for destroying */
/* a projection definition. It does work generic to all */
@@ -183,15 +97,16 @@ void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) {
/* In most cases P->destructor()==pj_default_destructor. */
/************************************************************************/
-void pj_free(PJ *P) {
+PJ *proj_destroy(PJ *P) {
if (nullptr==P || !P->destructor)
- return;
+ return nullptr;
/* free projection parameters - all the hard work is done by */
/* pj_default_destructor, which is supposed */
/* to be called as the last step of the local destructor */
/* pointed to by P->destructor. In most cases, */
/* pj_default_destructor actually *is* what is pointed to */
P->destructor (P, proj_errno(P));
+ return nullptr;
}
/*****************************************************************************/
@@ -218,42 +133,42 @@ PJ *pj_default_destructor (PJ *P, int errlev) { /* Destructor */
/* Note that both, in the multithreaded case, may then contain undefined */
/* values. This is expected behavior. For MT have one ctx per thread */
if (0!=errlev)
- pj_ctx_set_errno (pj_get_ctx(P), errlev);
+ proj_context_errno_set (pj_get_ctx(P), errlev);
if (nullptr==P)
return nullptr;
- pj_dealloc(P->def_size);
- pj_dealloc(P->def_shape);
- pj_dealloc(P->def_spherification);
- pj_dealloc(P->def_ellps);
+ free(P->def_size);
+ free(P->def_shape);
+ free(P->def_spherification);
+ free(P->def_ellps);
delete static_cast<ListOfHGrids*>(P->hgrids_legacy);
delete static_cast<ListOfVGrids*>(P->vgrids_legacy);
- /* We used to call pj_dalloc( P->catalog ), but this will leak */
+ /* We used to call free( P->catalog ), but this will leak */
/* memory. The safe way to clear catalog and grid is to call */
- /* pj_gc_unloadall(pj_get_default_ctx()); and pj_deallocate_grids(); */
+ /* pj_gc_unloadall(pj_get_default_ctx()); and freeate_grids(); */
/* TODO: we should probably have a public pj_cleanup() method to do all */
/* that */
/* free the interface to Charles Karney's geodesic library */
- pj_dealloc( P->geod );
+ free( P->geod );
/* free parameter list elements */
- pj_dealloc_params (pj_get_ctx(P), P->params, errlev);
- pj_dealloc (P->def_full);
+ free_params (pj_get_ctx(P), P->params, errlev);
+ free (P->def_full);
/* free the cs2cs emulation elements */
- pj_free (P->axisswap);
- pj_free (P->helmert);
- pj_free (P->cart);
- pj_free (P->cart_wgs84);
- pj_free (P->hgridshift);
- pj_free (P->vgridshift);
-
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque));
+ proj_destroy (P->axisswap);
+ proj_destroy (P->helmert);
+ proj_destroy (P->cart);
+ proj_destroy (P->cart_wgs84);
+ proj_destroy (P->hgridshift);
+ proj_destroy (P->vgridshift);
+
+ free (static_cast<struct pj_opaque*>(P->opaque));
delete P;
return nullptr;
}
@@ -262,7 +177,6 @@ PJ *pj_default_destructor (PJ *P, int errlev) { /* Destructor */
void proj_cleanup() {
/*****************************************************************************/
pj_clear_initcache();
- pj_deallocate_grids();
FileManager::clearMemoryCache();
pj_clear_hgridshift_knowngrids_cache();
pj_clear_vgridshift_knowngrids_cache();
diff --git a/src/mlfn.cpp b/src/mlfn.cpp
index 80f9163b..763d83ee 100644
--- a/src/mlfn.cpp
+++ b/src/mlfn.cpp
@@ -26,7 +26,7 @@
double *pj_enfn(double es) {
double t, *en;
- en = (double *) pj_malloc(EN_SIZE * sizeof (double));
+ en = (double *) malloc(EN_SIZE * sizeof (double));
if (nullptr==en)
return nullptr;
@@ -45,7 +45,7 @@ pj_mlfn(double phi, double sphi, double cphi, const double *en) {
}
double
-pj_inv_mlfn(projCtx ctx, double arg, double es, const double *en) {
+pj_inv_mlfn(PJ_CONTEXT *ctx, double arg, double es, const double *en) {
double sinphi_ignored;
double cosphi_ignored;
return inline_pj_inv_mlfn(ctx, arg, es, en, &sinphi_ignored, &cosphi_ignored);
diff --git a/src/mlfn.hpp b/src/mlfn.hpp
index 26a2959f..228c65a4 100644
--- a/src/mlfn.hpp
+++ b/src/mlfn.hpp
@@ -15,7 +15,7 @@ inline static double inline_pj_mlfn(double phi, double sphi, double cphi, const
}
inline static double
-inline_pj_inv_mlfn(projCtx ctx, double arg, double es, const double *en,
+inline_pj_inv_mlfn(PJ_CONTEXT *ctx, double arg, double es, const double *en,
double* sinphi, double* cosphi) {
const double k = 1./(1.-es);
constexpr double INV_MLFN_EPS = 1e-11;
@@ -66,7 +66,7 @@ inline_pj_inv_mlfn(projCtx ctx, double arg, double es, const double *en,
}
*sinphi = s;
*cosphi = c;
- pj_ctx_set_errno( ctx, PJD_ERR_NON_CONV_INV_MERI_DIST );
+ proj_context_errno_set( ctx, PJD_ERR_NON_CONV_INV_MERI_DIST );
return phi;
}
diff --git a/src/mutex.cpp b/src/mutex.cpp
index 60ed5be1..9fc78acf 100644
--- a/src/mutex.cpp
+++ b/src/mutex.cpp
@@ -34,11 +34,6 @@
#ifndef _WIN32
#include "proj_config.h"
#include "proj_internal.h"
-#else
-#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#endif
-#include "proj_api.h"
#endif
/* on win32 we always use win32 mutexes, even if pthreads are available */
diff --git a/src/networkfilemanager.cpp b/src/networkfilemanager.cpp
index f6521ed2..9edffaad 100644
--- a/src/networkfilemanager.cpp
+++ b/src/networkfilemanager.cpp
@@ -1315,7 +1315,7 @@ std::unique_ptr<File> NetworkFile::open(PJ_CONTEXT *ctx, const char *filename) {
errorBuffer.resize(strlen(errorBuffer.data()));
pj_log(ctx, PJ_LOG_ERROR, "Cannot open %s: %s", filename,
errorBuffer.c_str());
- pj_ctx_set_errno(ctx, PJD_ERR_NETWORK_ERROR);
+ proj_context_errno_set(ctx, PJD_ERR_NETWORK_ERROR);
}
bool ok = false;
@@ -1404,7 +1404,7 @@ size_t NetworkFile::read(void *buffer, size_t sizeBytes) {
&nRead, errorBuffer.size(), &errorBuffer[0],
m_ctx->networking.user_data);
if (!m_handle) {
- pj_ctx_set_errno(m_ctx, PJD_ERR_NETWORK_ERROR);
+ proj_context_errno_set(m_ctx, PJD_ERR_NETWORK_ERROR);
return 0;
}
} else {
@@ -1420,7 +1420,7 @@ size_t NetworkFile::read(void *buffer, size_t sizeBytes) {
pj_log(m_ctx, PJ_LOG_ERROR, "Cannot read in %s: %s",
m_url.c_str(), errorBuffer.c_str());
}
- pj_ctx_set_errno(m_ctx, PJD_ERR_NETWORK_ERROR);
+ proj_context_errno_set(m_ctx, PJD_ERR_NETWORK_ERROR);
return 0;
}
diff --git a/src/param.cpp b/src/param.cpp
index 289faca3..28d6bc3e 100644
--- a/src/param.cpp
+++ b/src/param.cpp
@@ -38,7 +38,7 @@ static void unquote_string(char* param_str) {
paralist *pj_mkparam(const char *str) {
paralist *newitem;
- if((newitem = (paralist *)pj_malloc(sizeof(paralist) + strlen(str))) != nullptr) {
+ if((newitem = (paralist *)malloc(sizeof(paralist) + strlen(str))) != nullptr) {
newitem->used = 0;
newitem->next = nullptr;
if (*str == '+')
@@ -82,7 +82,7 @@ paralist *pj_mkparam_ws (const char *str, const char **next_str) {
*next_str = str + len;
/* Use calloc to automagically 0-terminate the copy */
- newitem = (paralist *) pj_calloc (1, sizeof(paralist) + len + 1);
+ newitem = (paralist *) calloc (1, sizeof(paralist) + len + 1);
if (nullptr==newitem)
return nullptr;
memcpy(newitem->param, str, len);
@@ -151,7 +151,7 @@ paralist *pj_param_exists (paralist *list, const char *parameter) {
/* */
/************************************************************************/
-PROJVALUE pj_param (projCtx ctx, paralist *pl, const char *opt) {
+PROJVALUE pj_param (PJ_CONTEXT *ctx, paralist *pl, const char *opt) {
int type;
unsigned l;
@@ -220,7 +220,7 @@ PROJVALUE pj_param (projCtx ctx, paralist *pl, const char *opt) {
value.i = 1;
break;
default:
- pj_ctx_set_errno (ctx, PJD_ERR_INVALID_BOOLEAN_PARAM);
+ proj_context_errno_set (ctx, PJD_ERR_INVALID_BOOLEAN_PARAM);
value.i = 0;
break;
}
diff --git a/src/phi2.cpp b/src/phi2.cpp
index 1c48d67f..2f258e47 100644
--- a/src/phi2.cpp
+++ b/src/phi2.cpp
@@ -7,7 +7,7 @@
#include "proj.h"
#include "proj_internal.h"
-double pj_sinhpsi2tanphi(projCtx ctx, const double taup, const double e) {
+double pj_sinhpsi2tanphi(PJ_CONTEXT *ctx, const double taup, const double e) {
/****************************************************************************
* Convert tau' = sinh(psi) = tan(chi) to tau = tan(phi). The code is taken
* from GeographicLib::Math::tauf(taup, e).
@@ -103,12 +103,12 @@ double pj_sinhpsi2tanphi(projCtx ctx, const double taup, const double e) {
break;
}
if (i == 0)
- pj_ctx_set_errno(ctx, PJD_ERR_NON_CONV_SINHPSI2TANPHI);
+ proj_context_errno_set(ctx, PJD_ERR_NON_CONV_SINHPSI2TANPHI);
return tau;
}
/*****************************************************************************/
-double pj_phi2(projCtx ctx, const double ts0, const double e) {
+double pj_phi2(PJ_CONTEXT *ctx, const double ts0, const double e) {
/****************************************************************************
* Determine latitude angle phi-2.
* Inputs:
diff --git a/src/pipeline.cpp b/src/pipeline.cpp
index 80ee0397..e9d11604 100644
--- a/src/pipeline.cpp
+++ b/src/pipeline.cpp
@@ -294,8 +294,8 @@ static PJ *destructor (PJ *P, int errlev) {
auto pipeline = static_cast<struct Pipeline*>(P->opaque);
- pj_dealloc (pipeline->argv);
- pj_dealloc (pipeline->current_argv);
+ free (pipeline->argv);
+ free (pipeline->current_argv);
delete pipeline;
P->opaque = nullptr;
@@ -321,7 +321,7 @@ static const char *argv_sentinel = "step";
static char **argv_params (paralist *params, size_t argc) {
char **argv;
size_t i = 0;
- argv = static_cast<char**>(pj_calloc (argc, sizeof (char *)));
+ argv = static_cast<char**>(calloc (argc, sizeof (char *)));
if (nullptr==argv)
return nullptr;
for (; params != nullptr; params = params->next)
@@ -461,7 +461,7 @@ PJ *OPERATION(pipeline,0) {
if (nullptr==argv)
return destructor (P, ENOMEM);
- pipeline->current_argv = current_argv = static_cast<char**>(pj_calloc (argc, sizeof (char *)));
+ pipeline->current_argv = current_argv = static_cast<char**>(calloc (argc, sizeof (char *)));
if (nullptr==current_argv)
return destructor (P, ENOMEM);
@@ -533,7 +533,7 @@ PJ *OPERATION(pipeline,0) {
int err_to_report = proj_errno(P);
if (0==err_to_report)
err_to_report = PJD_ERR_MALFORMED_PIPELINE;
- proj_log_error (P, "Pipeline: Bad step definition: %s (%s)", current_argv[0], pj_strerrno (err_to_report));
+ proj_log_error (P, "Pipeline: Bad step definition: %s (%s)", current_argv[0], proj_errno_string (err_to_report));
return destructor (P, err_to_report); /* ERROR: bad pipeline def */
}
next_step->parent = P;
@@ -679,7 +679,7 @@ static PJ_COORD pop(PJ_COORD point, PJ *P) {
static PJ *setup_pushpop(PJ *P) {
- auto pushpop = static_cast<struct PushPop*>(pj_calloc (1, sizeof(struct PushPop)));
+ auto pushpop = static_cast<struct PushPop*>(calloc (1, sizeof(struct PushPop)));
P->opaque = pushpop;
if (nullptr==P->opaque)
return destructor(P, ENOMEM);
diff --git a/src/pr_list.cpp b/src/pr_list.cpp
index 77db5bfb..30fc6571 100644
--- a/src/pr_list.cpp
+++ b/src/pr_list.cpp
@@ -66,7 +66,7 @@ char *pj_get_def( PJ *P, int options )
size_t def_max = 10;
(void) options;
- definition = (char *) pj_malloc(def_max);
+ definition = (char *) malloc(def_max);
if (!definition)
return nullptr;
definition[0] = '\0';
@@ -84,14 +84,14 @@ char *pj_get_def( PJ *P, int options )
char *def2;
def_max = def_max * 2 + l + 5;
- def2 = (char *) pj_malloc(def_max);
+ def2 = (char *) malloc(def_max);
if (def2) {
strcpy( def2, definition );
- pj_dalloc( definition );
+ free( definition );
definition = def2;
}
else {
- pj_dalloc( definition );
+ free( definition );
return nullptr;
}
}
diff --git a/src/proj.h b/src/proj.h
index 4185ddbf..d4defc47 100644
--- a/src/proj.h
+++ b/src/proj.h
@@ -119,8 +119,8 @@
#include <stddef.h> /* For size_t */
-#ifdef PROJ_API_H
-#error proj.h must be included before proj_api.h
+#ifdef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
+ #error "The proj_api.h header has been removed from PROJ with version 8.0.0"
#endif
#ifdef PROJ_RENAME_SYMBOLS
@@ -340,9 +340,9 @@ typedef enum PJ_LOG_LEVEL {
typedef void (*PJ_LOG_FUNCTION)(void *, int, const char *);
-/* The context type - properly namespaced synonym for projCtx */
-struct projCtx_t;
-typedef struct projCtx_t PJ_CONTEXT;
+/* The context type - properly namespaced synonym for pj_ctx */
+struct pj_ctx;
+typedef struct pj_ctx PJ_CONTEXT;
/* A P I */
diff --git a/src/proj_api.h b/src/proj_api.h
deleted file mode 100644
index a26088ca..00000000
--- a/src/proj_api.h
+++ /dev/null
@@ -1,227 +0,0 @@
-/******************************************************************************
- * Project: PROJ.4
- * Purpose: Public (application) include file for PROJ.4 API, and constants.
- * Author: Frank Warmerdam, <warmerdam@pobox.com>
- *
- ******************************************************************************
- * Copyright (c) 2001, Frank Warmerdam <warmerdam@pobox.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *****************************************************************************/
-
-/*
- * This version number should be updated with every release!
- *
- * This file is expected to be removed from the PROJ distribution
- * when a few minor-version releases has been made.
- *
- */
-
-#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#error 'To use the proj_api.h you must define the macro ACCEPT_USE_OF_DEPRECATED_PROJ_API_H'
-#endif
-
-#ifndef PJ_VERSION
-#define PJ_VERSION 800
-#endif
-
-#ifdef PROJ_RENAME_SYMBOLS
-#include "proj_symbol_rename.h"
-#endif
-
-
-/* If we're not asked for PJ_VERSION only, give them everything */
-#ifndef PROJ_API_INCLUDED_FOR_PJ_VERSION_ONLY
-/* General projections header file */
-#ifndef PROJ_API_H
-#define PROJ_API_H
-
-/* standard inclusions */
-#include <math.h>
-#include <stddef.h>
-#include <stdlib.h>
-
-#ifndef PROJ_DLL
-#ifdef PROJ_MSVC_DLL_EXPORT
-#define PROJ_DLL __declspec(dllexport)
-#elif defined(PROJ_MSVC_DLL_IMPORT)
-#define PROJ_DLL __declspec(dllimport)
-#elif defined(__GNUC__)
-#define PROJ_DLL __attribute__ ((visibility("default")))
-#else
-#define PROJ_DLL
-#endif
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* pj_init() and similar functions can be used with a non-C locale */
-/* Can be detected too at runtime if the symbol pj_atof exists */
-#define PJ_LOCALE_SAFE 1
-
-#define RAD_TO_DEG 57.295779513082321
-#define DEG_TO_RAD .017453292519943296
-
-
-#if defined(PROJ_H)
-#define PROJ_API_H_NOT_INVOKED_AS_PRIMARY_API
-#endif
-
-
-
-extern char const PROJ_DLL pj_release[]; /* global release id string */
-PROJ_DLL extern int pj_errno; /* global error return code */
-
-#ifndef PROJ_INTERNAL_H
-/* replaced by enum proj_log_level in proj_internal.h */
-#define PJ_LOG_NONE 0
-#define PJ_LOG_ERROR 1
-#define PJ_LOG_DEBUG_MAJOR 2
-#define PJ_LOG_DEBUG_MINOR 3
-#endif
-
-#ifdef PROJ_API_H_NOT_INVOKED_AS_PRIMARY_API
- /* These make the function declarations below conform with classic proj */
- typedef PJ *projPJ; /* projPJ is a pointer to PJ */
- typedef struct projCtx_t *projCtx; /* projCtx is a pointer to projCtx_t */
-# define projXY PJ_XY
-# define projLP PJ_LP
-# define projXYZ PJ_XYZ
-# define projLPZ PJ_LPZ
-
-#else
- /* i.e. proj_api invoked as primary API */
- typedef struct { double u, v; } projUV;
- typedef struct { double u, v, w; } projUVW;
- typedef void *projPJ;
- #define projXY projUV
- #define projLP projUV
- #define projXYZ projUVW
- #define projLPZ projUVW
- typedef void *projCtx;
-#endif
-
-
-/* If included *after* proj.h finishes, we have alternative names */
-/* file reading api, like stdio */
-typedef int *PAFile;
-typedef struct projFileAPI_t {
- PAFile (*FOpen)(projCtx ctx, const char *filename, const char *access);
- size_t (*FRead)(void *buffer, size_t size, size_t nmemb, PAFile file);
- int (*FSeek)(PAFile file, long offset, int whence);
- long (*FTell)(PAFile file);
- void (*FClose)(PAFile);
-} projFileAPI;
-
-
-
-/* procedure prototypes */
-
-projCtx PROJ_DLL pj_get_default_ctx(void);
-projCtx PROJ_DLL pj_get_ctx( projPJ );
-
-projXY PROJ_DLL pj_fwd(projLP, projPJ);
-projLP PROJ_DLL pj_inv(projXY, projPJ);
-
-projXYZ PROJ_DLL pj_fwd3d(projLPZ, projPJ);
-projLPZ PROJ_DLL pj_inv3d(projXYZ, projPJ);
-
-
-int PROJ_DLL pj_transform( projPJ src, projPJ dst, long point_count, int point_offset,
- double *x, double *y, double *z );
-int PROJ_DLL pj_datum_transform( projPJ src, projPJ dst, long point_count, int point_offset,
- double *x, double *y, double *z );
-int PROJ_DLL pj_geocentric_to_geodetic( double a, double es,
- long point_count, int point_offset,
- double *x, double *y, double *z );
-int PROJ_DLL pj_geodetic_to_geocentric( double a, double es,
- long point_count, int point_offset,
- double *x, double *y, double *z );
-int PROJ_DLL pj_compare_datums( projPJ srcdefn, projPJ dstdefn );
-int PROJ_DLL pj_apply_gridshift( projCtx, const char *, int,
- long point_count, int point_offset,
- double *x, double *y, double *z );
-void PROJ_DLL pj_deallocate_grids(void);
-void PROJ_DLL pj_clear_initcache(void);
-int PROJ_DLL pj_is_latlong(projPJ);
-int PROJ_DLL pj_is_geocent(projPJ);
-void PROJ_DLL pj_get_spheroid_defn(projPJ defn, double *major_axis, double *eccentricity_squared);
-void PROJ_DLL pj_pr_list(projPJ);
-void PROJ_DLL pj_free(projPJ);
-void PROJ_DLL pj_set_finder( const char *(*)(const char *) );
-void PROJ_DLL pj_set_searchpath ( int count, const char **path );
-projPJ PROJ_DLL pj_init(int, char **);
-projPJ PROJ_DLL pj_init_plus(const char *);
-projPJ PROJ_DLL pj_init_ctx( projCtx, int, char ** );
-projPJ PROJ_DLL pj_init_plus_ctx( projCtx, const char * );
-char PROJ_DLL *pj_get_def(projPJ, int);
-projPJ PROJ_DLL pj_latlong_from_proj( projPJ );
-int PROJ_DLL pj_has_inverse(projPJ);
-
-
-void PROJ_DLL *pj_malloc(size_t);
-void PROJ_DLL pj_dalloc(void *);
-void PROJ_DLL *pj_calloc (size_t n, size_t size);
-void PROJ_DLL *pj_dealloc (void *ptr);
-char PROJ_DLL *pj_strdup(const char *str);
-char PROJ_DLL *pj_strerrno(int);
-int PROJ_DLL *pj_get_errno_ref(void);
-const char PROJ_DLL *pj_get_release(void);
-void PROJ_DLL pj_acquire_lock(void);
-void PROJ_DLL pj_release_lock(void);
-void PROJ_DLL pj_cleanup_lock(void);
-
-void PROJ_DLL pj_set_ctx( projPJ, projCtx );
-projCtx PROJ_DLL pj_ctx_alloc(void);
-void PROJ_DLL pj_ctx_free( projCtx );
-int PROJ_DLL pj_ctx_get_errno( projCtx );
-void PROJ_DLL pj_ctx_set_errno( projCtx, int );
-void PROJ_DLL pj_ctx_set_debug( projCtx, int );
-void PROJ_DLL pj_ctx_set_logger( projCtx, void (*)(void *, int, const char *) );
-void PROJ_DLL pj_ctx_set_app_data( projCtx, void * );
-void PROJ_DLL *pj_ctx_get_app_data( projCtx );
-void PROJ_DLL pj_ctx_set_fileapi( projCtx, projFileAPI *);
-projFileAPI PROJ_DLL *pj_ctx_get_fileapi( projCtx );
-
-void PROJ_DLL pj_log( projCtx ctx, int level, const char *fmt, ... );
-void PROJ_DLL pj_stderr_logger( void *, int, const char * );
-
-/* file api */
-projFileAPI PROJ_DLL *pj_get_default_fileapi(void);
-
-PAFile PROJ_DLL pj_ctx_fopen(projCtx ctx, const char *filename, const char *access);
-size_t PROJ_DLL pj_ctx_fread(projCtx ctx, void *buffer, size_t size, size_t nmemb, PAFile file);
-int PROJ_DLL pj_ctx_fseek(projCtx ctx, PAFile file, long offset, int whence);
-long PROJ_DLL pj_ctx_ftell(projCtx ctx, PAFile file);
-void PROJ_DLL pj_ctx_fclose(projCtx ctx, PAFile file);
-char PROJ_DLL *pj_ctx_fgets(projCtx ctx, char *line, int size, PAFile file);
-
-PAFile PROJ_DLL pj_open_lib(projCtx, const char *, const char *);
-int PROJ_DLL pj_find_file(projCtx ctx, const char *short_filename,
- char* out_full_filename, size_t out_full_filename_size);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* ndef PROJ_API_H */
-#endif /* ndef PROJ_API_INCLUDED_FOR_PJ_VERSION_ONLY */
diff --git a/src/proj_internal.h b/src/proj_internal.h
index 203765a3..234ff80e 100644
--- a/src/proj_internal.h
+++ b/src/proj_internal.h
@@ -33,10 +33,6 @@
#error "proj_internal.h can only be included from a C++ file"
#endif
-#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#endif
-
#ifdef _MSC_VER
# ifndef _CRT_SECURE_NO_DEPRECATE
# define _CRT_SECURE_NO_DEPRECATE
@@ -66,10 +62,6 @@
#include "proj.h"
-#ifdef PROJ_API_H
-#error proj_internal.h must be included before proj_api.h
-#endif
-
#ifdef PROJ_RENAME_SYMBOLS
#include "proj_symbol_rename.h"
#endif
@@ -248,8 +240,6 @@ struct PJ_AREA {
double north_lat_degree;
};
-struct projCtx_t;
-typedef struct projCtx_t projCtx_t;
/*****************************************************************************
@@ -360,7 +350,7 @@ struct PJconsts {
**************************************************************************************/
- projCtx_t *ctx = nullptr;
+ PJ_CONTEXT *ctx = nullptr;
const char *descr = nullptr; /* From pj_list.h or individual PJ_*.c file */
paralist *params = nullptr; /* Parameter list */
char *def_full = nullptr; /* Full textual definition (usually 0 - set by proj_pj_info) */
@@ -401,7 +391,7 @@ struct PJconsts {
PJ_OPERATOR inv4d = nullptr;
PJ_DESTRUCTOR destructor = nullptr;
- void (*reassign_context)(PJ*, projCtx_t *) = nullptr;
+ void (*reassign_context)(PJ*, PJ_CONTEXT*) = nullptr;
/*************************************************************************************
@@ -716,12 +706,11 @@ struct projFileApiCallbackAndData
};
/* proj thread context */
-struct projCtx_t {
+struct pj_ctx{
int last_errno = 0;
int debug_level = 0;
void (*logger)(void *, int, const char *) = nullptr;
void *logger_app_data = nullptr;
- struct projFileAPI_t *fileapi_legacy = nullptr; // for proj_api.h legacy API
struct projCppContext* cpp_context = nullptr; /* internal context for C++ code */
int use_proj4_init_rules = -1; /* -1 = unknown, 0 = no, 1 = yes */
int epsg_file_exists = -1; /* -1 = unknown, 0 = no, 1 = yes */
@@ -753,18 +742,18 @@ struct projCtx_t {
int pipelineInitRecursiongCounter = 0; // to avoid potential infinite recursion in pipeline.cpp
- projCtx_t() = default;
- projCtx_t(const projCtx_t&);
- ~projCtx_t();
+ pj_ctx() = default;
+ pj_ctx(const pj_ctx&);
+ ~pj_ctx();
- projCtx_t& operator= (const projCtx_t&) = delete;
+ pj_ctx& operator= (const pj_ctx&) = delete;
projCppContext* get_cpp_context();
void safeAutoCloseDbIfNeeded();
void set_search_paths(const std::vector<std::string>& search_paths_in);
void set_ca_bundle_path(const std::string& ca_bundle_path_in);
- static projCtx_t createDefault();
+ static pj_ctx createDefault();
};
/* Generate pj_list external or make list from include file */
@@ -812,41 +801,41 @@ PJ *pj_projection_specific_setup_##name (PJ *P)
/* procedure prototypes */
double PROJ_DLL dmstor(const char *, char **);
-double dmstor_ctx(projCtx_t *ctx, const char *, char **);
+double dmstor_ctx(PJ_CONTEXT *ctx, const char *, char **);
void PROJ_DLL set_rtodms(int, int);
char PROJ_DLL *rtodms(char *, double, int, int);
double PROJ_DLL adjlon(double);
-double aacos(projCtx_t *,double);
-double aasin(projCtx_t *,double);
+double aacos(PJ_CONTEXT *,double);
+double aasin(PJ_CONTEXT *,double);
double asqrt(double);
double aatan2(double, double);
-PROJVALUE PROJ_DLL pj_param(projCtx_t *ctx, paralist *, const char *);
+PROJVALUE PROJ_DLL pj_param(PJ_CONTEXT *ctx, paralist *, const char *);
paralist PROJ_DLL *pj_param_exists (paralist *list, const char *parameter);
paralist PROJ_DLL *pj_mkparam(const char *);
paralist *pj_mkparam_ws (const char *str, const char **next_str);
-int PROJ_DLL pj_ell_set(projCtx_t *ctx, paralist *, double *, double *);
-int pj_datum_set(projCtx_t *,paralist *, PJ *);
+int PROJ_DLL pj_ell_set(PJ_CONTEXT *ctx, paralist *, double *, double *);
+int pj_datum_set(PJ_CONTEXT *,paralist *, PJ *);
int pj_angular_units_set(paralist *, PJ *);
paralist *pj_clone_paralist( const paralist* );
paralist *pj_search_initcache( const char *filekey );
void pj_insert_initcache( const char *filekey, const paralist *list);
-paralist *pj_expand_init(projCtx_t *ctx, paralist *init);
+paralist *pj_expand_init(PJ_CONTEXT *ctx, paralist *init);
-void *pj_dealloc_params (projCtx_t *ctx, paralist *start, int errlev);
+void *free_params (PJ_CONTEXT *ctx, paralist *start, int errlev);
double *pj_enfn(double);
double pj_mlfn(double, double, double, const double *);
-double pj_inv_mlfn(projCtx_t *, double, double, const double *);
+double pj_inv_mlfn(PJ_CONTEXT *, double, double, const double *);
double pj_qsfn(double, double, double);
double pj_tsfn(double, double, double);
double pj_msfn(double, double, double);
-double PROJ_DLL pj_phi2(projCtx_t *, const double, const double);
-double pj_sinhpsi2tanphi(projCtx_t *, const double, const double);
+double PROJ_DLL pj_phi2(PJ_CONTEXT *, const double, const double);
+double pj_sinhpsi2tanphi(PJ_CONTEXT *, const double, const double);
double pj_qsfn_(double, PJ *);
double *pj_authset(double);
double pj_authlat(double, double *);
@@ -859,10 +848,10 @@ int pj_factors(PJ_LP, const PJ *, double, struct FACTORS *);
void *proj_mdist_ini(double);
double proj_mdist(double, double, double, const void *);
-double proj_inv_mdist(projCtx_t *ctx, double, const void *);
+double proj_inv_mdist(PJ_CONTEXT *ctx, double, const void *);
void *pj_gauss_ini(double, double, double *,double *);
-PJ_LP pj_gauss(projCtx_t *, PJ_LP, const void *);
-PJ_LP pj_inv_gauss(projCtx_t *, PJ_LP, const void *);
+PJ_LP pj_gauss(PJ_CONTEXT *, PJ_LP, const void *);
+PJ_LP pj_inv_gauss(PJ_CONTEXT *, PJ_LP, const void *);
struct PJ_DATUMS PROJ_DLL *pj_get_datums_ref( void );
@@ -873,7 +862,7 @@ double PROJ_DLL pj_atof( const char* nptr );
double pj_strtod( const char *nptr, char **endptr );
void pj_freeup_plain (PJ *P);
-PJ* pj_init_ctx_with_allow_init_epsg( projCtx_t *ctx, int argc, char **argv, int allow_init_epsg );
+PJ* pj_init_ctx_with_allow_init_epsg( PJ_CONTEXT *ctx, int argc, char **argv, int allow_init_epsg );
std::string PROJ_DLL pj_add_type_crs_if_needed(const std::string& str);
std::string pj_double_quote_string_param_if_needed(const std::string& str);
@@ -910,7 +899,72 @@ void pj_clear_vgridshift_knowngrids_cache();
PJ_LP pj_generic_inverse_2d(PJ_XY xy, PJ *P, PJ_LP lpInitial);
-/* classic public API */
-#include "proj_api.h"
+
+
+
+/*****************************************************************************/
+/* */
+/* proj_api.h */
+/* */
+/* The rest of this header file includes what used to be "proj_api.h" */
+/* */
+/*****************************************************************************/
+
+/* pj_init() and similar functions can be used with a non-C locale */
+/* Can be detected too at runtime if the symbol pj_atof exists */
+#define PJ_LOCALE_SAFE 1
+
+#define RAD_TO_DEG 57.295779513082321
+#define DEG_TO_RAD .017453292519943296
+
+
+
+
+extern char const PROJ_DLL pj_release[]; /* global release id string */
+
+#ifndef PROJ_INTERNAL_H
+/* replaced by enum proj_log_level in proj_internal.h */
+#define PJ_LOG_NONE 0
+#define PJ_LOG_ERROR 1
+#define PJ_LOG_DEBUG_MAJOR 2
+#define PJ_LOG_DEBUG_MINOR 3
+#endif
+
+
+/* procedure prototypes */
+
+PJ_CONTEXT PROJ_DLL *pj_get_default_ctx(void);
+PJ_CONTEXT PROJ_DLL *pj_get_ctx( PJ *);
+
+PJ_XY PROJ_DLL pj_fwd(PJ_LP, PJ *);
+PJ_LP PROJ_DLL pj_inv(PJ_XY, PJ *);
+
+PJ_XYZ PROJ_DLL pj_fwd3d(PJ_LPZ, PJ *);
+PJ_LPZ PROJ_DLL pj_inv3d(PJ_XYZ, PJ *);
+
+
+void PROJ_DLL pj_clear_initcache(void);
+void PROJ_DLL pj_pr_list(PJ *);
+PJ PROJ_DLL *pj_init(int, char **);
+PJ PROJ_DLL *pj_init_plus(const char *);
+PJ PROJ_DLL *pj_init_ctx( PJ_CONTEXT *, int, char ** );
+PJ PROJ_DLL *pj_init_plus_ctx( PJ_CONTEXT *, const char * );
+char PROJ_DLL *pj_get_def(PJ *, int);
+int PROJ_DLL pj_has_inverse(PJ *);
+
+
+char PROJ_DLL *pj_strdup(const char *str);
+const char PROJ_DLL *pj_get_release(void);
+void PROJ_DLL pj_acquire_lock(void);
+void PROJ_DLL pj_release_lock(void);
+void PROJ_DLL pj_cleanup_lock(void);
+
+void PROJ_DLL pj_log( PJ_CONTEXT * ctx, int level, const char *fmt, ... );
+void PROJ_DLL pj_stderr_logger( void *, int, const char * );
+
+int PROJ_DLL pj_find_file(PJ_CONTEXT * ctx, const char *short_filename,
+ char* out_full_filename, size_t out_full_filename_size);
+
+
#endif /* ndef PROJ_INTERNAL_H */
diff --git a/src/proj_mdist.cpp b/src/proj_mdist.cpp
index c515f6c5..ed07ffd1 100644
--- a/src/proj_mdist.cpp
+++ b/src/proj_mdist.cpp
@@ -107,7 +107,7 @@ proj_mdist(double phi, double sphi, double cphi, const void *data) {
return(D + sc * sum);
}
double
-proj_inv_mdist(projCtx ctx, double dist, const void *data) {
+proj_inv_mdist(PJ_CONTEXT *ctx, double dist, const void *data) {
const struct MDIST *b = (const struct MDIST *)data;
double s, t, phi, k;
int i;
@@ -124,6 +124,6 @@ proj_inv_mdist(projCtx ctx, double dist, const void *data) {
return phi;
}
/* convergence failed */
- pj_ctx_set_errno(ctx, PJD_ERR_NON_CONV_INV_MERI_DIST);
+ proj_context_errno_set(ctx, PJD_ERR_NON_CONV_INV_MERI_DIST);
return phi;
}
diff --git a/src/projections/adams.cpp b/src/projections/adams.cpp
index 4f7d1a03..d1217ff1 100644
--- a/src/projections/adams.cpp
+++ b/src/projections/adams.cpp
@@ -205,7 +205,7 @@ static PJ_LP adams_inverse(PJ_XY xy, PJ *P)
static PJ *setup(PJ *P, projection_type mode) {
struct pj_opaque *Q = static_cast<struct pj_opaque*>(
- pj_calloc (1, sizeof (struct pj_opaque)));
+ calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
diff --git a/src/projections/aea.cpp b/src/projections/aea.cpp
index 6ffb4fd6..af0f292d 100644
--- a/src/projections/aea.cpp
+++ b/src/projections/aea.cpp
@@ -94,7 +94,7 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
@@ -219,7 +219,7 @@ static PJ *setup(PJ *P) {
PJ *PROJECTION(aea) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -232,7 +232,7 @@ PJ *PROJECTION(aea) {
PJ *PROJECTION(leac) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/aeqd.cpp b/src/projections/aeqd.cpp
index ad8c289e..d5d90b62 100644
--- a/src/projections/aeqd.cpp
+++ b/src/projections/aeqd.cpp
@@ -69,7 +69,7 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
@@ -274,7 +274,7 @@ static PJ_LP aeqd_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse
PJ *PROJECTION(aeqd) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/airy.cpp b/src/projections/airy.cpp
index f7602e53..15ff60d8 100644
--- a/src/projections/airy.cpp
+++ b/src/projections/airy.cpp
@@ -120,7 +120,7 @@ static PJ_XY airy_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward
PJ *PROJECTION(airy) {
double beta;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
diff --git a/src/projections/aitoff.cpp b/src/projections/aitoff.cpp
index 7920309c..857ebb80 100644
--- a/src/projections/aitoff.cpp
+++ b/src/projections/aitoff.cpp
@@ -170,7 +170,7 @@ static PJ_LP aitoff_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inver
if (iter == MAXITER && round == MAXROUND)
{
- pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
+ proj_context_errno_set( P->ctx, PJD_ERR_NON_CONVERGENT );
/* fprintf(stderr, "Warning: Accuracy of 1e-12 not reached. Last increments: dlat=%e and dlon=%e\n", dp, dl); */
}
@@ -187,7 +187,7 @@ static PJ *setup(PJ *P) {
PJ *PROJECTION(aitoff) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
@@ -198,7 +198,7 @@ PJ *PROJECTION(aitoff) {
PJ *PROJECTION(wintri) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/bacon.cpp b/src/projections/bacon.cpp
index 3efd4dbe..7ff2a7ac 100644
--- a/src/projections/bacon.cpp
+++ b/src/projections/bacon.cpp
@@ -43,7 +43,7 @@ static PJ_XY bacon_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forwar
PJ *PROJECTION(bacon) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -57,7 +57,7 @@ PJ *PROJECTION(bacon) {
PJ *PROJECTION(apian) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -70,7 +70,7 @@ PJ *PROJECTION(apian) {
PJ *PROJECTION(ortel) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/bertin1953.cpp b/src/projections/bertin1953.cpp
index b864f83a..58509e16 100644
--- a/src/projections/bertin1953.cpp
+++ b/src/projections/bertin1953.cpp
@@ -75,7 +75,7 @@ static PJ_XY bertin1953_s_forward (PJ_LP lp, PJ *P) {
PJ *PROJECTION(bertin1953) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/bipc.cpp b/src/projections/bipc.cpp
index bf4ba834..743acd1c 100644
--- a/src/projections/bipc.cpp
+++ b/src/projections/bipc.cpp
@@ -168,7 +168,7 @@ static PJ_LP bipc_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse
PJ *PROJECTION(bipc) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/bonne.cpp b/src/projections/bonne.cpp
index c94764cf..7817e968 100644
--- a/src/projections/bonne.cpp
+++ b/src/projections/bonne.cpp
@@ -106,14 +106,14 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(bonne) {
double c;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/calcofi.cpp b/src/projections/calcofi.cpp
index 57c12dde..d1e96de8 100644
--- a/src/projections/calcofi.cpp
+++ b/src/projections/calcofi.cpp
@@ -4,7 +4,6 @@
#include "proj.h"
#include "proj_internal.h"
-#include "proj_api.h"
PROJ_HEAD(calcofi,
"Cal Coop Ocean Fish Invest Lines/Stations") "\n\tCyl, Sph&Ell";
diff --git a/src/projections/cass.cpp b/src/projections/cass.cpp
index e253cafc..f5531f6a 100644
--- a/src/projections/cass.cpp
+++ b/src/projections/cass.cpp
@@ -95,7 +95,7 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
@@ -111,7 +111,7 @@ PJ *PROJECTION(cass) {
}
/* otherwise it's ellipsoidal */
- P->opaque = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ P->opaque = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==P->opaque)
return pj_default_destructor (P, ENOMEM);
P->destructor = destructor;
diff --git a/src/projections/ccon.cpp b/src/projections/ccon.cpp
index df995f21..7b3b7105 100644
--- a/src/projections/ccon.cpp
+++ b/src/projections/ccon.cpp
@@ -75,14 +75,14 @@ static PJ *destructor (PJ *P, int errlev) {
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(ccon) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/cea.cpp b/src/projections/cea.cpp
index 7e6d3212..b7874b90 100644
--- a/src/projections/cea.cpp
+++ b/src/projections/cea.cpp
@@ -66,14 +66,14 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->apa);
+ free (static_cast<struct pj_opaque*>(P->opaque)->apa);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(cea) {
double t = 0.0;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/chamb.cpp b/src/projections/chamb.cpp
index 36609e79..b315832a 100644
--- a/src/projections/chamb.cpp
+++ b/src/projections/chamb.cpp
@@ -29,7 +29,7 @@ PROJ_HEAD(chamb, "Chamberlin Trimetric") "\n\tMisc Sph, no inv"
#define TOL 1e-9
/* distance and azimuth from point 1 to point 2 */
-static VECT vect(projCtx ctx, double dphi, double c1, double s1, double c2, double s2, double dlam) {
+static VECT vect(PJ_CONTEXT *ctx, double dphi, double c1, double s1, double c2, double s2, double dlam) {
VECT v;
double cdl, dp, dl;
@@ -49,7 +49,7 @@ static VECT vect(projCtx ctx, double dphi, double c1, double s1, double c2, doub
}
/* law of cosines */
-static double lc(projCtx ctx, double b,double c,double a) {
+static double lc(PJ_CONTEXT *ctx, double b,double c,double a) {
return aacos(ctx, .5 * (b * b + c * c - a * a) / (b * c));
}
@@ -103,7 +103,7 @@ static PJ_XY chamb_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forwar
PJ *PROJECTION(chamb) {
int i, j;
char line[10];
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/col_urban.cpp b/src/projections/col_urban.cpp
index 5bc8407f..de0c178f 100644
--- a/src/projections/col_urban.cpp
+++ b/src/projections/col_urban.cpp
@@ -54,7 +54,7 @@ static PJ_LP col_urban_inverse (PJ_XY xy, PJ *P) {
}
PJ *PROJECTION(col_urban) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/comill.cpp b/src/projections/comill.cpp
index 189e583e..44524990 100644
--- a/src/projections/comill.cpp
+++ b/src/projections/comill.cpp
@@ -66,7 +66,7 @@ static PJ_LP comill_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inver
}
}
if( i == 0 )
- pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
+ proj_context_errno_set( P->ctx, PJD_ERR_NON_CONVERGENT );
lp.phi = yc;
/* longitude */
diff --git a/src/projections/eck3.cpp b/src/projections/eck3.cpp
index 0deeb4f3..2563053f 100644
--- a/src/projections/eck3.cpp
+++ b/src/projections/eck3.cpp
@@ -52,7 +52,7 @@ static PJ *setup(PJ *P) {
PJ *PROJECTION(eck3) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -67,7 +67,7 @@ PJ *PROJECTION(eck3) {
PJ *PROJECTION(kav7) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -85,7 +85,7 @@ PJ *PROJECTION(kav7) {
PJ *PROJECTION(wag6) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -100,7 +100,7 @@ PJ *PROJECTION(wag6) {
PJ *PROJECTION(putp1) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/eqc.cpp b/src/projections/eqc.cpp
index 194625ef..9ebc9286 100644
--- a/src/projections/eqc.cpp
+++ b/src/projections/eqc.cpp
@@ -39,7 +39,7 @@ static PJ_LP eqc_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse
PJ *PROJECTION(eqc) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/eqdc.cpp b/src/projections/eqdc.cpp
index 659488b1..28767d74 100644
--- a/src/projections/eqdc.cpp
+++ b/src/projections/eqdc.cpp
@@ -68,7 +68,7 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
@@ -77,7 +77,7 @@ PJ *PROJECTION(eqdc) {
double cosphi, sinphi;
int secant;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/eqearth.cpp b/src/projections/eqearth.cpp
index 832c9444..2ef2775b 100644
--- a/src/projections/eqearth.cpp
+++ b/src/projections/eqearth.cpp
@@ -110,7 +110,7 @@ static PJ_LP eqearth_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal/sphe
}
if( i == 0 ) {
- pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
+ proj_context_errno_set( P->ctx, PJD_ERR_NON_CONVERGENT );
return lp;
}
@@ -137,13 +137,13 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor */
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->apa);
+ free (static_cast<struct pj_opaque*>(P->opaque)->apa);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(eqearth) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/fouc_s.cpp b/src/projections/fouc_s.cpp
index c5989514..f7607635 100644
--- a/src/projections/fouc_s.cpp
+++ b/src/projections/fouc_s.cpp
@@ -55,7 +55,7 @@ static PJ_LP fouc_s_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inver
PJ *PROJECTION(fouc_s) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/geos.cpp b/src/projections/geos.cpp
index 338f07c2..5de4c7ca 100644
--- a/src/projections/geos.cpp
+++ b/src/projections/geos.cpp
@@ -199,7 +199,7 @@ static PJ_LP geos_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse
PJ *PROJECTION(geos) {
char *sweep_axis;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/gn_sinu.cpp b/src/projections/gn_sinu.cpp
index 815de8be..ef312613 100644
--- a/src/projections/gn_sinu.cpp
+++ b/src/projections/gn_sinu.cpp
@@ -102,7 +102,7 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
@@ -121,7 +121,7 @@ static void setup(PJ *P) {
PJ *PROJECTION(sinu) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -143,7 +143,7 @@ PJ *PROJECTION(sinu) {
PJ *PROJECTION(eck6) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -158,7 +158,7 @@ PJ *PROJECTION(eck6) {
PJ *PROJECTION(mbtfps) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -173,7 +173,7 @@ PJ *PROJECTION(mbtfps) {
PJ *PROJECTION(gn_sinu) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/gnom.cpp b/src/projections/gnom.cpp
index 23dee030..9abbb7ce 100644
--- a/src/projections/gnom.cpp
+++ b/src/projections/gnom.cpp
@@ -124,7 +124,7 @@ static PJ_LP gnom_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse
PJ *PROJECTION(gnom) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/goode.cpp b/src/projections/goode.cpp
index fdace387..c0afd2d8 100644
--- a/src/projections/goode.cpp
+++ b/src/projections/goode.cpp
@@ -54,15 +54,15 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor */
return nullptr;
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_free (static_cast<struct pj_opaque*>(P->opaque)->sinu);
- pj_free (static_cast<struct pj_opaque*>(P->opaque)->moll);
+ proj_destroy (static_cast<struct pj_opaque*>(P->opaque)->sinu);
+ proj_destroy (static_cast<struct pj_opaque*>(P->opaque)->moll);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(goode) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/gstmerc.cpp b/src/projections/gstmerc.cpp
index 50814bb5..b21f6ffd 100644
--- a/src/projections/gstmerc.cpp
+++ b/src/projections/gstmerc.cpp
@@ -54,7 +54,7 @@ static PJ_LP gstmerc_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inve
PJ *PROJECTION(gstmerc) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/hammer.cpp b/src/projections/hammer.cpp
index 8d6d9408..d9bcafc7 100644
--- a/src/projections/hammer.cpp
+++ b/src/projections/hammer.cpp
@@ -57,7 +57,7 @@ static PJ_LP hammer_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inver
PJ *PROJECTION(hammer) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/healpix.cpp b/src/projections/healpix.cpp
index aab5c41e..c778f28f 100644
--- a/src/projections/healpix.cpp
+++ b/src/projections/healpix.cpp
@@ -524,7 +524,7 @@ static PJ_LP s_healpix_inverse(PJ_XY xy, PJ *P) { /* sphere */
PJ_LP lp;
lp.lam = HUGE_VAL;
lp.phi = HUGE_VAL;
- pj_ctx_set_errno(P->ctx, PJD_ERR_INVALID_X_OR_Y);
+ proj_context_errno_set(P->ctx, PJD_ERR_INVALID_X_OR_Y);
return lp;
}
return healpix_spherhealpix_e_inverse(xy);
@@ -540,7 +540,7 @@ static PJ_LP e_healpix_inverse(PJ_XY xy, PJ *P) { /* ellipsoid */
if (in_image(xy.x, xy.y, 0, 0, 0) == 0) {
lp.lam = HUGE_VAL;
lp.phi = HUGE_VAL;
- pj_ctx_set_errno(P->ctx, PJD_ERR_INVALID_X_OR_Y);
+ proj_context_errno_set(P->ctx, PJD_ERR_INVALID_X_OR_Y);
return lp;
}
lp = healpix_spherhealpix_e_inverse(xy);
@@ -574,7 +574,7 @@ static PJ_LP s_rhealpix_inverse(PJ_XY xy, PJ *P) { /* sphere */
PJ_LP lp;
lp.lam = HUGE_VAL;
lp.phi = HUGE_VAL;
- pj_ctx_set_errno(P->ctx, PJD_ERR_INVALID_X_OR_Y);
+ proj_context_errno_set(P->ctx, PJD_ERR_INVALID_X_OR_Y);
return lp;
}
xy = combine_caps(xy.x, xy.y, Q->north_square, Q->south_square, 1);
@@ -590,7 +590,7 @@ static PJ_LP e_rhealpix_inverse(PJ_XY xy, PJ *P) { /* ellipsoid */
if (in_image(xy.x, xy.y, 1, Q->north_square, Q->south_square) == 0) {
lp.lam = HUGE_VAL;
lp.phi = HUGE_VAL;
- pj_ctx_set_errno(P->ctx, PJD_ERR_INVALID_X_OR_Y);
+ proj_context_errno_set(P->ctx, PJD_ERR_INVALID_X_OR_Y);
return lp;
}
xy = combine_caps(xy.x, xy.y, Q->north_square, Q->south_square, 1);
@@ -607,13 +607,13 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->apa);
+ free (static_cast<struct pj_opaque*>(P->opaque)->apa);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(healpix) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -641,7 +641,7 @@ PJ *PROJECTION(healpix) {
PJ *PROJECTION(rhealpix) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/igh.cpp b/src/projections/igh.cpp
index 2be94889..8aaaaba1 100644
--- a/src/projections/igh.cpp
+++ b/src/projections/igh.cpp
@@ -208,7 +208,7 @@ static bool setup_zone(PJ *P, struct pj_opaque *Q, int n,
PJ *PROJECTION(igh) {
PJ_XY xy1, xy3;
PJ_LP lp = { 0, phi_boundary };
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/igh_o.cpp b/src/projections/igh_o.cpp
index b14d79a5..80874845 100644
--- a/src/projections/igh_o.cpp
+++ b/src/projections/igh_o.cpp
@@ -222,7 +222,7 @@ static bool setup_zone(PJ *P, struct pj_opaque *Q, int n,
PJ *PROJECTION(igh_o) {
PJ_XY xy1, xy4;
PJ_LP lp = { 0, phi_boundary };
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/imw_p.cpp b/src/projections/imw_p.cpp
index ee206091..6e82d287 100644
--- a/src/projections/imw_p.cpp
+++ b/src/projections/imw_p.cpp
@@ -160,7 +160,7 @@ static PJ *destructor (PJ *P, int errlev) {
return pj_default_destructor (P, errlev);
if( static_cast<struct pj_opaque*>(P->opaque)->en )
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor(P, errlev);
}
@@ -169,7 +169,7 @@ static PJ *destructor (PJ *P, int errlev) {
PJ *PROJECTION(imw_p) {
double del, sig, s, t, x1, x2, T2, y1, m1, m2, y2;
int err;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/isea.cpp b/src/projections/isea.cpp
index dd1d48ff..77a5689b 100644
--- a/src/projections/isea.cpp
+++ b/src/projections/isea.cpp
@@ -1039,7 +1039,7 @@ static PJ_XY isea_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward
PJ *PROJECTION(isea) {
char *opt;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/krovak.cpp b/src/projections/krovak.cpp
index aef44d42..adc039fe 100644
--- a/src/projections/krovak.cpp
+++ b/src/projections/krovak.cpp
@@ -181,7 +181,7 @@ static PJ_LP krovak_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal,
fi1 = lp.phi;
}
if( i == 0 )
- pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
+ proj_context_errno_set( P->ctx, PJD_ERR_NON_CONVERGENT );
lp.lam -= P->lam0;
@@ -191,7 +191,7 @@ static PJ_LP krovak_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal,
PJ *PROJECTION(krovak) {
double u0, n0, g;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/labrd.cpp b/src/projections/labrd.cpp
index c9dfdfc6..4fbcf460 100644
--- a/src/projections/labrd.cpp
+++ b/src/projections/labrd.cpp
@@ -105,7 +105,7 @@ static PJ_LP labrd_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, invers
PJ *PROJECTION(labrd) {
double Az, sinp, R, N, t;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/laea.cpp b/src/projections/laea.cpp
index 3d135864..2d19cab1 100644
--- a/src/projections/laea.cpp
+++ b/src/projections/laea.cpp
@@ -234,7 +234,7 @@ static PJ *destructor (PJ *P, int errlev) {
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->apa);
+ free (static_cast<struct pj_opaque*>(P->opaque)->apa);
return pj_default_destructor(P, errlev);
}
@@ -242,7 +242,7 @@ static PJ *destructor (PJ *P, int errlev) {
PJ *PROJECTION(laea) {
double t;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/lagrng.cpp b/src/projections/lagrng.cpp
index d37a00e6..1029bf8d 100644
--- a/src/projections/lagrng.cpp
+++ b/src/projections/lagrng.cpp
@@ -71,7 +71,7 @@ static PJ_LP lagrng_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inver
PJ *PROJECTION(lagrng) {
double sin_phi1;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/lcc.cpp b/src/projections/lcc.cpp
index 46378ce4..525281f4 100644
--- a/src/projections/lcc.cpp
+++ b/src/projections/lcc.cpp
@@ -80,7 +80,7 @@ static PJ_LP lcc_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse
PJ *PROJECTION(lcc) {
double cosphi, sinphi;
int secant;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc(1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc(1, sizeof (struct pj_opaque)));
if (nullptr == Q)
return pj_default_destructor(P, ENOMEM);
diff --git a/src/projections/lcca.cpp b/src/projections/lcca.cpp
index 51dd28aa..53646fc6 100644
--- a/src/projections/lcca.cpp
+++ b/src/projections/lcca.cpp
@@ -128,14 +128,14 @@ static PJ *destructor (PJ *P, int errlev) {
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(lcca) {
double s2p0, N0, R0, tan0;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/loxim.cpp b/src/projections/loxim.cpp
index 2ee88037..64124bdd 100644
--- a/src/projections/loxim.cpp
+++ b/src/projections/loxim.cpp
@@ -56,7 +56,7 @@ static PJ_LP loxim_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, invers
PJ *PROJECTION(loxim) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/lsat.cpp b/src/projections/lsat.cpp
index f6114485..a811a3a6 100644
--- a/src/projections/lsat.cpp
+++ b/src/projections/lsat.cpp
@@ -158,7 +158,7 @@ static PJ_LP lsat_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse
PJ *PROJECTION(lsat) {
int land, path;
double lam, alf, esc, ess;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/misrsom.cpp b/src/projections/misrsom.cpp
index 71116e1e..d7e199f2 100644
--- a/src/projections/misrsom.cpp
+++ b/src/projections/misrsom.cpp
@@ -178,7 +178,7 @@ PJ *PROJECTION(misrsom) {
int path;
double lam, alf, esc, ess;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/mod_ster.cpp b/src/projections/mod_ster.cpp
index c7a8e899..0c30b7b6 100644
--- a/src/projections/mod_ster.cpp
+++ b/src/projections/mod_ster.cpp
@@ -134,7 +134,7 @@ PJ *PROJECTION(mil_os) {
{0.019430, 0.}
};
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -157,7 +157,7 @@ PJ *PROJECTION(lee_os) {
{-0.0088162, -0.00617325}
};
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -182,7 +182,7 @@ PJ *PROJECTION(gs48) {
{0.075528, 0.}
};
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -217,7 +217,7 @@ PJ *PROJECTION(alsk) {
{ .3660976, -.2937382}
};
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -265,7 +265,7 @@ PJ *PROJECTION(gs50) {
{-.0225161, .0853673}
};
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/moll.cpp b/src/projections/moll.cpp
index 5d4f7825..4864c8e1 100644
--- a/src/projections/moll.cpp
+++ b/src/projections/moll.cpp
@@ -77,7 +77,7 @@ static PJ * setup(PJ *P, double p) {
PJ *PROJECTION(moll) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -87,7 +87,7 @@ PJ *PROJECTION(moll) {
PJ *PROJECTION(wag4) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -96,7 +96,7 @@ PJ *PROJECTION(wag4) {
}
PJ *PROJECTION(wag5) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/natearth.cpp b/src/projections/natearth.cpp
index 5c096605..e1f71089 100644
--- a/src/projections/natearth.cpp
+++ b/src/projections/natearth.cpp
@@ -82,7 +82,7 @@ static PJ_LP natearth_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inv
}
}
if( i == 0 )
- pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
+ proj_context_errno_set( P->ctx, PJD_ERR_NON_CONVERGENT );
lp.phi = yc;
/* longitude */
diff --git a/src/projections/natearth2.cpp b/src/projections/natearth2.cpp
index d149ca85..e4516a0a 100644
--- a/src/projections/natearth2.cpp
+++ b/src/projections/natearth2.cpp
@@ -76,7 +76,7 @@ static PJ_LP natearth2_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, in
}
}
if( i == 0 )
- pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
+ proj_context_errno_set( P->ctx, PJD_ERR_NON_CONVERGENT );
lp.phi = yc;
/* longitude */
diff --git a/src/projections/nsper.cpp b/src/projections/nsper.cpp
index 903946b9..951111ac 100644
--- a/src/projections/nsper.cpp
+++ b/src/projections/nsper.cpp
@@ -180,7 +180,7 @@ static PJ *setup(PJ *P) {
PJ *PROJECTION(nsper) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -194,7 +194,7 @@ PJ *PROJECTION(nsper) {
PJ *PROJECTION(tpers) {
double omega, gamma;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/ob_tran.cpp b/src/projections/ob_tran.cpp
index 7cf1cf98..4990ab2a 100644
--- a/src/projections/ob_tran.cpp
+++ b/src/projections/ob_tran.cpp
@@ -142,7 +142,7 @@ static ARGS ob_tran_target_params (paralist *params) {
return args;
/* all args except the proj_ob_tran */
- args.argv = static_cast<char**>(pj_calloc (argc - 1, sizeof (char *)));
+ args.argv = static_cast<char**>(calloc (argc - 1, sizeof (char *)));
if (nullptr==args.argv)
return args;
@@ -160,7 +160,7 @@ static ARGS ob_tran_target_params (paralist *params) {
continue;
args.argv[i] += 2;
if (strcmp(args.argv[i], "proj=ob_tran") == 0 ) {
- pj_dealloc (args.argv);
+ free (args.argv);
args.argc = 0;
args.argv = nullptr;
}
@@ -177,7 +177,7 @@ PJ *PROJECTION(ob_tran) {
ARGS args;
PJ *R; /* projection to rotate */
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return destructor(P, ENOMEM);
@@ -195,7 +195,7 @@ PJ *PROJECTION(ob_tran) {
return destructor(P, PJD_ERR_FAILED_TO_FIND_PROJ);
}
R = pj_init_ctx (pj_get_ctx(P), args.argc, args.argv);
- pj_dealloc (args.argv);
+ free (args.argv);
if (nullptr==R)
return destructor (P, PJD_ERR_UNKNOWN_PROJECTION_ID);
diff --git a/src/projections/ocea.cpp b/src/projections/ocea.cpp
index de9838cb..c78e1ebc 100644
--- a/src/projections/ocea.cpp
+++ b/src/projections/ocea.cpp
@@ -52,7 +52,7 @@ static PJ_LP ocea_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse
PJ *PROJECTION(ocea) {
double phi_1, phi_2, lam_1, lam_2, lonz, alpha;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/oea.cpp b/src/projections/oea.cpp
index 61fb0647..46c00d16 100644
--- a/src/projections/oea.cpp
+++ b/src/projections/oea.cpp
@@ -58,7 +58,7 @@ static PJ_LP oea_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse
PJ *PROJECTION(oea) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/omerc.cpp b/src/projections/omerc.cpp
index e9f3b833..90067cc3 100644
--- a/src/projections/omerc.cpp
+++ b/src/projections/omerc.cpp
@@ -126,7 +126,7 @@ PJ *PROJECTION(omerc) {
gamma0, lamc=0, lam1=0, lam2=0, phi1=0, phi2=0, alpha_c=0;
int alp, gam, no_off = 0;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/ortho.cpp b/src/projections/ortho.cpp
index 8dcfb53c..4417dac7 100644
--- a/src/projections/ortho.cpp
+++ b/src/projections/ortho.cpp
@@ -273,13 +273,13 @@ static PJ_LP ortho_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inver
return lp;
}
}
- pj_ctx_set_errno(P->ctx, PJD_ERR_NON_CONVERGENT);
+ proj_context_errno_set(P->ctx, PJD_ERR_NON_CONVERGENT);
return lp;
}
PJ *PROJECTION(ortho) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/patterson.cpp b/src/projections/patterson.cpp
index 71099cdb..32544580 100644
--- a/src/projections/patterson.cpp
+++ b/src/projections/patterson.cpp
@@ -100,7 +100,7 @@ static PJ_LP patterson_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, in
}
}
if( i == 0 )
- pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
+ proj_context_errno_set( P->ctx, PJD_ERR_NON_CONVERGENT );
lp.phi = yc;
/* longitude */
diff --git a/src/projections/poly.cpp b/src/projections/poly.cpp
index 10d93ed2..4ea95cc7 100644
--- a/src/projections/poly.cpp
+++ b/src/projections/poly.cpp
@@ -147,14 +147,14 @@ static PJ *destructor(PJ *P, int errlev) {
return pj_default_destructor (P, errlev);
if (static_cast<struct pj_opaque*>(P->opaque)->en)
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor(P, errlev);
}
PJ *PROJECTION(poly) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
diff --git a/src/projections/putp3.cpp b/src/projections/putp3.cpp
index c2df20e8..09763851 100644
--- a/src/projections/putp3.cpp
+++ b/src/projections/putp3.cpp
@@ -38,7 +38,7 @@ static PJ_LP putp3_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, invers
PJ *PROJECTION(putp3) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -53,7 +53,7 @@ PJ *PROJECTION(putp3) {
}
PJ *PROJECTION(putp3p) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/putp4p.cpp b/src/projections/putp4p.cpp
index 365f7c1b..8df18972 100644
--- a/src/projections/putp4p.cpp
+++ b/src/projections/putp4p.cpp
@@ -45,7 +45,7 @@ static PJ_LP putp4p_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inver
PJ *PROJECTION(putp4p) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -62,7 +62,7 @@ PJ *PROJECTION(putp4p) {
PJ *PROJECTION(weren) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/putp5.cpp b/src/projections/putp5.cpp
index 1847e7a9..5e70382d 100644
--- a/src/projections/putp5.cpp
+++ b/src/projections/putp5.cpp
@@ -43,7 +43,7 @@ static PJ_LP putp5_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, invers
PJ *PROJECTION(putp5) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -60,7 +60,7 @@ PJ *PROJECTION(putp5) {
PJ *PROJECTION(putp5p) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/putp6.cpp b/src/projections/putp6.cpp
index db334ff9..da8c0a7c 100644
--- a/src/projections/putp6.cpp
+++ b/src/projections/putp6.cpp
@@ -59,7 +59,7 @@ static PJ_LP putp6_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, invers
PJ *PROJECTION(putp6) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
@@ -79,7 +79,7 @@ PJ *PROJECTION(putp6) {
PJ *PROJECTION(putp6p) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/qsc.cpp b/src/projections/qsc.cpp
index 98e3755e..dd9ce965 100644
--- a/src/projections/qsc.cpp
+++ b/src/projections/qsc.cpp
@@ -377,7 +377,7 @@ static PJ_LP qsc_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse
PJ *PROJECTION(qsc) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/robin.cpp b/src/projections/robin.cpp
index 8b646502..6a1405b6 100644
--- a/src/projections/robin.cpp
+++ b/src/projections/robin.cpp
@@ -138,7 +138,7 @@ static PJ_LP robin_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, invers
break;
}
if( iters == 0 )
- pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
+ proj_context_errno_set( P->ctx, PJD_ERR_NON_CONVERGENT );
lp.phi = (5 * i + t) * DEG_TO_RAD;
if (xy.y < 0.) lp.phi = -lp.phi;
lp.lam /= V(X[i], t);
diff --git a/src/projections/rouss.cpp b/src/projections/rouss.cpp
index f5a8f12f..2eb13b3d 100644
--- a/src/projections/rouss.cpp
+++ b/src/projections/rouss.cpp
@@ -93,7 +93,7 @@ static PJ *destructor (PJ *P, int errlev) {
return pj_default_destructor (P, errlev);
if (static_cast<struct pj_opaque*>(P->opaque)->en)
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, ENOMEM);
}
@@ -102,7 +102,7 @@ static PJ *destructor (PJ *P, int errlev) {
PJ *PROJECTION(rouss) {
double N0, es2, t, t2, R_R0_2, R_R0_4;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/rpoly.cpp b/src/projections/rpoly.cpp
index b065861f..e3f09c59 100644
--- a/src/projections/rpoly.cpp
+++ b/src/projections/rpoly.cpp
@@ -44,7 +44,7 @@ static PJ_XY rpoly_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forwar
PJ *PROJECTION(rpoly) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/sch.cpp b/src/projections/sch.cpp
index 7548039d..359e8efc 100644
--- a/src/projections/sch.cpp
+++ b/src/projections/sch.cpp
@@ -184,7 +184,7 @@ static PJ *setup(PJ *P) { /* general initialization */
PJ *PROJECTION(sch) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/sconics.cpp b/src/projections/sconics.cpp
index f305e291..c12b05a2 100644
--- a/src/projections/sconics.cpp
+++ b/src/projections/sconics.cpp
@@ -117,7 +117,7 @@ static PJ_LP sconics_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, (and ellipsoi
static PJ *setup(PJ *P, enum Type type) {
double del, cs;
int err;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/somerc.cpp b/src/projections/somerc.cpp
index fe6477fa..a184500c 100644
--- a/src/projections/somerc.cpp
+++ b/src/projections/somerc.cpp
@@ -71,7 +71,7 @@ static PJ_LP somerc_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inver
PJ *PROJECTION(somerc) {
double cp, phip0, sp;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/stere.cpp b/src/projections/stere.cpp
index 3fff722d..ad1caae2 100644
--- a/src/projections/stere.cpp
+++ b/src/projections/stere.cpp
@@ -302,7 +302,7 @@ static PJ *setup(PJ *P) { /* general initialization */
PJ *PROJECTION(stere) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -315,7 +315,7 @@ PJ *PROJECTION(stere) {
PJ *PROJECTION(ups) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/sterea.cpp b/src/projections/sterea.cpp
index 55404c86..4dd22d2f 100644
--- a/src/projections/sterea.cpp
+++ b/src/projections/sterea.cpp
@@ -93,14 +93,14 @@ static PJ *destructor (PJ *P, int errlev) {
if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
+ free (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(sterea) {
double R;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
diff --git a/src/projections/sts.cpp b/src/projections/sts.cpp
index cbc36b7d..75190e85 100644
--- a/src/projections/sts.cpp
+++ b/src/projections/sts.cpp
@@ -70,7 +70,7 @@ static PJ *setup(PJ *P, double p, double q, int mode) {
PJ *PROJECTION(fouc) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
@@ -80,7 +80,7 @@ PJ *PROJECTION(fouc) {
PJ *PROJECTION(kav5) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
@@ -91,7 +91,7 @@ PJ *PROJECTION(kav5) {
PJ *PROJECTION(qua_aut) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
@@ -101,7 +101,7 @@ PJ *PROJECTION(qua_aut) {
PJ *PROJECTION(mbt_s) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/tmerc.cpp b/src/projections/tmerc.cpp
index 69f4d352..8cae9968 100644
--- a/src/projections/tmerc.cpp
+++ b/src/projections/tmerc.cpp
@@ -89,7 +89,7 @@ static PJ_XY approx_e_fwd (PJ_LP lp, PJ *P)
if( lp.lam < -M_HALFPI || lp.lam > M_HALFPI ) {
xy.x = HUGE_VAL;
xy.y = HUGE_VAL;
- pj_ctx_set_errno( P->ctx, PJD_ERR_LAT_OR_LON_EXCEED_LIMIT );
+ proj_context_errno_set( P->ctx, PJD_ERR_LAT_OR_LON_EXCEED_LIMIT );
return xy;
}
@@ -130,7 +130,7 @@ static PJ_XY approx_s_fwd (PJ_LP lp, PJ *P) {
if( lp.lam < -M_HALFPI || lp.lam > M_HALFPI ) {
xy.x = HUGE_VAL;
xy.y = HUGE_VAL;
- pj_ctx_set_errno( P->ctx, PJD_ERR_LAT_OR_LON_EXCEED_LIMIT );
+ proj_context_errno_set( P->ctx, PJD_ERR_LAT_OR_LON_EXCEED_LIMIT );
return xy;
}
@@ -221,7 +221,7 @@ static PJ *destructor(PJ *P, int errlev) {
if (nullptr==P->opaque)
return pj_default_destructor(P, errlev);
- pj_dealloc (static_cast<struct tmerc_data*>(P->opaque)->approx.en);
+ free (static_cast<struct tmerc_data*>(P->opaque)->approx.en);
return pj_default_destructor(P, errlev);
}
@@ -592,7 +592,7 @@ static PJ_LP auto_e_inv (PJ_XY xy, PJ *P) {
static PJ *setup(PJ *P, TMercAlgo eAlg) {
- struct tmerc_data *Q = static_cast<struct tmerc_data*>(pj_calloc (1, sizeof (struct tmerc_data)));
+ struct tmerc_data *Q = static_cast<struct tmerc_data*>(calloc (1, sizeof (struct tmerc_data)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -679,7 +679,7 @@ static bool getAlgoFromParams(PJ* P, TMercAlgo& algo)
else
{
pj_load_ini(P->ctx); // if not already done
- pj_ctx_set_errno(P->ctx, 0); // reset error in case proj.ini couldn't be found
+ proj_context_errno_set(P->ctx, 0); // reset error in case proj.ini couldn't be found
algo = P->ctx->defaultTmercAlgo;
}
diff --git a/src/projections/tpeqd.cpp b/src/projections/tpeqd.cpp
index 58aeb8e1..90efb395 100644
--- a/src/projections/tpeqd.cpp
+++ b/src/projections/tpeqd.cpp
@@ -64,7 +64,7 @@ static PJ_LP tpeqd_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, invers
PJ *PROJECTION(tpeqd) {
double lam_1, lam_2, phi_1, phi_2, A12;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/urm5.cpp b/src/projections/urm5.cpp
index 499644d2..c3021841 100644
--- a/src/projections/urm5.cpp
+++ b/src/projections/urm5.cpp
@@ -30,7 +30,7 @@ static PJ_XY urm5_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward
PJ *PROJECTION(urm5) {
double alpha, t;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/urmfps.cpp b/src/projections/urmfps.cpp
index 3f9fdf23..5d689f9f 100644
--- a/src/projections/urmfps.cpp
+++ b/src/projections/urmfps.cpp
@@ -47,7 +47,7 @@ static PJ *setup(PJ *P) {
PJ *PROJECTION(urmfps) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
@@ -66,7 +66,7 @@ PJ *PROJECTION(urmfps) {
PJ *PROJECTION(wag1) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/vandg2.cpp b/src/projections/vandg2.cpp
index 223620d6..cd7e7b6c 100644
--- a/src/projections/vandg2.cpp
+++ b/src/projections/vandg2.cpp
@@ -53,7 +53,7 @@ static PJ_XY vandg2_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forwa
PJ *PROJECTION(vandg2) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -65,7 +65,7 @@ PJ *PROJECTION(vandg2) {
}
PJ *PROJECTION(vandg3) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/wag3.cpp b/src/projections/wag3.cpp
index 33313cdb..ed3250ef 100644
--- a/src/projections/wag3.cpp
+++ b/src/projections/wag3.cpp
@@ -35,7 +35,7 @@ static PJ_LP wag3_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse
PJ *PROJECTION(wag3) {
double ts;
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
diff --git a/src/projections/wink1.cpp b/src/projections/wink1.cpp
index d097978f..f4ffafe3 100644
--- a/src/projections/wink1.cpp
+++ b/src/projections/wink1.cpp
@@ -33,7 +33,7 @@ static PJ_LP wink1_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, invers
PJ *PROJECTION(wink1) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/projections/wink2.cpp b/src/projections/wink2.cpp
index d457f842..b5b1e812 100644
--- a/src/projections/wink2.cpp
+++ b/src/projections/wink2.cpp
@@ -53,7 +53,7 @@ static PJ_LP wink2_s_inverse(PJ_XY xy, PJ *P)
PJ *PROJECTION(wink2) {
- struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/strerrno.cpp b/src/strerrno.cpp
index 1c8673d0..3d0131c6 100644
--- a/src/strerrno.cpp
+++ b/src/strerrno.cpp
@@ -1,4 +1,4 @@
-/* list of projection system pj_errno values */
+/* list of projection system errno values */
#include <stddef.h>
#include <stdio.h>
@@ -74,10 +74,11 @@ pj_err_list[] = {
"network error", /* -62 */
/* When adding error messages, remember to update ID defines in
- projects.h, and transient_error array in pj_transform */
+ src/proj_internal.h and src/apps/gie.cpp */
};
-char *pj_strerrno(int err) {
+
+const char* proj_errno_string(int err) {
const int max_error = 9999;
static char note[50];
size_t adjusted_err;
@@ -98,7 +99,7 @@ char *pj_strerrno(int err) {
#endif
}
- /* PROJ.4 error codes are negative: -1 to -9999 */
+ /* PROJ error codes are negative: -1 to -9999 */
adjusted_err = err < -max_error ? max_error : -err - 1;
if (adjusted_err < (sizeof(pj_err_list) / sizeof(char *)))
return (char *)pj_err_list[adjusted_err];
@@ -107,7 +108,3 @@ char *pj_strerrno(int err) {
(err > -max_error) ? err: -max_error);
return note;
}
-
-const char* proj_errno_string(int err) {
- return pj_strerrno(err);
-}
diff --git a/src/tests/multistresstest.cpp b/src/tests/multistresstest.cpp
index 33d2d738..6b7099ce 100644
--- a/src/tests/multistresstest.cpp
+++ b/src/tests/multistresstest.cpp
@@ -30,11 +30,7 @@
#include <stdlib.h>
#include <string.h>
-#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#endif
-
-#include "proj_api.h"
+#include "proj.h"
#ifdef _WIN32
#include <windows.h>
@@ -51,8 +47,8 @@ typedef struct {
const char *src_def;
const char *dst_def;
- double src_x, src_y, src_z;
- double dst_x, dst_y, dst_z;
+ PJ_COORD src;
+ PJ_COORD dst;
int dst_error;
int skip;
@@ -62,125 +58,120 @@ static TestItem test_list[] = {
{
"+proj=utm +zone=11 +datum=WGS84",
"+proj=latlong +datum=WGS84",
- 150000.0, 3000000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 3000000.0, 0.0, 0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=utm +zone=11 +datum=NAD83",
"+proj=latlong +datum=NAD27",
- 150000.0, 3000000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 3000000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=utm +zone=11 +datum=NAD83",
"+proj=latlong +nadgrids=@null +ellps=WGS84",
- 150000.0, 3000000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 3000000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=utm +zone=11 +datum=WGS84",
"+proj=merc +datum=potsdam",
- 150000.0, 3000000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 3000000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=latlong +nadgrids=nzgd2kgrid0005.gsb",
"+proj=latlong +datum=WGS84",
- 150000.0, 3000000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 3000000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=latlong +nadgrids=nzgd2kgrid0005.gsb",
"+proj=latlong +datum=WGS84",
- 170 * DEG_TO_RAD, -40 * DEG_TO_RAD, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(170, -40, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=latlong +ellps=GRS80 +towgs84=2,3,5",
"+proj=latlong +ellps=intl +towgs84=10,12,15",
- 170 * DEG_TO_RAD, -40 * DEG_TO_RAD, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(170, -40, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=eqc +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
"+proj=stere +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
- 150000.0, 250000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 250000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=cea +lat_ts=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=merc +lon_0=12 +k=0.999 +x_0=100000 +y_0=200000 +datum=WGS84 ",
- 150000.0, 250000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 250000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=bonne +lat_1=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=cass +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
- 150000.0, 250000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 250000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=nzmg +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=gnom +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
- 150000.0, 250000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 250000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=ortho +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=laea +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
- 150000.0, 250000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 250000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=aeqd +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=eqdc +lat_1=20 +lat_2=5 +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
- 150000.0, 250000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 250000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+proj=mill +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=moll +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
- 150000.0, 250000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 250000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
"+init=epsg:3309",
"+init=epsg:4326",
- 150000.0, 30000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 30000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
},
{
/* Bad projection (invalid ellipsoid parameter +R_A=0) */
"+proj=utm +zone=11 +datum=WGS84",
"+proj=merc +datum=potsdam +R_A=0",
- 150000.0, 3000000.0, 0.0,
- 0.0, 0.0, 0.0,
+ proj_coord(150000.0, 3000000.0, 0.0, 0.0),
+ proj_coord(0.0, 0.0, 0.0, 0.0),
0, 0
}
};
static volatile int active_thread_count = 0;
-static projPJ custom_pj_init_plus_ctx(projCtx ctx, const char* def)
-{
- return pj_init_plus_ctx(ctx, def);
-}
-
/************************************************************************/
/* TestThread() */
/************************************************************************/
@@ -195,11 +186,10 @@ static void TestThread()
/* -------------------------------------------------------------------- */
/* Initialize coordinate system definitions. */
/* -------------------------------------------------------------------- */
- projPJ *src_pj_list, *dst_pj_list;
- projCtx ctx = pj_ctx_alloc();
+ PJ **pj_list;
+ PJ_CONTEXT *ctx = proj_context_create();
- src_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ));
- dst_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ));
+ pj_list = (PJ **) calloc(test_count,sizeof(PJ*));
if(!reinit_every_iteration)
{
@@ -207,8 +197,9 @@ static void TestThread()
{
TestItem *test = test_list + i;
- src_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->src_def );
- dst_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->dst_def );
+ pj_list[i] = proj_create_crs_to_crs(
+ ctx, test->src_def, test->dst_def, nullptr
+ );
}
}
@@ -221,28 +212,23 @@ static void TestThread()
for( i = 0; i < test_count; i++ )
{
TestItem *test = test_list + i;
- double x, y, z;
- int error;
-
- x = test->src_x;
- y = test->src_y;
- z = test->src_z;
if( reinit_every_iteration )
{
- src_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->src_def );
- dst_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->dst_def );
+ proj_context_use_proj4_init_rules(nullptr, true);
+ pj_list[i] = proj_create_crs_to_crs(
+ ctx, test->src_def, test->dst_def, nullptr
+ );
{
- int skipTest = (src_pj_list[i] == nullptr || dst_pj_list[i] == nullptr);
+ int skipTest = (pj_list[i] == nullptr);
if ( skipTest != test->skip )
fprintf( stderr, "Threaded projection initialization does not match unthreaded initialization\n" );
if (skipTest)
{
- pj_free( src_pj_list[i] );
- pj_free( dst_pj_list[i] );
+ proj_destroy( pj_list[i] );
continue;
}
}
@@ -251,31 +237,32 @@ static void TestThread()
if ( test->skip )
continue;
- error = pj_transform( src_pj_list[i], dst_pj_list[i], 1, 0,
- &x, &y, &z );
+ PJ_COORD out = proj_trans(pj_list[i], PJ_FWD, test->src);
+ int error = proj_errno(pj_list[i]);
if( error != test->dst_error )
{
fprintf( stderr, "Got error %d, expected %d\n",
error, test->dst_error );
}
+ proj_errno_reset(pj_list[i]);
- if( x != test->dst_x || y != test->dst_y || z != test->dst_z )
+ if ( out.xyz.x != test->dst.xyz.x || out.xyz.y != test->dst.xyz.y || out.xyz.z != test->dst.xyz.z)
+ //if( x != test->dst_x || y != test->dst_y || z != test->dst_z )
{
fprintf( stderr,
"Got %.15g,%.15g,%.15g\n"
"Expected %.15g,%.15g,%.15g\n"
"Diff %.15g,%.15g,%.15g\n",
- x, y, z,
- test->dst_x, test->dst_y, test->dst_z,
- x-test->dst_x, y-test->dst_y, z-test->dst_z);
+ out.xyz.x, out.xyz.y, out.xyz.z,
+ test->dst.xyz.x, test->dst.xyz.y, test->dst.xyz.z,
+ out.xyz.x-test->dst.xyz.x, out.xyz.y-test->dst.xyz.y, out.xyz.z-test->dst.xyz.z);
}
if( reinit_every_iteration )
{
- pj_free( src_pj_list[i] );
- pj_free( dst_pj_list[i] );
+ proj_destroy( pj_list[i] );
}
}
}
@@ -287,15 +274,13 @@ static void TestThread()
{
for( i = 0; i < test_count; i++ )
{
- pj_free( src_pj_list[i] );
- pj_free( dst_pj_list[i] );
+ proj_destroy( pj_list[i] );
}
}
- free( src_pj_list );
- free( dst_pj_list );
+ free( pj_list );
- pj_ctx_free( ctx );
+ proj_context_destroy( ctx );
printf( "%d iterations of the %d tests complete in thread X\n",
repeat_count, test_count );
@@ -349,43 +334,32 @@ static int do_main(void)
{
TestItem *test = test_list + i;
- projPJ src_pj, dst_pj;
+ PJ *pj;
- src_pj = custom_pj_init_plus_ctx( pj_get_default_ctx(), test->src_def );
- dst_pj = custom_pj_init_plus_ctx( pj_get_default_ctx(), test->dst_def );
-
- if( src_pj == nullptr )
- {
- printf( "Unable to translate:\n%s\n", test->src_def );
- test->skip = 1;
- pj_free (dst_pj);
- continue;
- }
+ proj_context_use_proj4_init_rules(nullptr, true);
+ pj = proj_create_crs_to_crs(
+ nullptr, test->src_def, test->dst_def, nullptr
+ );
- if( dst_pj == nullptr )
+ if( pj == nullptr )
{
- printf( "Unable to translate:\n%s\n", test->dst_def );
+ printf( "Unable to translate:\n%s\n or\n%s\n", test->src_def, test->dst_def );
test->skip = 1;
- pj_free (src_pj);
+ proj_destroy(pj);
continue;
}
- test->dst_x = test->src_x;
- test->dst_y = test->src_y;
- test->dst_z = test->src_z;
- test->dst_error = pj_transform( src_pj, dst_pj, 1, 0,
- &(test->dst_x),
- &(test->dst_y),
- &(test->dst_z) );
+ PJ_COORD out = proj_trans(pj, PJ_FWD, test->src);
+ test->dst = out;
+ test->dst_error = proj_errno(pj);
- pj_free( src_pj );
- pj_free( dst_pj );
+ proj_destroy(pj);
test->skip = 0;
-#ifdef notdef
- printf( "Test %d - output %.14g,%.14g,%g\n", i, test->dst_x, test->dst_y, test->dst_z );
+#ifdef nodef
+ printf( "Test %d - output %.14g,%.14g,%g\n", i, test->dst.xyz.x, test->dst.xyz.y, test->dst.xyz.z );
#endif
}
diff --git a/src/tests/test228.cpp b/src/tests/test228.cpp
index 8ae17c87..ae2eb9cc 100644
--- a/src/tests/test228.cpp
+++ b/src/tests/test228.cpp
@@ -26,11 +26,7 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
-#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-#endif
-
-#include "proj_api.h"
+#include "proj_internal.h"
#include <stdio.h> /* for printf declaration */
@@ -54,9 +50,9 @@ static volatile int started = 0;
static void* thread_main(void* unused)
{
- projCtx p_proj_ctxt;
- projPJ p_WGS84_proj;
- projPJ p_OSGB36_proj;
+ PJ_CONTEXT *p_proj_ctxt;
+ PJ *p_WGS84_proj;
+ PJ * p_OSGB36_proj;
(void)unused;
__sync_add_and_fetch(&started, 1);
diff --git a/src/transform.cpp b/src/transform.cpp
deleted file mode 100644
index cff89232..00000000
--- a/src/transform.cpp
+++ /dev/null
@@ -1,1850 +0,0 @@
-/******************************************************************************
- * Project: PROJ.4
- * Purpose: Perform overall coordinate system to coordinate system
- * transformations (pj_transform() function) including reprojection
- * and datum shifting.
- * Author: Frank Warmerdam, warmerdam@pobox.com
- *
- ******************************************************************************
- * Copyright (c) 2000, Frank Warmerdam
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *****************************************************************************/
-
-#include <errno.h>
-#include <math.h>
-#include <string.h>
-
-#include "proj.h"
-#include "proj_internal.h"
-#include "grids.hpp"
-
-using namespace NS_PROJ;
-
-
-///////////////////////////////////////////////////////////////////////////////
-/// From older geocent.h
-///////////////////////////////////////////////////////////////////////////////
-
-
-/***************************************************************************/
-/* RSC IDENTIFIER: GEOCENTRIC
- *
- * ABSTRACT
- *
- * This component provides conversions between Geodetic coordinates (latitude,
- * longitude in radians and height in meters) and Geocentric coordinates
- * (X, Y, Z) in meters.
- *
- * ERROR HANDLING
- *
- * This component checks parameters for valid values. If an invalid value
- * is found, the error code is combined with the current error code using
- * the bitwise or. This combining allows multiple error codes to be
- * returned. The possible error codes are:
- *
- * GEOCENT_NO_ERROR : No errors occurred in function
- * GEOCENT_LAT_ERROR : Latitude out of valid range
- * (-90 to 90 degrees)
- * GEOCENT_LON_ERROR : Longitude out of valid range
- * (-180 to 360 degrees)
- * GEOCENT_A_ERROR : Semi-major axis less than or equal to zero
- * GEOCENT_B_ERROR : Semi-minor axis less than or equal to zero
- * GEOCENT_A_LESS_B_ERROR : Semi-major axis less than semi-minor axis
- *
- *
- * REUSE NOTES
- *
- * GEOCENTRIC is intended for reuse by any application that performs
- * coordinate conversions between geodetic coordinates and geocentric
- * coordinates.
- *
- *
- * REFERENCES
- *
- * An Improved Algorithm for Geocentric to Geodetic Coordinate Conversion,
- * Ralph Toms, February 1996 UCRL-JC-123138.
- *
- * Further information on GEOCENTRIC can be found in the Reuse Manual.
- *
- * GEOCENTRIC originated from : U.S. Army Topographic Engineering Center
- * Geospatial Information Division
- * 7701 Telegraph Road
- * Alexandria, VA 22310-3864
- *
- * LICENSES
- *
- * None apply to this component.
- *
- * RESTRICTIONS
- *
- * GEOCENTRIC has no restrictions.
- *
- * ENVIRONMENT
- *
- * GEOCENTRIC was tested and certified in the following environments:
- *
- * 1. Solaris 2.5 with GCC version 2.8.1
- * 2. Windows 95 with MS Visual C++ version 6
- *
- * MODIFICATIONS
- *
- * Date Description
- * ---- -----------
- *
- *
- */
-
-
-/***************************************************************************/
-/*
- * DEFINES
- */
-#define GEOCENT_NO_ERROR 0x0000
-#define GEOCENT_LAT_ERROR 0x0001
-#define GEOCENT_LON_ERROR 0x0002
-#define GEOCENT_A_ERROR 0x0004
-#define GEOCENT_B_ERROR 0x0008
-#define GEOCENT_A_LESS_B_ERROR 0x0010
-
-
-/***************************************************************************/
-/*
- * FUNCTION PROTOTYPES
- */
-
-/* ensure proper linkage to c++ programs */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct
-{
- double Geocent_a; /* Semi-major axis of ellipsoid in meters */
- double Geocent_b; /* Semi-minor axis of ellipsoid */
- double Geocent_a2; /* Square of semi-major axis */
- double Geocent_b2; /* Square of semi-minor axis */
- double Geocent_e2; /* Eccentricity squared */
- double Geocent_ep2; /* 2nd eccentricity squared */
-} GeocentricInfo;
-
-void pj_Init_Geocentric( GeocentricInfo *gi );
-long pj_Set_Geocentric_Parameters( GeocentricInfo *gi,
- double a,
- double b);
-
-/*
- * The function Set_Geocentric_Parameters receives the ellipsoid parameters
- * as inputs and sets the corresponding state variables.
- *
- * a : Semi-major axis, in meters. (input)
- * b : Semi-minor axis, in meters. (input)
- */
-
-
-void pj_Get_Geocentric_Parameters ( GeocentricInfo *gi,
- double *a,
- double *b);
-
-/*
- * The function Get_Geocentric_Parameters returns the ellipsoid parameters
- * to be used in geocentric coordinate conversions.
- *
- * a : Semi-major axis, in meters. (output)
- * b : Semi-minor axis, in meters. (output)
- */
-
-
-long pj_Convert_Geodetic_To_Geocentric ( GeocentricInfo *gi,
- double Latitude,
- double Longitude,
- double Height,
- double *X,
- double *Y,
- double *Z);
-/*
- * The function Convert_Geodetic_To_Geocentric converts geodetic coordinates
- * (latitude, longitude, and height) to geocentric coordinates (X, Y, Z),
- * according to the current ellipsoid parameters.
- *
- * Latitude : Geodetic latitude in radians (input)
- * Longitude : Geodetic longitude in radians (input)
- * Height : Geodetic height, in meters (input)
- * X : Calculated Geocentric X coordinate, in meters. (output)
- * Y : Calculated Geocentric Y coordinate, in meters. (output)
- * Z : Calculated Geocentric Z coordinate, in meters. (output)
- *
- */
-
-
-void pj_Convert_Geocentric_To_Geodetic (GeocentricInfo *gi,
- double X,
- double Y,
- double Z,
- double *Latitude,
- double *Longitude,
- double *Height);
-/*
- * The function Convert_Geocentric_To_Geodetic converts geocentric
- * coordinates (X, Y, Z) to geodetic coordinates (latitude, longitude,
- * and height), according to the current ellipsoid parameters.
- *
- * X : Geocentric X coordinate, in meters. (input)
- * Y : Geocentric Y coordinate, in meters. (input)
- * Z : Geocentric Z coordinate, in meters. (input)
- * Latitude : Calculated latitude value in radians. (output)
- * Longitude : Calculated longitude value in radians. (output)
- * Height : Calculated height value, in meters. (output)
- */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-///////////////////////////////////////////////////////////////////////////////
-/// From older geocent.cpp
-///////////////////////////////////////////////////////////////////////////////
-
-
-/***************************************************************************/
-/* RSC IDENTIFIER: GEOCENTRIC
- *
- * ABSTRACT
- *
- * This component provides conversions between Geodetic coordinates (latitude,
- * longitude in radians and height in meters) and Geocentric coordinates
- * (X, Y, Z) in meters.
- *
- * ERROR HANDLING
- *
- * This component checks parameters for valid values. If an invalid value
- * is found, the error code is combined with the current error code using
- * the bitwise or. This combining allows multiple error codes to be
- * returned. The possible error codes are:
- *
- * GEOCENT_NO_ERROR : No errors occurred in function
- * GEOCENT_LAT_ERROR : Latitude out of valid range
- * (-90 to 90 degrees)
- * GEOCENT_LON_ERROR : Longitude out of valid range
- * (-180 to 360 degrees)
- * GEOCENT_A_ERROR : Semi-major axis lessthan or equal to zero
- * GEOCENT_B_ERROR : Semi-minor axis lessthan or equal to zero
- * GEOCENT_A_LESS_B_ERROR : Semi-major axis less than semi-minor axis
- *
- *
- * REUSE NOTES
- *
- * GEOCENTRIC is intended for reuse by any application that performs
- * coordinate conversions between geodetic coordinates and geocentric
- * coordinates.
- *
- *
- * REFERENCES
- *
- * An Improved Algorithm for Geocentric to Geodetic Coordinate Conversion,
- * Ralph Toms, February 1996 UCRL-JC-123138.
- *
- * Further information on GEOCENTRIC can be found in the Reuse Manual.
- *
- * GEOCENTRIC originated from : U.S. Army Topographic Engineering Center
- * Geospatial Information Division
- * 7701 Telegraph Road
- * Alexandria, VA 22310-3864
- *
- * LICENSES
- *
- * None apply to this component.
- *
- * RESTRICTIONS
- *
- * GEOCENTRIC has no restrictions.
- *
- * ENVIRONMENT
- *
- * GEOCENTRIC was tested and certified in the following environments:
- *
- * 1. Solaris 2.5 with GCC version 2.8.1
- * 2. Windows 95 with MS Visual C++ version 6
- *
- * MODIFICATIONS
- *
- * Date Description
- * ---- -----------
- * 25-02-97 Original Code
- *
- */
-
-
-/***************************************************************************/
-/*
- * INCLUDES
- */
-#include <math.h>
-//#include "geocent.h"
-/*
- * math.h - is needed for calls to sin, cos, tan and sqrt.
- * geocent.h - is needed for Error codes and prototype error checking.
- */
-
-
-/***************************************************************************/
-/*
- * DEFINES
- */
-#define PI 3.14159265358979323e0
-#define PI_OVER_2 (PI / 2.0e0)
-#define FALSE 0
-#define TRUE 1
-#define COS_67P5 0.38268343236508977 /* cosine of 67.5 degrees */
-#define AD_C 1.0026000 /* Toms region 1 constant */
-
-
-/***************************************************************************/
-/*
- * FUNCTIONS
- */
-
-
-long pj_Set_Geocentric_Parameters (GeocentricInfo *gi, double a, double b)
-
-{ /* BEGIN Set_Geocentric_Parameters */
-/*
- * The function Set_Geocentric_Parameters receives the ellipsoid parameters
- * as inputs and sets the corresponding state variables.
- *
- * a : Semi-major axis, in meters. (input)
- * b : Semi-minor axis, in meters. (input)
- */
- long Error_Code = GEOCENT_NO_ERROR;
-
- if (a <= 0.0)
- Error_Code |= GEOCENT_A_ERROR;
- if (b <= 0.0)
- Error_Code |= GEOCENT_B_ERROR;
- if (a < b)
- Error_Code |= GEOCENT_A_LESS_B_ERROR;
- if (!Error_Code)
- {
- gi->Geocent_a = a;
- gi->Geocent_b = b;
- gi->Geocent_a2 = a * a;
- gi->Geocent_b2 = b * b;
- gi->Geocent_e2 = (gi->Geocent_a2 - gi->Geocent_b2) / gi->Geocent_a2;
- gi->Geocent_ep2 = (gi->Geocent_a2 - gi->Geocent_b2) / gi->Geocent_b2;
- }
- return (Error_Code);
-} /* END OF Set_Geocentric_Parameters */
-
-
-void pj_Get_Geocentric_Parameters (GeocentricInfo *gi,
- double *a,
- double *b)
-{ /* BEGIN Get_Geocentric_Parameters */
-/*
- * The function Get_Geocentric_Parameters returns the ellipsoid parameters
- * to be used in geocentric coordinate conversions.
- *
- * a : Semi-major axis, in meters. (output)
- * b : Semi-minor axis, in meters. (output)
- */
-
- *a = gi->Geocent_a;
- *b = gi->Geocent_b;
-} /* END OF Get_Geocentric_Parameters */
-
-
-long pj_Convert_Geodetic_To_Geocentric (GeocentricInfo *gi,
- double Latitude,
- double Longitude,
- double Height,
- double *X,
- double *Y,
- double *Z)
-{ /* BEGIN Convert_Geodetic_To_Geocentric */
-/*
- * The function Convert_Geodetic_To_Geocentric converts geodetic coordinates
- * (latitude, longitude, and height) to geocentric coordinates (X, Y, Z),
- * according to the current ellipsoid parameters.
- *
- * Latitude : Geodetic latitude in radians (input)
- * Longitude : Geodetic longitude in radians (input)
- * Height : Geodetic height, in meters (input)
- * X : Calculated Geocentric X coordinate, in meters (output)
- * Y : Calculated Geocentric Y coordinate, in meters (output)
- * Z : Calculated Geocentric Z coordinate, in meters (output)
- *
- */
- long Error_Code = GEOCENT_NO_ERROR;
- double Rn; /* Earth radius at location */
- double Sin_Lat; /* sin(Latitude) */
- double Sin2_Lat; /* Square of sin(Latitude) */
- double Cos_Lat; /* cos(Latitude) */
-
- /*
- ** Don't blow up if Latitude is just a little out of the value
- ** range as it may just be a rounding issue. Also removed longitude
- ** test, it should be wrapped by cos() and sin(). NFW for PROJ.4, Sep/2001.
- */
- if( Latitude < -PI_OVER_2 && Latitude > -1.001 * PI_OVER_2 )
- Latitude = -PI_OVER_2;
- else if( Latitude > PI_OVER_2 && Latitude < 1.001 * PI_OVER_2 )
- Latitude = PI_OVER_2;
- else if ((Latitude < -PI_OVER_2) || (Latitude > PI_OVER_2))
- { /* Latitude out of range */
- Error_Code |= GEOCENT_LAT_ERROR;
- }
-
- if (!Error_Code)
- { /* no errors */
- if (Longitude > PI)
- Longitude -= (2*PI);
- Sin_Lat = sin(Latitude);
- Cos_Lat = cos(Latitude);
- Sin2_Lat = Sin_Lat * Sin_Lat;
- Rn = gi->Geocent_a / (sqrt(1.0e0 - gi->Geocent_e2 * Sin2_Lat));
- *X = (Rn + Height) * Cos_Lat * cos(Longitude);
- *Y = (Rn + Height) * Cos_Lat * sin(Longitude);
- *Z = ((Rn * (1 - gi->Geocent_e2)) + Height) * Sin_Lat;
-
- }
- return (Error_Code);
-} /* END OF Convert_Geodetic_To_Geocentric */
-
-/*
- * The function Convert_Geocentric_To_Geodetic converts geocentric
- * coordinates (X, Y, Z) to geodetic coordinates (latitude, longitude,
- * and height), according to the current ellipsoid parameters.
- *
- * X : Geocentric X coordinate, in meters. (input)
- * Y : Geocentric Y coordinate, in meters. (input)
- * Z : Geocentric Z coordinate, in meters. (input)
- * Latitude : Calculated latitude value in radians. (output)
- * Longitude : Calculated longitude value in radians. (output)
- * Height : Calculated height value, in meters. (output)
- */
-
-#define USE_ITERATIVE_METHOD
-
-void pj_Convert_Geocentric_To_Geodetic (GeocentricInfo *gi,
- double X,
- double Y,
- double Z,
- double *Latitude,
- double *Longitude,
- double *Height)
-{ /* BEGIN Convert_Geocentric_To_Geodetic */
-#if !defined(USE_ITERATIVE_METHOD)
-/*
- * The method used here is derived from 'An Improved Algorithm for
- * Geocentric to Geodetic Coordinate Conversion', by Ralph Toms, Feb 1996
- */
-
-/* Note: Variable names follow the notation used in Toms, Feb 1996 */
-
- double W; /* distance from Z axis */
- double W2; /* square of distance from Z axis */
- double T0; /* initial estimate of vertical component */
- double T1; /* corrected estimate of vertical component */
- double S0; /* initial estimate of horizontal component */
- double S1; /* corrected estimate of horizontal component */
- double Sin_B0; /* sin(B0), B0 is estimate of Bowring aux variable */
- double Sin3_B0; /* cube of sin(B0) */
- double Cos_B0; /* cos(B0) */
- double Sin_p1; /* sin(phi1), phi1 is estimated latitude */
- double Cos_p1; /* cos(phi1) */
- double Rn; /* Earth radius at location */
- double Sum; /* numerator of cos(phi1) */
- int At_Pole; /* indicates location is in polar region */
-
- At_Pole = FALSE;
- if (X != 0.0)
- {
- *Longitude = atan2(Y,X);
- }
- else
- {
- if (Y > 0)
- {
- *Longitude = PI_OVER_2;
- }
- else if (Y < 0)
- {
- *Longitude = -PI_OVER_2;
- }
- else
- {
- At_Pole = TRUE;
- *Longitude = 0.0;
- if (Z > 0.0)
- { /* north pole */
- *Latitude = PI_OVER_2;
- }
- else if (Z < 0.0)
- { /* south pole */
- *Latitude = -PI_OVER_2;
- }
- else
- { /* center of earth */
- *Latitude = PI_OVER_2;
- *Height = -Geocent_b;
- return;
- }
- }
- }
- W2 = X*X + Y*Y;
- W = sqrt(W2);
- T0 = Z * AD_C;
- S0 = sqrt(T0 * T0 + W2);
- Sin_B0 = T0 / S0;
- Cos_B0 = W / S0;
- Sin3_B0 = Sin_B0 * Sin_B0 * Sin_B0;
- T1 = Z + gi->Geocent_b * gi->Geocent_ep2 * Sin3_B0;
- Sum = W - gi->Geocent_a * gi->Geocent_e2 * Cos_B0 * Cos_B0 * Cos_B0;
- S1 = sqrt(T1*T1 + Sum * Sum);
- Sin_p1 = T1 / S1;
- Cos_p1 = Sum / S1;
- Rn = gi->Geocent_a / sqrt(1.0 - gi->Geocent_e2 * Sin_p1 * Sin_p1);
- if (Cos_p1 >= COS_67P5)
- {
- *Height = W / Cos_p1 - Rn;
- }
- else if (Cos_p1 <= -COS_67P5)
- {
- *Height = W / -Cos_p1 - Rn;
- }
- else
- {
- *Height = Z / Sin_p1 + Rn * (gi->Geocent_e2 - 1.0);
- }
- if (At_Pole == FALSE)
- {
- *Latitude = atan(Sin_p1 / Cos_p1);
- }
-#else /* defined(USE_ITERATIVE_METHOD) */
-/*
-* Reference...
-* ============
-* Wenzel, H.-G.(1985): Hochauflösende Kugelfunktionsmodelle für
-* das Gravitationspotential der Erde. Wiss. Arb. Univ. Hannover
-* Nr. 137, p. 130-131.
-
-* Programmed by GGA- Leibniz-Institute of Applied Geophysics
-* Stilleweg 2
-* D-30655 Hannover
-* Federal Republic of Germany
-* Internet: www.gga-hannover.de
-*
-* Hannover, March 1999, April 2004.
-* see also: comments in statements
-* remarks:
-* Mathematically exact and because of symmetry of rotation-ellipsoid,
-* each point (X,Y,Z) has at least two solutions (Latitude1,Longitude1,Height1) and
-* (Latitude2,Longitude2,Height2). Is point=(0.,0.,Z) (P=0.), so you get even
-* four solutions, every two symmetrical to the semi-minor axis.
-* Here Height1 and Height2 have at least a difference in order of
-* radius of curvature (e.g. (0,0,b)=> (90.,0.,0.) or (-90.,0.,-2b);
-* (a+100.)*(sqrt(2.)/2.,sqrt(2.)/2.,0.) => (0.,45.,100.) or
-* (0.,225.,-(2a+100.))).
-* The algorithm always computes (Latitude,Longitude) with smallest |Height|.
-* For normal computations, that means |Height|<10000.m, algorithm normally
-* converges after to 2-3 steps!!!
-* But if |Height| has the amount of length of ellipsoid's axis
-* (e.g. -6300000.m), algorithm needs about 15 steps.
-*/
-
-/* local definitions and variables */
-/* end-criterium of loop, accuracy of sin(Latitude) */
-#define genau 1.E-12
-#define genau2 (genau*genau)
-#define maxiter 30
-
- double P; /* distance between semi-minor axis and location */
- double RR; /* distance between center and location */
- double CT; /* sin of geocentric latitude */
- double ST; /* cos of geocentric latitude */
- double RX;
- double RK;
- double RN; /* Earth radius at location */
- double CPHI0; /* cos of start or old geodetic latitude in iterations */
- double SPHI0; /* sin of start or old geodetic latitude in iterations */
- double CPHI; /* cos of searched geodetic latitude */
- double SPHI; /* sin of searched geodetic latitude */
- double SDPHI; /* end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1)) */
- int iter; /* # of continuous iteration, max. 30 is always enough (s.a.) */
-
- P = sqrt(X*X+Y*Y);
- RR = sqrt(X*X+Y*Y+Z*Z);
-
-/* special cases for latitude and longitude */
- if (P/gi->Geocent_a < genau) {
-
-/* special case, if P=0. (X=0., Y=0.) */
- *Longitude = 0.;
-
-/* if (X,Y,Z)=(0.,0.,0.) then Height becomes semi-minor axis
- * of ellipsoid (=center of mass), Latitude becomes PI/2 */
- if (RR/gi->Geocent_a < genau) {
- *Latitude = PI_OVER_2;
- *Height = -gi->Geocent_b;
- return ;
-
- }
- }
- else {
-/* ellipsoidal (geodetic) longitude
- * interval: -PI < Longitude <= +PI */
- *Longitude=atan2(Y,X);
- }
-
-/* --------------------------------------------------------------
- * Following iterative algorithm was developed by
- * "Institut für Erdmessung", University of Hannover, July 1988.
- * Internet: www.ife.uni-hannover.de
- * Iterative computation of CPHI,SPHI and Height.
- * Iteration of CPHI and SPHI to 10**-12 radian resp.
- * 2*10**-7 arcsec.
- * --------------------------------------------------------------
- */
- CT = Z/RR;
- ST = P/RR;
- {
- const double denominator = 1.0-gi->Geocent_e2*(2.0-gi->Geocent_e2)*ST*ST;
- if( denominator == 0 )
- {
- *Latitude = HUGE_VAL;
- *Longitude = HUGE_VAL;
- *Height = HUGE_VAL;
- return;
- }
- RX = 1.0/sqrt(denominator);
- }
- CPHI0 = ST*(1.0-gi->Geocent_e2)*RX;
- SPHI0 = CT*RX;
- iter = 0;
-
-/* loop to find sin(Latitude) resp. Latitude
- * until |sin(Latitude(iter)-Latitude(iter-1))| < genau */
- do
- {
- iter++;
- RN = gi->Geocent_a/sqrt(1.0-gi->Geocent_e2*SPHI0*SPHI0);
-
-/* ellipsoidal (geodetic) height */
- *Height = P*CPHI0+Z*SPHI0-RN*(1.0-gi->Geocent_e2*SPHI0*SPHI0);
-
- /* avoid zero division */
- if (RN+*Height==0.0) {
- *Latitude = 0.0;
- return;
- }
- RK = gi->Geocent_e2*RN/(RN+*Height);
- {
- const double denominator = 1.0-RK*(2.0-RK)*ST*ST;
- if( denominator == 0 )
- {
- *Latitude = HUGE_VAL;
- *Longitude = HUGE_VAL;
- *Height = HUGE_VAL;
- return;
- }
- RX = 1.0/sqrt(denominator);
- }
- CPHI = ST*(1.0-RK)*RX;
- SPHI = CT*RX;
- SDPHI = SPHI*CPHI0-CPHI*SPHI0;
- CPHI0 = CPHI;
- SPHI0 = SPHI;
- }
- while (SDPHI*SDPHI > genau2 && iter < maxiter);
-
-/* ellipsoidal (geodetic) latitude */
- *Latitude=atan2(SPHI, fabs(CPHI));
-
-#endif /* defined(USE_ITERATIVE_METHOD) */
-} /* END OF Convert_Geocentric_To_Geodetic */
-
-
-///////////////////////////////////////////////////////////////////////////////
-/// Main of transform.cpp
-///////////////////////////////////////////////////////////////////////////////
-
-
-static int adjust_axis( projCtx ctx, const char *axis, int denormalize_flag,
- long point_count, int point_offset,
- double *x, double *y, double *z );
-
-#ifndef SRS_WGS84_SEMIMAJOR
-#define SRS_WGS84_SEMIMAJOR 6378137.0
-#endif
-
-#ifndef SRS_WGS84_ESQUARED
-#define SRS_WGS84_ESQUARED 0.0066943799901413165
-#endif
-
-#define Dx_BF (defn->datum_params[0])
-#define Dy_BF (defn->datum_params[1])
-#define Dz_BF (defn->datum_params[2])
-#define Rx_BF (defn->datum_params[3])
-#define Ry_BF (defn->datum_params[4])
-#define Rz_BF (defn->datum_params[5])
-#define M_BF (defn->datum_params[6])
-
-/*
-** This table is intended to indicate for any given error code
-** whether that error will occur for all locations (ie.
-** it is a problem with the coordinate system as a whole) in which case the
-** value would be 0, or if the problem is with the point being transformed
-** in which case the value is 1.
-**
-** At some point we might want to move this array in with the error message
-** list or something, but while experimenting with it this should be fine.
-**
-**
-** NOTE (2017-10-01): Non-transient errors really should have resulted in a
-** PJ==0 during initialization, and hence should be handled at the level
-** before calling pj_transform. The only obvious example of the contrary
-** appears to be the PJD_ERR_GRID_AREA case, which may also be taken to
-** mean "no grids available"
-**
-**
-*/
-
-static const int transient_error[70] = {
- /* 0 1 2 3 4 5 6 7 8 9 */
- /* 0 to 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- /* 10 to 19 */ 0, 0, 0, 0, 1, 1, 0, 1, 1, 1,
- /* 20 to 29 */ 1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
- /* 30 to 39 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- /* 40 to 49 */ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
- /* 50 to 59 */ 1, 0, 1, 0, 1, 1, 1, 1, 0, 0,
- /* 60 to 69 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
-
-
-/* -------------------------------------------------------------------- */
-/* Read transient_error[] in a safe way. */
-/* -------------------------------------------------------------------- */
-static int get_transient_error_value(int pos_index)
-{
- const int array_size =
- (int)(sizeof(transient_error) / sizeof(transient_error[0]));
- if( pos_index < 0 || pos_index >= array_size ) {
- return 0;
- }
- return transient_error[pos_index];
-}
-
-
-/* -------------------------------------------------------------------- */
-/* Transform unusual input coordinate axis orientation to */
-/* standard form if needed. */
-/* -------------------------------------------------------------------- */
-static int adjust_axes (PJ *P, PJ_DIRECTION dir, long n, int dist, double *x, double *y, double *z) {
- /* Nothing to do? */
- if (0==strcmp(P->axis,"enu"))
- return 0;
-
- return adjust_axis( P->ctx, P->axis,
- dir==PJ_FWD ? 1: 0, n, dist, x, y, z );
-}
-
-
-
-/* ----------------------------------------------------------------------- */
-/* Transform geographic (lat/long) source coordinates to */
-/* cartesian ("geocentric"), if needed */
-/* ----------------------------------------------------------------------- */
-static int geographic_to_cartesian (PJ *P, PJ_DIRECTION dir, long n, int dist, double *x, double *y, double *z) {
- int res;
- long i;
- double fac = P->to_meter;
-
- /* Nothing to do? */
- if (!P->is_geocent)
- return 0;
-
- if ( z == nullptr ) {
- pj_ctx_set_errno( pj_get_ctx(P), PJD_ERR_GEOCENTRIC);
- return PJD_ERR_GEOCENTRIC;
- }
-
- if (PJ_FWD==dir) {
- fac = P->fr_meter;
- res = pj_geodetic_to_geocentric( P->a_orig, P->es_orig, n, dist, x, y, z );
- if (res)
- return res;
- }
-
- if (fac != 1.0) {
- for( i = 0; i < n; i++ ) {
- if( x[dist*i] != HUGE_VAL ) {
- x[dist*i] *= fac;
- y[dist*i] *= fac;
- z[dist*i] *= fac;
- }
- }
- }
-
- if (PJ_FWD==dir)
- return 0;
- return pj_geocentric_to_geodetic(
- P->a_orig, P->es_orig,
- n, dist,
- x, y, z
- );
-}
-
-
-
-
-
-
-
-
-
-
-/* -------------------------------------------------------------------- */
-/* Transform destination points to projection coordinates, if */
-/* desired. */
-/* */
-/* Ought to fold this into projected_to_geographic */
-/* -------------------------------------------------------------------- */
-static int geographic_to_projected (PJ *P, long n, int dist, double *x, double *y, double *z) {
- long i;
-
- /* Nothing to do? */
- if (P->is_latlong && !P->geoc && P->vto_meter == 1.0)
- return 0;
- if (P->is_geocent)
- return 0;
-
- if(P->fwd3d != nullptr && !(z == nullptr && P->is_latlong))
- {
- /* Three dimensions must be defined */
- if ( z == nullptr)
- {
- pj_ctx_set_errno( pj_get_ctx(P), PJD_ERR_GEOCENTRIC);
- return PJD_ERR_GEOCENTRIC;
- }
-
- for( i = 0; i < n; i++ )
- {
- PJ_XYZ projected_loc;
- PJ_LPZ geodetic_loc;
-
- geodetic_loc.lam = x[dist*i];
- geodetic_loc.phi = y[dist*i];
- geodetic_loc.z = z[dist*i];
-
- if (geodetic_loc.lam == HUGE_VAL)
- continue;
-
- proj_errno_reset( P );
- projected_loc = pj_fwd3d( geodetic_loc, P);
- if( P->ctx->last_errno != 0 )
- {
- if( (P->ctx->last_errno != EDOM
- && P->ctx->last_errno != ERANGE)
- && (P->ctx->last_errno > 0
- || P->ctx->last_errno < -44 || n == 1
- || get_transient_error_value(-P->ctx->last_errno) == 0 ) )
- {
- return P->ctx->last_errno;
- }
- else
- {
- projected_loc.x = HUGE_VAL;
- projected_loc.y = HUGE_VAL;
- projected_loc.z = HUGE_VAL;
- }
- }
-
- x[dist*i] = projected_loc.x;
- y[dist*i] = projected_loc.y;
- z[dist*i] = projected_loc.z;
- }
- return 0;
- }
-
- // Ugly hack. See https://github.com/OSGeo/PROJ/issues/1782
- if( P->right == PJ_IO_UNITS_WHATEVER && P->descr &&
- strncmp(P->descr, "General Oblique Transformation",
- strlen("General Oblique Transformation")) == 0 )
- {
- P->right = PJ_IO_UNITS_PROJECTED;
- }
-
- for( i = 0; i <n; i++ )
- {
- PJ_XY projected_loc;
- PJ_LP geodetic_loc;
-
- geodetic_loc.lam = x[dist*i];
- geodetic_loc.phi = y[dist*i];
-
- if( geodetic_loc.lam == HUGE_VAL )
- continue;
-
- proj_errno_reset( P );
- projected_loc = pj_fwd( geodetic_loc, P );
- if( P->ctx->last_errno != 0 )
- {
- if( (P->ctx->last_errno != EDOM
- && P->ctx->last_errno != ERANGE)
- && (P->ctx->last_errno > 0
- || P->ctx->last_errno < -44 || n == 1
- || get_transient_error_value(-P->ctx->last_errno) == 0 ) )
- {
- return P->ctx->last_errno;
- }
- else
- {
- projected_loc.x = HUGE_VAL;
- projected_loc.y = HUGE_VAL;
- }
- }
-
- x[dist*i] = projected_loc.x;
- y[dist*i] = projected_loc.y;
- }
- return 0;
-}
-
-
-
-
-
-/* ----------------------------------------------------------------------- */
-/* Transform projected source coordinates to lat/long, if needed */
-/* ----------------------------------------------------------------------- */
-static int projected_to_geographic (PJ *P, long n, int dist, double *x, double *y, double *z) {
- long i;
-
- /* Nothing to do? */
- if (P->is_latlong && !P->geoc && P->vto_meter == 1.0)
- return 0;
- if (P->is_geocent)
- return 0;
-
- /* Check first if projection is invertible. */
- if( (P->inv3d == nullptr) && (P->inv == nullptr))
- {
- pj_ctx_set_errno(pj_get_ctx(P), PJD_ERR_NON_CONV_INV_MERI_DIST);
- pj_log( pj_get_ctx(P), PJ_LOG_ERROR,
- "pj_transform(): source projection not invertable" );
- return PJD_ERR_NON_CONV_INV_MERI_DIST;
- }
-
- /* If invertible - First try inv3d if defined */
- if (P->inv3d != nullptr && !(z == nullptr && P->is_latlong))
- {
- /* Three dimensions must be defined */
- if ( z == nullptr)
- {
- pj_ctx_set_errno( pj_get_ctx(P), PJD_ERR_GEOCENTRIC);
- return PJD_ERR_GEOCENTRIC;
- }
-
- for (i=0; i < n; i++)
- {
- PJ_XYZ projected_loc;
- PJ_LPZ geodetic_loc;
-
- projected_loc.x = x[dist*i];
- projected_loc.y = y[dist*i];
- projected_loc.z = z[dist*i];
-
- if (projected_loc.x == HUGE_VAL)
- continue;
-
- proj_errno_reset( P );
- geodetic_loc = pj_inv3d(projected_loc, P);
- if( P->ctx->last_errno != 0 )
- {
- if( (P->ctx->last_errno != EDOM
- && P->ctx->last_errno != ERANGE)
- && (P->ctx->last_errno > 0
- || P->ctx->last_errno < -44 || n == 1
- || get_transient_error_value(-P->ctx->last_errno) == 0 ) )
- {
- return P->ctx->last_errno;
- }
- else
- {
- geodetic_loc.lam = HUGE_VAL;
- geodetic_loc.phi = HUGE_VAL;
- geodetic_loc.z = HUGE_VAL;
- }
- }
-
- x[dist*i] = geodetic_loc.lam;
- y[dist*i] = geodetic_loc.phi;
- z[dist*i] = geodetic_loc.z;
-
- }
- return 0;
- }
-
- // Ugly hack. See https://github.com/OSGeo/PROJ/issues/1782
- if( P->right == PJ_IO_UNITS_WHATEVER && P->descr &&
- strncmp(P->descr, "General Oblique Transformation",
- strlen("General Oblique Transformation")) == 0 )
- {
- P->right = PJ_IO_UNITS_PROJECTED;
- }
-
- /* Fallback to the original PROJ.4 API 2d inversion - inv */
- for( i = 0; i < n; i++ ) {
- PJ_XY projected_loc;
- PJ_LP geodetic_loc;
-
- projected_loc.x = x[dist*i];
- projected_loc.y = y[dist*i];
-
- if( projected_loc.x == HUGE_VAL )
- continue;
-
- proj_errno_reset( P );
- geodetic_loc = pj_inv( projected_loc, P );
- if( P->ctx->last_errno != 0 )
- {
- if( (P->ctx->last_errno != EDOM
- && P->ctx->last_errno != ERANGE)
- && (P->ctx->last_errno > 0
- || P->ctx->last_errno < -44 || n == 1
- || get_transient_error_value(-P->ctx->last_errno) == 0 ) )
- {
- return P->ctx->last_errno;
- }
- else
- {
- geodetic_loc.lam = HUGE_VAL;
- geodetic_loc.phi = HUGE_VAL;
- }
- }
-
- x[dist*i] = geodetic_loc.lam;
- y[dist*i] = geodetic_loc.phi;
- }
- return 0;
-}
-
-
-
-/* -------------------------------------------------------------------- */
-/* Adjust for the prime meridian if needed. */
-/* -------------------------------------------------------------------- */
-static int prime_meridian (PJ *P, PJ_DIRECTION dir, long n, int dist, double *x) {
- int i;
- double pm = P->from_greenwich;
-
- /* Nothing to do? */
- if (pm==0.0)
- return 0;
- if (!(P->is_geocent || P->is_latlong))
- return 0;
-
- if (dir==PJ_FWD)
- pm = -pm;
-
- for (i = 0; i < n; i++)
- if (x[dist*i] != HUGE_VAL)
- x[dist*i] += pm;
-
- return 0;
-}
-
-
-
-/* -------------------------------------------------------------------- */
-/* Adjust for vertical scale factor if needed */
-/* -------------------------------------------------------------------- */
-static int height_unit (PJ *P, PJ_DIRECTION dir, long n, int dist, double *z) {
- int i;
- double fac = P->vto_meter;
-
- if (PJ_FWD==dir)
- fac = P->vfr_meter;
-
- /* Nothing to do? */
- if (fac==1.0)
- return 0;
- if (nullptr==z)
- return 0;
- if (P->is_latlong)
- return 0; /* done in pj_inv3d() / pj_fwd3d() */
-
- for (i = 0; i < n; i++)
- if (z[dist*i] != HUGE_VAL )
- z[dist*i] *= fac;
-
- return 0;
-}
-
-
-/************************************************************************/
-/* pj_apply_vgridshift() */
-/* */
-/* This implementation takes uses the gridlist from a coordinate */
-/* system definition. If the gridlist has not yet been */
-/* populated in the coordinate system definition we set it up */
-/* now. */
-/************************************************************************/
-static int pj_apply_vgridshift( PJ *defn,
- int inverse,
- long point_count, int point_offset,
- double *x, double *y, double *z )
-
-{
- if( defn->vgrids_legacy == nullptr )
- {
- defn->vgrids_legacy = new ListOfVGrids;
- auto vgrids = pj_vgrid_init(defn, "geoidgrids");
- if( vgrids.empty() )
- return 0;
- *static_cast<ListOfVGrids*>(defn->vgrids_legacy) = std::move(vgrids);
- }
- if( static_cast<ListOfVGrids*>(defn->vgrids_legacy)->empty() )
- {
- return 0;
- }
-
- for( int i = 0; i < point_count; i++ )
- {
- double value;
- long io = i * point_offset;
- PJ_LP input;
-
- input.phi = y[io];
- input.lam = x[io];
-
- value = pj_vgrid_value(defn, *static_cast<ListOfVGrids*>(defn->vgrids_legacy), input, 1.0);
-
- if( inverse )
- z[io] -= value;
- else
- z[io] += value;
-
- if( value == HUGE_VAL )
- {
- std::string gridlist;
-
- proj_log_debug(defn,
- "pj_apply_vgridshift(): failed to find a grid shift table for\n"
- " location (%.7fdW,%.7fdN)",
- x[io] * RAD_TO_DEG,
- y[io] * RAD_TO_DEG );
-
- for( const auto& gridset: *static_cast<ListOfVGrids*>(defn->vgrids_legacy) )
- {
- if( gridlist.empty() )
- gridlist += " tried: ";
- else
- gridlist += ',';
- gridlist += gridset->name();
- }
-
- proj_log_debug(defn, "%s", gridlist.c_str());
- pj_ctx_set_errno( defn->ctx, PJD_ERR_GRID_AREA );
-
- return PJD_ERR_GRID_AREA;
- }
- }
-
- return 0;
-}
-
-
-/* -------------------------------------------------------------------- */
-/* Transform to ellipsoidal heights if needed */
-/* -------------------------------------------------------------------- */
-static int geometric_to_orthometric (PJ *P, PJ_DIRECTION dir, long n, int dist, double *x, double *y, double *z) {
- int err;
- if (0==P->has_geoid_vgrids)
- return 0;
- if (z==nullptr)
- return PJD_ERR_GEOCENTRIC;
- err = pj_apply_vgridshift (P, dir==PJ_FWD ? 1 : 0, n, dist, x, y, z );
- if (err)
- return pj_ctx_get_errno(P->ctx);
- return 0;
-}
-
-
-
-/* -------------------------------------------------------------------- */
-/* Convert datums if needed, and possible. */
-/* -------------------------------------------------------------------- */
-static int datum_transform (PJ *P, PJ *Q, long n, int dist, double *x, double *y, double *z) {
- if (0==pj_datum_transform (P, Q, n, dist, x, y, z))
- return 0;
- if (P->ctx->last_errno)
- return P->ctx->last_errno;
- return Q->ctx->last_errno;
-}
-
-
-
-
-
-/* -------------------------------------------------------------------- */
-/* If a wrapping center other than 0 is provided, rewrap around */
-/* the suggested center (for latlong coordinate systems only). */
-/* -------------------------------------------------------------------- */
-static int long_wrap (PJ *P, long n, int dist, double *x) {
- long i;
-
- /* Nothing to do? */
- if (P->is_geocent)
- return 0;
- if (!P->is_long_wrap_set)
- return 0;
- if (!P->is_latlong)
- return 0;
-
- for (i = 0; i < n; i++ ) {
- double val = x[dist*i];
- if (val == HUGE_VAL)
- continue;
-
- /* Get fast in ] -2 PI, 2 PI [ range */
- val = fmod(val, M_TWOPI);
- while( val < P->long_wrap_center - M_PI )
- val += M_TWOPI;
- while( val > P->long_wrap_center + M_PI )
- val -= M_TWOPI;
- x[dist*i] = val;
- }
- return 0;
-}
-
-
-
-/************************************************************************/
-/* pj_transform() */
-/* */
-/* Currently this function doesn't recognise if two projections */
-/* are identical (to short circuit reprojection) because it is */
-/* difficult to compare PJ structures (since there are some */
-/* projection specific components). */
-/************************************************************************/
-
-int pj_transform(
- PJ *src, PJ *dst,
- long point_count, int point_offset,
- double *x, double *y, double *z
-){
- int err;
-
- src->ctx->last_errno = 0;
- dst->ctx->last_errno = 0;
-
- if( point_offset == 0 )
- point_offset = 1;
-
- /* Bring input to "normal form": longitude, latitude, ellipsoidal height */
-
- err = adjust_axes (src, PJ_INV, point_count, point_offset, x, y, z);
- if (err)
- return err;
- err = geographic_to_cartesian (src, PJ_INV, point_count, point_offset, x, y, z);
- if (err)
- return err;
- err = projected_to_geographic (src, point_count, point_offset, x, y, z);
- if (err)
- return err;
- err = prime_meridian (src, PJ_INV, point_count, point_offset, x);
- if (err)
- return err;
- err = height_unit (src, PJ_INV, point_count, point_offset, z);
- if (err)
- return err;
- err = geometric_to_orthometric (src, PJ_INV, point_count, point_offset, x, y, z);
- if (err)
- return err;
-
- /* At the center of the process we do the datum shift (if needed) */
-
- err = datum_transform(src, dst, point_count, point_offset, x, y, z );
- if (err)
- return err;
-
- /* Now get out on the other side: Bring "normal form" to output form */
-
- err = geometric_to_orthometric (dst, PJ_FWD, point_count, point_offset, x, y, z);
- if (err)
- return err;
- err = height_unit (dst, PJ_FWD, point_count, point_offset, z);
- if (err)
- return err;
- err = prime_meridian (dst, PJ_FWD, point_count, point_offset, x);
- if (err)
- return err;
- err = geographic_to_cartesian (dst, PJ_FWD, point_count, point_offset, x, y, z);
- if (err)
- return err;
- err = geographic_to_projected (dst, point_count, point_offset, x, y, z);
- if (err)
- return err;
- err = long_wrap (dst, point_count, point_offset, x);
- if (err)
- return err;
- err = adjust_axes (dst, PJ_FWD, point_count, point_offset, x, y, z);
- if (err)
- return err;
-
- return 0;
-}
-
-
-
-/************************************************************************/
-/* pj_geodetic_to_geocentric() */
-/************************************************************************/
-
-int pj_geodetic_to_geocentric( double a, double es,
- long point_count, int point_offset,
- double *x, double *y, double *z )
-
-{
- double b;
- int i;
- GeocentricInfo gi;
- int ret_errno = 0;
-
- if( es == 0.0 )
- b = a;
- else
- b = a * sqrt(1-es);
-
- if( pj_Set_Geocentric_Parameters( &gi, a, b ) != 0 )
- {
- return PJD_ERR_GEOCENTRIC;
- }
-
- for( i = 0; i < point_count; i++ )
- {
- long io = i * point_offset;
-
- if( x[io] == HUGE_VAL )
- continue;
-
- if( pj_Convert_Geodetic_To_Geocentric( &gi, y[io], x[io], z[io],
- x+io, y+io, z+io ) != 0 )
- {
- ret_errno = PJD_ERR_LAT_OR_LON_EXCEED_LIMIT;
- x[io] = y[io] = HUGE_VAL;
- /* but keep processing points! */
- }
- }
-
- return ret_errno;
-}
-
-/************************************************************************/
-/* pj_geocentric_to_geodetic() */
-/************************************************************************/
-
-int pj_geocentric_to_geodetic( double a, double es,
- long point_count, int point_offset,
- double *x, double *y, double *z )
-
-{
- double b;
- int i;
- GeocentricInfo gi;
-
- if( es == 0.0 )
- b = a;
- else
- b = a * sqrt(1-es);
-
- if( pj_Set_Geocentric_Parameters( &gi, a, b ) != 0 )
- {
- return PJD_ERR_GEOCENTRIC;
- }
-
- for( i = 0; i < point_count; i++ )
- {
- long io = i * point_offset;
-
- if( x[io] == HUGE_VAL )
- continue;
-
- pj_Convert_Geocentric_To_Geodetic( &gi, x[io], y[io], z[io],
- y+io, x+io, z+io );
- }
-
- return 0;
-}
-
-/************************************************************************/
-/* pj_compare_datums() */
-/* */
-/* Returns TRUE if the two datums are identical, otherwise */
-/* FALSE. */
-/************************************************************************/
-
-int pj_compare_datums( PJ *srcdefn, PJ *dstdefn )
-
-{
- if( srcdefn->datum_type != dstdefn->datum_type )
- {
- return 0;
- }
- else if( srcdefn->a_orig != dstdefn->a_orig
- || ABS(srcdefn->es_orig - dstdefn->es_orig) > 0.000000000050 )
- {
- /* the tolerance for es is to ensure that GRS80 and WGS84 are
- considered identical */
- return 0;
- }
- else if( srcdefn->datum_type == PJD_3PARAM )
- {
- return (srcdefn->datum_params[0] == dstdefn->datum_params[0]
- && srcdefn->datum_params[1] == dstdefn->datum_params[1]
- && srcdefn->datum_params[2] == dstdefn->datum_params[2]);
- }
- else if( srcdefn->datum_type == PJD_7PARAM )
- {
- return (srcdefn->datum_params[0] == dstdefn->datum_params[0]
- && srcdefn->datum_params[1] == dstdefn->datum_params[1]
- && srcdefn->datum_params[2] == dstdefn->datum_params[2]
- && srcdefn->datum_params[3] == dstdefn->datum_params[3]
- && srcdefn->datum_params[4] == dstdefn->datum_params[4]
- && srcdefn->datum_params[5] == dstdefn->datum_params[5]
- && srcdefn->datum_params[6] == dstdefn->datum_params[6]);
- }
- else if( srcdefn->datum_type == PJD_GRIDSHIFT )
- {
- const char* srcnadgrids =
- pj_param(srcdefn->ctx, srcdefn->params,"snadgrids").s;
- const char* dstnadgrids =
- pj_param(dstdefn->ctx, dstdefn->params,"snadgrids").s;
- return srcnadgrids != nullptr && dstnadgrids != nullptr &&
- strcmp( srcnadgrids, dstnadgrids ) == 0;
- }
- else
- return 1;
-}
-
-/************************************************************************/
-/* pj_geocentic_to_wgs84() */
-/************************************************************************/
-
-static
-int pj_geocentric_to_wgs84( PJ *defn,
- long point_count, int point_offset,
- double *x, double *y, double *z )
-
-{
- int i;
-
- if( defn->datum_type == PJD_3PARAM )
- {
- for( i = 0; i < point_count; i++ )
- {
- long io = i * point_offset;
-
- if( x[io] == HUGE_VAL )
- continue;
-
- x[io] = x[io] + Dx_BF;
- y[io] = y[io] + Dy_BF;
- z[io] = z[io] + Dz_BF;
- }
- }
- else if( defn->datum_type == PJD_7PARAM )
- {
- for( i = 0; i < point_count; i++ )
- {
- long io = i * point_offset;
- double x_out, y_out, z_out;
-
- if( x[io] == HUGE_VAL )
- continue;
-
- x_out = M_BF*( x[io] - Rz_BF*y[io] + Ry_BF*z[io]) + Dx_BF;
- y_out = M_BF*( Rz_BF*x[io] + y[io] - Rx_BF*z[io]) + Dy_BF;
- z_out = M_BF*(-Ry_BF*x[io] + Rx_BF*y[io] + z[io]) + Dz_BF;
-
- x[io] = x_out;
- y[io] = y_out;
- z[io] = z_out;
- }
- }
-
- return 0;
-}
-
-/************************************************************************/
-/* pj_geocentic_from_wgs84() */
-/************************************************************************/
-
-static
-int pj_geocentric_from_wgs84( PJ *defn,
- long point_count, int point_offset,
- double *x, double *y, double *z )
-
-{
- int i;
-
- if( defn->datum_type == PJD_3PARAM )
- {
- for( i = 0; i < point_count; i++ )
- {
- long io = i * point_offset;
-
- if( x[io] == HUGE_VAL )
- continue;
-
- x[io] = x[io] - Dx_BF;
- y[io] = y[io] - Dy_BF;
- z[io] = z[io] - Dz_BF;
- }
- }
- else if( defn->datum_type == PJD_7PARAM )
- {
- for( i = 0; i < point_count; i++ )
- {
- long io = i * point_offset;
- double x_tmp, y_tmp, z_tmp;
-
- if( x[io] == HUGE_VAL )
- continue;
-
- x_tmp = (x[io] - Dx_BF) / M_BF;
- y_tmp = (y[io] - Dy_BF) / M_BF;
- z_tmp = (z[io] - Dz_BF) / M_BF;
-
- x[io] = x_tmp + Rz_BF*y_tmp - Ry_BF*z_tmp;
- y[io] = -Rz_BF*x_tmp + y_tmp + Rx_BF*z_tmp;
- z[io] = Ry_BF*x_tmp - Rx_BF*y_tmp + z_tmp;
- }
- }
-
- return 0;
-}
-
-
-/************************************************************************/
-/* pj_apply_gridshift_2() */
-/* */
-/* This implementation uses the gridlist from a coordinate */
-/* system definition. If the gridlist has not yet been */
-/* populated in the coordinate system definition we set it up */
-/* now. */
-/************************************************************************/
-static
-int pj_apply_gridshift_2( PJ *defn, int inverse,
- long point_count, int point_offset,
- double *x, double *y, double * /*z*/ )
-
-{
- if( defn->hgrids_legacy == nullptr )
- {
- defn->hgrids_legacy = new ListOfHGrids;
- auto hgrids = pj_hgrid_init(defn, "nadgrids");
- if( hgrids.empty() )
- return 0;
- *static_cast<ListOfHGrids*>(defn->hgrids_legacy) = std::move(hgrids);
- }
- if( static_cast<ListOfHGrids*>(defn->hgrids_legacy)->empty() )
- {
- return 0;
- }
-
- for( long i = 0; i < point_count; i++ )
- {
- PJ_LP input;
-
- long io = i * point_offset;
- input.phi = y[io];
- input.lam = x[io];
-
- auto output = pj_hgrid_apply(defn->ctx, *static_cast<ListOfHGrids*>(defn->hgrids_legacy), input, inverse ? PJ_INV : PJ_FWD);
-
- if ( output.lam != HUGE_VAL )
- {
- y[io] = output.phi;
- x[io] = output.lam;
- }
- else
- {
- if( defn->ctx->debug_level >= PJ_LOG_DEBUG_MAJOR )
- {
- pj_log( defn->ctx, PJ_LOG_DEBUG_MAJOR,
- "pj_apply_gridshift(): failed to find a grid shift table for\n"
- " location (%.7fdW,%.7fdN)",
- x[io] * RAD_TO_DEG,
- y[io] * RAD_TO_DEG );
- }
- }
- }
-
- return 0;
-}
-
-
-/************************************************************************/
-/* pj_datum_transform() */
-/* */
-/* The input should be long/lat/z coordinates in radians in the */
-/* source datum, and the output should be long/lat/z */
-/* coordinates in radians in the destination datum. */
-/************************************************************************/
-
-int pj_datum_transform( PJ *src, PJ *dst,
- long point_count, int point_offset,
- double *x, double *y, double *z )
-
-{
- double src_a, src_es, dst_a, dst_es;
- int z_is_temp = FALSE;
-
-/* -------------------------------------------------------------------- */
-/* We cannot do any meaningful datum transformation if either */
-/* the source or destination are of an unknown datum type */
-/* (ie. only a +ellps declaration, no +datum). This is new */
-/* behavior for PROJ 4.6.0. */
-/* -------------------------------------------------------------------- */
- if( src->datum_type == PJD_UNKNOWN
- || dst->datum_type == PJD_UNKNOWN )
- return 0;
-
-/* -------------------------------------------------------------------- */
-/* Short cut if the datums are identical. */
-/* -------------------------------------------------------------------- */
- if( pj_compare_datums( src, dst ) )
- return 0;
-
- src_a = src->a_orig;
- src_es = src->es_orig;
-
- dst_a = dst->a_orig;
- dst_es = dst->es_orig;
-
-/* -------------------------------------------------------------------- */
-/* Create a temporary Z array if one is not provided. */
-/* -------------------------------------------------------------------- */
- if( z == nullptr )
- {
- size_t bytes = sizeof(double) * point_count * point_offset;
- z = (double *) pj_malloc(bytes);
- memset( z, 0, bytes );
- z_is_temp = TRUE;
- }
-
-#define CHECK_RETURN(defn) {if( defn->ctx->last_errno != 0 && (defn->ctx->last_errno > 0 || get_transient_error_value(-defn->ctx->last_errno) == 0) ) { if( z_is_temp ) pj_dalloc(z); return defn->ctx->last_errno; }}
-
-/* -------------------------------------------------------------------- */
-/* If this datum requires grid shifts, then apply it to geodetic */
-/* coordinates. */
-/* -------------------------------------------------------------------- */
- if( src->datum_type == PJD_GRIDSHIFT )
- {
- pj_apply_gridshift_2( src, 0, point_count, point_offset, x, y, z );
- CHECK_RETURN(src);
-
- src_a = SRS_WGS84_SEMIMAJOR;
- src_es = SRS_WGS84_ESQUARED;
- }
-
- if( dst->datum_type == PJD_GRIDSHIFT )
- {
- dst_a = SRS_WGS84_SEMIMAJOR;
- dst_es = SRS_WGS84_ESQUARED;
- }
-
-/* ==================================================================== */
-/* Do we need to go through geocentric coordinates? */
-/* ==================================================================== */
- if( src_es != dst_es || src_a != dst_a
- || src->datum_type == PJD_3PARAM
- || src->datum_type == PJD_7PARAM
- || dst->datum_type == PJD_3PARAM
- || dst->datum_type == PJD_7PARAM)
- {
-/* -------------------------------------------------------------------- */
-/* Convert to geocentric coordinates. */
-/* -------------------------------------------------------------------- */
- src->ctx->last_errno =
- pj_geodetic_to_geocentric( src_a, src_es,
- point_count, point_offset, x, y, z );
- CHECK_RETURN(src);
-
-/* -------------------------------------------------------------------- */
-/* Convert between datums. */
-/* -------------------------------------------------------------------- */
- if( src->datum_type == PJD_3PARAM
- || src->datum_type == PJD_7PARAM )
- {
- pj_geocentric_to_wgs84( src, point_count, point_offset,x,y,z);
- CHECK_RETURN(src);
- }
-
- if( dst->datum_type == PJD_3PARAM
- || dst->datum_type == PJD_7PARAM )
- {
- pj_geocentric_from_wgs84( dst, point_count,point_offset,x,y,z);
- CHECK_RETURN(dst);
- }
-
-/* -------------------------------------------------------------------- */
-/* Convert back to geodetic coordinates. */
-/* -------------------------------------------------------------------- */
- dst->ctx->last_errno =
- pj_geocentric_to_geodetic( dst_a, dst_es,
- point_count, point_offset, x, y, z );
- CHECK_RETURN(dst);
- }
-
-/* -------------------------------------------------------------------- */
-/* Apply grid shift to destination if required. */
-/* -------------------------------------------------------------------- */
- if( dst->datum_type == PJD_GRIDSHIFT )
- {
- pj_apply_gridshift_2( dst, 1, point_count, point_offset, x, y, z );
- CHECK_RETURN(dst);
- }
-
- if( z_is_temp )
- pj_dalloc( z );
-
- return 0;
-}
-
-/************************************************************************/
-/* adjust_axis() */
-/* */
-/* Normalize or de-normalized the x/y/z axes. The normal form */
-/* is "enu" (easting, northing, up). */
-/************************************************************************/
-static int adjust_axis( projCtx ctx,
- const char *axis, int denormalize_flag,
- long point_count, int point_offset,
- double *x, double *y, double *z )
-
-{
- double x_in, y_in, z_in = 0.0;
- int i, i_axis;
-
- if( !denormalize_flag )
- {
- for( i = 0; i < point_count; i++ )
- {
- x_in = x[point_offset*i];
- y_in = y[point_offset*i];
- if( z )
- z_in = z[point_offset*i];
-
- for( i_axis = 0; i_axis < 3; i_axis++ )
- {
- double value;
-
- if( i_axis == 0 )
- value = x_in;
- else if( i_axis == 1 )
- value = y_in;
- else
- value = z_in;
-
- switch( axis[i_axis] )
- {
- case 'e':
- x[point_offset*i] = value;
- break;
- case 'w':
- x[point_offset*i] = -value;
- break;
- case 'n':
- y[point_offset*i] = value;
- break;
- case 's':
- y[point_offset*i] = -value;
- break;
- case 'u':
- if( z )
- z[point_offset*i] = value;
- break;
- case 'd':
- if( z )
- z[point_offset*i] = -value;
- break;
- default:
- pj_ctx_set_errno( ctx, PJD_ERR_AXIS );
- return PJD_ERR_AXIS;
- }
- } /* i_axis */
- } /* i (point) */
- }
-
- else /* denormalize */
- {
- for( i = 0; i < point_count; i++ )
- {
- x_in = x[point_offset*i];
- y_in = y[point_offset*i];
- if( z )
- z_in = z[point_offset*i];
-
- for( i_axis = 0; i_axis < 3; i_axis++ )
- {
- double *target;
-
- if( i_axis == 2 && z == nullptr )
- continue;
-
- if( i_axis == 0 )
- target = x;
- else if( i_axis == 1 )
- target = y;
- else
- target = z;
-
- switch( axis[i_axis] )
- {
- case 'e':
- target[point_offset*i] = x_in; break;
- case 'w':
- target[point_offset*i] = -x_in; break;
- case 'n':
- target[point_offset*i] = y_in; break;
- case 's':
- target[point_offset*i] = -y_in; break;
- case 'u':
- target[point_offset*i] = z_in; break;
- case 'd':
- target[point_offset*i] = -z_in; break;
- default:
- pj_ctx_set_errno( ctx, PJD_ERR_AXIS );
- return PJD_ERR_AXIS;
- }
- } /* i_axis */
- } /* i (point) */
- }
-
- return 0;
-}
-// ---------------------------------------------------------------------------
-
-void pj_deallocate_grids()
-{
-}
diff --git a/src/transformations/affine.cpp b/src/transformations/affine.cpp
index 28f73b9a..43fd8642 100644
--- a/src/transformations/affine.cpp
+++ b/src/transformations/affine.cpp
@@ -110,7 +110,7 @@ static PJ_LP reverse_2d(PJ_XY xy, PJ *P) {
}
static struct pj_opaque_affine * initQ() {
- struct pj_opaque_affine *Q = static_cast<struct pj_opaque_affine *>(pj_calloc(1, sizeof(struct pj_opaque_affine)));
+ struct pj_opaque_affine *Q = static_cast<struct pj_opaque_affine *>(calloc(1, sizeof(struct pj_opaque_affine)));
if (nullptr==Q)
return nullptr;
diff --git a/src/transformations/helmert.cpp b/src/transformations/helmert.cpp
index d3857d89..99aa74a4 100644
--- a/src/transformations/helmert.cpp
+++ b/src/transformations/helmert.cpp
@@ -476,7 +476,7 @@ static PJ_COORD helmert_reverse_4d (PJ_COORD point, PJ *P) {
static PJ* init_helmert_six_parameters(PJ* P) {
- struct pj_opaque_helmert *Q = static_cast<struct pj_opaque_helmert*>(pj_calloc (1, sizeof (struct pj_opaque_helmert)));
+ struct pj_opaque_helmert *Q = static_cast<struct pj_opaque_helmert*>(calloc (1, sizeof (struct pj_opaque_helmert)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = (void *) Q;
diff --git a/src/transformations/horner.cpp b/src/transformations/horner.cpp
index a6638773..2c049186 100644
--- a/src/transformations/horner.cpp
+++ b/src/transformations/horner.cpp
@@ -89,8 +89,8 @@
PROJ_HEAD(horner, "Horner polynomial evaluation");
/* make horner.h interface with proj's memory management */
-#define horner_dealloc(x) pj_dealloc(x)
-#define horner_calloc(n,x) pj_calloc(n,x)
+#define horner_dealloc(x) free(x)
+#define horner_calloc(n,x) calloc(n,x)
namespace { // anonymous namespace
struct horner {
@@ -412,7 +412,7 @@ static int parse_coefs (PJ *P, double *coefs, const char *param, int ncoefs) {
char *buf, *init, *next = nullptr;
int i;
- buf = static_cast<char*>(pj_calloc (strlen (param) + 2, sizeof(char)));
+ buf = static_cast<char*>(calloc (strlen (param) + 2, sizeof(char)));
if (nullptr==buf) {
proj_log_error (P, "Horner: No memory left");
return 0;
@@ -420,12 +420,12 @@ static int parse_coefs (PJ *P, double *coefs, const char *param, int ncoefs) {
sprintf (buf, "t%s", param);
if (0==pj_param (P->ctx, P->params, buf).i) {
- pj_dealloc (buf);
+ free (buf);
return 0;
}
sprintf (buf, "s%s", param);
init = pj_param(P->ctx, P->params, buf).s;
- pj_dealloc (buf);
+ free (buf);
for (i = 0; i < ncoefs; i++) {
if (i > 0) {
diff --git a/src/transformations/molodensky.cpp b/src/transformations/molodensky.cpp
index 7d17f64c..bf5960d2 100644
--- a/src/transformations/molodensky.cpp
+++ b/src/transformations/molodensky.cpp
@@ -298,7 +298,7 @@ static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) {
PJ *TRANSFORMATION(molodensky,1) {
int count_required_params = 0;
- struct pj_opaque_molodensky *Q = static_cast<struct pj_opaque_molodensky*>(pj_calloc(1, sizeof(struct pj_opaque_molodensky)));
+ struct pj_opaque_molodensky *Q = static_cast<struct pj_opaque_molodensky*>(calloc(1, sizeof(struct pj_opaque_molodensky)));
if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = (void *) Q;
diff --git a/src/utils.cpp b/src/utils.cpp
deleted file mode 100644
index 9cb13f44..00000000
--- a/src/utils.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-/******************************************************************************
- * Project: PROJ.4
- * Purpose: Some utility functions we don't want to bother putting in
- * their own source files.
- * Author: Frank Warmerdam, warmerdam@pobox.com
- *
- ******************************************************************************
- * Copyright (c) 2001, Frank Warmerdam
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *****************************************************************************/
-
-#define PJ_LIB__
-
-#include <stdio.h>
-#include <string.h>
-
-#include "proj.h"
-#include "proj_internal.h"
-
-/************************************************************************/
-/* pj_is_latlong() */
-/* */
-/* Returns TRUE if this coordinate system object is */
-/* geographic. */
-/************************************************************************/
-
-int pj_is_latlong( PJ *pj )
-
-{
- return pj == nullptr || pj->is_latlong;
-}
-
-/************************************************************************/
-/* pj_is_geocent() */
-/* */
-/* Returns TRUE if this coordinate system object is geocentric. */
-/************************************************************************/
-
-int pj_is_geocent( PJ *pj )
-
-{
- return pj != nullptr && pj->is_geocent;
-}
-
-/************************************************************************/
-/* pj_latlong_from_proj() */
-/* */
-/* Return a PJ* definition defining the lat/long coordinate */
-/* system on which a projection is based. If the coordinate */
-/* system passed in is latlong, a clone of the same will be */
-/* returned. */
-/************************************************************************/
-
-PJ *pj_latlong_from_proj( PJ *pj_in )
-
-{
- char defn[512];
- int got_datum = FALSE;
-
- pj_errno = 0;
- strcpy( defn, "+proj=latlong" );
-
- if( pj_param(pj_in->ctx, pj_in->params, "tdatum").i )
- {
- got_datum = TRUE;
- sprintf( defn+strlen(defn), " +datum=%s",
- pj_param(pj_in->ctx, pj_in->params,"sdatum").s );
- }
- else if( pj_param(pj_in->ctx, pj_in->params, "tellps").i )
- {
- sprintf( defn+strlen(defn), " +ellps=%s",
- pj_param(pj_in->ctx, pj_in->params,"sellps").s );
- }
- else if( pj_param(pj_in->ctx,pj_in->params, "ta").i )
- {
- sprintf( defn+strlen(defn), " +a=%s",
- pj_param(pj_in->ctx,pj_in->params,"sa").s );
-
- if( pj_param(pj_in->ctx,pj_in->params, "tb").i )
- sprintf( defn+strlen(defn), " +b=%s",
- pj_param(pj_in->ctx,pj_in->params,"sb").s );
- else if( pj_param(pj_in->ctx,pj_in->params, "tes").i )
- sprintf( defn+strlen(defn), " +es=%s",
- pj_param(pj_in->ctx,pj_in->params,"ses").s );
- else if( pj_param(pj_in->ctx,pj_in->params, "tf").i )
- sprintf( defn+strlen(defn), " +f=%s",
- pj_param(pj_in->ctx,pj_in->params,"sf").s );
- else
- {
- char* ptr = defn+strlen(defn);
- sprintf( ptr, " +es=%.16g", pj_in->es );
- /* TODO later: use C++ ostringstream with imbue(std::locale::classic()) */
- /* to be locale unaware */
- for(; *ptr; ptr++)
- {
- if( *ptr == ',' )
- *ptr = '.';
- }
- }
- }
- else
- {
- pj_ctx_set_errno( pj_in->ctx, PJD_ERR_MAJOR_AXIS_NOT_GIVEN );
-
- return nullptr;
- }
-
- if( !got_datum )
- {
- if( pj_param(pj_in->ctx,pj_in->params, "ttowgs84").i )
- sprintf( defn+strlen(defn), " +towgs84=%s",
- pj_param(pj_in->ctx,pj_in->params,"stowgs84").s );
-
- if( pj_param(pj_in->ctx,pj_in->params, "tnadgrids").i )
- sprintf( defn+strlen(defn), " +nadgrids=%s",
- pj_param(pj_in->ctx,pj_in->params,"snadgrids").s );
- }
-
- /* copy over some other information related to ellipsoid */
- if( pj_param(pj_in->ctx,pj_in->params, "tR").i )
- sprintf( defn+strlen(defn), " +R=%s",
- pj_param(pj_in->ctx,pj_in->params,"sR").s );
-
- if( pj_param(pj_in->ctx,pj_in->params, "tR_A").i )
- sprintf( defn+strlen(defn), " +R_A" );
-
- if( pj_param(pj_in->ctx,pj_in->params, "tR_V").i )
- sprintf( defn+strlen(defn), " +R_V" );
-
- if( pj_param(pj_in->ctx,pj_in->params, "tR_a").i )
- sprintf( defn+strlen(defn), " +R_a" );
-
- if( pj_param(pj_in->ctx,pj_in->params, "tR_lat_a").i )
- sprintf( defn+strlen(defn), " +R_lat_a=%s",
- pj_param(pj_in->ctx,pj_in->params,"sR_lat_a").s );
-
- if( pj_param(pj_in->ctx,pj_in->params, "tR_lat_g").i )
- sprintf( defn+strlen(defn), " +R_lat_g=%s",
- pj_param(pj_in->ctx,pj_in->params,"sR_lat_g").s );
-
- /* copy over prime meridian */
- if( pj_param(pj_in->ctx,pj_in->params, "tpm").i )
- sprintf( defn+strlen(defn), " +pm=%s",
- pj_param(pj_in->ctx,pj_in->params,"spm").s );
-
- return pj_init_plus_ctx( pj_in->ctx, defn );
-}
-
-/************************************************************************/
-/* pj_get_spheroid_defn() */
-/* */
-/* Fetch the internal definition of the spheroid. Note that */
-/* you can compute "b" from eccentricity_squared as: */
-/* */
-/* b = a * sqrt(1 - es) */
-/************************************************************************/
-
-void pj_get_spheroid_defn(projPJ defn, double *major_axis, double *eccentricity_squared)
-{
- if ( major_axis )
- *major_axis = defn->a;
-
- if ( eccentricity_squared )
- *eccentricity_squared = defn->es;
-}
diff --git a/test/fuzzers/standard_fuzzer.cpp b/test/fuzzers/standard_fuzzer.cpp
index 468e8cbb..d54caa79 100644
--- a/test/fuzzers/standard_fuzzer.cpp
+++ b/test/fuzzers/standard_fuzzer.cpp
@@ -34,9 +34,8 @@
#include <sys/types.h>
#include <unistd.h>
-#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#include "proj.h"
-#include "proj_api.h"
+#include "proj_internal.h"
/* Standalone build:
g++ -g -std=c++11 standard_fuzzer.cpp -o standard_fuzzer -fvisibility=hidden -DSTANDALONE ../../src/.libs/libproj.a -lpthread -lsqlite3 -I../../src -I../../include
@@ -95,13 +94,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
}
second_newline[0] = 0;
char* third_line = second_newline + 1;
- projPJ pj_src = pj_init_plus(first_line);
+ PJ *pj_src = pj_init_plus(first_line);
if( !pj_src )
{
free(buf_dup);
return 0;
}
- projPJ pj_dst = pj_init_plus(second_line);
+ PJ *pj_dst = pj_init_plus(second_line);
if( !pj_dst )
{
free(buf_dup);
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 2c0c19a9..3924f47d 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -69,17 +69,6 @@ set(PROJ_TEST_ENVIRONMENT
"PROJ_SOURCE_DATA=${PROJ_SOURCE_DIR}/data"
)
-add_executable(proj_pj_transform_test
- main.cpp
- pj_transform_test.cpp)
-target_link_libraries(proj_pj_transform_test
- GTest::gtest
- ${PROJ_LIBRARIES})
-add_test(NAME proj_pj_transform_test COMMAND proj_pj_transform_test)
-set_property(TEST proj_pj_transform_test
- PROPERTY ENVIRONMENT ${PROJ_TEST_ENVIRONMENT})
-
-
add_executable(proj_errno_string_test
main.cpp
proj_errno_string_test.cpp)
diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am
index 483cb0bd..4e931c2b 100644
--- a/test/unit/Makefile.am
+++ b/test/unit/Makefile.am
@@ -9,8 +9,7 @@ AM_CXXFLAGS = @CXX_WFLAGS@ @NO_ZERO_AS_NULL_POINTER_CONSTANT_FLAG@
PROJ_LIB ?= ../../data/for_tests
-noinst_PROGRAMS = pj_transform_test
-noinst_PROGRAMS += pj_phi2_test
+noinst_PROGRAMS = pj_phi2_test
noinst_PROGRAMS += proj_errno_string_test
noinst_PROGRAMS += proj_angular_io_test
noinst_PROGRAMS += proj_context_test
@@ -21,11 +20,6 @@ noinst_PROGRAMS += test_network
noinst_PROGRAMS += test_defmodel
noinst_PROGRAMS += test_tinshift
-pj_transform_test_SOURCES = pj_transform_test.cpp main.cpp
-pj_transform_test_LDADD = ../../src/libproj.la @GTEST_LIBS@
-
-pj_transform_test-check: pj_transform_test
- PROJ_SKIP_READ_USER_WRITABLE_DIRECTORY=YES PROJ_LIB=$(PROJ_LIB) ./pj_transform_test
pj_phi2_test_SOURCES = pj_phi2_test.cpp main.cpp
pj_phi2_test_LDADD = ../../src/libproj.la @GTEST_LIBS@
@@ -84,6 +78,6 @@ test_tinshift_LDADD = ../../src/libproj.la @GTEST_LIBS@
test_tinshift-check: test_tinshift
PROJ_LIB=$(PROJ_LIB) ./test_tinshift
-check-local: pj_transform_test-check pj_phi2_test-check proj_errno_string_test-check \
+check-local: pj_phi2_test-check proj_errno_string_test-check \
proj_angular_io_test-check proj_context_test-check test_cpp_api-check \
gie_self_tests-check test_network-check test_defmodel-check test_tinshift-check
diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp
index 6f1b3c32..f9252137 100644
--- a/test/unit/gie_self_tests.cpp
+++ b/test/unit/gie_self_tests.cpp
@@ -548,7 +548,7 @@ static void test_time(const char *args, double tol, double t_in, double t_exp) {
out = proj_trans(P, PJ_INV, out);
EXPECT_NEAR(out.xyzt.t, t_in, tol);
- pj_free(P);
+ proj_destroy(P);
proj_log_level(NULL, PJ_LOG_NONE);
}
diff --git a/test/unit/pj_phi2_test.cpp b/test/unit/pj_phi2_test.cpp
index b4e6b68f..7ccbb01c 100644
--- a/test/unit/pj_phi2_test.cpp
+++ b/test/unit/pj_phi2_test.cpp
@@ -37,7 +37,7 @@
namespace {
TEST(PjPhi2Test, Basic) {
- projCtx ctx = pj_get_default_ctx();
+ PJ_CONTEXT *ctx = pj_get_default_ctx();
// Expectation is that only sane values of e (and nan is here reckoned to
// be sane) are passed to pj_phi2. Thus the return value with other values
diff --git a/test/unit/pj_transform_test.cpp b/test/unit/pj_transform_test.cpp
deleted file mode 100644
index ddb054f0..00000000
--- a/test/unit/pj_transform_test.cpp
+++ /dev/null
@@ -1,740 +0,0 @@
-/******************************************************************************
- *
- * Project: PROJ
- * Purpose: Test pj_transform() legacy interface
- * Author: Even Rouault <even dot rouault at spatialys dot com>
- *
- ******************************************************************************
- * Copyright (c) 2018, Even Rouault <even dot rouault at spatialys dot com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- ****************************************************************************/
-
-#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
-
-#include "gtest_include.h"
-#include <memory>
-
-// PROJ include order is sensitive
-// clang-format off
-#include <proj.h>
-#include "proj_internal.h"
-#include <proj_api.h>
-// clang-format on
-
-namespace {
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_to_longlat) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_EQ(x, 2 * DEG_TO_RAD);
- EXPECT_EQ(y, 49 * DEG_TO_RAD);
-
- x = 182 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_EQ(x, 182 * DEG_TO_RAD);
- EXPECT_EQ(y, 49 * DEG_TO_RAD);
-
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_to_proj) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84");
- auto dst = pj_init_plus("+proj=utm +zone=31 +datum=WGS84");
- double x = 3 * DEG_TO_RAD;
- double y = 0 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 500000, 1e-8);
- EXPECT_NEAR(y, 0, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_to_proj_tometer) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84");
- auto dst = pj_init_plus("+proj=utm +zone=31 +datum=WGS84 +to_meter=1000");
- double x = 3 * DEG_TO_RAD;
- double y = 0 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 500, 1e-8);
- EXPECT_NEAR(y, 0, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, proj_to_longlat) {
- auto src = pj_init_plus("+proj=utm +zone=31 +datum=WGS84");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 500000;
- double y = 0;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 3 * DEG_TO_RAD, 1e-12);
- EXPECT_NEAR(y, 0 * DEG_TO_RAD, 1e-12);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, proj_to_proj) {
- auto src = pj_init_plus("+proj=utm +zone=31 +datum=WGS84");
- auto dst = pj_init_plus("+proj=utm +zone=31 +datum=WGS84");
- double x = 500000;
- double y = 0;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 500000, 1e-8);
- EXPECT_NEAR(y, 0, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_to_geocent) {
- auto src = pj_init_plus("+proj=longlat +R=2");
- auto dst = pj_init_plus("+proj=geocent +R=2");
- double x = 0;
- double y = 0;
- double z = 0;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 2, 1e-8);
- EXPECT_NEAR(y, 0, 1e-8);
- EXPECT_NEAR(z, 0, 1e-8);
-
- x = 90 * DEG_TO_RAD;
- y = 0;
- z = 0;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 0, 1e-8);
- EXPECT_NEAR(y, 2, 1e-8);
- EXPECT_NEAR(z, 0, 1e-8);
-
- x = 0;
- y = 90 * DEG_TO_RAD;
- z = 0.1;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 0, 1e-8);
- EXPECT_NEAR(y, 0, 1e-8);
- EXPECT_NEAR(z, 2 + 0.1, 1e-8);
-
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_to_geocent_to_meter) {
- auto src = pj_init_plus("+proj=longlat +R=2");
- auto dst = pj_init_plus("+proj=geocent +R=2 +to_meter=1000");
- double x = 0;
- double y = 0;
- double z = 0;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 2e-3, 1e-8);
- EXPECT_NEAR(y, 0, 1e-8);
- EXPECT_NEAR(z, 0, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, geocent_to_longlat) {
- auto src = pj_init_plus("+proj=geocent +R=2");
- auto dst = pj_init_plus("+proj=longlat +R=2");
- double x = 0;
- double y = 2;
- double z = 0;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 90 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 0, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 0, 1e-12);
-
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, geocent_to_meter_to_longlat) {
- auto src = pj_init_plus("+proj=geocent +to_meter=1000 +R=2");
- auto dst = pj_init_plus("+proj=longlat +R=2");
- double x = 0;
- double y = 2e-3;
- double z = 0;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 90 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 0, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 0, 1e-12);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, pm) {
- auto src = pj_init_plus("+proj=longlat +pm=3 +datum=WGS84");
- auto dst = pj_init_plus("+proj=longlat +pm=1 +datum=WGS84");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, (2 + 3 - 1) * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_EQ(y, 49 * DEG_TO_RAD) << y / DEG_TO_RAD;
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_geoc_to_longlat) {
- auto src = pj_init_plus("+proj=longlat +geoc +datum=WGS84");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 48.809360314691766 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_to_longlat_geoc) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84");
- auto dst = pj_init_plus("+proj=longlat +geoc +datum=WGS84");
- double x = 2 * DEG_TO_RAD;
- double y = 48.809360314691766 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, ellps_to_ellps_noop) {
- auto src = pj_init_plus("+proj=longlat +ellps=clrk66");
- auto dst = pj_init_plus("+proj=longlat +ellps=WGS84");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, towgs84_3param_noop) {
- auto src = pj_init_plus("+proj=longlat +ellps=WGS84 +towgs84=1,2,3");
- auto dst = pj_init_plus("+proj=longlat +ellps=WGS84 +towgs84=1,2,3");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- double z = 10;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 10, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, towgs84_7param_noop) {
- auto src =
- pj_init_plus("+proj=longlat +ellps=WGS84 +towgs84=1,2,3,4,5,6,7");
- auto dst =
- pj_init_plus("+proj=longlat +ellps=WGS84 +towgs84=1,2,3,4,5,6,7");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- double z = 10;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 10, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_towgs84_3param_to_datum) {
- auto src = pj_init_plus("+proj=longlat +ellps=WGS84 +towgs84=0,1,0");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 90 * DEG_TO_RAD;
- double y = 0 * DEG_TO_RAD;
- double z = 10;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 90 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 0 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 10 + 1, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_towgs84_3param_to_datum_no_z) {
- auto src = pj_init_plus("+proj=longlat +ellps=WGS84 +towgs84=0,1,0");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 90 * DEG_TO_RAD;
- double y = 0 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 90 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 0 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_towgs84_7param_to_datum) {
- auto src =
- pj_init_plus("+proj=longlat +ellps=WGS84 +towgs84=0,1,0,0,0,0,0.5");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 90 * DEG_TO_RAD;
- double y = 0 * DEG_TO_RAD;
- double z = 10;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 90 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 0 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 14.189073500223458, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, datum_to_longlat_towgs84_3param) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84");
- auto dst = pj_init_plus("+proj=longlat +ellps=WGS84 +towgs84=0,1,0");
- double x = 90 * DEG_TO_RAD;
- double y = 0 * DEG_TO_RAD;
- double z = 10 + 1;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 90 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 0 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 10, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, datum_to_longlat_towgs84_7param) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84");
- auto dst =
- pj_init_plus("+proj=longlat +ellps=WGS84 +towgs84=0,1,0,0,0,0,0.5");
- double x = 90 * DEG_TO_RAD;
- double y = 0 * DEG_TO_RAD;
- double z = 14.189073500223458;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 90 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 0 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 10, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, ellps_grs80_towgs84_to_datum_wgs84) {
- auto src = pj_init_plus("+proj=longlat +ellps=GRS80 +towgs84=0,0,0");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- double z = 10;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-15) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-15) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 10, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, longlat_nadgrids_to_datum) {
- auto src = pj_init_plus("+proj=longlat +ellps=clrk66 +nadgrids=conus");
- auto dst = pj_init_plus("+proj=longlat +datum=NAD83");
- double x = -100 * DEG_TO_RAD;
- double y = 40 * DEG_TO_RAD;
- double z = 10;
- int ret = pj_transform(src, dst, 1, 0, &x, &y, &z);
- EXPECT_TRUE(ret == 0 || ret == PJD_ERR_FAILED_TO_LOAD_GRID);
- if (ret == 0) {
- EXPECT_NEAR(x, -100.00040583667015 * DEG_TO_RAD, 1e-12)
- << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 40.000005895651363 * DEG_TO_RAD, 1e-12)
- << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 10.000043224543333, 1e-8);
- }
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, nadgrids_noop) {
- auto src = pj_init_plus("+proj=longlat +ellps=clrk66 +nadgrids=conus");
- auto dst = pj_init_plus("+proj=longlat +ellps=clrk66 +nadgrids=conus");
- double x = -100 * DEG_TO_RAD;
- double y = 40 * DEG_TO_RAD;
- double z = 10;
- int ret = pj_transform(src, dst, 1, 0, &x, &y, &z);
- EXPECT_TRUE(ret == 0);
- if (ret == 0) {
- EXPECT_NEAR(x, -100 * DEG_TO_RAD, 1e-15) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 40 * DEG_TO_RAD, 1e-15) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 10, 1e-8);
- }
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, datum_to_longlat_nadgrids) {
- auto src = pj_init_plus("+proj=longlat +datum=NAD83");
- auto dst = pj_init_plus("+proj=longlat +ellps=clrk66 +nadgrids=conus");
- double x = -100.00040583667015 * DEG_TO_RAD;
- double y = 40.000005895651363 * DEG_TO_RAD;
- double z = 10.000043224543333;
- int ret = pj_transform(src, dst, 1, 0, &x, &y, &z);
- EXPECT_TRUE(ret == 0 || ret == PJD_ERR_FAILED_TO_LOAD_GRID);
- if (ret == 0) {
- EXPECT_NEAR(x, -100 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 40 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 10, 1e-8);
- }
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, long_wrap) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84 +lon_wrap=180");
- double x = -1 * DEG_TO_RAD;
- double y = 0 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 359 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 0 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, src_vto_meter) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84 +vto_meter=1000");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- double z = 1;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 1000, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, dest_vto_meter) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84 +vto_meter=1000");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- double z = 1000;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 1, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, src_axis_neu_with_z) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84 +axis=neu");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 49 * DEG_TO_RAD;
- double y = 2 * DEG_TO_RAD;
- double z = 1;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 1, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, src_axis_neu_without_z) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84 +axis=neu");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 49 * DEG_TO_RAD;
- double y = 2 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, src_axis_swd) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84 +axis=swd");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84");
- double x = 49 * DEG_TO_RAD;
- double y = 2 * DEG_TO_RAD;
- double z = -1;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, -2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, -49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 1, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, dst_axis_neu) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84 +axis=neu");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- double z = 1;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, 49 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 2 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, 1, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, dst_axis_swd) {
- auto src = pj_init_plus("+proj=longlat +datum=WGS84");
- auto dst = pj_init_plus("+proj=longlat +datum=WGS84 +axis=swd");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- double z = 1;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, &z), 0);
- EXPECT_NEAR(x, -49 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, -2 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- EXPECT_NEAR(z, -1, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, init_epsg) {
- auto src = pj_init_plus("+init=epsg:4326");
- ASSERT_TRUE(src != nullptr);
- auto dst = pj_init_plus("+init=epsg:32631");
- ASSERT_TRUE(dst != nullptr);
- double x = 3 * DEG_TO_RAD;
- double y = 0 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 500000, 1e-8);
- EXPECT_NEAR(y, 0, 1e-8);
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(proj_api_h, pj_set_searchpath) {
-
- const char *path = "/i_do/not/exit";
- pj_set_searchpath(1, &path);
- {
- auto info = proj_info();
- EXPECT_EQ(info.path_count, 1U);
- ASSERT_NE(info.paths, nullptr);
- ASSERT_NE(info.paths[0], nullptr);
- EXPECT_EQ(std::string(info.paths[0]), path);
- }
-
- pj_set_searchpath(0, nullptr);
- {
- auto info = proj_info();
- EXPECT_EQ(info.path_count, 0U);
- EXPECT_EQ(info.paths, nullptr);
- }
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(proj_api_h, pj_set_finder) {
-
- const auto myfinder = [](const char *) -> const char * { return nullptr; };
- pj_set_finder(myfinder);
-
- pj_set_finder(nullptr);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(proj_api_h, default_fileapi) {
- auto ctx = pj_ctx_alloc();
- auto fid = pj_open_lib(ctx, "proj.db", "rb");
- ASSERT_NE(fid, nullptr);
- char header[6];
- ASSERT_EQ(pj_ctx_fread(ctx, header, 1, 6, fid), 6U);
- ASSERT_TRUE(memcmp(header, "SQLite", 6) == 0);
- ASSERT_EQ(pj_ctx_ftell(ctx, fid), 6);
- ASSERT_EQ(pj_ctx_fseek(ctx, fid, 0, SEEK_SET), 0);
- ASSERT_EQ(pj_ctx_ftell(ctx, fid), 0);
- pj_ctx_fclose(ctx, fid);
- pj_ctx_free(ctx);
-}
-
-// ---------------------------------------------------------------------------
-
-TEST(pj_transform_test, ob_tran_to_meter_as_dest) {
- auto src = pj_init_plus(
- "+ellps=WGS84 +a=57.29577951308232 +proj=eqc +lon_0=0.0 +no_defs");
- auto dst = pj_init_plus("+ellps=WGS84 +proj=ob_tran +o_proj=latlon "
- "+o_lon_p=0.0 +o_lat_p=90.0 +lon_0=360.0 "
- "+to_meter=0.0174532925199433 +no_defs");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- pj_free(src);
- pj_free(dst);
-}
-
-// ---------------------------------------------------------------------------
-
-struct Spy {
- bool gotInMyFOpen = false;
- bool gotInMyFRead = false;
- bool gotInMyFSeek = false;
- bool gotInMyFTell = false;
- bool gotInMyFClose = false;
-};
-
-struct MyFile {
- FILE *fp;
- Spy *spy;
-};
-
-static PAFile myFOpen(projCtx ctx, const char *filename, const char *access) {
- FILE *fp = fopen(filename, access);
- if (!fp)
- return nullptr;
- MyFile *myF = new MyFile;
- myF->spy = (Spy *)pj_ctx_get_app_data(ctx);
- myF->spy->gotInMyFOpen = true;
- myF->fp = fp;
- return reinterpret_cast<PAFile>(myF);
-}
-
-static size_t myFRead(void *buffer, size_t size, size_t nmemb, PAFile file) {
- MyFile *myF = reinterpret_cast<MyFile *>(file);
- myF->spy->gotInMyFRead = true;
- return fread(buffer, size, nmemb, myF->fp);
-}
-
-static int myFSeek(PAFile file, long offset, int whence) {
- MyFile *myF = reinterpret_cast<MyFile *>(file);
- myF->spy->gotInMyFSeek = true;
- return fseek(myF->fp, offset, whence);
-}
-
-static long myFTell(PAFile file) {
- MyFile *myF = reinterpret_cast<MyFile *>(file);
- myF->spy->gotInMyFTell = true;
- return ftell(myF->fp);
-}
-
-static void myFClose(PAFile file) {
- MyFile *myF = reinterpret_cast<MyFile *>(file);
- myF->spy->gotInMyFClose = true;
- fclose(myF->fp);
- delete myF;
-}
-
-TEST(proj_api_h, custom_fileapi) {
- auto ctx = pj_ctx_alloc();
- Spy spy;
- pj_ctx_set_app_data(ctx, &spy);
- projFileAPI myAPI = {myFOpen, myFRead, myFSeek, myFTell, myFClose};
- pj_ctx_set_fileapi(ctx, &myAPI);
- EXPECT_EQ(pj_ctx_get_fileapi(ctx), &myAPI);
- auto fid = pj_open_lib(ctx, "proj.db", "rb");
- ASSERT_NE(fid, nullptr);
- char header[6];
- ASSERT_EQ(pj_ctx_fread(ctx, header, 1, 6, fid), 6U);
- ASSERT_TRUE(memcmp(header, "SQLite", 6) == 0);
- ASSERT_EQ(pj_ctx_ftell(ctx, fid), 6);
- ASSERT_EQ(pj_ctx_fseek(ctx, fid, 0, SEEK_SET), 0);
- ASSERT_EQ(pj_ctx_ftell(ctx, fid), 0);
- pj_ctx_fclose(ctx, fid);
- pj_ctx_free(ctx);
- EXPECT_TRUE(spy.gotInMyFOpen);
- EXPECT_TRUE(spy.gotInMyFRead);
- EXPECT_TRUE(spy.gotInMyFSeek);
- EXPECT_TRUE(spy.gotInMyFTell);
- EXPECT_TRUE(spy.gotInMyFClose);
-}
-
-TEST(pj_transform_test, ob_tran_to_meter_as_srouce) {
- auto src = pj_init_plus("+ellps=WGS84 +proj=ob_tran +o_proj=latlon "
- "+o_lon_p=0.0 +o_lat_p=90.0 +lon_0=360.0 "
- "+to_meter=0.0174532925199433 +no_defs");
- auto dst = pj_init_plus(
- "+ellps=WGS84 +a=57.29577951308232 +proj=eqc +lon_0=0.0 +no_defs");
- double x = 2 * DEG_TO_RAD;
- double y = 49 * DEG_TO_RAD;
- EXPECT_EQ(pj_transform(src, dst, 1, 0, &x, &y, nullptr), 0);
- EXPECT_NEAR(x, 2 * DEG_TO_RAD, 1e-12) << x / DEG_TO_RAD;
- EXPECT_NEAR(y, 49 * DEG_TO_RAD, 1e-12) << y / DEG_TO_RAD;
- pj_free(src);
- pj_free(dst);
-}
-
-} // namespace