aboutsummaryrefslogtreecommitdiff
path: root/src/proj_internal.h
AgeCommit message (Collapse)Author
2022-02-12proj.ini: add a 'ca_bundle_path' variableEven Rouault
Cf thread https://lists.osgeo.org/pipermail/gdal-dev/2022-February/thread.html#55391
2021-12-01Cache result of proj_get_type() to help for performance of proj_factors() ↵Even Rouault
(fixes #2965)
2021-11-12Add new option to proj_create_crs_to_crs_from_pj method to force +over on ↵Peter Townsend
transformation operations (#2914) Fixes #2512
2021-07-22Add pj_log_active() to determine if logging is activeEven Rouault
2021-06-03Make proj_context_set_autoclose_database() a no-op as it would defeat the ↵Even Rouault
purpose of the new database connection sharing
2021-06-03factory.cpp: preparation steps for global sqlite3* handle, but no functional ↵Even Rouault
change
2021-03-17Fix proj_clone() to work on 'meta' coordinate operation PJ* objects that can ↵Even Rouault
be returned by proj_create_crs_to_crs()
2021-02-19LOG: Default log level PJ_LOG_ERRORsnowman2
2020-12-15Remove internal use of PJ_LOG_DEBUG_MINOR and PJ_LOG_DEBUG_MAJOREven Rouault
2020-12-15proj_log_XXX functions(): add the short name of the operation as prefix in ↵Even Rouault
the error message
2020-12-15Revise error codes to have a reduced set exposed in the public API.Even Rouault
Fixes #2482 And also add proj_context_errno_string() Revise gie 'expect failure errno XXXX' strings
2020-11-30API cleanup: unexport number of internal symbols, and remove/replace a few ↵Even Rouault
unused ones
2020-11-20Remove old pj_ memory (de)allocation functionsKristian Evers
Gone are pj_malloc, pj_calloc, pj_dalloc and pj_dealloc. Their primary function as API memory functions in proj_api.h is no longer there and the other use as a workaround for old errno problems is no longer valid either. Replaced with malloc and free across the codebase.
2020-11-20Remove pj_errno and related functionsKristian Evers
2020-11-20Remove pj_free() and move it's functional parts to proj_destroy()Kristian Evers
2020-11-20Removed unused function pj_set_searchpath() and pj_set_finder()Kristian Evers
2020-11-20Remove unused pj_apply_gridshift()Kristian Evers
2020-11-20Removed unused functions from src/utils.cppKristian Evers
2020-11-20Remove pj_ctx_* functions and use their proj_context counterpartsKristian Evers
2020-11-20Remove legacy file APIKristian Evers
2020-11-20Weed out proj_api.h datatypes and replace them with their proj.h counterpartsKristian Evers
2020-11-20Remove src/transform.cpp and related testsKristian Evers
2020-11-20Remove ACCEPT_USE_OF_DEPRECATED_PROJ_API_H macroKristian Evers
2020-11-20Remove proj_api.hKristian Evers
Removes proj_api.h from the public API. The contents of the header file has been moved to proj_internal.h verbatim and any references to proj_api.h has been changed to proj_internal.h. The documentation of proj_api.h has been removed. The only exception to this is the API migration guides which still mention the old API. Fixes #837
2020-10-26Update Mercator projectionCharles Karney
Introduction ------------ The existing formulation for the Mercator projection is "satisfactory"; it is reasonably accurate. However for a core projection like Mercator, I think we should strive for full double precision accuracy. This commit uses cleaner, more accurate, and faster methods for computing the forward and inverse projections. These use the formulation in terms of hyperbolic functions that are manifestly odd in latitude psi = asinh(tan(phi)) - e * atanh(e * sin(phi)) (phi = latitude; psi = isometric latitude = Mercator y coordinate). Contrast this with the existing formulation psi = log(tan(pi/4 - phi/2)) - e/2 * log((1 + e * sin(phi)) / (1 - e * sin(phi))) where psi(-phi) isn't exactly equal to -psi(phi) and psi(0) isn't guaranteed to be 0. Implementation -------------- There's no particular issue implementing the forward projection, just apply the formulas above. The inverse projection is tricky because there's no closed form solution for the inverse. The existing code for the inverse uses an iterative method from Snyder. This is the usual hokey function iteration, and, as usual, the convergence rate is linear (error reduced by a constant factor on each iteration). This is OK (just) for low accuracy work. But nowadays, something with quadratic convergence (e.g., Newton's method, number of correct digits doubles on each iteration) is preferred (and used here). More on this later. The solution for phi(psi) I use is described in my TM paper and I lifted the specific formulation from GeographicLib's Math::tauf, which uses the same underlying machinery for all conformal projections. It solves for tan(phi) in terms of sinh(psi) which as a near identity mapping is ideal for Newton's method. For comparison I also look at the approach adopted by Poder + Engsager in their TM paper and implemented in etmerc. This uses trigonometric series (accurate to n^6) to convert phi <-> chi. psi is then given by psi = asinh(tan(chi)) Accuracy -------- I tested just the routines for transforming phi <-> psi from merc.cpp and measured the errors (converted to true nm = nanometers) for the forward and inverse mapping. I also included in my analysis the method used by etmerc. This uses a trigonometric series to convert phi <-> chi = atan(sinh(psi)), the conformal latitude. forward inverse max rms max rms old merc 3.60 0.85 2189.47 264.81 etmerc 1.82 0.38 1.42 0.37 new merc 1.83 0.30 2.12 0.31 1 nm is pretty much the absolute limit for accuracy in double precision (1 nm = 10e6 m / 2^53, approximately), and 5 nm is probably the limit on what you should routinely expect. So the old merc inverse is considerably less accurate that it could be. The old merc forward is OK on accuracy -- except that if does not preserve the parity of the projection. The accuracy of etmerc is fine (the truncation error of the 6th order series is small compared with the round-off error). However, situation reverses as the flattening is increased. E.g., at f = 1/150, the max error for the inverse projection is 8 nm. etmerc is OK for terrestrial applications, but couldn't be used for Mars. Timing ------ Here's what I get with g++ -O3 on various Linux machines with recent versions of g++. As always, you should take these with a grain of salt. You might expect the relative timings to vary by 20% or so when switching between compilers/machines. Times per call in ns = nanoseconds. forward inverse old merc 121 360 etmerc 4e-6 1.4 new merc 20 346 The new merc method is 6 times faster at the forward projection and modestly faster at the inverse projection (despite being more accurate). The latter result is because it only take 2 iterations of Newton's method to get full accuracy compared with an average of 5 iterations for the old method to get only um accuracy. A shocking aspect of these timings is how fast etmerc is. Another is that forward etmerc is streaks faster that inverse etmerc (it made be doubt my timing code). Evidently, asinh(tan(chi)) is a lot faster to compute than atan(sinh(psi)). The hesitation about adopting etmerc then comes down to: * the likelihood that Mercator may be used for non-terrestrial bodies; * the question of whether the timing benefits for the etmerc method would be noticeable in a realistic application; * need to duplicate the machinery for evaluating the coefficients for the series and for Clenshaw summation in the current code layout. Ripple effects ============== The Mercator routines used the the Snyder method, pj_tsfn and pj_phi2, are used in other projections. These relate phi to t = exp(-psi) (a rather bizarre choice in my book). I've retrofitted these to use the more accurate methods. These do the "right thing" for phi in [-pi/2, pi/2] , t in [0, inf], and e in [0, 1). NANs are properly handled. Of course, phi = pi/2 in double precision is actually less than pi/2, so cos(pi/2) > 0. So no special handling is needed for pi/2. Even if angles were handled in such a way that 90deg were exactly represented, these routines would still "work", with, e.g., tan(pi/2) -> inf. (A caution: with long doubles = a 64-bit fraction, we have cos(pi/2) < 0; and now we would need to be careful.) As a consequence, there no need for error handling in pj_tsfn; the HUGE_VAL return has gone and, of course, HUGE_VAL is a perfectly legal input to tsfn's inverse, phi2, which would return -pi/2. This "error handling" was only needed for e = 1, a case which is filtered out upstream. I will note that bad argument handling is much more natural using NAN instead of HUGE_VAL. See issue #2376 I've renamed the error condition for non-convergence of the inverse projection from "non-convergent inverse phi2" to "non-convergent sinh(psi) to tan(phi)". Now that pj_tsfn and pj_phi2 now return "better" results, there were some malfunctions in the projections that called them, specifically gstmerc, lcc, and tobmerc. * gstmerc invoked pj_tsfn(phi, sinphi, e) with a value of sinphi that wasn't equal to sin(phi). Disaster followed. I fixed this. I also replaced numerous occurrences of "-1.0 * x" by "-x". (Defining a function with arguments phi and sinphi is asking for trouble.) * lcc incorrectly thinks that the projection isn't defined for standard latitude = +/- 90d. This happens to be false (it reduces to polar stereographic in this limit). The check was whether tsfn(phi) = 0 (which only tested for the north pole not the south pole). However since tsfn(pi/2) now (correctly) returns a nonzero result, this test fails. I now just test for |phi| = pi/2. This is clearer and catches both poles (I'm assuming that the current implementation will probably fail in these cases). * tobmerc similarly thinks that phi close to +/- pi/2 can't be transformed even though psi(pi/2) is only 38. I'm disincline to fight this. However I did tighten up the failure condition (strict equality of |phi| == pi/2). OTHER STUFF =========== Testing ------- builtins.gei: I tightened up the tests for merc (and while I was about it etmerc and tmerc) to reflect full double precision accuracy. My test values are generated with MPFR enabled code and so should be accurate to all digits given. For the record, for GRS80 I use f = 1/298.2572221008827112431628366 in these calculations. pj_phi2_test: many of the tests were bogus testing irrelevant input parameters, like negative values of exp(-psi), and freezing in the arbitrary behavior of phi2. I've reworked most for the tests to be semi-useful. @schwehr can you review. Documentation ------------- I've updated merc.rst to outline the calculation of the inverse projection. phi2.cpp includes detailed notes about applying Newton's method to find tan(phi) in terms of sinh(psi). Future work ----------- lcc needs some tender loving care. It can easily (and should) be modified to allow stdlat = +/- 90 (reduces to polar stereographic), stdlat = 0 and stdlat_1 + stdlat_2 = 0 (reduces to Mercator). A little more elbow grease will allow the treatment of stdlat_1 close to stdlat_2 using divided differences. (See my implementation of the LambertConformalConic class in GeographicLib.) All the places where pj_tsfn and pj_phi2 are called need to be reworked to cut out the use of Snyder's t = exp(-psi() variable and instead use sinh(psi). Maybe include the machinery for series conversions between all auxiliary latitudes as "support functions". Then etmerc could use this (as could mlfn for computing meridional distance). merc could offer the etmerc style projection via chi as an option when the flattening is sufficiently small.
2020-08-20projCtx_t: Copy ini file settings, proj4_init_rules, etc.. when initializing ↵Alan D. Snow
context from global (#2331)
2020-08-19Add methods to ensure safer interactions with cpp_contextsnowman2
2020-08-16ENH: Add support for custum CA Bundle path (#2323)Alan D. Snow
Fixes #2320
2020-05-28Implement wink2 inverse by generic inversion of forward methodEven Rouault
- Move the generic method initiated from adams_ws2 to a pj_generic_inverse_2d() method - Use it in adams_ws2 - Use it in wink2 Fixes https://github.com/qgis/QGIS/issues/35512
2020-04-26pipeline initialization: avoid deep recursion on corrupted PROJ string like ↵Even Rouault
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21889
2020-04-21Typo fixes in code comments [ci skip]Even Rouault
2020-04-20Moved proj_context_get_url_endpoint & ↵Alan D. Snow
proj_context_get_user_writable_directory to proj.h (#2162) Fixes #2028
2020-04-15tmerc/utm: add a +algo=auto/evenden_snyder/poder_engsager parameterEven Rouault
The default remains +alg=poder_engsager. This default value can be changed in proj.ini +algo=auto will use Evenden Synder implementation if the error in doing so remains below 0.1 mm on Earth-sized ellipsoid
2020-04-12Add proj_degree_input() and proj_degree_output()Kristian Evers
Equivalent to proj_angular_input() and proj_angular_output() but checking for degree units instead. proj_create_crs_to_crs() rarely, if ever, returns pipelines that has radians as input or output so using proj_angular_*() is not a useful check for io units of pipelines. These two new functions should make life a bit easier for users that generally store there angular coordinates in radians. Closes #2027
2020-04-06Move inline code for optimize mlfn from tmerc to mlfn.hpp to avoid code ↵Even Rouault
duplication
2020-04-04hgridshift/vgridshift: defer grid opening when grid has already been openedEven Rouault
Relates to #2115 With the fix of https://github.com/OSGeo/PROJ/pull/2128, transforming between EPSG:4326+3855 and EPSG:4269+5703 leads to many operations with many grids, and opening a file handle for each operation saturates the limit of 1024 file handles opened simunalteously. This fix defers grid opening when a transformation has already been instanciated with the same grid.
2020-03-30Merge pull request #2052 from rouault/speedup_phi2Even Rouault
pj_phi2(): speed-up computation (and thus inverse ellipsoidal Mercator and LCC)
2020-03-17Deprecate proj_list_angular_units(). Follow-up of ↵Even Rouault
https://github.com/OSGeo/PROJ/pull/2065
2020-03-16Merge branch 'master' into add_proj_get_suggested_operationEven Rouault
2020-03-13Tag proj_list_units() as deprecatedEven Rouault
2020-03-13Add proj_get_suggested_operation()Even Rouault
Return the index of the operation that would be the most appropriate to transform the specified coordinates. This operation may use resources that are not locally available, depending on the search criteria used by proj_create_operations(). This could be done by using proj_create_operations() with a punctual bounding box, but this function is faster when one needs to evaluate on many points with the same (source_crs, target_crs) tuple.
2020-03-11pj_phi2(): speed-up computation (and thus inverse ellipsoidal Mercator and LCC)Even Rouault
This does not change the numeric values returned by the method, as far as I could see on a few samplings. The tricks used save a call to sin() and atan() at each iteration. This directly affects speed of inverse Mercator and LCC (among others), in their ellipsoidal formulation. Timings on inverse Mercator show a 31% speed-up at mid-latitudes where pj_phi2() needs 5 iterations, and 24% at latitudes close to 0 or 90deg where it needs one iteration.
2020-03-06proj_internal.h: fix typo in macro name due to bad copy&paste. (No ↵Even Rouault
functional impact)
2020-02-24Expose proj_context_is_network_enabled() in C APIEven Rouault
2020-02-11Use relative directory to locate PROJ resource files.Even Rouault
Fixes #1490 This is an extension of the Window-specific logic added recently to Unix builds. This reuses parts of proposed past commit https://github.com/OSGeo/PROJ/pull/1517/commits/82a07e51c6e24ddb936d131ababe29f1ac36ef14 (credits to @abellgithub)
2020-02-06Travis: update CLang Static Analyzer to CLang 9Even Rouault
Enable optional checkers Fix two false positives
2020-02-04Add projsync utilityEven Rouault
Fixes #1750
2020-01-27projinfo: add --remote-data switchEven Rouault
2020-01-22Merge RFC4 (#1865)Even Rouault
This commit is the result of the squashing of rfc4_dev branch in a single commit. It implements mostly RFC 4 related work. * Grid handling: - remove obsolete and presumably unfinished implementation of grid catalog functionality - all grid functionality is in grids.cpp/.hpp - vertical and horizontal grid shift: rework to no longer load whole grid into memory - remove hgrids and vgrids member from PJ structure, and store them in hgridshift/vgridshift/deformation structures - build systems: add optional libtiff dependency. Must be explicitly disabled if not desired - add support for horizontal and vertical grids in GeoTIFF, if libtiff is available - add GenericShiftGridSet and GenericShiftGrid classes, relying on TIFF grids, that can be used for generic purpose grid-based adjustment - add a +proj=xyzgridshift method to perform geocentric translation by grid. Used for French NTF to RGF93 transformation using gr3df97a.tif grid - deformation: add support for +grids= for GeoTIFF grids - horizontal grid shift: fix failures on points slightly outside a subgrid (fixes #209) * File management: - add a filemanager.cpp/.hpp to deal with file related work - test for legacy proj_api.h fileapi - proj.h: add proj_context_set_fileapi() and proj_context_set_sqlite3_vfs_name() (fixes #866) - add capability to read resource files from the user writable directory * Network access: - build systems: add optional curl dependency - add a curl-based default implementation for network related functionality - proj.h: add C API to control network functionality, and optionaly provide network callbacks - add data/proj.ini with default settings - add a SQLite3 local cache of downloaded chunks - add proj_is_download_needed() and proj_download_file() * Use Win32 Unicode APIs and expect all strings to be UTF-8 (fixes #1765) For backward compatibility, if PROJ_LIB content is found to be not UTF-8 or pointing to a non existing directory, then an attempt at interpretating it in the ANSI page encoding is done. proj_context_set_search_paths() now assumes strings to be in UTF-8, and functions returning paths will also return values in UTF-8.
2019-12-14Horizontal grid shift: fix issue on iterative inverse computation when ↵Even Rouault
switching between (sub)grids (fixes #1663) Given in.txt with 53.999759140 5.144478208 252.6995 Before the fix, cct -t 0 -d 4 +proj=pipeline +step +proj=axisswap +order=2,1,3,4 +step +proj=hgridshift +inv +grids=rdtrans2018.gsb +step +proj=vgridshift +grids=naptrans2018.gtx +step +proj=sterea +lat_0=52.156160556 +lon_0=5.387638889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel in.txt returned: 139079.8814 668306.0302 212.1724 0.0000 It now returns: 139079.8850 668306.0458 212.1724 0.0000 which meets with the 1mm accuracy the expected result of test point ``` 30010049 53.999759140 5.144478208 252.6995 139079.8850 668306.0460 212.1723 ```