Codebase list python-pyproj / ae79423
New upstream version 2.6.1~rc0+ds Bas Couwenberg 3 years ago
28 changed file(s) with 693 addition(s) and 346 deletion(s). Raw diff Collapse all Expand all
2323 "review",
2424 "question",
2525 "maintenance",
26 "infra"
26 "infra",
27 "bug"
2728 ]
2829 },
2930 {
4041 "infra",
4142 "ideas",
4243 "review",
43 "question"
44 "question",
45 "bug"
4446 ]
4547 },
4648 {
5557 "maintenance",
5658 "infra",
5759 "review",
58 "question"
60 "question",
61 "bug"
5962 ]
6063 },
6164 {
6871 "code",
6972 "ideas",
7073 "review",
71 "question"
74 "question",
75 "bug",
76 "test"
7277 ]
7378 },
7479 {
289294 "contributions": [
290295 "platform",
291296 "question",
292 "bug"
297 "bug",
298 "test"
293299 ]
294300 },
295301 {
341347 "ideas",
342348 "test"
343349 ]
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 ]
344362 }
345363 ],
346364 "contributorsPerLine": 7
00 [settings]
11 line_length=88
22 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
45 include_trailing_comma=true
2929 - python: 3.6
3030 - python: 3.6
3131 env:
32 - PROJ_NETWORK=ON
33 - python: 3.6
34 env:
35 - PROJSYNC=ALL
36 - python: 3.6
37 env:
3238 - PROJSOURCE=6.2.0
3339 - python: 3.6
3440 env:
3945 - python: 3.6
4046 env:
4147 - 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
4258 - python: 3.7
4359 env:
4460 - DOC=true
107123 ci/travis/proj-dl-and-compile "$PROJSOURCE"
108124 fi
109125 - 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
110130
111131 install:
112132 # coverage report requires a local install
3636 <!-- markdownlint-disable -->
3737 <table>
3838 <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>
4343 <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>
4444 <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>
4545 <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>
6868 <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>
6969 <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>
7070 <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>
7272 <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>
7373 </tr>
7474 <tr>
7676 <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>
7777 <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>
7878 <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>
7980 </tr>
8081 </table>
8182
2727 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2828 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2929 """
30 __version__ = "2.6.0"
30 __version__ = "2.6.1rc0"
3131 __all__ = [
3232 "Proj",
3333 "Geod",
4444 "get_units_map",
4545 "show_versions",
4646 ]
47
4847 import warnings
4948
5049 from pyproj import _datadir
6463 from pyproj.proj import Proj, pj_list, proj_version_str # noqa: F401
6564 from pyproj.transformer import Transformer, itransform, transform # noqa: F401
6665
66 __proj_version__ = proj_version_str
67
68
6769 try:
6870 _datadir.pyproj_global_context_initialize()
6971 except DataDirError as err:
66
77 import argparse
88
9 from pyproj import __version__, _show_versions, proj_version_str
9 from pyproj import __proj_version__, __version__, _show_versions
1010
1111 parser = argparse.ArgumentParser()
1212 parser.add_argument(
1919 if args.verbose:
2020 _show_versions.show_versions()
2121 else:
22 print("pyproj version: {} [PROJ version: {}]".format(__version__, proj_version_str))
22 print("pyproj version: {} [PROJ version: {}]".format(__version__, __proj_version__))
2323 parser.print_help()
11
22 from collections import namedtuple
33 from enum import IntEnum
4 import warnings
45
56 from pyproj.compat import cstrencode, pystrdecode
67 from pyproj.enums import PJType
7374 dict:
7475 Units supported by PROJ
7576 """
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 )
7683 cdef PJ_UNITS *proj_units = proj_list_units()
7784 cdef int iii = 0
7885 units_map = {}
94101 dict:
95102 Angular units supported by PROJ
96103 """
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 )
97111 cdef PJ_UNITS *proj_units = proj_list_angular_units()
98112 cdef int iii = 0
99113 units_map = {}
257257 Equivalent to `proj -S` command line.
258258 """
259259 cdef PyBuffWriteManager lonbuff = PyBuffWriteManager(longitude)
260 cdef PyBuffWriteManager latbuff = PyBuffWriteManager(longitude)
260 cdef PyBuffWriteManager latbuff = PyBuffWriteManager(latitude)
261261
262262 if not lonbuff.len or not (lonbuff.len == latbuff.len):
263263 raise ProjError('longitude and latitude must be same size')
4242
4343 blob = [
4444 ("pyproj", pyproj.__version__),
45 ("PROJ", pyproj.proj_version_str),
45 ("PROJ", pyproj.__proj_version__),
4646 ("data dir", data_dir),
4747 ]
4848
5252 prime_meridian = None
5353 prime_meridian_name = cf_params.get("prime_meridian_name")
5454 try:
55 ellipsoid = CustomPrimeMeridian(
55 prime_meridian = CustomPrimeMeridian(
5656 name=prime_meridian_name or "undefined",
57 longitude=cf_params["prime_meridian_longitude"],
57 longitude=cf_params["longitude_of_prime_meridian"],
5858 )
5959 except KeyError:
6060 if prime_meridian_name:
11351135 """
11361136 Parameters
11371137 ----------
1138 longitude_natural_origin: float, optional
1138 latitude_natural_origin: float, optional
11391139 Latitude of natural origin (lat_0). Defaults to 0.0.
11401140 longitude_natural_origin: float, optional
11411141 Longitude of natural origin (lon_0). Defaults to 0.0.
4343 if isinstance(value, (list, tuple)):
4444 value = ",".join([str(val) for val in value])
4545 # issue 183 (+ no_rot)
46 if value is None or value is True:
46 if value is None or str(value) == "True":
4747 pjargs.append("+{key}".format(key=key))
48 elif str(value) == str(False):
48 elif str(value) == "False":
4949 pass
5050 else:
5151 pjargs.append("+{key}={value}".format(key=key, value=value))
579579 CF-1.8 version of the projection.
580580
581581 """
582 unknown_names = ("unknown", "undefined")
583582 cf_dict = {"crs_wkt": self.to_wkt(wkt_version)} # type: Dict[str, Any]
584583
585584 # handle bound CRS
607606 vert_json = self.to_json_dict()
608607 if "geoid_model" in vert_json:
609608 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:
611610 cf_dict["geopotential_datum_name"] = self.datum.name
612611 return cf_dict
613612
618617 semi_minor_axis=self.ellipsoid.semi_minor_metre,
619618 inverse_flattening=self.ellipsoid.inverse_flattening,
620619 )
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
623621 if self.prime_meridian:
624622 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
627624
628625 # handle geographic CRS
629 if self.geodetic_crs and self.geodetic_crs.name not in unknown_names:
626 if self.geodetic_crs:
630627 cf_dict["geographic_crs_name"] = self.geodetic_crs.name
631628
632629 if self.is_geographic:
636633 self.coordinate_operation.method_name.lower()
637634 ](self.coordinate_operation)
638635 )
639 if self.datum and self.datum.name not in unknown_names:
636 if self.datum:
640637 cf_dict["horizontal_datum_name"] = self.datum.name
641638 else:
642639 cf_dict["grid_mapping_name"] = "latitude_longitude"
643640 return cf_dict
644641
645642 # 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:
647644 cf_dict["horizontal_datum_name"] = self.datum.name
648645 coordinate_operation = None
649646 if not self.is_bound and self.is_projected:
650647 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
653649 coordinate_operation_name = (
654650 None
655651 if not coordinate_operation
699695 -------
700696 CRS
701697 """
698 unknown_names = ("unknown", "undefined")
702699 if "crs_wkt" in in_cf:
703700 return CRS(in_cf["crs_wkt"])
704701 elif "spatial_ref" in in_cf: # for previous supported WKT key
724721 geographic_crs = GeographicCRS(
725722 name=geographic_crs_name or "undefined", datum=datum,
726723 ) # type: CRS
727 elif geographic_crs_name:
724 elif geographic_crs_name and geographic_crs_name not in unknown_names:
728725 geographic_crs = CRS(geographic_crs_name)
729726 else:
730727 geographic_crs = GeographicCRS()
906903
907904 def __eq__(self, other: Any) -> bool:
908905 return self.equals(other)
906
907 def __ne__(self, other: Any) -> bool:
908 return not self == other
909909
910910 def __reduce__(self) -> Tuple[Type["CRS"], Tuple[str]]:
911911 """special method that allows CRS instance to be pickled"""
2828
2929 class Proj(_Proj):
3030 """
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).
5534
5635 Attributes
5736 ----------
6645 self, projparams: Any = None, preserve_units: bool = True, **kwargs
6746 ) -> None:
6847 """
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.
7354
7455 Parameters
7556 ----------
149130 projstring = re.sub(r"\s\+?type=crs", "", projstring)
150131 super().__init__(cstrencode(projstring.strip()))
151132
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]:
154140 """
155141 Calling a Proj class instance with the arguments lon, lat will
156142 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).
163144
164145 Inputs should be doubles (they will be cast to doubles if they
165146 are not, causing a slight performance hit).
166147
167148 Works with numpy and regular python array objects, python
168149 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 """
173169 # 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)
176172 # call PROJ functions. inx and iny modified in place.
177173 if inverse:
178174 self._inv(inx, iny, errcheck=errcheck)
209205 radians: boolean, optional
210206 If True, will expect input data to be in radians.
211207 Default is False (degrees).
212 errcheck: boolean, optional (default False)
208 errcheck: boolean, optional
213209 If True an exception is raised if the errors are found in the process.
214210 By default errcheck=False and ``inf`` is returned.
215211
88 "TransformerGroup",
99 "AreaOfInterest",
1010 ]
11 import warnings
1112 from array import array
1213 from itertools import chain, islice
1314 from typing import Any, Iterable, Iterator, List, Optional, Tuple, Union
6768 The area of interest to help order the transformations based on the
6869 best operation for the area.
6970
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
8071 """
8172 super().__init__(
8273 CRS.from_user_input(crs_from),
372363 If True, will expect input data to be in radians and will return radians
373364 if the projection is geographic. Default is False (degrees). Ignored for
374365 pipeline transformations.
375 errcheck: boolean, optional (default False)
366 errcheck: boolean, optional
376367 If True an exception is raised if the transformation is invalid.
377368 By default errcheck=False and an invalid transformation
378369 returns ``inf`` and no exception is raised.
486477 If True, will expect input data to be in radians and will return radians
487478 if the projection is geographic. Default is False (degrees). Ignored for
488479 pipeline transformations.
489 errcheck: boolean, optional (default False)
480 errcheck: boolean, optional
490481 If True an exception is raised if the transformation is invalid.
491482 By default errcheck=False and an invalid transformation
492483 returns ``inf`` and no exception is raised.
684675 .. versionadded:: 2.1.2 skip_equivalent
685676 .. versionadded:: 2.2.0 always_xy
686677
678 .. warning:: This function is deprecated. See: :ref:`upgrade_transformer`
679
687680 x2, y2, z2 = transform(p1, p2, x1, y1, z1)
688681
689682 Transform points between two coordinate systems defined by the
753746 >>> '%8.3f %8.3f %8.3f %5.3f %5.3f %5.3f' % xy
754747 ' -92.220 -94.720 -90.370 38.830 39.320 38.750'
755748 """
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 )
756758 return Transformer.from_proj(
757759 p1, p2, skip_equivalent=skip_equivalent, always_xy=always_xy
758760 ).transform(xx=x, yy=y, zz=z, tt=tt, radians=radians, errcheck=errcheck)
772774 """
773775 .. versionadded:: 2.1.2 skip_equivalent
774776 .. versionadded:: 2.2.0 always_xy
777
778 .. warning:: This function is deprecated. See: :ref:`upgrade_transformer`
775779
776780 points2 = itransform(p1, p2, points1)
777781 Iterator/generator version of the function pyproj.transform.
826830 '30 60'
827831
828832 """
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 )
829842 return Transformer.from_proj(
830843 p1, p2, skip_equivalent=skip_equivalent, always_xy=always_xy
831844 ).itransform(
(New empty file)
00 import os
1 import shutil
2 import tempfile
1 from pathlib import Path
32
4 import pytest
5
6 import pyproj
3 from pyproj.datadir import get_data_dir
74
85
9 @pytest.fixture(scope="session")
10 def aoi_data_directory():
6 def grids_available(*grid_names):
117 """
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
149 """
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
00 import json
11 from distutils.version import LooseVersion
22
3 import numpy
34 import pytest
45
5 from pyproj import CRS, Transformer, proj_version_str
6 from pyproj import CRS, __proj_version__
67 from pyproj.crs import (
78 CoordinateOperation,
89 CoordinateSystem,
1314 from pyproj.crs.enums import CoordinateOperationType, DatumType
1415 from pyproj.enums import ProjVersion, WktVersion
1516 from pyproj.exceptions import CRSError
17 from pyproj.transformer import TransformerGroup
1618
1719
1820 class CustomCRS(object):
536538
537539 def test_coordinate_operation_grids():
538540 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 )
544553
545554
546555 def test_coordinate_operation_grids__alternative_grid_name():
550559 assert grid.direct_download is True
551560 assert grid.open_license is True
552561 assert grid.available is True
553 if LooseVersion(proj_version_str) >= LooseVersion("7.0.0"):
562 if LooseVersion(__proj_version__) >= LooseVersion("7.0.0"):
554563 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 )
556567 assert grid.package_name == ""
557568 assert grid.url == "https://cdn.proj.org/ca_nrc_ntv1_can.tif"
558569 else:
11021113
11031114 def test_equals_different_type():
11041115 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
11051123
11061124
11071125 def test_is_exact_same_different_type():
11851203 "proj": "ob_tran",
11861204 }
11871205 )
1188 if LooseVersion(proj_version_str) >= LooseVersion("6.3.0"):
1206 if LooseVersion(__proj_version__) >= LooseVersion("6.3.0"):
11891207 with pytest.warns(UserWarning):
11901208 assert crs.to_dict() == {
11911209 "R": 6371229,
12361254
12371255
12381256 def test_operations():
1239 transformer = Transformer.from_crs(28356, 7856)
1257 transformer = TransformerGroup(28356, 7856).transformers[0]
12401258 coord_op = CoordinateOperation.from_string(transformer.to_wkt())
12411259 assert coord_op.operations == transformer.operations
12421260
12431261
12441262 def test_operations__scope_remarks():
1245 transformer = Transformer.from_crs(28356, 7856)
1263
1264 transformer = TransformerGroup(28356, 7856).transformers[0]
12461265 coord_op = CoordinateOperation.from_string(transformer.to_wkt())
12471266 assert coord_op.operations == transformer.operations
12481267 # scope does not transfer for some reason
12791298 @pytest.mark.parametrize("crs_input", ["+proj=tmerc", "epsg:4326"])
12801299 def test_utm_zone__none(crs_input):
12811300 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
22 import pytest
33 from numpy.testing import assert_almost_equal
44
5 from pyproj import CRS, proj_version_str
5 from pyproj import CRS, __proj_version__
66 from pyproj.crs import ProjectedCRS
77 from pyproj.crs._cf1x8 import _try_list_if_string
88 from pyproj.crs.coordinate_operation import (
7272 "false_easting": 2520000.0,
7373 "false_northing": 0.0,
7474 "scale_factor_at_central_meridian": 0.9996,
75 "geographic_crs_name": "unknown",
76 "projected_crs_name": "unknown",
7577 }
7678 cf_dict = crs.to_cf()
7779 assert cf_dict.pop("crs_wkt").startswith("BOUNDCRS[")
128130 "false_easting": 2520000.0,
129131 "false_northing": 0.0,
130132 "scale_factor_at_central_meridian": 1.0,
133 "geographic_crs_name": "undefined",
134 "projected_crs_name": "undefined",
135 "horizontal_datum_name": "undefined",
131136 }
132137 cf_dict = crs.to_cf()
133138 assert cf_dict.pop("crs_wkt").startswith("BOUNDCRS[")
153158 "longitude_of_prime_meridian": 0.0,
154159 "prime_meridian_name": "Greenwich",
155160 "grid_mapping_name": "latitude_longitude",
161 "geographic_crs_name": "undefined",
162 "reference_ellipsoid_name": "undefined",
156163 }
157164 cf_dict = crs.to_cf()
158165 assert cf_dict.pop("crs_wkt").startswith("GEOGCRS[")
252259 "grid_north_pole_latitude": 32.5,
253260 "grid_north_pole_longitude": 170.0,
254261 "north_pole_grid_longitude": 0.0,
262 "geographic_crs_name": "undefined",
255263 }
256264 cf_dict = crs.to_cf()
257265 assert cf_dict.pop("crs_wkt").startswith("GEOGCRS[")
260268 _test_roundtrip(expected_cf, "GEOGCRS[")
261269 with pytest.warns(UserWarning):
262270 proj_dict = crs.to_dict()
263 if LooseVersion(proj_version_str) >= LooseVersion("6.3.0"):
271 if LooseVersion(__proj_version__) >= LooseVersion("6.3.0"):
264272 assert proj_dict == {
265273 "proj": "ob_tran",
266274 "o_proj": "longlat",
286294 )
287295 with pytest.warns(UserWarning):
288296 proj_dict = crs.to_dict()
289 if LooseVersion(proj_version_str) >= LooseVersion("6.3.0"):
297 if LooseVersion(__proj_version__) >= LooseVersion("6.3.0"):
290298 assert proj_dict == {
291299 "proj": "ob_tran",
292300 "o_proj": "longlat",
323331 "false_easting": 0.0,
324332 "false_northing": 0.0,
325333 "standard_parallel": 25.0,
334 "geographic_crs_name": "undefined",
335 "projected_crs_name": "undefined",
326336 }
327337 cf_dict = crs.to_cf()
328338 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
371381 "longitude_of_central_meridian": 265.0,
372382 "false_easting": 0.0,
373383 "false_northing": 0.0,
384 "geographic_crs_name": "undefined",
385 "projected_crs_name": "undefined",
374386 }
375387 cf_dict = crs.to_cf()
376388 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
421433 "scale_factor_at_projection_origin": 1.0,
422434 "false_easting": 0.0,
423435 "false_northing": 0.0,
436 "geographic_crs_name": "undefined",
437 "projected_crs_name": "undefined",
438 "horizontal_datum_name": "undefined",
424439 }
425440 cf_dict = crs.to_cf()
426441 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
493508 "longitude_of_projection_origin": 0.0,
494509 "false_easting": 0.0,
495510 "false_northing": 0.0,
511 "geographic_crs_name": "undefined",
512 "projected_crs_name": "undefined",
496513 }
497514 cf_dict = crs.to_cf()
498515 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
524541 "longitude_of_projection_origin": 0.0,
525542 "false_easting": 0.0,
526543 "false_northing": 0.0,
544 "geographic_crs_name": "undefined",
545 "projected_crs_name": "undefined",
527546 }
528547 cf_dict = crs.to_cf()
529548 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
547566 "longitude_of_projection_origin": 0.0,
548567 "false_easting": 0.0,
549568 "false_northing": 0.0,
569 "geographic_crs_name": "unknown",
570 "horizontal_datum_name": "unknown",
571 "projected_crs_name": "unknown",
572 "reference_ellipsoid_name": "unknown",
550573 }
551574 cf_dict = crs.to_cf()
552575 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
586609 "longitude_of_projection_origin": 10.0,
587610 "false_easting": 0.0,
588611 "false_northing": 0.0,
612 "geographic_crs_name": "undefined",
613 "projected_crs_name": "undefined",
589614 }
590615 with pytest.warns(UserWarning):
591616 assert crs.to_dict() == {
663688
664689
665690 @pytest.mark.skipif(
666 LooseVersion(proj_version_str) < LooseVersion("6.3.0"),
691 LooseVersion(__proj_version__) < LooseVersion("6.3.0"),
667692 reason="geoid model does not work in PROJ < 6.3.0",
668693 )
669694 def test_geoid_model_name():
810835 "longitude_of_projection_origin": 2.0,
811836 "false_easting": 3.0,
812837 "false_northing": 4.0,
838 "geographic_crs_name": "undefined",
839 "projected_crs_name": "undefined",
813840 }
814841 cf_dict = crs.to_cf()
815842 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
833860 "longitude_of_central_meridian": 2.0,
834861 "false_easting": 3.0,
835862 "false_northing": 4.0,
863 "geographic_crs_name": "undefined",
864 "projected_crs_name": "undefined",
836865 }
837866 cf_dict = crs.to_cf()
838867 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
857886 "false_easting": 3.0,
858887 "false_northing": 4.0,
859888 "scale_factor_at_projection_origin": 1.0,
889 "geographic_crs_name": "undefined",
890 "projected_crs_name": "undefined",
860891 }
861892 cf_dict = crs.to_cf()
862893 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
880911 "longitude_of_projection_origin": 2.0,
881912 "false_easting": 3.0,
882913 "false_northing": 4.0,
914 "geographic_crs_name": "undefined",
915 "projected_crs_name": "undefined",
883916 }
884917 cf_dict = crs.to_cf()
885918 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
904937 "false_easting": 2.0,
905938 "false_northing": 3.0,
906939 "scale_factor_at_projection_origin": 1.0,
940 "geographic_crs_name": "undefined",
941 "projected_crs_name": "undefined",
907942 }
908943 cf_dict = crs.to_cf()
909944 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
927962 "straight_vertical_longitude_from_pole": 1.0,
928963 "false_easting": 2.0,
929964 "false_northing": 3.0,
965 "geographic_crs_name": "undefined",
966 "projected_crs_name": "undefined",
930967 }
931968 cf_dict = crs.to_cf()
932969 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
951988 "false_easting": 2.0,
952989 "false_northing": 3.0,
953990 "scale_factor_at_projection_origin": 1.0,
991 "geographic_crs_name": "undefined",
992 "projected_crs_name": "undefined",
954993 }
955994 cf_dict = crs.to_cf()
956995 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
9731012 "longitude_of_projection_origin": 0.0,
9741013 "false_easting": 1.0,
9751014 "false_northing": 2.0,
1015 "geographic_crs_name": "undefined",
1016 "projected_crs_name": "undefined",
9761017 }
9771018 cf_dict = crs.to_cf()
9781019 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
9971038 "longitude_of_projection_origin": 1.0,
9981039 "false_easting": 2.0,
9991040 "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.")
22 import pytest
33 from numpy.testing import assert_almost_equal
44
5 from pyproj import proj_version_str
5 from pyproj import __proj_version__
66 from pyproj.crs import GeographicCRS
77 from pyproj.crs.coordinate_operation import (
88 AlbersEqualAreaConversion,
616616
617617 def test_lambert_cylindrical_equal_area_scale_operation__defaults():
618618 lceaop = LambertCylindricalEqualAreaScaleConversion()
619 if LooseVersion(proj_version_str) >= LooseVersion("6.3.1"):
619 if LooseVersion(__proj_version__) >= LooseVersion("6.3.1"):
620620 assert lceaop.name == "unknown"
621621 assert lceaop.method_name == "Lambert Cylindrical Equal Area"
622622 assert _to_dict(lceaop) == {
641641 false_northing=4,
642642 scale_factor_natural_origin=0.999,
643643 )
644 if LooseVersion(proj_version_str) >= LooseVersion("6.3.1"):
644 if LooseVersion(__proj_version__) >= LooseVersion("6.3.1"):
645645 assert lceaop.name == "unknown"
646646 assert lceaop.method_name == "Lambert Cylindrical Equal Area"
647647 op_dict = _to_dict(lceaop)
11
22 import pytest
33
4 from pyproj import proj_version_str
4 from pyproj import __proj_version__
55 from pyproj.crs import (
66 BoundCRS,
77 CompoundCRS,
6161 assert vc.name == "NAVD88 height"
6262 assert vc.type_name == "Vertical CRS"
6363 assert vc.coordinate_system == VerticalCS()
64 if LooseVersion(proj_version_str) >= LooseVersion("6.3.0"):
64 if LooseVersion(__proj_version__) >= LooseVersion("6.3.0"):
6565 assert vc.to_json_dict()["geoid_model"]["name"] == "GEOID12B"
6666
6767
22 import numpy
33 from numpy.testing import assert_allclose
44
5 from pyproj import Proj, proj_version_str
5 from pyproj import Proj, __proj_version__
66
77 try:
88 from time import perf_counter
2525 # awips221 = Proj(params)
2626 # or keyword args
2727 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__)
2929 # AWIPS grid 221 parameters
3030 # (from http://www.nco.ncep.noaa.gov/pmb/docs/on388/tableb.html)
3131 llcrnrx, llcrnry = awips221(-145.5, 1.0)
22 import pytest
33 from numpy.testing import assert_almost_equal
44
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
67
78
89 @pytest.mark.parametrize("proj_class", [Proj, CRS])
9 def test_datum(proj_class, aoi_data_directory):
10 def test_datum(proj_class):
1011 p1 = proj_class(proj="latlong", datum="WGS84")
1112 s_1 = -111.5
1213 s_2 = 45.25919444444
1314 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 )
1721 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)
00 import pytest
11 from numpy.testing import assert_almost_equal
22
3 from pyproj import Proj, proj_version_str, transform
3 from pyproj import Proj, transform
44
55 # illustrates the use of the transform function to
66 # perform coordinate transformations with datum shifts.
3232 GAUSSSB_PROJ = Proj(
3333 init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
3434 )
35 print("proj4 library version = ", proj_version_str)
3635
3736
3837 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 )
4242 assert_almost_equal((xutm33, yutm33, zutm33), (UTM_x, UTM_y, UTM_z))
4343
4444
4545 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 )
4750 assert_almost_equal((back_lon, back_lat, back_z), (WGS84_lon, WGS84_lat, WGS84_z))
4851
4952
5053 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)
5256 assert_almost_equal((xgb, ygb, zgb), (GB_x, 5055619.899, 0), decimal=2)
5357
5458
5559 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)
5762 assert_almost_equal(
5863 (back_lon, back_lat, back_z), (WGS84_lon, WGS84_lat, 0), decimal=3
5964 )
00 """
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
32 """
43 import doctest
54 import os
76 import sys
87 import warnings
98
9 import pytest
10
1011 import pyproj
1112
1213
13 def test_doctests(aoi_data_directory):
14 def test_doctests():
1415 """run the examples in the docstrings using the doctest module"""
1516
1617 with warnings.catch_warnings():
2324 failure_count_proj, test_count = doctest.testmod(pyproj.proj, verbose=True)
2425 failure_count_crs, test_count_crs = doctest.testmod(pyproj.crs, verbose=True)
2526 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 )
2931
3032 failure_count = (
3133 failure_count_proj
1414
1515
1616 def test_units_map():
17 units_map = get_units_map()
17 with pytest.warns(DeprecationWarning):
18 units_map = get_units_map()
1819 assert isinstance(units_map["m"], Unit)
1920 assert units_map["m"].id == "m"
2021 assert units_map["m"].name == "Meter"
2122
2223
2324 def test_angular_units_map():
24 ang_map = get_angular_units_map()
25 with pytest.warns(DeprecationWarning):
26 ang_map = get_angular_units_map()
2527 assert isinstance(ang_map["deg"], Unit)
2628 assert ang_map["deg"].id == "deg"
2729 assert ang_map["deg"].name == "Degree"
124124 def test_tranform_none_1st_parmeter(self):
125125 # test should raise Type error if projections are not of Proj classes
126126 # version 1.9.4 produced AttributeError, now should raise TypeError
127 with self.assertRaises(CRSError):
127 with pytest.warns(DeprecationWarning), pytest.raises(CRSError):
128128 transform(None, self.p, -74, 39)
129129
130130 def test_tranform_none_2nd_parmeter(self):
131131 # test should raise Type error if projections are not of Proj classes
132132 # 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):
134134 transform(self.p, None, -74, 39)
135135
136136
149149 p = Proj("+proj=stere +lon_0=-39 +lat_0=90 +lat_ts=71.0 +ellps=WGS84")
150150 self.assertTrue(isinstance(p, Proj))
151151 # 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)
153154
154155
155156 @unittest.skipIf(
431432 longitude=longitude, latitude=latitude, radians=radians
432433 )
433434 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]],
441442 )
442443 assert_almost_equal(factors.angular_distortion, [[0, 0], [0, 0]], decimal=5)
443444 assert_almost_equal(
444 factors.meridian_parallel_angle, [[90, 90], [90, 90]],
445 factors.meridian_parallel_angle, [[89.99, 90], [90, 90]], decimal=2
445446 )
446447 assert_almost_equal(factors.meridian_convergence, [[0, 0], [0, 0]])
447448 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]],
452453 )
453454 assert_almost_equal(
454455 factors.dx_dlam, [[1, 1], [1, 1]],
456457 assert_almost_equal(factors.dx_dphi, [[0, 0], [0, 0]])
457458 assert_almost_equal(factors.dy_dlam, [[0, 0], [0, 0]])
458459 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)
461479
462480
463481 def test_get_factors__nan_inf():
465483 factors = transformer.get_factors(
466484 longitude=[0, np.nan, np.inf, 0], latitude=[np.nan, 2, 2, np.inf]
467485 )
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])
480500
481501
482502 def test_get_factors__errcheck():
485505 transformer.get_factors(longitude=40, latitude=70, errcheck=True, radians=True)
486506
487507
488 def test_numpy_bool_kwarg():
489 # Issue 546
508 def test_numpy_bool_kwarg_false():
509 # Issue 564
490510 south = np.array(50) < 0
491511 proj = Proj(
492512 proj="utm", zone=32, ellipsis="WGS84", datum="WGS84", units="m", south=south
493513 )
494514 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
00 import numpy
1 import pytest
12 from numpy.testing import assert_allclose
23
3 from pyproj import Proj, proj_version_str, transform
4 from pyproj import Proj, __proj_version__, transform
45
56
67 def test_transform():
1112 dx = 12190.58
1213 dy = dx
1314 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__)
1516 llcrnrx, llcrnry = awips221(-145.5, 1)
1617 awips221 = Proj(
1718 proj="lcc",
3435 print("max/min x and y for awips218 grid")
3536 print(numpy.minimum.reduce(numpy.ravel(x1)), numpy.maximum.reduce(numpy.ravel(x1)))
3637 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)
3840 print("max/min x and y for awips218 grid in awips221 coordinates")
3941 print(numpy.minimum.reduce(numpy.ravel(x2)), numpy.maximum.reduce(numpy.ravel(x2)))
4042 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)
4245 print("error for reverse transformation back to awips218 coords")
4346 print("(should be close to zero)")
4447 assert_allclose(numpy.minimum.reduce(numpy.ravel(x3 - x1)), 0, atol=1e-4)
4851
4952
5053 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)
5256 assert (xeq, yeq) == (30, 60)
44 from numpy.testing import assert_almost_equal
55
66 import pyproj
7 from pyproj import Proj, Transformer, itransform, transform
7 from pyproj import Proj, Transformer, __proj_version__, itransform, transform
88 from pyproj.enums import TransformDirection
99 from pyproj.exceptions import ProjError
1010 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")
1114
1215
1316 def test_tranform_wgs84_to_custom():
1720 )
1821 wgs84 = pyproj.Proj("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
1922 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)
2125 assert "{:.3f} {:.3f}".format(xx, yy) == "212.623 4604.975"
2226
2327
2630 lat_lon_proj = pyproj.Proj(init="epsg:4326", preserve_units=False)
2731 alaska_aea_proj = pyproj.Proj(init="epsg:2964", preserve_units=False)
2832 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)
3035 assert "{:.3f} {:.3f}".format(xx, yy) == "-1824924.495 330822.800"
3136
3237
3540 with pytest.warns(FutureWarning):
3641 p1 = pyproj.Proj(init="epsg:4326")
3742 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 )
4147 assert np.all(np.isinf(xx))
4248 assert np.all(np.isinf(yy))
43 with pytest.raises(ProjError):
49 with pytest.warns(DeprecationWarning), pytest.raises(ProjError):
4450 pyproj.transform(
4551 p1, p2, (-180, -180, 180, 180, -180), (-90, 90, 90, -90, -90), errcheck=True
4652 )
5561 E = 567623.931
5662 N = 256422.787
5763 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)
6066 assert_almost_equal((Long1, Lat1, H1), (-4.6753456, 32.902199, 1341.467), decimal=5)
6167
6268
147153
148154
149155 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 )
154163
155164
156165 def test_4d_transform_crs_obs2():
172181
173182
174183 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 )
179189
180190
181191 def test_4d_itransform():
203213
204214
205215 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 )
212225
213226
214227 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 )
221237
222238
223239 def test_itransform_time_3rd_invalid():
224240
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 ):
226244 list(
227245 itransform(
228246 7789,
231249 time_3rd=True,
232250 )
233251 )
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 ):
235255 list(itransform(7789, 8401, [(3496737.2679, 743254.4507)], time_3rd=True))
236256
237257
239259 with pytest.warns(FutureWarning):
240260 pj = Proj(init="epsg:4555")
241261 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)
243264
244265
245266 def test_itransform_no_error():
246267 with pytest.warns(FutureWarning):
247268 pj = Proj(init="epsg:4555")
248269 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))
250272
251273
252274 def test_transform_no_exception():
260282 def test_transform__out_of_bounds():
261283 with pytest.warns(FutureWarning):
262284 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"):
264286 with pytest.raises(pyproj.exceptions.ProjError):
265287 transformer.transform(100000, 100000, errcheck=True)
266288 else:
271293 with pytest.warns(FutureWarning):
272294 WGS84 = pyproj.Proj("+init=EPSG:4326")
273295 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 )
292315
293316
294317 def test_itransform_radians():
295318 with pytest.warns(FutureWarning):
296319 WGS84 = pyproj.Proj("+init=EPSG:4326")
297320 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 )
318345
319346
320347 def test_4d_transform__inverse():
353380
354381
355382 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 )
360388
361389
362390 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 )
367396
368397
369398 def test_transform_direction__string():
422451 assert str(Transformer.from_crs(4326, 3857)).startswith("proj=pipeline")
423452
424453
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
447492
448493
449494 def test_to_json_dict():
474519
475520
476521 def test_transformer__operations():
477 transformer = Transformer.from_crs(28356, 7856)
522 transformer = TransformerGroup(28356, 7856).transformers[0]
478523 assert [op.name for op in transformer.operations] == [
479524 "Inverse of Map Grid of Australia zone 56",
480525 "GDA94 to GDA2020 (1)",
487532
488533
489534 def test_transformer__operations__scope_remarks():
490 transformer = Transformer.from_crs(28356, 7856)
535 transformer = TransformerGroup(28356, 7856).transformers[0]
491536 assert transformer.scope is None
492537 assert [op.scope for op in transformer.operations] == [
493538 None,
511556 assert trans_group.best_available
512557
513558
514 def test_transformer_group__unavailable(aoi_data_directory):
559 def test_transformer_group__unavailable():
515560 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():
526582 with pytest.warns(FutureWarning):
527583 lat_lon_proj = pyproj.Proj(init="epsg:4326", preserve_units=False)
528584 alaska_aea_proj = pyproj.Proj(init="epsg:2964", preserve_units=False)
529585
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
533600 trans_group = pyproj.transformer.TransformerGroup(
534601 lat_lon_proj.crs, alaska_aea_proj.crs
535602 )
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 )
553638
554639
555640 def test_transformer_group__get_transform_crs():
556641 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
559647 else:
560648 assert len(tg.transformers) == 4
561649
562650
563 def test_transformer__area_of_interest(aoi_data_directory):
651 def test_transformer__area_of_interest():
564652 transformer = Transformer.from_crs(
565653 4326, 2964, area_of_interest=AreaOfInterest(-136.46, 49.0, -60.72, 83.17)
566654 )
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():
571666 transformer = Transformer.from_proj(
572667 4326, 2964, area_of_interest=AreaOfInterest(-136.46, 49.0, -60.72, 83.17)
573668 )
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():
578680 with pytest.raises(ProjError):
579681 Transformer.from_crs(
580682 4326, 2964, area_of_interest=(-136.46, 49.0, -60.72, 83.17)
581683 )
582684
583685
584 def test_transformer_group__area_of_interest__invalid(aoi_data_directory):
686 def test_transformer_group__area_of_interest__invalid():
585687 with pytest.raises(ProjError):
586688 TransformerGroup(4326, 2964, area_of_interest=(-136.46, 49.0, -60.72, 83.17))
587689
588690
589691 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 )
591696
592697
593698 @pytest.mark.parametrize(