New upstream version 2.6.1~rc0+ds
Bas Couwenberg
3 years ago
23 | 23 | "review", |
24 | 24 | "question", |
25 | 25 | "maintenance", |
26 | "infra" | |
26 | "infra", | |
27 | "bug" | |
27 | 28 | ] |
28 | 29 | }, |
29 | 30 | { |
40 | 41 | "infra", |
41 | 42 | "ideas", |
42 | 43 | "review", |
43 | "question" | |
44 | "question", | |
45 | "bug" | |
44 | 46 | ] |
45 | 47 | }, |
46 | 48 | { |
55 | 57 | "maintenance", |
56 | 58 | "infra", |
57 | 59 | "review", |
58 | "question" | |
60 | "question", | |
61 | "bug" | |
59 | 62 | ] |
60 | 63 | }, |
61 | 64 | { |
68 | 71 | "code", |
69 | 72 | "ideas", |
70 | 73 | "review", |
71 | "question" | |
74 | "question", | |
75 | "bug", | |
76 | "test" | |
72 | 77 | ] |
73 | 78 | }, |
74 | 79 | { |
289 | 294 | "contributions": [ |
290 | 295 | "platform", |
291 | 296 | "question", |
292 | "bug" | |
297 | "bug", | |
298 | "test" | |
293 | 299 | ] |
294 | 300 | }, |
295 | 301 | { |
341 | 347 | "ideas", |
342 | 348 | "test" |
343 | 349 | ] |
350 | }, | |
351 | { | |
352 | "login": "mraspaud", | |
353 | "name": "Martin Raspaud", | |
354 | "avatar_url": "https://avatars1.githubusercontent.com/u/167802?v=4", | |
355 | "profile": "https://github.com/mraspaud", | |
356 | "contributions": [ | |
357 | "bug", | |
358 | "code", | |
359 | "test", | |
360 | "ideas" | |
361 | ] | |
344 | 362 | } |
345 | 363 | ], |
346 | 364 | "contributorsPerLine": 7 |
0 | 0 | [settings] |
1 | 1 | line_length=88 |
2 | 2 | multi_line_output=3 |
3 | known_third_party=mock,numpy,pkg_resources,pytest,setuptools,test | |
3 | known_third_party=mock,numpy,pkg_resources,pytest,setuptools | |
4 | known_first_party=pyproj,test | |
4 | 5 | include_trailing_comma=true |
29 | 29 | - python: 3.6 |
30 | 30 | - python: 3.6 |
31 | 31 | env: |
32 | - PROJ_NETWORK=ON | |
33 | - python: 3.6 | |
34 | env: | |
35 | - PROJSYNC=ALL | |
36 | - python: 3.6 | |
37 | env: | |
32 | 38 | - PROJSOURCE=6.2.0 |
33 | 39 | - python: 3.6 |
34 | 40 | env: |
39 | 45 | - python: 3.6 |
40 | 46 | env: |
41 | 47 | - PROJSOURCE=6.3.1 |
48 | - python: 3.6 | |
49 | env: | |
50 | - PROJSOURCE=6.3.2 | |
51 | - python: 3.6 | |
52 | env: | |
53 | - PROJSOURCE=7.0.1 | |
54 | - python: 3.6 | |
55 | env: | |
56 | - PROJSOURCE=7.0.1 | |
57 | - PROJ_NETWORK=ON | |
42 | 58 | - python: 3.7 |
43 | 59 | env: |
44 | 60 | - DOC=true |
107 | 123 | ci/travis/proj-dl-and-compile "$PROJSOURCE" |
108 | 124 | fi |
109 | 125 | - export PROJ_LIB=$PROJ_DIR/share/proj |
126 | - | | |
127 | if [ "$PROJSYNC" = "ALL" ]; then | |
128 | $PROJ_DIR/bin/projsync --quiet --bbox -175,0,-50,85 | |
129 | fi | |
110 | 130 | |
111 | 131 | install: |
112 | 132 | # coverage report requires a local install |
36 | 36 | <!-- markdownlint-disable --> |
37 | 37 | <table> |
38 | 38 | <tr> |
39 | <td align="center"><a href="https://github.com/jswhit"><img src="https://avatars2.githubusercontent.com/u/579593?v=4" width="100px;" alt="Jeff Whitaker"/><br /><sub><b>Jeff Whitaker</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=jswhit" title="Documentation">📖</a> <a href="https://github.com/pyproj4/pyproj/commits?author=jswhit" title="Tests">⚠️</a> <a href="https://github.com/pyproj4/pyproj/commits?author=jswhit" title="Code">💻</a> <a href="#example-jswhit" title="Examples">💡</a> <a href="#ideas-jswhit" title="Ideas, Planning, & Feedback">🤔</a> <a href="#review-jswhit" title="Reviewed Pull Requests">👀</a> <a href="#question-jswhit" title="Answering Questions">💬</a> <a href="#maintenance-jswhit" title="Maintenance">🚧</a> <a href="#infra-jswhit" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td> | |
40 | <td align="center"><a href="https://github.com/snowman2"><img src="https://avatars3.githubusercontent.com/u/8699967?v=4" width="100px;" alt="Alan D. Snow"/><br /><sub><b>Alan D. Snow</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=snowman2" title="Documentation">📖</a> <a href="https://github.com/pyproj4/pyproj/commits?author=snowman2" title="Tests">⚠️</a> <a href="https://github.com/pyproj4/pyproj/commits?author=snowman2" title="Code">💻</a> <a href="#example-snowman2" title="Examples">💡</a> <a href="#maintenance-snowman2" title="Maintenance">🚧</a> <a href="#infra-snowman2" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#ideas-snowman2" title="Ideas, Planning, & Feedback">🤔</a> <a href="#review-snowman2" title="Reviewed Pull Requests">👀</a> <a href="#question-snowman2" title="Answering Questions">💬</a></td> | |
41 | <td align="center"><a href="https://github.com/micahcochran"><img src="https://avatars0.githubusercontent.com/u/7433104?v=4" width="100px;" alt="Micah Cochran"/><br /><sub><b>Micah Cochran</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=micahcochran" title="Documentation">📖</a> <a href="https://github.com/pyproj4/pyproj/commits?author=micahcochran" title="Tests">⚠️</a> <a href="https://github.com/pyproj4/pyproj/commits?author=micahcochran" title="Code">💻</a> <a href="#maintenance-micahcochran" title="Maintenance">🚧</a> <a href="#infra-micahcochran" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#review-micahcochran" title="Reviewed Pull Requests">👀</a> <a href="#question-micahcochran" title="Answering Questions">💬</a></td> | |
42 | <td align="center"><a href="https://jorisvandenbossche.github.io/"><img src="https://avatars2.githubusercontent.com/u/1020496?v=4" width="100px;" alt="Joris Van den Bossche"/><br /><sub><b>Joris Van den Bossche</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=jorisvandenbossche" title="Documentation">📖</a> <a href="https://github.com/pyproj4/pyproj/commits?author=jorisvandenbossche" title="Code">💻</a> <a href="#ideas-jorisvandenbossche" title="Ideas, Planning, & Feedback">🤔</a> <a href="#review-jorisvandenbossche" title="Reviewed Pull Requests">👀</a> <a href="#question-jorisvandenbossche" title="Answering Questions">💬</a></td> | |
39 | <td align="center"><a href="https://github.com/jswhit"><img src="https://avatars2.githubusercontent.com/u/579593?v=4" width="100px;" alt="Jeff Whitaker"/><br /><sub><b>Jeff Whitaker</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=jswhit" title="Documentation">📖</a> <a href="https://github.com/pyproj4/pyproj/commits?author=jswhit" title="Tests">⚠️</a> <a href="https://github.com/pyproj4/pyproj/commits?author=jswhit" title="Code">💻</a> <a href="#example-jswhit" title="Examples">💡</a> <a href="#ideas-jswhit" title="Ideas, Planning, & Feedback">🤔</a> <a href="#review-jswhit" title="Reviewed Pull Requests">👀</a> <a href="#question-jswhit" title="Answering Questions">💬</a> <a href="#maintenance-jswhit" title="Maintenance">🚧</a> <a href="#infra-jswhit" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/pyproj4/pyproj/issues?q=author%3Ajswhit" title="Bug reports">🐛</a></td> | |
40 | <td align="center"><a href="https://github.com/snowman2"><img src="https://avatars3.githubusercontent.com/u/8699967?v=4" width="100px;" alt="Alan D. Snow"/><br /><sub><b>Alan D. Snow</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=snowman2" title="Documentation">📖</a> <a href="https://github.com/pyproj4/pyproj/commits?author=snowman2" title="Tests">⚠️</a> <a href="https://github.com/pyproj4/pyproj/commits?author=snowman2" title="Code">💻</a> <a href="#example-snowman2" title="Examples">💡</a> <a href="#maintenance-snowman2" title="Maintenance">🚧</a> <a href="#infra-snowman2" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#ideas-snowman2" title="Ideas, Planning, & Feedback">🤔</a> <a href="#review-snowman2" title="Reviewed Pull Requests">👀</a> <a href="#question-snowman2" title="Answering Questions">💬</a> <a href="https://github.com/pyproj4/pyproj/issues?q=author%3Asnowman2" title="Bug reports">🐛</a></td> | |
41 | <td align="center"><a href="https://github.com/micahcochran"><img src="https://avatars0.githubusercontent.com/u/7433104?v=4" width="100px;" alt="Micah Cochran"/><br /><sub><b>Micah Cochran</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=micahcochran" title="Documentation">📖</a> <a href="https://github.com/pyproj4/pyproj/commits?author=micahcochran" title="Tests">⚠️</a> <a href="https://github.com/pyproj4/pyproj/commits?author=micahcochran" title="Code">💻</a> <a href="#maintenance-micahcochran" title="Maintenance">🚧</a> <a href="#infra-micahcochran" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#review-micahcochran" title="Reviewed Pull Requests">👀</a> <a href="#question-micahcochran" title="Answering Questions">💬</a> <a href="https://github.com/pyproj4/pyproj/issues?q=author%3Amicahcochran" title="Bug reports">🐛</a></td> | |
42 | <td align="center"><a href="https://jorisvandenbossche.github.io/"><img src="https://avatars2.githubusercontent.com/u/1020496?v=4" width="100px;" alt="Joris Van den Bossche"/><br /><sub><b>Joris Van den Bossche</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=jorisvandenbossche" title="Documentation">📖</a> <a href="https://github.com/pyproj4/pyproj/commits?author=jorisvandenbossche" title="Code">💻</a> <a href="#ideas-jorisvandenbossche" title="Ideas, Planning, & Feedback">🤔</a> <a href="#review-jorisvandenbossche" title="Reviewed Pull Requests">👀</a> <a href="#question-jorisvandenbossche" title="Answering Questions">💬</a> <a href="https://github.com/pyproj4/pyproj/issues?q=author%3Ajorisvandenbossche" title="Bug reports">🐛</a> <a href="https://github.com/pyproj4/pyproj/commits?author=jorisvandenbossche" title="Tests">⚠️</a></td> | |
43 | 43 | <td align="center"><a href="https://github.com/cjmayo"><img src="https://avatars1.githubusercontent.com/u/921089?v=4" width="100px;" alt="Chris Mayo"/><br /><sub><b>Chris Mayo</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=cjmayo" title="Tests">⚠️</a></td> |
44 | 44 | <td align="center"><a href="https://www.petrel.org"><img src="https://avatars1.githubusercontent.com/u/2298266?v=4" width="100px;" alt="Charles Karney"/><br /><sub><b>Charles Karney</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=cffk" title="Code">💻</a> <a href="https://github.com/pyproj4/pyproj/commits?author=cffk" title="Tests">⚠️</a></td> |
45 | 45 | <td align="center"><a href="http://www.justaprogrammer.net/profile/justin"><img src="https://avatars3.githubusercontent.com/u/146930?v=4" width="100px;" alt="Justin Dearing"/><br /><sub><b>Justin Dearing</b></sub></a><br /><a href="#infra-zippy1981" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td> |
68 | 68 | <td align="center"><a href="https://github.com/ChrisBarker-NOAA"><img src="https://avatars2.githubusercontent.com/u/916576?v=4" width="100px;" alt="Christopher H. Barker"/><br /><sub><b>Christopher H. Barker</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=ChrisBarker-NOAA" title="Code">💻</a></td> |
69 | 69 | <td align="center"><a href="https://evers.dev/"><img src="https://avatars3.githubusercontent.com/u/13132571?v=4" width="100px;" alt="Kristian Evers"/><br /><sub><b>Kristian Evers</b></sub></a><br /><a href="#question-kbevers" title="Answering Questions">💬</a> <a href="#ideas-kbevers" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/pyproj4/pyproj/commits?author=kbevers" title="Documentation">📖</a></td> |
70 | 70 | <td align="center"><a href="http://www.spatialys.com/en/about/"><img src="https://avatars2.githubusercontent.com/u/1192433?v=4" width="100px;" alt="Even Rouault"/><br /><sub><b>Even Rouault</b></sub></a><br /><a href="#question-rouault" title="Answering Questions">💬</a></td> |
71 | <td align="center"><a href="https://github.com/cgohlke"><img src="https://avatars3.githubusercontent.com/u/483428?v=4" width="100px;" alt="Christoph Gohlke"/><br /><sub><b>Christoph Gohlke</b></sub></a><br /><a href="#platform-cgohlke" title="Packaging/porting to new platform">📦</a> <a href="#question-cgohlke" title="Answering Questions">💬</a> <a href="https://github.com/pyproj4/pyproj/issues?q=author%3Acgohlke" title="Bug reports">🐛</a></td> | |
71 | <td align="center"><a href="https://github.com/cgohlke"><img src="https://avatars3.githubusercontent.com/u/483428?v=4" width="100px;" alt="Christoph Gohlke"/><br /><sub><b>Christoph Gohlke</b></sub></a><br /><a href="#platform-cgohlke" title="Packaging/porting to new platform">📦</a> <a href="#question-cgohlke" title="Answering Questions">💬</a> <a href="https://github.com/pyproj4/pyproj/issues?q=author%3Acgohlke" title="Bug reports">🐛</a> <a href="https://github.com/pyproj4/pyproj/commits?author=cgohlke" title="Tests">⚠️</a></td> | |
72 | 72 | <td align="center"><a href="https://github.com/chrrrisw"><img src="https://avatars0.githubusercontent.com/u/5555320?v=4" width="100px;" alt="Chris Willoughby"/><br /><sub><b>Chris Willoughby</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=chrrrisw" title="Code">💻</a></td> |
73 | 73 | </tr> |
74 | 74 | <tr> |
76 | 76 | <td align="center"><a href="https://github.com/edpop"><img src="https://avatars3.githubusercontent.com/u/13479292?v=4" width="100px;" alt="Eduard Popov"/><br /><sub><b>Eduard Popov</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/commits?author=edpop" title="Documentation">📖</a></td> |
77 | 77 | <td align="center"><a href="http://www.personal.psu.edu/jar339"><img src="https://avatars2.githubusercontent.com/u/7864460?v=4" width="100px;" alt="Joe Ranalli"/><br /><sub><b>Joe Ranalli</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/issues?q=author%3Ajranalli" title="Bug reports">🐛</a> <a href="https://github.com/pyproj4/pyproj/commits?author=jranalli" title="Code">💻</a> <a href="https://github.com/pyproj4/pyproj/commits?author=jranalli" title="Tests">⚠️</a></td> |
78 | 78 | <td align="center"><a href="https://github.com/gberardinelli"><img src="https://avatars0.githubusercontent.com/u/13799588?v=4" width="100px;" alt="Greg Berardinelli"/><br /><sub><b>Greg Berardinelli</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/issues?q=author%3Agberardinelli" title="Bug reports">🐛</a> <a href="https://github.com/pyproj4/pyproj/commits?author=gberardinelli" title="Code">💻</a> <a href="#ideas-gberardinelli" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/pyproj4/pyproj/commits?author=gberardinelli" title="Tests">⚠️</a></td> |
79 | <td align="center"><a href="https://github.com/mraspaud"><img src="https://avatars1.githubusercontent.com/u/167802?v=4" width="100px;" alt="Martin Raspaud"/><br /><sub><b>Martin Raspaud</b></sub></a><br /><a href="https://github.com/pyproj4/pyproj/issues?q=author%3Amraspaud" title="Bug reports">🐛</a> <a href="https://github.com/pyproj4/pyproj/commits?author=mraspaud" title="Code">💻</a> <a href="https://github.com/pyproj4/pyproj/commits?author=mraspaud" title="Tests">⚠️</a> <a href="#ideas-mraspaud" title="Ideas, Planning, & Feedback">🤔</a></td> | |
79 | 80 | </tr> |
80 | 81 | </table> |
81 | 82 |
27 | 27 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
28 | 28 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
29 | 29 | """ |
30 | __version__ = "2.6.0" | |
30 | __version__ = "2.6.1rc0" | |
31 | 31 | __all__ = [ |
32 | 32 | "Proj", |
33 | 33 | "Geod", |
44 | 44 | "get_units_map", |
45 | 45 | "show_versions", |
46 | 46 | ] |
47 | ||
48 | 47 | import warnings |
49 | 48 | |
50 | 49 | from pyproj import _datadir |
64 | 63 | from pyproj.proj import Proj, pj_list, proj_version_str # noqa: F401 |
65 | 64 | from pyproj.transformer import Transformer, itransform, transform # noqa: F401 |
66 | 65 | |
66 | __proj_version__ = proj_version_str | |
67 | ||
68 | ||
67 | 69 | try: |
68 | 70 | _datadir.pyproj_global_context_initialize() |
69 | 71 | except DataDirError as err: |
6 | 6 | |
7 | 7 | import argparse |
8 | 8 | |
9 | from pyproj import __version__, _show_versions, proj_version_str | |
9 | from pyproj import __proj_version__, __version__, _show_versions | |
10 | 10 | |
11 | 11 | parser = argparse.ArgumentParser() |
12 | 12 | parser.add_argument( |
19 | 19 | if args.verbose: |
20 | 20 | _show_versions.show_versions() |
21 | 21 | else: |
22 | print("pyproj version: {} [PROJ version: {}]".format(__version__, proj_version_str)) | |
22 | print("pyproj version: {} [PROJ version: {}]".format(__version__, __proj_version__)) | |
23 | 23 | parser.print_help() |
1 | 1 | |
2 | 2 | from collections import namedtuple |
3 | 3 | from enum import IntEnum |
4 | import warnings | |
4 | 5 | |
5 | 6 | from pyproj.compat import cstrencode, pystrdecode |
6 | 7 | from pyproj.enums import PJType |
73 | 74 | dict: |
74 | 75 | Units supported by PROJ |
75 | 76 | """ |
77 | warnings.warn( | |
78 | "The behavior of 'pyproj.get_units_map' is deprecated " | |
79 | "and will change in version 3.0.0.", | |
80 | DeprecationWarning, | |
81 | stacklevel=2, | |
82 | ) | |
76 | 83 | cdef PJ_UNITS *proj_units = proj_list_units() |
77 | 84 | cdef int iii = 0 |
78 | 85 | units_map = {} |
94 | 101 | dict: |
95 | 102 | Angular units supported by PROJ |
96 | 103 | """ |
104 | warnings.warn( | |
105 | "'pyproj.get_angular_units_map' is deprecated. " | |
106 | "Angular units will be available " | |
107 | "in 'pyproj.get_units_map' in version 3.0.0.", | |
108 | DeprecationWarning, | |
109 | stacklevel=2, | |
110 | ) | |
97 | 111 | cdef PJ_UNITS *proj_units = proj_list_angular_units() |
98 | 112 | cdef int iii = 0 |
99 | 113 | units_map = {} |
257 | 257 | Equivalent to `proj -S` command line. |
258 | 258 | """ |
259 | 259 | cdef PyBuffWriteManager lonbuff = PyBuffWriteManager(longitude) |
260 | cdef PyBuffWriteManager latbuff = PyBuffWriteManager(longitude) | |
260 | cdef PyBuffWriteManager latbuff = PyBuffWriteManager(latitude) | |
261 | 261 | |
262 | 262 | if not lonbuff.len or not (lonbuff.len == latbuff.len): |
263 | 263 | raise ProjError('longitude and latitude must be same size') |
42 | 42 | |
43 | 43 | blob = [ |
44 | 44 | ("pyproj", pyproj.__version__), |
45 | ("PROJ", pyproj.proj_version_str), | |
45 | ("PROJ", pyproj.__proj_version__), | |
46 | 46 | ("data dir", data_dir), |
47 | 47 | ] |
48 | 48 |
52 | 52 | prime_meridian = None |
53 | 53 | prime_meridian_name = cf_params.get("prime_meridian_name") |
54 | 54 | try: |
55 | ellipsoid = CustomPrimeMeridian( | |
55 | prime_meridian = CustomPrimeMeridian( | |
56 | 56 | name=prime_meridian_name or "undefined", |
57 | longitude=cf_params["prime_meridian_longitude"], | |
57 | longitude=cf_params["longitude_of_prime_meridian"], | |
58 | 58 | ) |
59 | 59 | except KeyError: |
60 | 60 | if prime_meridian_name: |
1135 | 1135 | """ |
1136 | 1136 | Parameters |
1137 | 1137 | ---------- |
1138 | longitude_natural_origin: float, optional | |
1138 | latitude_natural_origin: float, optional | |
1139 | 1139 | Latitude of natural origin (lat_0). Defaults to 0.0. |
1140 | 1140 | longitude_natural_origin: float, optional |
1141 | 1141 | Longitude of natural origin (lon_0). Defaults to 0.0. |
43 | 43 | if isinstance(value, (list, tuple)): |
44 | 44 | value = ",".join([str(val) for val in value]) |
45 | 45 | # issue 183 (+ no_rot) |
46 | if value is None or value is True: | |
46 | if value is None or str(value) == "True": | |
47 | 47 | pjargs.append("+{key}".format(key=key)) |
48 | elif str(value) == str(False): | |
48 | elif str(value) == "False": | |
49 | 49 | pass |
50 | 50 | else: |
51 | 51 | pjargs.append("+{key}={value}".format(key=key, value=value)) |
579 | 579 | CF-1.8 version of the projection. |
580 | 580 | |
581 | 581 | """ |
582 | unknown_names = ("unknown", "undefined") | |
583 | 582 | cf_dict = {"crs_wkt": self.to_wkt(wkt_version)} # type: Dict[str, Any] |
584 | 583 | |
585 | 584 | # handle bound CRS |
607 | 606 | vert_json = self.to_json_dict() |
608 | 607 | if "geoid_model" in vert_json: |
609 | 608 | cf_dict["geoid_name"] = vert_json["geoid_model"]["name"] |
610 | if self.datum and self.datum.name not in unknown_names: | |
609 | if self.datum: | |
611 | 610 | cf_dict["geopotential_datum_name"] = self.datum.name |
612 | 611 | return cf_dict |
613 | 612 | |
618 | 617 | semi_minor_axis=self.ellipsoid.semi_minor_metre, |
619 | 618 | inverse_flattening=self.ellipsoid.inverse_flattening, |
620 | 619 | ) |
621 | if self.ellipsoid.name not in unknown_names: | |
622 | cf_dict["reference_ellipsoid_name"] = self.ellipsoid.name | |
620 | cf_dict["reference_ellipsoid_name"] = self.ellipsoid.name | |
623 | 621 | if self.prime_meridian: |
624 | 622 | cf_dict["longitude_of_prime_meridian"] = self.prime_meridian.longitude |
625 | if self.prime_meridian.name not in unknown_names: | |
626 | cf_dict["prime_meridian_name"] = self.prime_meridian.name | |
623 | cf_dict["prime_meridian_name"] = self.prime_meridian.name | |
627 | 624 | |
628 | 625 | # handle geographic CRS |
629 | if self.geodetic_crs and self.geodetic_crs.name not in unknown_names: | |
626 | if self.geodetic_crs: | |
630 | 627 | cf_dict["geographic_crs_name"] = self.geodetic_crs.name |
631 | 628 | |
632 | 629 | if self.is_geographic: |
636 | 633 | self.coordinate_operation.method_name.lower() |
637 | 634 | ](self.coordinate_operation) |
638 | 635 | ) |
639 | if self.datum and self.datum.name not in unknown_names: | |
636 | if self.datum: | |
640 | 637 | cf_dict["horizontal_datum_name"] = self.datum.name |
641 | 638 | else: |
642 | 639 | cf_dict["grid_mapping_name"] = "latitude_longitude" |
643 | 640 | return cf_dict |
644 | 641 | |
645 | 642 | # handle projected CRS |
646 | if self.is_projected and self.datum and self.datum.name not in unknown_names: | |
643 | if self.is_projected and self.datum: | |
647 | 644 | cf_dict["horizontal_datum_name"] = self.datum.name |
648 | 645 | coordinate_operation = None |
649 | 646 | if not self.is_bound and self.is_projected: |
650 | 647 | coordinate_operation = self.coordinate_operation |
651 | if self.name not in unknown_names: | |
652 | cf_dict["projected_crs_name"] = self.name | |
648 | cf_dict["projected_crs_name"] = self.name | |
653 | 649 | coordinate_operation_name = ( |
654 | 650 | None |
655 | 651 | if not coordinate_operation |
699 | 695 | ------- |
700 | 696 | CRS |
701 | 697 | """ |
698 | unknown_names = ("unknown", "undefined") | |
702 | 699 | if "crs_wkt" in in_cf: |
703 | 700 | return CRS(in_cf["crs_wkt"]) |
704 | 701 | elif "spatial_ref" in in_cf: # for previous supported WKT key |
724 | 721 | geographic_crs = GeographicCRS( |
725 | 722 | name=geographic_crs_name or "undefined", datum=datum, |
726 | 723 | ) # type: CRS |
727 | elif geographic_crs_name: | |
724 | elif geographic_crs_name and geographic_crs_name not in unknown_names: | |
728 | 725 | geographic_crs = CRS(geographic_crs_name) |
729 | 726 | else: |
730 | 727 | geographic_crs = GeographicCRS() |
906 | 903 | |
907 | 904 | def __eq__(self, other: Any) -> bool: |
908 | 905 | return self.equals(other) |
906 | ||
907 | def __ne__(self, other: Any) -> bool: | |
908 | return not self == other | |
909 | 909 | |
910 | 910 | def __reduce__(self) -> Tuple[Type["CRS"], Tuple[str]]: |
911 | 911 | """special method that allows CRS instance to be pickled""" |
28 | 28 | |
29 | 29 | class Proj(_Proj): |
30 | 30 | """ |
31 | Performs cartographic transformations (converts from | |
32 | longitude,latitude to native map projection x,y coordinates and | |
33 | vice versa) using PROJ (https://proj.org). | |
34 | ||
35 | A Proj class instance is initialized with proj map projection | |
36 | control parameter key/value pairs. The key/value pairs can | |
37 | either be passed in a dictionary, or as keyword arguments, | |
38 | or as a PROJ string (compatible with the proj command). See | |
39 | https://proj.org/operations/projections/index.html for examples of | |
40 | key/value pairs defining different map projections. | |
41 | ||
42 | Calling a Proj class instance with the arguments lon, lat will | |
43 | convert lon/lat (in degrees) to x/y native map projection | |
44 | coordinates (in meters). If optional keyword 'inverse' is True | |
45 | (default is False), the inverse transformation from x/y to | |
46 | lon/lat is performed. If optional keyword 'errcheck' is True (default is | |
47 | False) an exception is raised if the transformation is invalid. | |
48 | If errcheck=False and the transformation is invalid, no | |
49 | exception is raised and 'inf' is returned. If the optional keyword | |
50 | 'preserve_units' is True, the units in map projection coordinates | |
51 | are not forced to be meters. | |
52 | ||
53 | Works with numpy and regular python array objects, python | |
54 | sequences and scalars. | |
31 | Performs cartographic transformations. Converts from | |
32 | longitude, latitude to native map projection x,y coordinates and | |
33 | vice versa using PROJ (https://proj.org). | |
55 | 34 | |
56 | 35 | Attributes |
57 | 36 | ---------- |
66 | 45 | self, projparams: Any = None, preserve_units: bool = True, **kwargs |
67 | 46 | ) -> None: |
68 | 47 | """ |
69 | initialize a Proj class instance. | |
70 | ||
71 | See the PROJ documentation (https://proj.org) | |
72 | for more information about projection parameters. | |
48 | A Proj class instance is initialized with proj map projection | |
49 | control parameter key/value pairs. The key/value pairs can | |
50 | either be passed in a dictionary, or as keyword arguments, | |
51 | or as a PROJ string (compatible with the proj command). See | |
52 | https://proj.org/operations/projections/index.html for examples of | |
53 | key/value pairs defining different map projections. | |
73 | 54 | |
74 | 55 | Parameters |
75 | 56 | ---------- |
149 | 130 | projstring = re.sub(r"\s\+?type=crs", "", projstring) |
150 | 131 | super().__init__(cstrencode(projstring.strip())) |
151 | 132 | |
152 | def __call__(self, *args, **kw) -> Tuple[Any, Any]: | |
153 | # ,lon,lat,inverse=False,errcheck=False): | |
133 | def __call__( | |
134 | self, | |
135 | longitude: Any, | |
136 | latitude: Any, | |
137 | inverse: bool = False, | |
138 | errcheck: bool = False, | |
139 | ) -> Tuple[Any, Any]: | |
154 | 140 | """ |
155 | 141 | Calling a Proj class instance with the arguments lon, lat will |
156 | 142 | convert lon/lat (in degrees) to x/y native map projection |
157 | coordinates (in meters). If optional keyword 'inverse' is True | |
158 | (default is False), the inverse transformation from x/y to | |
159 | lon/lat is performed. If optional keyword 'errcheck' is True (default is | |
160 | False) an exception is raised if the transformation is invalid. | |
161 | If errcheck=False and the transformation is invalid, no | |
162 | exception is raised and 'inf' is returned. | |
143 | coordinates (in meters). | |
163 | 144 | |
164 | 145 | Inputs should be doubles (they will be cast to doubles if they |
165 | 146 | are not, causing a slight performance hit). |
166 | 147 | |
167 | 148 | Works with numpy and regular python array objects, python |
168 | 149 | sequences and scalars, but is fastest for array objects. |
169 | """ | |
170 | inverse = kw.get("inverse", False) | |
171 | errcheck = kw.get("errcheck", False) | |
172 | lon, lat = args | |
150 | ||
151 | Parameters | |
152 | ---------- | |
153 | longitude: scalar or array (numpy or python) | |
154 | Input longitude coordinate(s). | |
155 | latitude: scalar or array (numpy or python) | |
156 | Input latitude coordinate(s). | |
157 | inverse: boolean, optional | |
158 | If inverse is True the inverse transformation from x/y to | |
159 | lon/lat is performed. Default is False. | |
160 | errcheck: boolean, optional | |
161 | If True an exception is raised if the errors are found in the process. | |
162 | By default errcheck=False and ``inf`` is returned. | |
163 | ||
164 | Returns | |
165 | ------- | |
166 | Tuple[Any, Any]: | |
167 | The transformed coordinates. | |
168 | """ | |
173 | 169 | # process inputs, making copies that support buffer API. |
174 | inx, xisfloat, xislist, xistuple = _copytobuffer(lon) | |
175 | iny, yisfloat, yislist, yistuple = _copytobuffer(lat) | |
170 | inx, xisfloat, xislist, xistuple = _copytobuffer(longitude) | |
171 | iny, yisfloat, yislist, yistuple = _copytobuffer(latitude) | |
176 | 172 | # call PROJ functions. inx and iny modified in place. |
177 | 173 | if inverse: |
178 | 174 | self._inv(inx, iny, errcheck=errcheck) |
209 | 205 | radians: boolean, optional |
210 | 206 | If True, will expect input data to be in radians. |
211 | 207 | Default is False (degrees). |
212 | errcheck: boolean, optional (default False) | |
208 | errcheck: boolean, optional | |
213 | 209 | If True an exception is raised if the errors are found in the process. |
214 | 210 | By default errcheck=False and ``inf`` is returned. |
215 | 211 |
8 | 8 | "TransformerGroup", |
9 | 9 | "AreaOfInterest", |
10 | 10 | ] |
11 | import warnings | |
11 | 12 | from array import array |
12 | 13 | from itertools import chain, islice |
13 | 14 | from typing import Any, Iterable, Iterator, List, Optional, Tuple, Union |
67 | 68 | The area of interest to help order the transformations based on the |
68 | 69 | best operation for the area. |
69 | 70 | |
70 | ||
71 | Example: | |
72 | ||
73 | >>> from pyproj.transformer import TransformerGroup | |
74 | >>> trans_group = TransformerGroup(4326, 2964) | |
75 | >>> trans_group | |
76 | <TransformerGroup: best_available=True> | |
77 | - transformers: 8 | |
78 | - unavailable_operations: 1 | |
79 | ||
80 | 71 | """ |
81 | 72 | super().__init__( |
82 | 73 | CRS.from_user_input(crs_from), |
372 | 363 | If True, will expect input data to be in radians and will return radians |
373 | 364 | if the projection is geographic. Default is False (degrees). Ignored for |
374 | 365 | pipeline transformations. |
375 | errcheck: boolean, optional (default False) | |
366 | errcheck: boolean, optional | |
376 | 367 | If True an exception is raised if the transformation is invalid. |
377 | 368 | By default errcheck=False and an invalid transformation |
378 | 369 | returns ``inf`` and no exception is raised. |
486 | 477 | If True, will expect input data to be in radians and will return radians |
487 | 478 | if the projection is geographic. Default is False (degrees). Ignored for |
488 | 479 | pipeline transformations. |
489 | errcheck: boolean, optional (default False) | |
480 | errcheck: boolean, optional | |
490 | 481 | If True an exception is raised if the transformation is invalid. |
491 | 482 | By default errcheck=False and an invalid transformation |
492 | 483 | returns ``inf`` and no exception is raised. |
684 | 675 | .. versionadded:: 2.1.2 skip_equivalent |
685 | 676 | .. versionadded:: 2.2.0 always_xy |
686 | 677 | |
678 | .. warning:: This function is deprecated. See: :ref:`upgrade_transformer` | |
679 | ||
687 | 680 | x2, y2, z2 = transform(p1, p2, x1, y1, z1) |
688 | 681 | |
689 | 682 | Transform points between two coordinate systems defined by the |
753 | 746 | >>> '%8.3f %8.3f %8.3f %5.3f %5.3f %5.3f' % xy |
754 | 747 | ' -92.220 -94.720 -90.370 38.830 39.320 38.750' |
755 | 748 | """ |
749 | warnings.warn( | |
750 | ( | |
751 | "This function is deprecated. " | |
752 | "See: https://pyproj4.github.io/pyproj/stable/" | |
753 | "gotchas.html#upgrading-to-pyproj-2-from-pyproj-1" | |
754 | ), | |
755 | DeprecationWarning, | |
756 | stacklevel=2, | |
757 | ) | |
756 | 758 | return Transformer.from_proj( |
757 | 759 | p1, p2, skip_equivalent=skip_equivalent, always_xy=always_xy |
758 | 760 | ).transform(xx=x, yy=y, zz=z, tt=tt, radians=radians, errcheck=errcheck) |
772 | 774 | """ |
773 | 775 | .. versionadded:: 2.1.2 skip_equivalent |
774 | 776 | .. versionadded:: 2.2.0 always_xy |
777 | ||
778 | .. warning:: This function is deprecated. See: :ref:`upgrade_transformer` | |
775 | 779 | |
776 | 780 | points2 = itransform(p1, p2, points1) |
777 | 781 | Iterator/generator version of the function pyproj.transform. |
826 | 830 | '30 60' |
827 | 831 | |
828 | 832 | """ |
833 | warnings.warn( | |
834 | ( | |
835 | "This function is deprecated. " | |
836 | "See: https://pyproj4.github.io/pyproj/stable/" | |
837 | "gotchas.html#upgrading-to-pyproj-2-from-pyproj-1" | |
838 | ), | |
839 | DeprecationWarning, | |
840 | stacklevel=2, | |
841 | ) | |
829 | 842 | return Transformer.from_proj( |
830 | 843 | p1, p2, skip_equivalent=skip_equivalent, always_xy=always_xy |
831 | 844 | ).itransform( |
0 | 0 | import os |
1 | import shutil | |
2 | import tempfile | |
1 | from pathlib import Path | |
3 | 2 | |
4 | import pytest | |
5 | ||
6 | import pyproj | |
3 | from pyproj.datadir import get_data_dir | |
7 | 4 | |
8 | 5 | |
9 | @pytest.fixture(scope="session") | |
10 | def aoi_data_directory(): | |
6 | def grids_available(*grid_names): | |
11 | 7 | """ |
12 | This is to ensure that the ntv2_0.gsb file is actually | |
13 | missing for the AOI tests. | |
8 | Check if the grids are available | |
14 | 9 | """ |
15 | data_dir = pyproj.datadir.get_data_dir() | |
16 | with tempfile.TemporaryDirectory() as tmpdir: | |
17 | tmp_data_dir = os.path.join(tmpdir, "proj") | |
18 | shutil.copytree(data_dir, tmp_data_dir) | |
19 | try: | |
20 | os.remove(os.path.join(str(tmp_data_dir), "ntv2_0.gsb")) | |
21 | except OSError: | |
22 | pass | |
23 | try: | |
24 | pyproj.datadir.set_data_dir(str(tmp_data_dir)) | |
25 | yield | |
26 | finally: | |
27 | pyproj.datadir.set_data_dir(data_dir) | |
10 | if os.environ.get("PROJ_NETWORK") == "ON": | |
11 | return True | |
12 | for grid_name in grid_names: | |
13 | if Path(get_data_dir(), grid_name).exists(): | |
14 | return True | |
15 | return False |
0 | 0 | import json |
1 | 1 | from distutils.version import LooseVersion |
2 | 2 | |
3 | import numpy | |
3 | 4 | import pytest |
4 | 5 | |
5 | from pyproj import CRS, Transformer, proj_version_str | |
6 | from pyproj import CRS, __proj_version__ | |
6 | 7 | from pyproj.crs import ( |
7 | 8 | CoordinateOperation, |
8 | 9 | CoordinateSystem, |
13 | 14 | from pyproj.crs.enums import CoordinateOperationType, DatumType |
14 | 15 | from pyproj.enums import ProjVersion, WktVersion |
15 | 16 | from pyproj.exceptions import CRSError |
17 | from pyproj.transformer import TransformerGroup | |
16 | 18 | |
17 | 19 | |
18 | 20 | class CustomCRS(object): |
536 | 538 | |
537 | 539 | def test_coordinate_operation_grids(): |
538 | 540 | cc = CoordinateOperation.from_epsg(1312) |
539 | assert ( | |
540 | repr(cc.grids) | |
541 | == "[Grid(short_name=NTv1_0.gsb, full_name=, package_name=, url=, " | |
542 | "direct_download=False, open_license=False, available=False)]" | |
543 | ) | |
541 | if not cc.grids[0].full_name: | |
542 | assert ( | |
543 | repr(cc.grids) | |
544 | == "[Grid(short_name=NTv1_0.gsb, full_name=, package_name=, url=, " | |
545 | "direct_download=False, open_license=False, available=False)]" | |
546 | ) | |
547 | else: | |
548 | assert ( | |
549 | repr(cc.grids) | |
550 | == "[Grid(short_name=NTv1_0.gsb, full_name=NTv1_0.gsb, package_name=, " | |
551 | "url=, direct_download=False, open_license=False, available=False)]" | |
552 | ) | |
544 | 553 | |
545 | 554 | |
546 | 555 | def test_coordinate_operation_grids__alternative_grid_name(): |
550 | 559 | assert grid.direct_download is True |
551 | 560 | assert grid.open_license is True |
552 | 561 | assert grid.available is True |
553 | if LooseVersion(proj_version_str) >= LooseVersion("7.0.0"): | |
562 | if LooseVersion(__proj_version__) >= LooseVersion("7.0.0"): | |
554 | 563 | assert grid.short_name == "ca_nrc_ntv1_can.tif" |
555 | assert grid.full_name.endswith("ntv1_can.dat") | |
564 | assert grid.full_name.endswith("ntv1_can.dat") or grid.full_name.endswith( | |
565 | grid.short_name | |
566 | ) | |
556 | 567 | assert grid.package_name == "" |
557 | 568 | assert grid.url == "https://cdn.proj.org/ca_nrc_ntv1_can.tif" |
558 | 569 | else: |
1102 | 1113 | |
1103 | 1114 | def test_equals_different_type(): |
1104 | 1115 | assert CRS("epsg:4326") != "" |
1116 | assert not CRS("epsg:4326") == "" | |
1117 | ||
1118 | assert CRS("epsg:4326") != 27700 | |
1119 | assert not CRS("epsg:4326") == 27700 | |
1120 | ||
1121 | assert not CRS("epsg:4326") != 4326 | |
1122 | assert CRS("epsg:4326") == 4326 | |
1105 | 1123 | |
1106 | 1124 | |
1107 | 1125 | def test_is_exact_same_different_type(): |
1185 | 1203 | "proj": "ob_tran", |
1186 | 1204 | } |
1187 | 1205 | ) |
1188 | if LooseVersion(proj_version_str) >= LooseVersion("6.3.0"): | |
1206 | if LooseVersion(__proj_version__) >= LooseVersion("6.3.0"): | |
1189 | 1207 | with pytest.warns(UserWarning): |
1190 | 1208 | assert crs.to_dict() == { |
1191 | 1209 | "R": 6371229, |
1236 | 1254 | |
1237 | 1255 | |
1238 | 1256 | def test_operations(): |
1239 | transformer = Transformer.from_crs(28356, 7856) | |
1257 | transformer = TransformerGroup(28356, 7856).transformers[0] | |
1240 | 1258 | coord_op = CoordinateOperation.from_string(transformer.to_wkt()) |
1241 | 1259 | assert coord_op.operations == transformer.operations |
1242 | 1260 | |
1243 | 1261 | |
1244 | 1262 | def test_operations__scope_remarks(): |
1245 | transformer = Transformer.from_crs(28356, 7856) | |
1263 | ||
1264 | transformer = TransformerGroup(28356, 7856).transformers[0] | |
1246 | 1265 | coord_op = CoordinateOperation.from_string(transformer.to_wkt()) |
1247 | 1266 | assert coord_op.operations == transformer.operations |
1248 | 1267 | # scope does not transfer for some reason |
1279 | 1298 | @pytest.mark.parametrize("crs_input", ["+proj=tmerc", "epsg:4326"]) |
1280 | 1299 | def test_utm_zone__none(crs_input): |
1281 | 1300 | assert CRS(crs_input).utm_zone is None |
1301 | ||
1302 | ||
1303 | def test_numpy_bool_kwarg_false(): | |
1304 | # Issue 564 | |
1305 | south = numpy.array(50) < 0 | |
1306 | crs = CRS( | |
1307 | proj="utm", zone=32, ellipsis="WGS84", datum="WGS84", units="m", south=south | |
1308 | ) | |
1309 | assert "south" not in crs.srs | |
1310 | ||
1311 | ||
1312 | def test_numpy_bool_kwarg_true(): | |
1313 | # Issue 564 | |
1314 | south = numpy.array(50) > 0 | |
1315 | crs = CRS( | |
1316 | proj="utm", zone=32, ellipsis="WGS84", datum="WGS84", units="m", south=south | |
1317 | ) | |
1318 | assert "+south " in crs.srs |
2 | 2 | import pytest |
3 | 3 | from numpy.testing import assert_almost_equal |
4 | 4 | |
5 | from pyproj import CRS, proj_version_str | |
5 | from pyproj import CRS, __proj_version__ | |
6 | 6 | from pyproj.crs import ProjectedCRS |
7 | 7 | from pyproj.crs._cf1x8 import _try_list_if_string |
8 | 8 | from pyproj.crs.coordinate_operation import ( |
72 | 72 | "false_easting": 2520000.0, |
73 | 73 | "false_northing": 0.0, |
74 | 74 | "scale_factor_at_central_meridian": 0.9996, |
75 | "geographic_crs_name": "unknown", | |
76 | "projected_crs_name": "unknown", | |
75 | 77 | } |
76 | 78 | cf_dict = crs.to_cf() |
77 | 79 | assert cf_dict.pop("crs_wkt").startswith("BOUNDCRS[") |
128 | 130 | "false_easting": 2520000.0, |
129 | 131 | "false_northing": 0.0, |
130 | 132 | "scale_factor_at_central_meridian": 1.0, |
133 | "geographic_crs_name": "undefined", | |
134 | "projected_crs_name": "undefined", | |
135 | "horizontal_datum_name": "undefined", | |
131 | 136 | } |
132 | 137 | cf_dict = crs.to_cf() |
133 | 138 | assert cf_dict.pop("crs_wkt").startswith("BOUNDCRS[") |
153 | 158 | "longitude_of_prime_meridian": 0.0, |
154 | 159 | "prime_meridian_name": "Greenwich", |
155 | 160 | "grid_mapping_name": "latitude_longitude", |
161 | "geographic_crs_name": "undefined", | |
162 | "reference_ellipsoid_name": "undefined", | |
156 | 163 | } |
157 | 164 | cf_dict = crs.to_cf() |
158 | 165 | assert cf_dict.pop("crs_wkt").startswith("GEOGCRS[") |
252 | 259 | "grid_north_pole_latitude": 32.5, |
253 | 260 | "grid_north_pole_longitude": 170.0, |
254 | 261 | "north_pole_grid_longitude": 0.0, |
262 | "geographic_crs_name": "undefined", | |
255 | 263 | } |
256 | 264 | cf_dict = crs.to_cf() |
257 | 265 | assert cf_dict.pop("crs_wkt").startswith("GEOGCRS[") |
260 | 268 | _test_roundtrip(expected_cf, "GEOGCRS[") |
261 | 269 | with pytest.warns(UserWarning): |
262 | 270 | proj_dict = crs.to_dict() |
263 | if LooseVersion(proj_version_str) >= LooseVersion("6.3.0"): | |
271 | if LooseVersion(__proj_version__) >= LooseVersion("6.3.0"): | |
264 | 272 | assert proj_dict == { |
265 | 273 | "proj": "ob_tran", |
266 | 274 | "o_proj": "longlat", |
286 | 294 | ) |
287 | 295 | with pytest.warns(UserWarning): |
288 | 296 | proj_dict = crs.to_dict() |
289 | if LooseVersion(proj_version_str) >= LooseVersion("6.3.0"): | |
297 | if LooseVersion(__proj_version__) >= LooseVersion("6.3.0"): | |
290 | 298 | assert proj_dict == { |
291 | 299 | "proj": "ob_tran", |
292 | 300 | "o_proj": "longlat", |
323 | 331 | "false_easting": 0.0, |
324 | 332 | "false_northing": 0.0, |
325 | 333 | "standard_parallel": 25.0, |
334 | "geographic_crs_name": "undefined", | |
335 | "projected_crs_name": "undefined", | |
326 | 336 | } |
327 | 337 | cf_dict = crs.to_cf() |
328 | 338 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
371 | 381 | "longitude_of_central_meridian": 265.0, |
372 | 382 | "false_easting": 0.0, |
373 | 383 | "false_northing": 0.0, |
384 | "geographic_crs_name": "undefined", | |
385 | "projected_crs_name": "undefined", | |
374 | 386 | } |
375 | 387 | cf_dict = crs.to_cf() |
376 | 388 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
421 | 433 | "scale_factor_at_projection_origin": 1.0, |
422 | 434 | "false_easting": 0.0, |
423 | 435 | "false_northing": 0.0, |
436 | "geographic_crs_name": "undefined", | |
437 | "projected_crs_name": "undefined", | |
438 | "horizontal_datum_name": "undefined", | |
424 | 439 | } |
425 | 440 | cf_dict = crs.to_cf() |
426 | 441 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
493 | 508 | "longitude_of_projection_origin": 0.0, |
494 | 509 | "false_easting": 0.0, |
495 | 510 | "false_northing": 0.0, |
511 | "geographic_crs_name": "undefined", | |
512 | "projected_crs_name": "undefined", | |
496 | 513 | } |
497 | 514 | cf_dict = crs.to_cf() |
498 | 515 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
524 | 541 | "longitude_of_projection_origin": 0.0, |
525 | 542 | "false_easting": 0.0, |
526 | 543 | "false_northing": 0.0, |
544 | "geographic_crs_name": "undefined", | |
545 | "projected_crs_name": "undefined", | |
527 | 546 | } |
528 | 547 | cf_dict = crs.to_cf() |
529 | 548 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
547 | 566 | "longitude_of_projection_origin": 0.0, |
548 | 567 | "false_easting": 0.0, |
549 | 568 | "false_northing": 0.0, |
569 | "geographic_crs_name": "unknown", | |
570 | "horizontal_datum_name": "unknown", | |
571 | "projected_crs_name": "unknown", | |
572 | "reference_ellipsoid_name": "unknown", | |
550 | 573 | } |
551 | 574 | cf_dict = crs.to_cf() |
552 | 575 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
586 | 609 | "longitude_of_projection_origin": 10.0, |
587 | 610 | "false_easting": 0.0, |
588 | 611 | "false_northing": 0.0, |
612 | "geographic_crs_name": "undefined", | |
613 | "projected_crs_name": "undefined", | |
589 | 614 | } |
590 | 615 | with pytest.warns(UserWarning): |
591 | 616 | assert crs.to_dict() == { |
663 | 688 | |
664 | 689 | |
665 | 690 | @pytest.mark.skipif( |
666 | LooseVersion(proj_version_str) < LooseVersion("6.3.0"), | |
691 | LooseVersion(__proj_version__) < LooseVersion("6.3.0"), | |
667 | 692 | reason="geoid model does not work in PROJ < 6.3.0", |
668 | 693 | ) |
669 | 694 | def test_geoid_model_name(): |
810 | 835 | "longitude_of_projection_origin": 2.0, |
811 | 836 | "false_easting": 3.0, |
812 | 837 | "false_northing": 4.0, |
838 | "geographic_crs_name": "undefined", | |
839 | "projected_crs_name": "undefined", | |
813 | 840 | } |
814 | 841 | cf_dict = crs.to_cf() |
815 | 842 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
833 | 860 | "longitude_of_central_meridian": 2.0, |
834 | 861 | "false_easting": 3.0, |
835 | 862 | "false_northing": 4.0, |
863 | "geographic_crs_name": "undefined", | |
864 | "projected_crs_name": "undefined", | |
836 | 865 | } |
837 | 866 | cf_dict = crs.to_cf() |
838 | 867 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
857 | 886 | "false_easting": 3.0, |
858 | 887 | "false_northing": 4.0, |
859 | 888 | "scale_factor_at_projection_origin": 1.0, |
889 | "geographic_crs_name": "undefined", | |
890 | "projected_crs_name": "undefined", | |
860 | 891 | } |
861 | 892 | cf_dict = crs.to_cf() |
862 | 893 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
880 | 911 | "longitude_of_projection_origin": 2.0, |
881 | 912 | "false_easting": 3.0, |
882 | 913 | "false_northing": 4.0, |
914 | "geographic_crs_name": "undefined", | |
915 | "projected_crs_name": "undefined", | |
883 | 916 | } |
884 | 917 | cf_dict = crs.to_cf() |
885 | 918 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
904 | 937 | "false_easting": 2.0, |
905 | 938 | "false_northing": 3.0, |
906 | 939 | "scale_factor_at_projection_origin": 1.0, |
940 | "geographic_crs_name": "undefined", | |
941 | "projected_crs_name": "undefined", | |
907 | 942 | } |
908 | 943 | cf_dict = crs.to_cf() |
909 | 944 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
927 | 962 | "straight_vertical_longitude_from_pole": 1.0, |
928 | 963 | "false_easting": 2.0, |
929 | 964 | "false_northing": 3.0, |
965 | "geographic_crs_name": "undefined", | |
966 | "projected_crs_name": "undefined", | |
930 | 967 | } |
931 | 968 | cf_dict = crs.to_cf() |
932 | 969 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
951 | 988 | "false_easting": 2.0, |
952 | 989 | "false_northing": 3.0, |
953 | 990 | "scale_factor_at_projection_origin": 1.0, |
991 | "geographic_crs_name": "undefined", | |
992 | "projected_crs_name": "undefined", | |
954 | 993 | } |
955 | 994 | cf_dict = crs.to_cf() |
956 | 995 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
973 | 1012 | "longitude_of_projection_origin": 0.0, |
974 | 1013 | "false_easting": 1.0, |
975 | 1014 | "false_northing": 2.0, |
1015 | "geographic_crs_name": "undefined", | |
1016 | "projected_crs_name": "undefined", | |
976 | 1017 | } |
977 | 1018 | cf_dict = crs.to_cf() |
978 | 1019 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
997 | 1038 | "longitude_of_projection_origin": 1.0, |
998 | 1039 | "false_easting": 2.0, |
999 | 1040 | "false_northing": 3.0, |
1000 | } | |
1001 | cf_dict = crs.to_cf() | |
1002 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") | |
1003 | assert cf_dict == expected_cf | |
1004 | # test roundtrip | |
1005 | _test_roundtrip(expected_cf, "PROJCRS[") | |
1041 | "geographic_crs_name": "undefined", | |
1042 | "projected_crs_name": "undefined", | |
1043 | } | |
1044 | cf_dict = crs.to_cf() | |
1045 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") | |
1046 | assert cf_dict == expected_cf | |
1047 | # test roundtrip | |
1048 | _test_roundtrip(expected_cf, "PROJCRS[") | |
1049 | ||
1050 | ||
1051 | def test_build_custom_datum(): | |
1052 | cf_dict = { | |
1053 | "semi_major_axis": 6370997.0, | |
1054 | "semi_minor_axis": 6370997.0, | |
1055 | "inverse_flattening": 0.0, | |
1056 | "reference_ellipsoid_name": "Normal Sphere (r=6370997)", | |
1057 | "longitude_of_prime_meridian": 1.0, | |
1058 | "grid_mapping_name": "oblique_mercator", | |
1059 | "latitude_of_projection_origin": 0.0, | |
1060 | "longitude_of_projection_origin": 13.809602948622212, | |
1061 | "azimuth_of_central_line": 8.998112717187938, | |
1062 | "scale_factor_at_projection_origin": 1.0, | |
1063 | "false_easting": 0.0, | |
1064 | "false_northing": 0.0, | |
1065 | } | |
1066 | crs = CRS.from_cf(cf_dict) | |
1067 | assert crs.datum.name == "undefined" | |
1068 | assert crs.ellipsoid.name == "Normal Sphere (r=6370997)" | |
1069 | assert crs.prime_meridian.name == "undefined" | |
1070 | assert crs.prime_meridian.longitude == 1 | |
1071 | ||
1072 | ||
1073 | def test_build_custom_datum__default_prime_meridian(): | |
1074 | cf_dict = { | |
1075 | "semi_major_axis": 6370997.0, | |
1076 | "semi_minor_axis": 6370997.0, | |
1077 | "inverse_flattening": 0.0, | |
1078 | "grid_mapping_name": "oblique_mercator", | |
1079 | "latitude_of_projection_origin": 0.0, | |
1080 | "longitude_of_projection_origin": 13.809602948622212, | |
1081 | "azimuth_of_central_line": 8.998112717187938, | |
1082 | "scale_factor_at_projection_origin": 1.0, | |
1083 | "false_easting": 0.0, | |
1084 | "false_northing": 0.0, | |
1085 | } | |
1086 | crs = CRS.from_cf(cf_dict) | |
1087 | assert crs.datum.name == "undefined" | |
1088 | assert crs.ellipsoid.name == "undefined" | |
1089 | assert crs.prime_meridian.name == "Greenwich" | |
1090 | assert crs.prime_meridian.longitude == 0 | |
1091 | ||
1092 | ||
1093 | def test_build_custom_datum__default_ellipsoid(): | |
1094 | cf_dict = { | |
1095 | "prime_meridian_name": "Paris", | |
1096 | "grid_mapping_name": "oblique_mercator", | |
1097 | "latitude_of_projection_origin": 0.0, | |
1098 | "longitude_of_projection_origin": 13.809602948622212, | |
1099 | "azimuth_of_central_line": 8.998112717187938, | |
1100 | "scale_factor_at_projection_origin": 1.0, | |
1101 | "false_easting": 0.0, | |
1102 | "false_northing": 0.0, | |
1103 | } | |
1104 | crs = CRS.from_cf(cf_dict) | |
1105 | assert crs.datum.name == "undefined" | |
1106 | assert crs.ellipsoid.name == "WGS 84" | |
1107 | assert crs.prime_meridian.name == "Paris" | |
1108 | assert str(crs.prime_meridian.longitude).startswith("2.") |
2 | 2 | import pytest |
3 | 3 | from numpy.testing import assert_almost_equal |
4 | 4 | |
5 | from pyproj import proj_version_str | |
5 | from pyproj import __proj_version__ | |
6 | 6 | from pyproj.crs import GeographicCRS |
7 | 7 | from pyproj.crs.coordinate_operation import ( |
8 | 8 | AlbersEqualAreaConversion, |
616 | 616 | |
617 | 617 | def test_lambert_cylindrical_equal_area_scale_operation__defaults(): |
618 | 618 | lceaop = LambertCylindricalEqualAreaScaleConversion() |
619 | if LooseVersion(proj_version_str) >= LooseVersion("6.3.1"): | |
619 | if LooseVersion(__proj_version__) >= LooseVersion("6.3.1"): | |
620 | 620 | assert lceaop.name == "unknown" |
621 | 621 | assert lceaop.method_name == "Lambert Cylindrical Equal Area" |
622 | 622 | assert _to_dict(lceaop) == { |
641 | 641 | false_northing=4, |
642 | 642 | scale_factor_natural_origin=0.999, |
643 | 643 | ) |
644 | if LooseVersion(proj_version_str) >= LooseVersion("6.3.1"): | |
644 | if LooseVersion(__proj_version__) >= LooseVersion("6.3.1"): | |
645 | 645 | assert lceaop.name == "unknown" |
646 | 646 | assert lceaop.method_name == "Lambert Cylindrical Equal Area" |
647 | 647 | op_dict = _to_dict(lceaop) |
1 | 1 | |
2 | 2 | import pytest |
3 | 3 | |
4 | from pyproj import proj_version_str | |
4 | from pyproj import __proj_version__ | |
5 | 5 | from pyproj.crs import ( |
6 | 6 | BoundCRS, |
7 | 7 | CompoundCRS, |
61 | 61 | assert vc.name == "NAVD88 height" |
62 | 62 | assert vc.type_name == "Vertical CRS" |
63 | 63 | assert vc.coordinate_system == VerticalCS() |
64 | if LooseVersion(proj_version_str) >= LooseVersion("6.3.0"): | |
64 | if LooseVersion(__proj_version__) >= LooseVersion("6.3.0"): | |
65 | 65 | assert vc.to_json_dict()["geoid_model"]["name"] == "GEOID12B" |
66 | 66 | |
67 | 67 |
2 | 2 | import numpy |
3 | 3 | from numpy.testing import assert_allclose |
4 | 4 | |
5 | from pyproj import Proj, proj_version_str | |
5 | from pyproj import Proj, __proj_version__ | |
6 | 6 | |
7 | 7 | try: |
8 | 8 | from time import perf_counter |
25 | 25 | # awips221 = Proj(params) |
26 | 26 | # or keyword args |
27 | 27 | awips221 = Proj(proj="lcc", R=6371200, lat_1=50, lat_2=50, lon_0=-107) |
28 | print("proj4 library version = ", proj_version_str) | |
28 | print("proj4 library version = ", __proj_version__) | |
29 | 29 | # AWIPS grid 221 parameters |
30 | 30 | # (from http://www.nco.ncep.noaa.gov/pmb/docs/on388/tableb.html) |
31 | 31 | llcrnrx, llcrnry = awips221(-145.5, 1.0) |
2 | 2 | import pytest |
3 | 3 | from numpy.testing import assert_almost_equal |
4 | 4 | |
5 | from pyproj import CRS, Proj, proj_version_str, transform | |
5 | from pyproj import CRS, Proj, __proj_version__, transform | |
6 | from test.conftest import grids_available | |
6 | 7 | |
7 | 8 | |
8 | 9 | @pytest.mark.parametrize("proj_class", [Proj, CRS]) |
9 | def test_datum(proj_class, aoi_data_directory): | |
10 | def test_datum(proj_class): | |
10 | 11 | p1 = proj_class(proj="latlong", datum="WGS84") |
11 | 12 | s_1 = -111.5 |
12 | 13 | s_2 = 45.25919444444 |
13 | 14 | p2 = proj_class(proj="utm", zone=10, datum="NAD27") |
14 | x2, y2 = transform(p1, p2, s_1, s_2) | |
15 | if LooseVersion(proj_version_str) < LooseVersion("6.3.0"): | |
16 | assert_almost_equal((x2, y2), (1402291.0833290431, 5076289.591846835)) | |
15 | with pytest.warns(DeprecationWarning): | |
16 | x2, y2 = transform(p1, p2, s_1, s_2) | |
17 | if LooseVersion(__proj_version__) < LooseVersion("6.3.0"): | |
18 | assert_almost_equal( | |
19 | (x2, y2), (1402291.0833290431, 5076289.591846835), decimal=2 | |
20 | ) | |
17 | 21 | else: |
18 | # https://github.com/OSGeo/PROJ/issues/1808 | |
19 | assert_almost_equal((x2, y2), (1402285.9829252, 5076292.4212746)) | |
22 | if grids_available("ca_nrc_ntv2_0.tif"): | |
23 | assert_almost_equal((x2, y2), (1402286.3333203, 5076292.2955777), decimal=2) | |
24 | else: | |
25 | # https://github.com/OSGeo/PROJ/issues/1808 | |
26 | assert_almost_equal((x2, y2), (1402285.9829252, 5076292.4212746), decimal=2) |
0 | 0 | import pytest |
1 | 1 | from numpy.testing import assert_almost_equal |
2 | 2 | |
3 | from pyproj import Proj, proj_version_str, transform | |
3 | from pyproj import Proj, transform | |
4 | 4 | |
5 | 5 | # illustrates the use of the transform function to |
6 | 6 | # perform coordinate transformations with datum shifts. |
32 | 32 | GAUSSSB_PROJ = Proj( |
33 | 33 | init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62" |
34 | 34 | ) |
35 | print("proj4 library version = ", proj_version_str) | |
36 | 35 | |
37 | 36 | |
38 | 37 | def test_shift_wgs84_to_utm33(): |
39 | xutm33, yutm33, zutm33 = transform( | |
40 | WGS84_PROJ, UTM_33_PROJ, WGS84_lon, WGS84_lat, WGS84_z | |
41 | ) | |
38 | with pytest.warns(DeprecationWarning): | |
39 | xutm33, yutm33, zutm33 = transform( | |
40 | WGS84_PROJ, UTM_33_PROJ, WGS84_lon, WGS84_lat, WGS84_z | |
41 | ) | |
42 | 42 | assert_almost_equal((xutm33, yutm33, zutm33), (UTM_x, UTM_y, UTM_z)) |
43 | 43 | |
44 | 44 | |
45 | 45 | def test_shift_utm33_to_wgs84(): |
46 | back_lon, back_lat, back_z = transform(UTM_33_PROJ, WGS84_PROJ, UTM_x, UTM_y, UTM_z) | |
46 | with pytest.warns(DeprecationWarning): | |
47 | back_lon, back_lat, back_z = transform( | |
48 | UTM_33_PROJ, WGS84_PROJ, UTM_x, UTM_y, UTM_z | |
49 | ) | |
47 | 50 | assert_almost_equal((back_lon, back_lat, back_z), (WGS84_lon, WGS84_lat, WGS84_z)) |
48 | 51 | |
49 | 52 | |
50 | 53 | def test_shift_wgs84_to_gaussb_no_ellisoidal_height(): |
51 | xgb, ygb, zgb = transform(WGS84_PROJ, GAUSSSB_PROJ, WGS84_lon, WGS84_lat, 0) | |
54 | with pytest.warns(DeprecationWarning): | |
55 | xgb, ygb, zgb = transform(WGS84_PROJ, GAUSSSB_PROJ, WGS84_lon, WGS84_lat, 0) | |
52 | 56 | assert_almost_equal((xgb, ygb, zgb), (GB_x, 5055619.899, 0), decimal=2) |
53 | 57 | |
54 | 58 | |
55 | 59 | def test_shift_gaussb_to_wgs84_no_ellisoidal_height(): |
56 | back_lon, back_lat, back_z = transform(GAUSSSB_PROJ, WGS84_PROJ, GB_x, GB_y, 0) | |
60 | with pytest.warns(DeprecationWarning): | |
61 | back_lon, back_lat, back_z = transform(GAUSSSB_PROJ, WGS84_PROJ, GB_x, GB_y, 0) | |
57 | 62 | assert_almost_equal( |
58 | 63 | (back_lon, back_lat, back_z), (WGS84_lon, WGS84_lat, 0), decimal=3 |
59 | 64 | ) |
0 | 0 | """ |
1 | This is a wrapper for the doctests in lib/pyproj/__init__.py so that | |
2 | pytest can conveniently run all the tests in a single command line. | |
1 | This is a wrapper for the doctests in pyproj | |
3 | 2 | """ |
4 | 3 | import doctest |
5 | 4 | import os |
7 | 6 | import sys |
8 | 7 | import warnings |
9 | 8 | |
9 | import pytest | |
10 | ||
10 | 11 | import pyproj |
11 | 12 | |
12 | 13 | |
13 | def test_doctests(aoi_data_directory): | |
14 | def test_doctests(): | |
14 | 15 | """run the examples in the docstrings using the doctest module""" |
15 | 16 | |
16 | 17 | with warnings.catch_warnings(): |
23 | 24 | failure_count_proj, test_count = doctest.testmod(pyproj.proj, verbose=True) |
24 | 25 | failure_count_crs, test_count_crs = doctest.testmod(pyproj.crs, verbose=True) |
25 | 26 | failure_count_geod, test_count_geod = doctest.testmod(pyproj.geod, verbose=True) |
26 | failure_count_transform, test_count_transform = doctest.testmod( | |
27 | pyproj.transformer, verbose=True | |
28 | ) | |
27 | with pytest.warns(DeprecationWarning): | |
28 | failure_count_transform, test_count_transform = doctest.testmod( | |
29 | pyproj.transformer, verbose=True | |
30 | ) | |
29 | 31 | |
30 | 32 | failure_count = ( |
31 | 33 | failure_count_proj |
14 | 14 | |
15 | 15 | |
16 | 16 | def test_units_map(): |
17 | units_map = get_units_map() | |
17 | with pytest.warns(DeprecationWarning): | |
18 | units_map = get_units_map() | |
18 | 19 | assert isinstance(units_map["m"], Unit) |
19 | 20 | assert units_map["m"].id == "m" |
20 | 21 | assert units_map["m"].name == "Meter" |
21 | 22 | |
22 | 23 | |
23 | 24 | def test_angular_units_map(): |
24 | ang_map = get_angular_units_map() | |
25 | with pytest.warns(DeprecationWarning): | |
26 | ang_map = get_angular_units_map() | |
25 | 27 | assert isinstance(ang_map["deg"], Unit) |
26 | 28 | assert ang_map["deg"].id == "deg" |
27 | 29 | assert ang_map["deg"].name == "Degree" |
124 | 124 | def test_tranform_none_1st_parmeter(self): |
125 | 125 | # test should raise Type error if projections are not of Proj classes |
126 | 126 | # version 1.9.4 produced AttributeError, now should raise TypeError |
127 | with self.assertRaises(CRSError): | |
127 | with pytest.warns(DeprecationWarning), pytest.raises(CRSError): | |
128 | 128 | transform(None, self.p, -74, 39) |
129 | 129 | |
130 | 130 | def test_tranform_none_2nd_parmeter(self): |
131 | 131 | # test should raise Type error if projections are not of Proj classes |
132 | 132 | # version 1.9.4 has a Segmentation Fault, now should raise TypeError |
133 | with self.assertRaises(CRSError): | |
133 | with pytest.warns(DeprecationWarning), pytest.raises(CRSError): | |
134 | 134 | transform(self.p, None, -74, 39) |
135 | 135 | |
136 | 136 | |
149 | 149 | p = Proj("+proj=stere +lon_0=-39 +lat_0=90 +lat_ts=71.0 +ellps=WGS84") |
150 | 150 | self.assertTrue(isinstance(p, Proj)) |
151 | 151 | # if not patched this line raises a "TypeError: p2 must be a Proj class" |
152 | lon, lat = transform(p, p.to_latlong(), 200000, 400000) | |
152 | with pytest.warns(DeprecationWarning): | |
153 | lon, lat = transform(p, p.to_latlong(), 200000, 400000) | |
153 | 154 | |
154 | 155 | |
155 | 156 | @unittest.skipIf( |
431 | 432 | longitude=longitude, latitude=latitude, radians=radians |
432 | 433 | ) |
433 | 434 | assert_almost_equal( |
434 | factors.meridional_scale, [[1.0, 1.00015233], [1.00060954, 1.00137235]], | |
435 | ) | |
436 | assert_almost_equal( | |
437 | factors.parallel_scale, [[1.0, 1.00015233], [1.00060954, 1.00137235]], | |
438 | ) | |
439 | assert_almost_equal( | |
440 | factors.areal_scale, [[1.0, 1.00030468], [1.00121946, 1.00274658]], | |
435 | factors.meridional_scale, [[1.0001523, 1.0006095], [1.0013723, 1.0024419]], | |
436 | ) | |
437 | assert_almost_equal( | |
438 | factors.parallel_scale, [[1.0001523, 1.0006095], [1.0013723, 1.0024419]], | |
439 | ) | |
440 | assert_almost_equal( | |
441 | factors.areal_scale, [[1.00030468, 1.00121946], [1.00274658, 1.00488976]], | |
441 | 442 | ) |
442 | 443 | assert_almost_equal(factors.angular_distortion, [[0, 0], [0, 0]], decimal=5) |
443 | 444 | assert_almost_equal( |
444 | factors.meridian_parallel_angle, [[90, 90], [90, 90]], | |
445 | factors.meridian_parallel_angle, [[89.99, 90], [90, 90]], decimal=2 | |
445 | 446 | ) |
446 | 447 | assert_almost_equal(factors.meridian_convergence, [[0, 0], [0, 0]]) |
447 | 448 | assert_almost_equal( |
448 | factors.tissot_semimajor, [[1.0, 1.00015233], [1.00060955, 1.00137235]], | |
449 | ) | |
450 | assert_almost_equal( | |
451 | factors.tissot_semiminor, [[1.0, 1.00015233], [1.00060953, 1.00137235]], | |
449 | factors.tissot_semimajor, [[1.00015234, 1.00060955], [1.00137235, 1.0024419]], | |
450 | ) | |
451 | assert_almost_equal( | |
452 | factors.tissot_semiminor, [[1.00015232, 1.00060953], [1.00137235, 1.0024419]], | |
452 | 453 | ) |
453 | 454 | assert_almost_equal( |
454 | 455 | factors.dx_dlam, [[1, 1], [1, 1]], |
456 | 457 | assert_almost_equal(factors.dx_dphi, [[0, 0], [0, 0]]) |
457 | 458 | assert_almost_equal(factors.dy_dlam, [[0, 0], [0, 0]]) |
458 | 459 | assert_almost_equal( |
459 | factors.dy_dphi, [[1.0, 1.00015233], [1.00060954, 1.00137235]], | |
460 | ) | |
460 | factors.dy_dphi, [[1.00015233, 1.00060954], [1.00137235, 1.0024419]], | |
461 | ) | |
462 | ||
463 | ||
464 | def test_get_factors(): | |
465 | transformer = Proj(3717) | |
466 | factors = transformer.get_factors(-120, 34) | |
467 | assert_almost_equal(factors.meridional_scale, 1.0005466) | |
468 | assert_almost_equal(factors.parallel_scale, 1.0005466) | |
469 | assert_almost_equal(factors.areal_scale, 1.00109349) | |
470 | assert_almost_equal(factors.angular_distortion, 0) | |
471 | assert_almost_equal(factors.meridian_parallel_angle, 90) | |
472 | assert_almost_equal(factors.meridian_convergence, 1.67864770) | |
473 | assert_almost_equal(factors.tissot_semimajor, 1.00055, decimal=5) | |
474 | assert_almost_equal(factors.tissot_semiminor, 1.00055, decimal=5) | |
475 | assert_almost_equal(factors.dx_dlam, 0.8300039) | |
476 | assert_almost_equal(factors.dx_dphi, -0.0292052) | |
477 | assert_almost_equal(factors.dy_dlam, 0.0243244) | |
478 | assert_almost_equal(factors.dy_dphi, 0.9965495) | |
461 | 479 | |
462 | 480 | |
463 | 481 | def test_get_factors__nan_inf(): |
465 | 483 | factors = transformer.get_factors( |
466 | 484 | longitude=[0, np.nan, np.inf, 0], latitude=[np.nan, 2, 2, np.inf] |
467 | 485 | ) |
468 | assert_almost_equal(factors.meridional_scale, [1, np.inf, np.inf, 1]) | |
469 | assert_almost_equal(factors.parallel_scale, [1, np.inf, np.inf, 1]) | |
470 | assert_almost_equal(factors.areal_scale, [1, np.inf, np.inf, 1]) | |
471 | assert_almost_equal(factors.angular_distortion, [0, np.inf, np.inf, 0]) | |
472 | assert_almost_equal(factors.meridian_parallel_angle, [90, np.inf, np.inf, 90]) | |
473 | assert_almost_equal(factors.meridian_convergence, [0.0, np.inf, np.inf, 0.0]) | |
474 | assert_almost_equal(factors.tissot_semimajor, [1, np.inf, np.inf, 1]) | |
475 | assert_almost_equal(factors.tissot_semiminor, [1, np.inf, np.inf, 1]) | |
476 | assert_almost_equal(factors.dx_dlam, [1, np.inf, np.inf, 1]) | |
477 | assert_almost_equal(factors.dx_dphi, [0.0, np.inf, np.inf, 0.0]) | |
478 | assert_almost_equal(factors.dy_dlam, [0.0, np.inf, np.inf, 0.0]) | |
479 | assert_almost_equal(factors.dy_dphi, [1, np.inf, np.inf, 1]) | |
486 | assert_almost_equal(factors.meridional_scale, [np.inf, np.inf, np.inf, np.inf]) | |
487 | assert_almost_equal(factors.parallel_scale, [np.inf, np.inf, np.inf, np.inf]) | |
488 | assert_almost_equal(factors.areal_scale, [np.inf, np.inf, np.inf, np.inf]) | |
489 | assert_almost_equal(factors.angular_distortion, [np.inf, np.inf, np.inf, np.inf]) | |
490 | assert_almost_equal( | |
491 | factors.meridian_parallel_angle, [np.inf, np.inf, np.inf, np.inf] | |
492 | ) | |
493 | assert_almost_equal(factors.meridian_convergence, [np.inf, np.inf, np.inf, np.inf]) | |
494 | assert_almost_equal(factors.tissot_semimajor, [np.inf, np.inf, np.inf, np.inf]) | |
495 | assert_almost_equal(factors.tissot_semiminor, [np.inf, np.inf, np.inf, np.inf]) | |
496 | assert_almost_equal(factors.dx_dlam, [np.inf, np.inf, np.inf, np.inf]) | |
497 | assert_almost_equal(factors.dx_dphi, [np.inf, np.inf, np.inf, np.inf]) | |
498 | assert_almost_equal(factors.dy_dlam, [np.inf, np.inf, np.inf, np.inf]) | |
499 | assert_almost_equal(factors.dy_dphi, [np.inf, np.inf, np.inf, np.inf]) | |
480 | 500 | |
481 | 501 | |
482 | 502 | def test_get_factors__errcheck(): |
485 | 505 | transformer.get_factors(longitude=40, latitude=70, errcheck=True, radians=True) |
486 | 506 | |
487 | 507 | |
488 | def test_numpy_bool_kwarg(): | |
489 | # Issue 546 | |
508 | def test_numpy_bool_kwarg_false(): | |
509 | # Issue 564 | |
490 | 510 | south = np.array(50) < 0 |
491 | 511 | proj = Proj( |
492 | 512 | proj="utm", zone=32, ellipsis="WGS84", datum="WGS84", units="m", south=south |
493 | 513 | ) |
494 | 514 | assert "south" not in proj.srs |
515 | ||
516 | ||
517 | def test_numpy_bool_kwarg_true(): | |
518 | # Issue 564 | |
519 | south = np.array(50) > 0 | |
520 | proj = Proj( | |
521 | proj="utm", zone=32, ellipsis="WGS84", datum="WGS84", units="m", south=south | |
522 | ) | |
523 | assert "+south " in proj.srs |
0 | 0 | import numpy |
1 | import pytest | |
1 | 2 | from numpy.testing import assert_allclose |
2 | 3 | |
3 | from pyproj import Proj, proj_version_str, transform | |
4 | from pyproj import Proj, __proj_version__, transform | |
4 | 5 | |
5 | 6 | |
6 | 7 | def test_transform(): |
11 | 12 | dx = 12190.58 |
12 | 13 | dy = dx |
13 | 14 | awips221 = Proj(proj="lcc", R=6371200, lat_1=50, lat_2=50, lon_0=-107) |
14 | print("proj4 library version = ", proj_version_str) | |
15 | print("proj4 library version = ", __proj_version__) | |
15 | 16 | llcrnrx, llcrnry = awips221(-145.5, 1) |
16 | 17 | awips221 = Proj( |
17 | 18 | proj="lcc", |
34 | 35 | print("max/min x and y for awips218 grid") |
35 | 36 | print(numpy.minimum.reduce(numpy.ravel(x1)), numpy.maximum.reduce(numpy.ravel(x1))) |
36 | 37 | print(numpy.minimum.reduce(numpy.ravel(y1)), numpy.maximum.reduce(numpy.ravel(y1))) |
37 | x2, y2 = transform(awips218, awips221, x1, y1) | |
38 | with pytest.warns(DeprecationWarning): | |
39 | x2, y2 = transform(awips218, awips221, x1, y1) | |
38 | 40 | print("max/min x and y for awips218 grid in awips221 coordinates") |
39 | 41 | print(numpy.minimum.reduce(numpy.ravel(x2)), numpy.maximum.reduce(numpy.ravel(x2))) |
40 | 42 | print(numpy.minimum.reduce(numpy.ravel(y2)), numpy.maximum.reduce(numpy.ravel(y2))) |
41 | x3, y3 = transform(awips221, awips218, x2, y2) | |
43 | with pytest.warns(DeprecationWarning): | |
44 | x3, y3 = transform(awips221, awips218, x2, y2) | |
42 | 45 | print("error for reverse transformation back to awips218 coords") |
43 | 46 | print("(should be close to zero)") |
44 | 47 | assert_allclose(numpy.minimum.reduce(numpy.ravel(x3 - x1)), 0, atol=1e-4) |
48 | 51 | |
49 | 52 | |
50 | 53 | def test_skip_equivalent(): |
51 | xeq, yeq = transform(4326, 4326, 30, 60, skip_equivalent=True) | |
54 | with pytest.warns(DeprecationWarning): | |
55 | xeq, yeq = transform(4326, 4326, 30, 60, skip_equivalent=True) | |
52 | 56 | assert (xeq, yeq) == (30, 60) |
4 | 4 | from numpy.testing import assert_almost_equal |
5 | 5 | |
6 | 6 | import pyproj |
7 | from pyproj import Proj, Transformer, itransform, transform | |
7 | from pyproj import Proj, Transformer, __proj_version__, itransform, transform | |
8 | 8 | from pyproj.enums import TransformDirection |
9 | 9 | from pyproj.exceptions import ProjError |
10 | 10 | from pyproj.transformer import AreaOfInterest, TransformerGroup |
11 | from test.conftest import grids_available | |
12 | ||
13 | _PROJ_gte_701 = LooseVersion(__proj_version__) >= LooseVersion("7.0.1") | |
11 | 14 | |
12 | 15 | |
13 | 16 | def test_tranform_wgs84_to_custom(): |
17 | 20 | ) |
18 | 21 | wgs84 = pyproj.Proj("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") |
19 | 22 | lat, lon = 51.04715, 3.23406 |
20 | xx, yy = pyproj.transform(wgs84, custom_proj, lon, lat) | |
23 | with pytest.warns(DeprecationWarning): | |
24 | xx, yy = pyproj.transform(wgs84, custom_proj, lon, lat) | |
21 | 25 | assert "{:.3f} {:.3f}".format(xx, yy) == "212.623 4604.975" |
22 | 26 | |
23 | 27 | |
26 | 30 | lat_lon_proj = pyproj.Proj(init="epsg:4326", preserve_units=False) |
27 | 31 | alaska_aea_proj = pyproj.Proj(init="epsg:2964", preserve_units=False) |
28 | 32 | test = (-179.72638, 49.752533) |
29 | xx, yy = pyproj.transform(lat_lon_proj, alaska_aea_proj, *test) | |
33 | with pytest.warns(DeprecationWarning): | |
34 | xx, yy = pyproj.transform(lat_lon_proj, alaska_aea_proj, *test) | |
30 | 35 | assert "{:.3f} {:.3f}".format(xx, yy) == "-1824924.495 330822.800" |
31 | 36 | |
32 | 37 | |
35 | 40 | with pytest.warns(FutureWarning): |
36 | 41 | p1 = pyproj.Proj(init="epsg:4326") |
37 | 42 | p2 = pyproj.Proj(init="epsg:3857") |
38 | xx, yy = pyproj.transform( | |
39 | p1, p2, (-180, -180, 180, 180, -180), (-90, 90, 90, -90, -90) | |
40 | ) | |
43 | with pytest.warns(DeprecationWarning): | |
44 | xx, yy = pyproj.transform( | |
45 | p1, p2, (-180, -180, 180, 180, -180), (-90, 90, 90, -90, -90) | |
46 | ) | |
41 | 47 | assert np.all(np.isinf(xx)) |
42 | 48 | assert np.all(np.isinf(yy)) |
43 | with pytest.raises(ProjError): | |
49 | with pytest.warns(DeprecationWarning), pytest.raises(ProjError): | |
44 | 50 | pyproj.transform( |
45 | 51 | p1, p2, (-180, -180, 180, 180, -180), (-90, 90, 90, -90, -90), errcheck=True |
46 | 52 | ) |
55 | 61 | E = 567623.931 |
56 | 62 | N = 256422.787 |
57 | 63 | h = 1341.467 |
58 | ||
59 | Long1, Lat1, H1 = pyproj.transform(Midelt, WGS84, E, N, h, radians=False) | |
64 | with pytest.warns(DeprecationWarning): | |
65 | Long1, Lat1, H1 = pyproj.transform(Midelt, WGS84, E, N, h, radians=False) | |
60 | 66 | assert_almost_equal((Long1, Lat1, H1), (-4.6753456, 32.902199, 1341.467), decimal=5) |
61 | 67 | |
62 | 68 | |
147 | 153 | |
148 | 154 | |
149 | 155 | def test_4d_transform_orginal_crs_obs1(): |
150 | assert_almost_equal( | |
151 | transform(7789, 8401, x=3496737.2679, y=743254.4507, z=5264462.9620, tt=2019.0), | |
152 | (3496737.757717311, 743253.9940103051, 5264462.701132784, 2019.0), | |
153 | ) | |
156 | with pytest.warns(DeprecationWarning): | |
157 | assert_almost_equal( | |
158 | transform( | |
159 | 7789, 8401, x=3496737.2679, y=743254.4507, z=5264462.9620, tt=2019.0 | |
160 | ), | |
161 | (3496737.757717311, 743253.9940103051, 5264462.701132784, 2019.0), | |
162 | ) | |
154 | 163 | |
155 | 164 | |
156 | 165 | def test_4d_transform_crs_obs2(): |
172 | 181 | |
173 | 182 | |
174 | 183 | def test_2d_with_time_transform_original_crs_obs2(): |
175 | assert_almost_equal( | |
176 | transform(4896, 7930, x=3496737.2679, y=743254.4507, tt=2019.0), | |
177 | (3496737.4105305015, 743254.1014318303, 2019.0), | |
178 | ) | |
184 | with pytest.warns(DeprecationWarning): | |
185 | assert_almost_equal( | |
186 | transform(4896, 7930, x=3496737.2679, y=743254.4507, tt=2019.0), | |
187 | (3496737.4105305015, 743254.1014318303, 2019.0), | |
188 | ) | |
179 | 189 | |
180 | 190 | |
181 | 191 | def test_4d_itransform(): |
203 | 213 | |
204 | 214 | |
205 | 215 | def test_4d_itransform_orginal_crs_obs1(): |
206 | assert_almost_equal( | |
207 | list( | |
208 | itransform(7789, 8401, [(3496737.2679, 743254.4507, 5264462.9620, 2019.0)]) | |
209 | ), | |
210 | [(3496737.757717311, 743253.9940103051, 5264462.701132784, 2019.0)], | |
211 | ) | |
216 | with pytest.warns(DeprecationWarning): | |
217 | assert_almost_equal( | |
218 | list( | |
219 | itransform( | |
220 | 7789, 8401, [(3496737.2679, 743254.4507, 5264462.9620, 2019.0)] | |
221 | ) | |
222 | ), | |
223 | [(3496737.757717311, 743253.9940103051, 5264462.701132784, 2019.0)], | |
224 | ) | |
212 | 225 | |
213 | 226 | |
214 | 227 | def test_2d_with_time_itransform_original_crs_obs2(): |
215 | assert_almost_equal( | |
216 | list( | |
217 | itransform(4896, 7930, [(3496737.2679, 743254.4507, 2019.0)], time_3rd=True) | |
218 | ), | |
219 | [(3496737.4105305015, 743254.1014318303, 2019.0)], | |
220 | ) | |
228 | with pytest.warns(DeprecationWarning): | |
229 | assert_almost_equal( | |
230 | list( | |
231 | itransform( | |
232 | 4896, 7930, [(3496737.2679, 743254.4507, 2019.0)], time_3rd=True | |
233 | ) | |
234 | ), | |
235 | [(3496737.4105305015, 743254.1014318303, 2019.0)], | |
236 | ) | |
221 | 237 | |
222 | 238 | |
223 | 239 | def test_itransform_time_3rd_invalid(): |
224 | 240 | |
225 | with pytest.raises(ValueError, match="'time_3rd' is only valid for 3 coordinates."): | |
241 | with pytest.warns(DeprecationWarning), pytest.raises( | |
242 | ValueError, match="'time_3rd' is only valid for 3 coordinates." | |
243 | ): | |
226 | 244 | list( |
227 | 245 | itransform( |
228 | 246 | 7789, |
231 | 249 | time_3rd=True, |
232 | 250 | ) |
233 | 251 | ) |
234 | with pytest.raises(ValueError, match="'time_3rd' is only valid for 3 coordinates."): | |
252 | with pytest.warns(DeprecationWarning), pytest.raises( | |
253 | ValueError, match="'time_3rd' is only valid for 3 coordinates." | |
254 | ): | |
235 | 255 | list(itransform(7789, 8401, [(3496737.2679, 743254.4507)], time_3rd=True)) |
236 | 256 | |
237 | 257 | |
239 | 259 | with pytest.warns(FutureWarning): |
240 | 260 | pj = Proj(init="epsg:4555") |
241 | 261 | pjx, pjy = pj(116.366, 39.867) |
242 | transform(pj, Proj(4326), pjx, pjy, radians=True, errcheck=True) | |
262 | with pytest.warns(DeprecationWarning): | |
263 | transform(pj, Proj(4326), pjx, pjy, radians=True, errcheck=True) | |
243 | 264 | |
244 | 265 | |
245 | 266 | def test_itransform_no_error(): |
246 | 267 | with pytest.warns(FutureWarning): |
247 | 268 | pj = Proj(init="epsg:4555") |
248 | 269 | pjx, pjy = pj(116.366, 39.867) |
249 | list(itransform(pj, Proj(4326), [(pjx, pjy)], radians=True, errcheck=True)) | |
270 | with pytest.warns(DeprecationWarning): | |
271 | list(itransform(pj, Proj(4326), [(pjx, pjy)], radians=True, errcheck=True)) | |
250 | 272 | |
251 | 273 | |
252 | 274 | def test_transform_no_exception(): |
260 | 282 | def test_transform__out_of_bounds(): |
261 | 283 | with pytest.warns(FutureWarning): |
262 | 284 | transformer = Transformer.from_proj("+init=epsg:4326", "+init=epsg:27700") |
263 | if LooseVersion(pyproj.proj_version_str) >= LooseVersion("7.0.0"): | |
285 | if LooseVersion(pyproj.__proj_version__) >= LooseVersion("7.0.0"): | |
264 | 286 | with pytest.raises(pyproj.exceptions.ProjError): |
265 | 287 | transformer.transform(100000, 100000, errcheck=True) |
266 | 288 | else: |
271 | 293 | with pytest.warns(FutureWarning): |
272 | 294 | WGS84 = pyproj.Proj("+init=EPSG:4326") |
273 | 295 | ECEF = pyproj.Proj(proj="geocent", ellps="WGS84", datum="WGS84") |
274 | assert_almost_equal( | |
275 | pyproj.transform( | |
276 | ECEF, WGS84, -2704026.010, -4253051.810, 3895878.820, radians=True | |
277 | ), | |
278 | (-2.137113493845668, 0.6613203738996222, -20.531156923621893), | |
279 | ) | |
280 | ||
281 | assert_almost_equal( | |
282 | pyproj.transform( | |
283 | WGS84, | |
284 | ECEF, | |
285 | -2.137113493845668, | |
286 | 0.6613203738996222, | |
287 | -20.531156923621893, | |
288 | radians=True, | |
289 | ), | |
290 | (-2704026.010, -4253051.810, 3895878.820), | |
291 | ) | |
296 | with pytest.warns(DeprecationWarning): | |
297 | assert_almost_equal( | |
298 | pyproj.transform( | |
299 | ECEF, WGS84, -2704026.010, -4253051.810, 3895878.820, radians=True | |
300 | ), | |
301 | (-2.137113493845668, 0.6613203738996222, -20.531156923621893), | |
302 | ) | |
303 | ||
304 | assert_almost_equal( | |
305 | pyproj.transform( | |
306 | WGS84, | |
307 | ECEF, | |
308 | -2.137113493845668, | |
309 | 0.6613203738996222, | |
310 | -20.531156923621893, | |
311 | radians=True, | |
312 | ), | |
313 | (-2704026.010, -4253051.810, 3895878.820), | |
314 | ) | |
292 | 315 | |
293 | 316 | |
294 | 317 | def test_itransform_radians(): |
295 | 318 | with pytest.warns(FutureWarning): |
296 | 319 | WGS84 = pyproj.Proj("+init=EPSG:4326") |
297 | 320 | ECEF = pyproj.Proj(proj="geocent", ellps="WGS84", datum="WGS84") |
298 | assert_almost_equal( | |
299 | list( | |
300 | pyproj.itransform( | |
301 | ECEF, WGS84, [(-2704026.010, -4253051.810, 3895878.820)], radians=True | |
302 | ) | |
303 | ), | |
304 | [(-2.137113493845668, 0.6613203738996222, -20.531156923621893)], | |
305 | ) | |
306 | ||
307 | assert_almost_equal( | |
308 | list( | |
309 | pyproj.itransform( | |
310 | WGS84, | |
311 | ECEF, | |
312 | [(-2.137113493845668, 0.6613203738996222, -20.531156923621893)], | |
313 | radians=True, | |
314 | ) | |
315 | ), | |
316 | [(-2704026.010, -4253051.810, 3895878.820)], | |
317 | ) | |
321 | with pytest.warns(DeprecationWarning): | |
322 | assert_almost_equal( | |
323 | list( | |
324 | pyproj.itransform( | |
325 | ECEF, | |
326 | WGS84, | |
327 | [(-2704026.010, -4253051.810, 3895878.820)], | |
328 | radians=True, | |
329 | ) | |
330 | ), | |
331 | [(-2.137113493845668, 0.6613203738996222, -20.531156923621893)], | |
332 | ) | |
333 | ||
334 | assert_almost_equal( | |
335 | list( | |
336 | pyproj.itransform( | |
337 | WGS84, | |
338 | ECEF, | |
339 | [(-2.137113493845668, 0.6613203738996222, -20.531156923621893)], | |
340 | radians=True, | |
341 | ) | |
342 | ), | |
343 | [(-2704026.010, -4253051.810, 3895878.820)], | |
344 | ) | |
318 | 345 | |
319 | 346 | |
320 | 347 | def test_4d_transform__inverse(): |
353 | 380 | |
354 | 381 | |
355 | 382 | def test_always_xy__transform(): |
356 | assert_almost_equal( | |
357 | transform(2193, 4326, 1625350, 5504853, always_xy=True), | |
358 | (173.29964730317386, -40.60674802693758), | |
359 | ) | |
383 | with pytest.warns(DeprecationWarning): | |
384 | assert_almost_equal( | |
385 | transform(2193, 4326, 1625350, 5504853, always_xy=True), | |
386 | (173.29964730317386, -40.60674802693758), | |
387 | ) | |
360 | 388 | |
361 | 389 | |
362 | 390 | def test_always_xy__itransform(): |
363 | assert_almost_equal( | |
364 | list(itransform(2193, 4326, [(1625350, 5504853)], always_xy=True)), | |
365 | [(173.29964730317386, -40.60674802693758)], | |
366 | ) | |
391 | with pytest.warns(DeprecationWarning): | |
392 | assert_almost_equal( | |
393 | list(itransform(2193, 4326, [(1625350, 5504853)], always_xy=True)), | |
394 | [(173.29964730317386, -40.60674802693758)], | |
395 | ) | |
367 | 396 | |
368 | 397 | |
369 | 398 | def test_transform_direction__string(): |
422 | 451 | assert str(Transformer.from_crs(4326, 3857)).startswith("proj=pipeline") |
423 | 452 | |
424 | 453 | |
425 | def test_repr(): | |
426 | assert repr(Transformer.from_crs(7789, 8401)) == ( | |
427 | "<Transformation Transformer: helmert>\n" | |
428 | "Description: ITRF2014 to ETRF2014 (1)\n" | |
429 | "Area of Use:\n" | |
430 | "- name: Europe - ETRS89\n" | |
431 | "- bounds: (-16.1, 32.88, 40.18, 84.17)" | |
432 | ) | |
433 | ||
434 | assert repr(Transformer.from_crs(4326, 3857)) == ( | |
435 | "<Conversion Transformer: pipeline>\n" | |
436 | "Description: Popular Visualisation Pseudo-Mercator\n" | |
437 | "Area of Use:\n" | |
438 | "- name: World\n" | |
439 | "- bounds: (-180.0, -90.0, 180.0, 90.0)" | |
440 | ) | |
441 | ||
442 | assert repr(Transformer.from_crs(4326, 26917)) == ( | |
443 | "<Unknown Transformer: unknown>\n" | |
444 | "Description: unavailable until proj_trans is called\n" | |
445 | "Area of Use:\n- undefined" | |
446 | ) | |
454 | @pytest.mark.parametrize( | |
455 | "from_crs, to_crs, expected_repr", | |
456 | [ | |
457 | ( | |
458 | 7789, | |
459 | 8401, | |
460 | ( | |
461 | "<Transformation Transformer: helmert>\n" | |
462 | "Description: ITRF2014 to ETRF2014 (1)\n" | |
463 | "Area of Use:\n" | |
464 | "- name: Europe - {}\n" | |
465 | "- bounds: (-16.1, 32.88, 40.18, 84.17)" | |
466 | ).format("ETRF by country" if _PROJ_gte_701 else "ETRS89"), | |
467 | ), | |
468 | ( | |
469 | 4326, | |
470 | 3857, | |
471 | ( | |
472 | "<Conversion Transformer: pipeline>\n" | |
473 | "Description: Popular Visualisation Pseudo-Mercator\n" | |
474 | "Area of Use:\n" | |
475 | "- name: World\n" | |
476 | "- bounds: (-180.0, -90.0, 180.0, 90.0)" | |
477 | ), | |
478 | ), | |
479 | ( | |
480 | 4326, | |
481 | 26917, | |
482 | ( | |
483 | "<Unknown Transformer: unknown>\n" | |
484 | "Description: unavailable until proj_trans is called\n" | |
485 | "Area of Use:\n- undefined" | |
486 | ), | |
487 | ), | |
488 | ], | |
489 | ) | |
490 | def test_repr(from_crs, to_crs, expected_repr): | |
491 | assert repr(Transformer.from_crs(from_crs, to_crs)) == expected_repr | |
447 | 492 | |
448 | 493 | |
449 | 494 | def test_to_json_dict(): |
474 | 519 | |
475 | 520 | |
476 | 521 | def test_transformer__operations(): |
477 | transformer = Transformer.from_crs(28356, 7856) | |
522 | transformer = TransformerGroup(28356, 7856).transformers[0] | |
478 | 523 | assert [op.name for op in transformer.operations] == [ |
479 | 524 | "Inverse of Map Grid of Australia zone 56", |
480 | 525 | "GDA94 to GDA2020 (1)", |
487 | 532 | |
488 | 533 | |
489 | 534 | def test_transformer__operations__scope_remarks(): |
490 | transformer = Transformer.from_crs(28356, 7856) | |
535 | transformer = TransformerGroup(28356, 7856).transformers[0] | |
491 | 536 | assert transformer.scope is None |
492 | 537 | assert [op.scope for op in transformer.operations] == [ |
493 | 538 | None, |
511 | 556 | assert trans_group.best_available |
512 | 557 | |
513 | 558 | |
514 | def test_transformer_group__unavailable(aoi_data_directory): | |
559 | def test_transformer_group__unavailable(): | |
515 | 560 | trans_group = TransformerGroup(4326, 2964) |
516 | assert len(trans_group.unavailable_operations) == 1 | |
517 | assert ( | |
518 | trans_group.unavailable_operations[0].name | |
519 | == "Inverse of NAD27 to WGS 84 (33) + Alaska Albers" | |
520 | ) | |
521 | assert len(trans_group.transformers) == 8 | |
522 | assert trans_group.best_available | |
523 | ||
524 | ||
525 | def test_transform_group__missing_best(aoi_data_directory): | |
561 | if not grids_available("ntv2_0.gsb", "ca_nrc_ntv2_0.tif"): | |
562 | assert len(trans_group.unavailable_operations) == 1 | |
563 | assert ( | |
564 | trans_group.unavailable_operations[0].name | |
565 | == "Inverse of NAD27 to WGS 84 (33) + Alaska Albers" | |
566 | ) | |
567 | if _PROJ_gte_701: | |
568 | assert len(trans_group.transformers) == 9 | |
569 | else: | |
570 | assert len(trans_group.transformers) == 8 | |
571 | assert trans_group.best_available | |
572 | else: | |
573 | assert len(trans_group.unavailable_operations) == 0 | |
574 | if _PROJ_gte_701: | |
575 | assert len(trans_group.transformers) == 10 | |
576 | else: | |
577 | assert len(trans_group.transformers) == 9 | |
578 | assert trans_group.best_available | |
579 | ||
580 | ||
581 | def test_transform_group__missing_best(): | |
526 | 582 | with pytest.warns(FutureWarning): |
527 | 583 | lat_lon_proj = pyproj.Proj(init="epsg:4326", preserve_units=False) |
528 | 584 | alaska_aea_proj = pyproj.Proj(init="epsg:2964", preserve_units=False) |
529 | 585 | |
530 | with pytest.warns( | |
531 | UserWarning, match="Best transformation is not available due to missing Grid" | |
532 | ): | |
586 | if not grids_available("ntv2_0.gsb", "ca_nrc_ntv2_0.tif"): | |
587 | with pytest.warns( | |
588 | UserWarning, | |
589 | match="Best transformation is not available due to missing Grid", | |
590 | ): | |
591 | trans_group = pyproj.transformer.TransformerGroup( | |
592 | lat_lon_proj.crs, alaska_aea_proj.crs | |
593 | ) | |
594 | ||
595 | assert not trans_group.best_available | |
596 | assert len(trans_group.transformers) == 37 | |
597 | assert len(trans_group.unavailable_operations) == 41 | |
598 | else: | |
599 | # assuming all grids avaiable or PROJ_NETWORK=ON | |
533 | 600 | trans_group = pyproj.transformer.TransformerGroup( |
534 | 601 | lat_lon_proj.crs, alaska_aea_proj.crs |
535 | 602 | ) |
536 | ||
537 | assert not trans_group.best_available | |
538 | assert len(trans_group.transformers) == 37 | |
539 | assert len(trans_group.unavailable_operations) == 41 | |
540 | ||
541 | ||
542 | def test_transform_group__area_of_interest(aoi_data_directory): | |
543 | with pytest.warns( | |
544 | UserWarning, match="Best transformation is not available due to missing Grid" | |
545 | ): | |
546 | trans_group = TransformerGroup( | |
547 | 4326, 2964, area_of_interest=AreaOfInterest(-136.46, 49.0, -60.72, 83.17) | |
548 | ) | |
549 | assert ( | |
550 | trans_group.transformers[0].description | |
551 | == "Inverse of NAD27 to WGS 84 (13) + Alaska Albers" | |
552 | ) | |
603 | assert trans_group.best_available | |
604 | assert len(trans_group.transformers) == 78 | |
605 | assert len(trans_group.unavailable_operations) == 0 | |
606 | ||
607 | ||
608 | def test_transform_group__area_of_interest(): | |
609 | if not grids_available("ntv2_0.gsb", "ca_nrc_ntv2_0.tif"): | |
610 | with pytest.warns( | |
611 | UserWarning, | |
612 | match="Best transformation is not available due to missing Grid", | |
613 | ): | |
614 | trans_group = pyproj.transformer.TransformerGroup( | |
615 | 4326, | |
616 | 2964, | |
617 | area_of_interest=pyproj.transformer.AreaOfInterest( | |
618 | -136.46, 49.0, -60.72, 83.17 | |
619 | ), | |
620 | ) | |
621 | assert ( | |
622 | trans_group.transformers[0].description | |
623 | == "Inverse of NAD27 to WGS 84 (13) + Alaska Albers" | |
624 | ) | |
625 | else: | |
626 | trans_group = pyproj.transformer.TransformerGroup( | |
627 | 4326, | |
628 | 2964, | |
629 | area_of_interest=pyproj.transformer.AreaOfInterest( | |
630 | -136.46, 49.0, -60.72, 83.17 | |
631 | ), | |
632 | ) | |
633 | assert trans_group.best_available | |
634 | assert ( | |
635 | trans_group.transformers[0].description | |
636 | == "Inverse of NAD27 to WGS 84 (33) + Alaska Albers" | |
637 | ) | |
553 | 638 | |
554 | 639 | |
555 | 640 | def test_transformer_group__get_transform_crs(): |
556 | 641 | tg = TransformerGroup("epsg:4258", "epsg:7415") |
557 | if LooseVersion(pyproj.proj_version_str) >= LooseVersion("6.3.1"): | |
558 | assert len(tg.transformers) == 1 | |
642 | if LooseVersion(pyproj.__proj_version__) >= LooseVersion("6.3.1"): | |
643 | if not grids_available("nl_nsgi_rdtrans2018.tif"): | |
644 | assert len(tg.transformers) == 1 | |
645 | else: | |
646 | assert len(tg.transformers) == 2 | |
559 | 647 | else: |
560 | 648 | assert len(tg.transformers) == 4 |
561 | 649 | |
562 | 650 | |
563 | def test_transformer__area_of_interest(aoi_data_directory): | |
651 | def test_transformer__area_of_interest(): | |
564 | 652 | transformer = Transformer.from_crs( |
565 | 653 | 4326, 2964, area_of_interest=AreaOfInterest(-136.46, 49.0, -60.72, 83.17) |
566 | 654 | ) |
567 | assert transformer.description == "Inverse of NAD27 to WGS 84 (13) + Alaska Albers" | |
568 | ||
569 | ||
570 | def test_transformer_proj__area_of_interest(aoi_data_directory): | |
655 | if not grids_available("ntv2_0.gsb", "ca_nrc_ntv2_0.tif"): | |
656 | assert ( | |
657 | transformer.description == "Inverse of NAD27 to WGS 84 (13) + Alaska Albers" | |
658 | ) | |
659 | else: | |
660 | assert ( | |
661 | transformer.description == "Inverse of NAD27 to WGS 84 (33) + Alaska Albers" | |
662 | ) | |
663 | ||
664 | ||
665 | def test_transformer_proj__area_of_interest(): | |
571 | 666 | transformer = Transformer.from_proj( |
572 | 667 | 4326, 2964, area_of_interest=AreaOfInterest(-136.46, 49.0, -60.72, 83.17) |
573 | 668 | ) |
574 | assert transformer.description == "Inverse of NAD27 to WGS 84 (13) + Alaska Albers" | |
575 | ||
576 | ||
577 | def test_transformer__area_of_interest__invalid(aoi_data_directory): | |
669 | if not grids_available("ntv2_0.gsb", "ca_nrc_ntv2_0.tif"): | |
670 | assert ( | |
671 | transformer.description == "Inverse of NAD27 to WGS 84 (13) + Alaska Albers" | |
672 | ) | |
673 | else: | |
674 | assert ( | |
675 | transformer.description == "Inverse of NAD27 to WGS 84 (33) + Alaska Albers" | |
676 | ) | |
677 | ||
678 | ||
679 | def test_transformer__area_of_interest__invalid(): | |
578 | 680 | with pytest.raises(ProjError): |
579 | 681 | Transformer.from_crs( |
580 | 682 | 4326, 2964, area_of_interest=(-136.46, 49.0, -60.72, 83.17) |
581 | 683 | ) |
582 | 684 | |
583 | 685 | |
584 | def test_transformer_group__area_of_interest__invalid(aoi_data_directory): | |
686 | def test_transformer_group__area_of_interest__invalid(): | |
585 | 687 | with pytest.raises(ProjError): |
586 | 688 | TransformerGroup(4326, 2964, area_of_interest=(-136.46, 49.0, -60.72, 83.17)) |
587 | 689 | |
588 | 690 | |
589 | 691 | def test_transformer_equals(): |
590 | assert Transformer.from_crs(28356, 7856) == Transformer.from_crs(28356, 7856) | |
692 | assert ( | |
693 | TransformerGroup(28356, 7856).transformers[0] | |
694 | == TransformerGroup(28356, 7856).transformers[0] | |
695 | ) | |
591 | 696 | |
592 | 697 | |
593 | 698 | @pytest.mark.parametrize( |