New upstream version 2.2.2+ds
Bas Couwenberg
4 years ago
10 | 10 | global: |
11 | 11 | - PROJ_BASE_DIR=$HOME/proj_install |
12 | 12 | - CYTHON_COVERAGE=True |
13 | - PROJSOURCE=6.1.0 | |
13 | - PROJSOURCE=6.1.1 | |
14 | 14 | # Following generated with |
15 | 15 | - WHEELHOUSE_UPLOADER_USERNAME=travis-worker |
16 | 16 | # Following generated by |
25 | 25 | os: osx |
26 | 26 | env: |
27 | 27 | - PYTHON=3.6.8 |
28 | - PROJSOURCE=6.1.0 | |
28 | - PROJSOURCE=6.1.1 | |
29 | 29 | - python: 2.7 |
30 | 30 | env: |
31 | - PROJSOURCE=6.1.0 | |
31 | - PROJSOURCE=6.1.1 | |
32 | 32 | - python: 3.5 |
33 | env: | |
34 | - PROJSOURCE=6.1.1 | |
35 | - python: 3.6 | |
33 | 36 | env: |
34 | 37 | - PROJSOURCE=6.1.0 |
35 | 38 | - python: 3.6 |
36 | 39 | env: |
37 | - PROJSOURCE=6.1.0 | |
40 | - PROJSOURCE=6.1.1 | |
38 | 41 | - python: 3.7 |
39 | 42 | dist: xenial |
40 | 43 | env: |
41 | - PROJSOURCE=6.1.0 | |
44 | - PROJSOURCE=6.1.1 | |
42 | 45 | - DOC=true |
43 | 46 | - python: "nightly" |
44 | 47 | env: |
87 | 90 | - pip install coveralls |
88 | 91 | |
89 | 92 | script: |
90 | - python -c "import pyproj; pyproj.Proj(init='epsg:4269')" | |
93 | - python -c "import pyproj; pyproj.Proj('epsg:4269')" | |
91 | 94 | - make test-coverage |
92 | 95 | # Building and uploading docs with doctr |
93 | 96 | - set -e |
26 | 26 | PYTHON_ARCH: "64" |
27 | 27 | VS_VERSION: Visual Studio 14 |
28 | 28 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 |
29 | PROJSOURCE: 6.1.0 | |
29 | PROJSOURCE: 6.1.1 | |
30 | 30 | # - PYTHON: "C:\\Python37-x64" |
31 | 31 | # PYTHON_VERSION: "3.7" |
32 | 32 | # PYTHON_ARCH: "64" |
33 | 33 | # VS_VERSION: Visual Studio 14 |
34 | 34 | # APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 |
35 | # PROJSOURCE: 6.1.0 | |
35 | # PROJSOURCE: 6.1.1 | |
36 | 36 | # - PYTHON: "C:\\Python36-x64" |
37 | 37 | # PYTHON_VERSION: "3.6" |
38 | 38 | # PYTHON_ARCH: "64" |
120 | 120 | |
121 | 121 | test_script: |
122 | 122 | # Run the project tests |
123 | - "%CMD_IN_ENV% python -c \"import pyproj; pyproj.Proj(init='epsg:4269')\"" | |
123 | - "%CMD_IN_ENV% python -c \"import pyproj; pyproj.Proj('epsg:4269')\"" | |
124 | 124 | - "%CMD_IN_ENV% py.test --cov-report term-missing --cov=pyproj -v -s" |
125 | 125 | |
126 | 126 | after_test: |
139 | 139 | # - "%CMD_IN_ENV% python setup.py bdist_msi" |
140 | 140 | # test wheel |
141 | 141 | - pip install pyproj --ignore-installed -f dist |
142 | - python -c "import pyproj; pyproj.Proj(init='epsg:4269')" | |
142 | - python -c "import pyproj; pyproj.Proj('epsg:4269')" | |
143 | 143 | # cleanup for test dir |
144 | 144 | - if %PROJSOURCE% == git del /F /Q dist\* |
145 | 145 | - ps: "ls dist" |
46 | 46 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
47 | 47 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
48 | 48 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ |
49 | __version__ = "2.2.1" | |
49 | __version__ = "2.2.2" | |
50 | 50 | __all__ = [ |
51 | 51 | "Proj", |
52 | 52 | "Geod", |
0 | 0 | include "proj.pxi" |
1 | 1 | |
2 | 2 | cdef class Axis: |
3 | cdef public object name | |
4 | cdef public object abbrev | |
5 | cdef public object direction | |
6 | cdef public double unit_conversion_factor | |
7 | cdef public object unit_name | |
8 | cdef public object unit_auth_code | |
9 | cdef public object unit_code | |
3 | cdef readonly object name | |
4 | cdef readonly object abbrev | |
5 | cdef readonly object direction | |
6 | cdef readonly double unit_conversion_factor | |
7 | cdef readonly object unit_name | |
8 | cdef readonly object unit_auth_code | |
9 | cdef readonly object unit_code | |
10 | 10 | |
11 | 11 | @staticmethod |
12 | 12 | cdef create(PJ_CONTEXT* projcontext, PJ* projobj, int index) |
13 | 13 | |
14 | 14 | cdef class AreaOfUse: |
15 | cdef public double west | |
16 | cdef public double south | |
17 | cdef public double east | |
18 | cdef public double north | |
19 | cdef public object name | |
15 | cdef readonly double west | |
16 | cdef readonly double south | |
17 | cdef readonly double east | |
18 | cdef readonly double north | |
19 | cdef readonly object name | |
20 | 20 | |
21 | 21 | @staticmethod |
22 | 22 | cdef create(PJ_CONTEXT* projcontext, PJ* projobj) |
25 | 25 | cdef class Base: |
26 | 26 | cdef PJ *projobj |
27 | 27 | cdef PJ_CONTEXT *projctx |
28 | cdef public object name | |
28 | cdef readonly object name | |
29 | 29 | |
30 | 30 | |
31 | 31 | cdef class Ellipsoid(Base): |
32 | 32 | cdef double _semi_major_metre |
33 | 33 | cdef double _semi_minor_metre |
34 | cdef public object is_semi_minor_computed | |
34 | cdef readonly object is_semi_minor_computed | |
35 | 35 | cdef double _inv_flattening |
36 | cdef public object ellipsoid_loaded | |
36 | cdef readonly object ellipsoid_loaded | |
37 | 37 | |
38 | 38 | @staticmethod |
39 | 39 | cdef create(PJ* ellipsoid_pj) |
40 | 40 | |
41 | 41 | cdef class PrimeMeridian(Base): |
42 | cdef public double longitude | |
43 | cdef public double unit_conversion_factor | |
44 | cdef public object unit_name | |
42 | cdef readonly double longitude | |
43 | cdef readonly double unit_conversion_factor | |
44 | cdef readonly object unit_name | |
45 | 45 | |
46 | 46 | @staticmethod |
47 | 47 | cdef create(PJ* prime_meridian_pj) |
48 | 48 | |
49 | 49 | |
50 | 50 | cdef class Datum(Base): |
51 | cdef public object _ellipsoid | |
52 | cdef public object _prime_meridian | |
51 | cdef readonly object _ellipsoid | |
52 | cdef readonly object _prime_meridian | |
53 | 53 | |
54 | 54 | @staticmethod |
55 | 55 | cdef create(PJ* datum_pj) |
56 | 56 | |
57 | 57 | |
58 | 58 | cdef class CoordinateSystem(Base): |
59 | cdef public object _axis_list | |
59 | cdef readonly object _axis_list | |
60 | 60 | |
61 | 61 | @staticmethod |
62 | 62 | cdef create(PJ* coordinate_system_pj) |
63 | 63 | |
64 | 64 | |
65 | 65 | cdef class Param: |
66 | cdef public object name | |
67 | cdef public object auth_name | |
68 | cdef public object code | |
69 | cdef public object value | |
70 | cdef public double unit_conversion_factor | |
71 | cdef public object unit_name | |
72 | cdef public object unit_auth_name | |
73 | cdef public object unit_code | |
74 | cdef public object unit_category | |
66 | cdef readonly object name | |
67 | cdef readonly object auth_name | |
68 | cdef readonly object code | |
69 | cdef readonly object value | |
70 | cdef readonly double unit_conversion_factor | |
71 | cdef readonly object unit_name | |
72 | cdef readonly object unit_auth_name | |
73 | cdef readonly object unit_code | |
74 | cdef readonly object unit_category | |
75 | 75 | |
76 | 76 | @staticmethod |
77 | 77 | cdef create(PJ_CONTEXT* projcontext, PJ* projobj, int param_idx) |
78 | 78 | |
79 | 79 | |
80 | 80 | cdef class Grid: |
81 | cdef public object short_name | |
82 | cdef public object full_name | |
83 | cdef public object package_name | |
84 | cdef public object url | |
85 | cdef public object direct_download | |
86 | cdef public object open_license | |
87 | cdef public object available | |
81 | cdef readonly object short_name | |
82 | cdef readonly object full_name | |
83 | cdef readonly object package_name | |
84 | cdef readonly object url | |
85 | cdef readonly object direct_download | |
86 | cdef readonly object open_license | |
87 | cdef readonly object available | |
88 | 88 | |
89 | 89 | @staticmethod |
90 | 90 | cdef create(PJ_CONTEXT* projcontext, PJ* projobj, int grid_idx) |
91 | 91 | |
92 | 92 | |
93 | 93 | cdef class CoordinateOperation(Base): |
94 | cdef public object _params | |
95 | cdef public object _grids | |
96 | cdef public object method_name | |
97 | cdef public object method_auth_name | |
98 | cdef public object method_code | |
99 | cdef public double accuracy | |
100 | cdef public object is_instantiable | |
101 | cdef public object has_ballpark_transformation | |
102 | cdef public object _towgs84 | |
94 | cdef readonly object _params | |
95 | cdef readonly object _grids | |
96 | cdef readonly object method_name | |
97 | cdef readonly object method_auth_name | |
98 | cdef readonly object method_code | |
99 | cdef readonly double accuracy | |
100 | cdef readonly object is_instantiable | |
101 | cdef readonly object has_ballpark_transformation | |
102 | cdef readonly object _towgs84 | |
103 | 103 | |
104 | 104 | @staticmethod |
105 | 105 | cdef create(PJ* coordinate_operation_pj) |
109 | 109 | cdef PJ_TYPE _type |
110 | 110 | cdef PJ_PROJ_INFO projpj_info |
111 | 111 | cdef char *pjinitstring |
112 | cdef public object srs | |
113 | cdef public object type_name | |
112 | cdef readonly object srs | |
113 | cdef readonly object type_name | |
114 | 114 | cdef object _ellipsoid |
115 | 115 | cdef object _area_of_use |
116 | 116 | cdef object _prime_meridian |
35 | 35 | """ |
36 | 36 | tmp_string = cstrencode(proj_string) |
37 | 37 | return proj_context_guess_wkt_dialect(NULL, tmp_string) != PJ_GUESSED_NOT_WKT |
38 | ||
39 | ||
40 | def is_proj(proj_string): | |
41 | """ | |
42 | Check if the input projection string is in the PROJ format. | |
43 | ||
44 | Parameters | |
45 | ---------- | |
46 | proj_string: str | |
47 | The projection string. | |
48 | ||
49 | Returns | |
50 | ------- | |
51 | bool: True if the string is in the PROJ format | |
52 | """ | |
53 | return not is_wkt(proj_string) and "=" in proj_string | |
38 | 54 | |
39 | 55 | |
40 | 56 | cdef _to_wkt(PJ_CONTEXT* projctx, PJ* projobj, version=WktVersion.WKT2_2018, pretty=False): |
281 | 297 | cdef class Base: |
282 | 298 | def __cinit__(self): |
283 | 299 | self.projobj = NULL |
284 | self.projctx = get_pyproj_context() | |
300 | self.projctx = NULL | |
285 | 301 | self.name = "undefined" |
286 | 302 | |
287 | 303 | def __dealloc__(self): |
290 | 306 | proj_destroy(self.projobj) |
291 | 307 | if self.projctx != NULL: |
292 | 308 | proj_context_destroy(self.projctx) |
309 | ||
310 | def __init__(self): | |
311 | self.projctx = get_pyproj_context() | |
293 | 312 | |
294 | 313 | def _set_name(self): |
295 | 314 | """ |
1285 | 1304 | self.type_name = "undefined" |
1286 | 1305 | |
1287 | 1306 | def __init__(self, proj_string): |
1307 | self.projctx = get_pyproj_context() | |
1288 | 1308 | # initialize projection |
1289 | 1309 | self.projobj = proj_create(self.projctx, cstrencode(proj_string)) |
1290 | 1310 | if self.projobj is NULL: |
1526 | 1546 | pyproj.CRS: The geodetic CRS from this CRS. |
1527 | 1547 | """ |
1528 | 1548 | warnings.warn( |
1529 | "This method is deprecated an has been replaced with `CRS.geodetic_crs`." | |
1549 | "This method is deprecated an has been replaced with `CRS.geodetic_crs`.", | |
1550 | DeprecationWarning, | |
1530 | 1551 | ) |
1531 | 1552 | return self.geodetic_crs |
1532 | 1553 | |
1546 | 1567 | the source CRS: |
1547 | 1568 | |
1548 | 1569 | >>> from pyproj import CRS |
1549 | >>> ccs = CRS("+init=epsg:4328 +towgs84=0,0,0") | |
1570 | >>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0") | |
1550 | 1571 | >>> ccs.to_epsg() |
1551 | 1572 | >>> ccs.source_crs.to_epsg() |
1552 | 1573 | 4978 |
1586 | 1607 | the source CRS: |
1587 | 1608 | |
1588 | 1609 | >>> from pyproj import CRS |
1589 | >>> ccs = CRS("+init=epsg:4328 +towgs84=0,0,0") | |
1610 | >>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0") | |
1590 | 1611 | >>> ccs.to_authority() |
1591 | 1612 | >>> ccs.source_crs.to_authority() |
1592 | 1613 | ('EPSG', '4978') |
1764 | 1785 | ------- |
1765 | 1786 | bool: True if CRS is valid. |
1766 | 1787 | """ |
1767 | warnings.warn("CRS.is_valid is deprecated.") | |
1788 | warnings.warn( | |
1789 | "CRS.is_valid is deprecated.", | |
1790 | DeprecationWarning, | |
1791 | ) | |
1768 | 1792 | return self._type != PJ_TYPE_UNKNOWN |
1769 | 1793 | |
1770 | 1794 | @property |
0 | 0 | include "proj.pxi" |
1 | 1 | |
2 | cdef PJ_CONTEXT* get_pyproj_context()⏎ | |
2 | cdef PJ_CONTEXT* get_pyproj_context() except * |
13 | 13 | ProjError.internal_proj_error = pystrdecode(error_msg) |
14 | 14 | |
15 | 15 | |
16 | cdef PJ_CONTEXT* get_pyproj_context(): | |
16 | cdef PJ_CONTEXT* get_pyproj_context() except *: | |
17 | 17 | data_dir = get_data_dir() |
18 | 18 | data_dir_list = data_dir.split(os.pathsep) |
19 | 19 | cdef PJ_CONTEXT* pyproj_context = NULL |
22 | 22 | |
23 | 23 | cdef class Geod: |
24 | 24 | cdef geod_geodesic _geod_geodesic |
25 | cdef public object initstring | |
26 | cdef public object a | |
27 | cdef public object b | |
28 | cdef public object f | |
29 | cdef public object es | |
30 | cdef public object sphere | |
25 | cdef readonly object initstring | |
26 | cdef readonly object a | |
27 | cdef readonly object b | |
28 | cdef readonly object f | |
29 | cdef readonly object es | |
30 | cdef readonly object sphere |
40 | 40 | def proj_version(self): |
41 | 41 | warnings.warn( |
42 | 42 | "'Proj.proj_version' is deprecated. " |
43 | "Please use `pyproj.proj_version_str` instead." | |
43 | "Please use `pyproj.proj_version_str` instead.", | |
44 | DeprecationWarning, | |
44 | 45 | ) |
45 | 46 | return self._proj_version |
46 | 47 |
0 | 0 | include "base.pxi" |
1 | 1 | |
2 | 2 | from pyproj._crs cimport Base, _CRS |
3 | from pyproj._datadir cimport get_pyproj_context | |
4 | 3 | from pyproj.compat import cstrencode, pystrdecode |
5 | 4 | from pyproj.enums import ProjVersion, TransformDirection |
6 | 5 | from pyproj.exceptions import ProjError |
81 | 81 | "DEFAULT": "scale_factor_at_projection_origin", |
82 | 82 | "transverse_mercator": "scale_factor_at_central_meridian", |
83 | 83 | } |
84 | ||
85 | ||
86 | METHOD_NAME_TO_CF_MAP = {"Transverse Mercator": "transverse_mercator"} | |
87 | ||
88 | ||
89 | PARAM_TO_CF_MAP = { | |
90 | "Latitude of natural origin": "latitude_of_projection_origin", | |
91 | "Longitude of natural origin": "longitude_of_central_meridian", | |
92 | "Latitude of false origin": "latitude_of_projection_origin", | |
93 | "Longitude of false origin": "longitude_of_central_meridian", | |
94 | "Scale factor at natural origin": "scale_factor_at_central_meridian", | |
95 | "Easting at projection centre": "false_easting", | |
96 | "Northing at projection centre": "false_northing", | |
97 | "Easting at false origin": "fase_easting", | |
98 | "Northing at false origin": "fase_northing", | |
99 | "False easting": "false_easting", | |
100 | "False northing": "false_northing", | |
101 | } |
25 | 25 | "Ellipsoid", |
26 | 26 | "PrimeMeridian", |
27 | 27 | "is_wkt", |
28 | "is_proj", | |
28 | 29 | ] |
29 | 30 | |
30 | 31 | import json |
35 | 36 | from pyproj._crs import Datum # noqa |
36 | 37 | from pyproj._crs import Ellipsoid # noqa |
37 | 38 | from pyproj._crs import PrimeMeridian # noqa |
38 | from pyproj._crs import _CRS, is_wkt | |
39 | from pyproj._crs import _CRS, is_proj, is_wkt | |
39 | 40 | from pyproj.cf1x8 import ( |
40 | 41 | GRID_MAPPING_NAME_MAP, |
41 | 42 | INVERSE_GRID_MAPPING_NAME_MAP, |
43 | 44 | K_0_MAP, |
44 | 45 | LON_0_MAP, |
45 | 46 | PROJ_PARAM_MAP, |
47 | PARAM_TO_CF_MAP, | |
48 | METHOD_NAME_TO_CF_MAP, | |
46 | 49 | ) |
47 | 50 | from pyproj.compat import string_types |
48 | 51 | from pyproj.exceptions import CRSError |
49 | 52 | from pyproj.geod import Geod |
50 | 53 | |
51 | 54 | |
52 | def _from_dict(projparams): | |
55 | def _prepare_from_dict(projparams): | |
53 | 56 | # convert a dict to a proj string. |
54 | 57 | pjargs = [] |
55 | 58 | for key, value in projparams.items(): |
63 | 66 | pass |
64 | 67 | else: |
65 | 68 | pjargs.append("+{key}={value}".format(key=key, value=value)) |
66 | return _from_string(" ".join(pjargs)) | |
67 | ||
68 | ||
69 | def _from_string(in_crs_string): | |
69 | return _prepare_from_string(" ".join(pjargs)) | |
70 | ||
71 | ||
72 | def _prepare_from_string(in_crs_string): | |
70 | 73 | if not in_crs_string: |
71 | 74 | raise CRSError("CRS is empty or invalid: {!r}".format(in_crs_string)) |
72 | 75 | elif "{" in in_crs_string: |
78 | 81 | |
79 | 82 | if not crs_dict: |
80 | 83 | raise CRSError("CRS is empty JSON") |
81 | return _from_dict(crs_dict) | |
82 | elif not is_wkt(in_crs_string) and "=" in in_crs_string: | |
83 | in_crs_string = re.sub(r"[\s+]?=[\s+]?", "=", in_crs_string) | |
84 | return _prepare_from_dict(crs_dict) | |
85 | elif is_proj(in_crs_string): | |
86 | in_crs_string = re.sub(r"[\s+]?=[\s+]?", "=", in_crs_string.lstrip()) | |
84 | 87 | # make sure the projection starts with +proj or +init |
85 | 88 | starting_params = ("+init", "+proj", "init", "proj") |
86 | if not in_crs_string.lstrip().startswith(starting_params): | |
89 | if not in_crs_string.startswith(starting_params): | |
87 | 90 | kvpairs = [] |
88 | 91 | first_item_inserted = False |
89 | 92 | for kvpair in in_crs_string.split(): |
104 | 107 | # look for EPSG, replace with epsg (EPSG only works |
105 | 108 | # on case-insensitive filesystems). |
106 | 109 | in_crs_string = in_crs_string.replace("+init=EPSG", "+init=epsg").strip() |
107 | # remove no_defs as it does nothing as of PROJ 6.0.0 and breaks | |
108 | # initialization with +init=epsg:... | |
109 | in_crs_string = re.sub(r"\s\+?no_defs([\w=]+)?", "", in_crs_string) | |
110 | if in_crs_string.startswith(("+init", "init")): | |
111 | warnings.warn( | |
112 | "'+init=<authority>:<code>' syntax is deprecated." | |
113 | " '<authority>:<code>' is the preferred initialization method.", | |
114 | DeprecationWarning, | |
115 | ) | |
110 | 116 | return in_crs_string |
111 | 117 | |
112 | 118 | |
113 | def _from_authority(auth_name, auth_code): | |
119 | def _prepare_from_authority(auth_name, auth_code): | |
114 | 120 | return "{}:{}".format(auth_name, auth_code) |
115 | 121 | |
116 | 122 | |
117 | def _from_epsg(auth_code): | |
118 | return _from_authority("epsg", auth_code) | |
123 | def _prepare_from_epsg(auth_code): | |
124 | return _prepare_from_authority("epsg", auth_code) | |
119 | 125 | |
120 | 126 | |
121 | 127 | class CRS(_CRS): |
280 | 286 | False |
281 | 287 | """ |
282 | 288 | if isinstance(projparams, string_types): |
283 | projstring = _from_string(projparams) | |
289 | projstring = _prepare_from_string(projparams) | |
284 | 290 | elif isinstance(projparams, dict): |
285 | projstring = _from_dict(projparams) | |
291 | projstring = _prepare_from_dict(projparams) | |
286 | 292 | elif kwargs: |
287 | projstring = _from_dict(kwargs) | |
293 | projstring = _prepare_from_dict(kwargs) | |
288 | 294 | elif isinstance(projparams, int): |
289 | projstring = _from_epsg(projparams) | |
295 | projstring = _prepare_from_epsg(projparams) | |
290 | 296 | elif isinstance(projparams, (list, tuple)) and len(projparams) == 2: |
291 | projstring = _from_authority(*projparams) | |
297 | projstring = _prepare_from_authority(*projparams) | |
292 | 298 | elif hasattr(projparams, "to_wkt"): |
293 | 299 | projstring = projparams.to_wkt() |
294 | 300 | else: |
311 | 317 | ------- |
312 | 318 | CRS |
313 | 319 | """ |
314 | return cls(_from_authority(auth_name, code)) | |
320 | return cls(_prepare_from_authority(auth_name, code)) | |
315 | 321 | |
316 | 322 | @classmethod |
317 | 323 | def from_epsg(cls, code): |
326 | 332 | ------- |
327 | 333 | CRS |
328 | 334 | """ |
329 | return cls(_from_epsg(code)) | |
335 | return cls(_prepare_from_epsg(code)) | |
330 | 336 | |
331 | 337 | @classmethod |
332 | 338 | def from_proj4(cls, in_proj_string): |
341 | 347 | ------- |
342 | 348 | CRS |
343 | 349 | """ |
344 | if is_wkt(in_proj_string) or "=" not in in_proj_string: | |
350 | if not is_proj(in_proj_string): | |
345 | 351 | raise CRSError("Invalid PROJ string: {}".format(in_proj_string)) |
346 | return cls(_from_string(in_proj_string)) | |
352 | return cls(_prepare_from_string(in_proj_string)) | |
347 | 353 | |
348 | 354 | @classmethod |
349 | 355 | def from_wkt(cls, in_wkt_string): |
360 | 366 | """ |
361 | 367 | if not is_wkt(in_wkt_string): |
362 | 368 | raise CRSError("Invalid WKT string: {}".format(in_wkt_string)) |
363 | return cls(_from_string(in_wkt_string)) | |
369 | return cls(_prepare_from_string(in_wkt_string)) | |
364 | 370 | |
365 | 371 | @classmethod |
366 | 372 | def from_string(cls, in_crs_string): |
381 | 387 | ------- |
382 | 388 | CRS |
383 | 389 | """ |
384 | return cls(_from_string(in_crs_string)) | |
390 | return cls(_prepare_from_string(in_crs_string)) | |
385 | 391 | |
386 | 392 | def to_string(self): |
387 | 393 | """Convert the CRS to a string. |
456 | 462 | ------- |
457 | 463 | CRS |
458 | 464 | """ |
459 | return cls(_from_dict(proj_dict)) | |
465 | return cls(_prepare_from_dict(proj_dict)) | |
460 | 466 | |
461 | 467 | def to_dict(self): |
462 | 468 | """ |
490 | 496 | val = [float(sval.strip()) for sval in val_split] |
491 | 497 | return val |
492 | 498 | |
499 | proj_string = self.to_proj4() | |
500 | if proj_string is None: | |
501 | return {} | |
502 | ||
493 | 503 | items = map( |
494 | 504 | lambda kv: len(kv) == 2 and (kv[0], parse(kv[1])) or (kv[0], None), |
495 | ( | |
496 | part.lstrip("+").split("=", 1) | |
497 | for part in self.to_proj4().strip().split() | |
498 | ), | |
505 | (part.lstrip("+").split("=", 1) for part in proj_string.strip().split()), | |
499 | 506 | ) |
500 | 507 | |
501 | 508 | return {key: value for key, value in items if value is not False} |
539 | 546 | if grid_mapping_name == "rotated_latitude_longitude": |
540 | 547 | if proj_dict.pop("o_proj") not in lonlat_possible_names: |
541 | 548 | grid_mapping_name = "unknown" |
549 | ||
550 | # derive parameters from the coordinate operation | |
551 | if ( | |
552 | grid_mapping_name == "unknown" | |
553 | and self.coordinate_operation | |
554 | and self.coordinate_operation.method_name in METHOD_NAME_TO_CF_MAP | |
555 | ): | |
556 | grid_mapping_name = METHOD_NAME_TO_CF_MAP[ | |
557 | self.coordinate_operation.method_name | |
558 | ] | |
559 | for param in self.coordinate_operation.params: | |
560 | cf_dict[PARAM_TO_CF_MAP[param.name]] = param.value | |
542 | 561 | |
543 | 562 | cf_dict["grid_mapping_name"] = grid_mapping_name |
544 | 563 |
95 | 95 | |
96 | 96 | if _VALIDATED_PROJ_DATA is None: |
97 | 97 | raise DataDirError( |
98 | "Valid PROJ data directory not found." | |
98 | "Valid PROJ data directory not found. " | |
99 | 99 | "Either set the path using the environmental variable PROJ_LIB or " |
100 | 100 | "with `pyproj.datadir.set_data_dir`." |
101 | 101 | ) |
128 | 128 | >>> x,y = p2(-120.108, 34.36116666) |
129 | 129 | >>> 'x=%9.3f y=%11.3f' % (x,y) |
130 | 130 | 'x=765975.641 y=3805993.134' |
131 | >>> p = Proj(init="epsg:32667", preserve_units=False) | |
131 | >>> p = Proj("epsg:32667", preserve_units=False) | |
132 | 132 | >>> 'x=%12.3f y=%12.3f (meters)' % p(-114.057222, 51.045) |
133 | 133 | 'x=-1783506.250 y= 6193827.033 (meters)' |
134 | >>> p = Proj("+init=epsg:32667") | |
134 | >>> p = Proj("epsg:32667") | |
135 | 135 | >>> 'x=%12.3f y=%12.3f (feet)' % p(-114.057222, 51.045) |
136 | 136 | 'x=-5851386.754 y=20320914.191 (feet)' |
137 | 137 | >>> # test data with radian inputs |
138 | >>> p1 = Proj(init="epsg:4214") | |
138 | >>> p1 = Proj("epsg:4214") | |
139 | 139 | >>> x1, y1 = p1(116.366, 39.867) |
140 | 140 | >>> '{:.3f} {:.3f}'.format(x1, y1) |
141 | 141 | '2.031 0.696' |
192 | 192 | def definition_string(self): |
193 | 193 | """Returns formal definition string for projection |
194 | 194 | |
195 | >>> Proj('+init=epsg:4326').definition_string() | |
195 | >>> Proj("epsg:4326").definition_string() | |
196 | 196 | 'proj=longlat datum=WGS84 no_defs ellps=WGS84 towgs84=0,0,0' |
197 | 197 | >>> |
198 | 198 | """ |
228 | 228 | '120.321 0.057' |
229 | 229 | >>> transproj = Transformer.from_crs( |
230 | 230 | ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'}, |
231 | ... '+init=EPSG:4326' | |
231 | ... "EPSG:4326", | |
232 | ... always_xy=True, | |
232 | 233 | ... ) |
233 | 234 | >>> xpj, ypj, zpj = transproj.transform( |
234 | 235 | ... -2704026.010, |
239 | 240 | >>> "%.3f %.3f %.3f" % (xpj, ypj, zpj) |
240 | 241 | '-2.137 0.661 -20.531' |
241 | 242 | >>> transprojr = Transformer.from_crs( |
242 | ... '+init=EPSG:4326', | |
243 | ... "EPSG:4326", | |
243 | 244 | ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'}, |
245 | ... always_xy=True, | |
244 | 246 | ... ) |
245 | 247 | >>> xpjr, ypjr, zpjr = transprojr.transform(xpj, ypj, zpj, radians=True) |
246 | 248 | >>> "%.3f %.3f %.3f" % (xpjr, ypjr, zpjr) |
336 | 338 | '120.321 0.057' |
337 | 339 | >>> transproj = Transformer.from_crs( |
338 | 340 | ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'}, |
339 | ... '+init=EPSG:4326', | |
341 | ... "EPSG:4326", | |
342 | ... always_xy=True, | |
340 | 343 | ... ) |
341 | 344 | >>> for pt in transproj.itransform( |
342 | 345 | ... [(-2704026.010, -4253051.810, 3895878.820)], |
344 | 347 | ... ): |
345 | 348 | ... '{:.3f} {:.3f} {:.3f}'.format(*pt) |
346 | 349 | '-2.137 0.661 -20.531' |
347 | >>> transprojr = Transformer.from_proj( | |
348 | ... '+init=EPSG:4326', | |
350 | >>> transprojr = Transformer.from_crs( | |
351 | ... "EPSG:4326", | |
349 | 352 | ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'}, |
353 | ... always_xy=True, | |
350 | 354 | ... ) |
351 | 355 | >>> for pt in transprojr.itransform( |
352 | 356 | ... [(-2.137, 0.661, -20.531)], |
355 | 359 | ... '{:.3f} {:.3f} {:.3f}'.format(*pt) |
356 | 360 | '-2704214.394 -4254414.478 3894270.731' |
357 | 361 | >>> transproj_eq = Transformer.from_proj( |
358 | ... '+init=EPSG:4326', | |
362 | ... 'EPSG:4326', | |
359 | 363 | ... '+proj=longlat +datum=WGS84 +no_defs +type=crs', |
364 | ... always_xy=True, | |
360 | 365 | ... skip_equivalent=True |
361 | 366 | ... ) |
362 | 367 | >>> for pt in transproj_eq.itransform([(-2.137, 0.661)]): |
493 | 498 | >>> from pyproj import Proj, transform |
494 | 499 | >>> # projection 1: UTM zone 15, grs80 ellipse, NAD83 datum |
495 | 500 | >>> # (defined by epsg code 26915) |
496 | >>> p1 = Proj(init='epsg:26915', preserve_units=False) | |
501 | >>> p1 = Proj('epsg:26915', preserve_units=False) | |
497 | 502 | >>> # projection 2: UTM zone 15, clrk66 ellipse, NAD27 datum |
498 | >>> p2 = Proj(init='epsg:26715', preserve_units=False) | |
503 | >>> p2 = Proj('epsg:26715', preserve_units=False) | |
499 | 504 | >>> # find x,y of Jefferson City, MO. |
500 | 505 | >>> x1, y1 = p1(-92.199881,38.56694) |
501 | 506 | >>> # transform this point to projection 2 coordinates. |
594 | 599 | >>> from pyproj import Proj, itransform |
595 | 600 | >>> # projection 1: WGS84 |
596 | 601 | >>> # (defined by epsg code 4326) |
597 | >>> p1 = Proj(init='epsg:4326', preserve_units=False) | |
602 | >>> p1 = Proj('epsg:4326', preserve_units=False) | |
598 | 603 | >>> # projection 2: GGRS87 / Greek Grid |
599 | >>> p2 = Proj(init='epsg:2100', preserve_units=False) | |
604 | >>> p2 = Proj('epsg:2100', preserve_units=False) | |
600 | 605 | >>> # Three points with coordinates lon, lat in p1 |
601 | 606 | >>> points = [(22.95, 40.63), (22.81, 40.53), (23.51, 40.86)] |
602 | 607 | >>> # transform this point to projection 2 coordinates. |
603 | >>> for pt in itransform(p1,p2,points): '%6.3f %7.3f' % pt | |
608 | >>> for pt in itransform(p1,p2,points, always_xy=True): '%6.3f %7.3f' % pt | |
604 | 609 | '411050.470 4497928.574' |
605 | 610 | '399060.236 4486978.710' |
606 | 611 | '458553.243 4523045.485' |
2 | 2 | import numpy |
3 | 3 | from numpy.testing import assert_allclose |
4 | 4 | |
5 | from pyproj import Proj | |
5 | from pyproj import Proj, proj_version_str | |
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 = ", awips221.proj_version) | |
28 | print("proj4 library version = ", proj_version_str) | |
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) |
55 | 55 | assert wgs84_crs.to_proj4() == "+proj=longlat +datum=WGS84 +no_defs +type=crs" |
56 | 56 | # Make sure this doesn't get handled using the from_epsg() |
57 | 57 | # even though 'epsg' is in the string |
58 | epsg_init_crs = CRS.from_string("+init=epsg:26911 +units=m +no_defs=True") | |
58 | with pytest.warns(DeprecationWarning): | |
59 | epsg_init_crs = CRS.from_string("+init=epsg:26911 +units=m +no_defs=True") | |
59 | 60 | assert ( |
60 | 61 | epsg_init_crs.to_proj4() |
61 | 62 | == "+proj=utm +zone=11 +datum=NAD83 +units=m +no_defs +type=crs" |
83 | 84 | |
84 | 85 | |
85 | 86 | def test_is_geographic(): |
86 | assert CRS({"init": "EPSG:4326"}).is_geographic is True | |
87 | assert CRS({"init": "EPSG:3857"}).is_geographic is False | |
87 | assert CRS("EPSG:4326").is_geographic is True | |
88 | assert CRS("EPSG:3857").is_geographic is False | |
88 | 89 | |
89 | 90 | wgs84_crs = CRS.from_string("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") |
90 | 91 | assert wgs84_crs.is_geographic is True |
100 | 101 | |
101 | 102 | |
102 | 103 | def test_is_projected(): |
103 | assert CRS({"init": "EPSG:3857"}).is_projected is True | |
104 | assert CRS("EPSG:3857").is_projected is True | |
104 | 105 | |
105 | 106 | lcc_crs = CRS.from_string( |
106 | 107 | "+lon_0=-95 +ellps=GRS80 +y_0=0 +no_defs=True +proj=lcc +x_0=0 " |
113 | 114 | |
114 | 115 | |
115 | 116 | def test_is_same_crs(): |
116 | crs1 = CRS({"init": "EPSG:4326"}) | |
117 | crs2 = CRS({"init": "EPSG:3857"}) | |
117 | crs1 = CRS("urn:ogc:def:crs:OGC::CRS84") | |
118 | crs2 = CRS("EPSG:3857") | |
118 | 119 | |
119 | 120 | assert crs1 == crs1 |
120 | 121 | assert crs1 != crs2 |
136 | 137 | |
137 | 138 | def test_to_proj4(): |
138 | 139 | assert ( |
139 | CRS({"init": "EPSG:4326"}).to_proj4(4) | |
140 | == "+proj=longlat +datum=WGS84 +no_defs +type=crs" | |
140 | CRS("EPSG:4326").to_proj4(4) == "+proj=longlat +datum=WGS84 +no_defs +type=crs" | |
141 | 141 | ) |
142 | 142 | |
143 | 143 | |
144 | 144 | def test_is_valid(): |
145 | with pytest.warns(UserWarning): | |
145 | with pytest.warns(DeprecationWarning): | |
146 | 146 | assert CRS(init="EPSG:4326").is_valid |
147 | 147 | |
148 | 148 | |
156 | 156 | |
157 | 157 | |
158 | 158 | def test_has_wkt_property(): |
159 | assert ( | |
160 | CRS({"init": "EPSG:4326"}) | |
161 | .to_wkt("WKT1_GDAL") | |
162 | .startswith('GEOGCS["WGS 84",DATUM') | |
163 | ) | |
159 | with pytest.warns(DeprecationWarning): | |
160 | assert ( | |
161 | CRS({"init": "EPSG:4326"}) | |
162 | .to_wkt("WKT1_GDAL") | |
163 | .startswith('GEOGCS["WGS 84",DATUM') | |
164 | ) | |
164 | 165 | |
165 | 166 | |
166 | 167 | def test_to_wkt_pretty(): |
170 | 171 | |
171 | 172 | |
172 | 173 | def test_repr(): |
173 | assert repr(CRS({"init": "EPSG:4326"})) == ( | |
174 | "<Geographic 2D CRS: +init=epsg:4326 +type=crs>\n" | |
175 | "Name: WGS 84\n" | |
176 | "Axis Info [ellipsoidal]:\n" | |
177 | "- lon[east]: Longitude (degree)\n" | |
178 | "- lat[north]: Latitude (degree)\n" | |
179 | "Area of Use:\n" | |
180 | "- name: World\n" | |
181 | "- bounds: (-180.0, -90.0, 180.0, 90.0)\n" | |
182 | "Datum: World Geodetic System 1984\n" | |
183 | "- Ellipsoid: WGS 84\n" | |
184 | "- Prime Meridian: Greenwich\n" | |
185 | ) | |
174 | with pytest.warns(DeprecationWarning): | |
175 | assert repr(CRS({"init": "EPSG:4326"})) == ( | |
176 | "<Geographic 2D CRS: +init=epsg:4326 +type=crs>\n" | |
177 | "Name: WGS 84\n" | |
178 | "Axis Info [ellipsoidal]:\n" | |
179 | "- lon[east]: Longitude (degree)\n" | |
180 | "- lat[north]: Latitude (degree)\n" | |
181 | "Area of Use:\n" | |
182 | "- name: World\n" | |
183 | "- bounds: (-180.0, -90.0, 180.0, 90.0)\n" | |
184 | "Datum: World Geodetic System 1984\n" | |
185 | "- Ellipsoid: WGS 84\n" | |
186 | "- Prime Meridian: Greenwich\n" | |
187 | ) | |
186 | 188 | |
187 | 189 | |
188 | 190 | def test_repr__long(): |
189 | assert repr(CRS(CRS({"init": "EPSG:4326"}).to_wkt())) == ( | |
190 | '<Geographic 2D CRS: GEOGCRS["WGS 84",DATUM["World Geodetic System 1984 ...>\n' | |
191 | "Name: WGS 84\n" | |
192 | "Axis Info [ellipsoidal]:\n" | |
193 | "- lon[east]: Longitude (degree)\n" | |
194 | "- lat[north]: Latitude (degree)\n" | |
195 | "Area of Use:\n" | |
196 | "- name: World\n" | |
197 | "- bounds: (-180.0, -90.0, 180.0, 90.0)\n" | |
198 | "Datum: World Geodetic System 1984\n" | |
199 | "- Ellipsoid: WGS 84\n" | |
200 | "- Prime Meridian: Greenwich\n" | |
201 | ) | |
191 | with pytest.warns(DeprecationWarning): | |
192 | assert repr(CRS(CRS({"init": "EPSG:4326"}).to_wkt())) == ( | |
193 | '<Geographic 2D CRS: GEOGCRS["WGS 84",' | |
194 | 'DATUM["World Geodetic System 1984 ...>\n' | |
195 | "Name: WGS 84\n" | |
196 | "Axis Info [ellipsoidal]:\n" | |
197 | "- lon[east]: Longitude (degree)\n" | |
198 | "- lat[north]: Latitude (degree)\n" | |
199 | "Area of Use:\n" | |
200 | "- name: World\n" | |
201 | "- bounds: (-180.0, -90.0, 180.0, 90.0)\n" | |
202 | "Datum: World Geodetic System 1984\n" | |
203 | "- Ellipsoid: WGS 84\n" | |
204 | "- Prime Meridian: Greenwich\n" | |
205 | ) | |
202 | 206 | |
203 | 207 | |
204 | 208 | def test_repr_epsg(): |
262 | 266 | |
263 | 267 | |
264 | 268 | def test_dunder_str(): |
265 | assert str(CRS({"init": "EPSG:4326"})) == CRS({"init": "EPSG:4326"}).srs | |
269 | with pytest.warns(DeprecationWarning): | |
270 | assert str(CRS({"init": "EPSG:4326"})) == CRS({"init": "EPSG:4326"}).srs | |
266 | 271 | |
267 | 272 | |
268 | 273 | def test_epsg(): |
269 | assert CRS({"init": "EPSG:4326"}).to_epsg(20) == 4326 | |
270 | assert CRS({"init": "EPSG:4326"}).to_epsg() is None | |
274 | with pytest.warns(DeprecationWarning): | |
275 | assert CRS({"init": "EPSG:4326"}).to_epsg(20) == 4326 | |
276 | assert CRS({"init": "EPSG:4326"}).to_epsg() is None | |
271 | 277 | assert CRS.from_user_input(4326).to_epsg() == 4326 |
272 | 278 | assert CRS.from_epsg(4326).to_epsg() == 4326 |
273 | 279 | assert CRS.from_user_input("epsg:4326").to_epsg() == 4326 |
315 | 321 | def test_crs_OSR_equivalence(): |
316 | 322 | crs1 = CRS.from_string("+proj=longlat +datum=WGS84 +no_defs") |
317 | 323 | crs2 = CRS.from_string("+proj=latlong +datum=WGS84 +no_defs") |
318 | crs3 = CRS({"init": "EPSG:4326"}) | |
324 | with pytest.warns(DeprecationWarning): | |
325 | crs3 = CRS({"init": "EPSG:4326"}) | |
319 | 326 | assert crs1 == crs2 |
320 | 327 | # these are not equivalent in proj.4 now as one uses degrees and the othe radians |
321 | 328 | assert crs1 == crs3 |
612 | 619 | |
613 | 620 | def test_coordinate_operation_towgs84_seven(): |
614 | 621 | crs = CRS( |
615 | init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62" | |
622 | "+proj=tmerc +lat_0=0 +lon_0=15 +k=0.9996 +x_0=2520000 +y_0=0 " | |
623 | "+ellps=intl +towgs84=-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62" | |
616 | 624 | ) |
617 | 625 | assert crs.coordinate_operation.towgs84 == [ |
618 | 626 | -122.74, |
626 | 634 | |
627 | 635 | |
628 | 636 | def test_coordinate_operation_towgs84_missing(): |
629 | crs = CRS(init="epsg:3004") | |
637 | crs = CRS("epsg:3004") | |
630 | 638 | assert crs.coordinate_operation.towgs84 == [] |
631 | 639 | |
632 | 640 | |
716 | 724 | |
717 | 725 | def test_deprecated_to_geodetic(): |
718 | 726 | cc = CRS("epsg:3004") |
719 | with pytest.warns(UserWarning): | |
727 | with pytest.warns(DeprecationWarning): | |
720 | 728 | assert cc.to_geodetic().to_epsg() == 4265 |
721 | 729 | |
722 | 730 | |
790 | 798 | def test_srs__no_plus(): |
791 | 799 | assert ( |
792 | 800 | CRS("proj=longlat datum=WGS84 no_defs").srs |
793 | == "proj=longlat datum=WGS84 type=crs" | |
794 | ) | |
795 | ||
796 | ||
797 | @pytest.mark.parametrize( | |
798 | "init_string, expected_srs", | |
799 | [ | |
800 | ("+init=epsg:4326 +no_defs=True", "+init=epsg:4326 +type=crs"), | |
801 | ("init=epsg:4326 no_defs=True", "init=epsg:4326 type=crs"), | |
802 | ("+init=epsg:4326 +no_defs", "+init=epsg:4326 +type=crs"), | |
803 | ("init=epsg:4326 no_defs", "init=epsg:4326 type=crs"), | |
804 | ], | |
805 | ) | |
806 | def test_removing_nodefs(init_string, expected_srs): | |
807 | assert CRS(init_string).srs == expected_srs | |
801 | == "proj=longlat datum=WGS84 no_defs type=crs" | |
802 | ) | |
808 | 803 | |
809 | 804 | |
810 | 805 | def test_equals_different_type(): |
818 | 813 | def test_compare_crs_non_crs(): |
819 | 814 | assert CRS.from_epsg(4326) != 4.2 |
820 | 815 | assert CRS.from_epsg(4326) == 4326 |
821 | assert CRS.from_dict({"init": "epsg:4326"}) == {"init": "epsg:4326"} | |
822 | assert CRS.from_dict({"init": "epsg:4326"}) != "epsg:4326" | |
816 | with pytest.warns(DeprecationWarning): | |
817 | assert CRS.from_dict({"init": "epsg:4326"}) == {"init": "epsg:4326"} | |
818 | assert CRS.from_dict({"init": "epsg:4326"}) != "epsg:4326" | |
823 | 819 | assert CRS("epsg:4326") == CustomCRS() |
824 | 820 | |
825 | 821 | |
826 | 822 | def test_is_geocentric__bound(): |
827 | ccs = CRS("+init=epsg:4328 +towgs84=0,0,0") | |
823 | with pytest.warns(DeprecationWarning): | |
824 | ccs = CRS("+init=epsg:4328 +towgs84=0,0,0") | |
828 | 825 | assert ccs.is_geocentric |
829 | 826 | |
830 | 827 | |
851 | 848 | |
852 | 849 | |
853 | 850 | def test_source_crs__bound(): |
854 | assert CRS("+init=epsg:4328 +towgs84=0,0,0").source_crs.name == "unknown" | |
851 | with pytest.warns(DeprecationWarning): | |
852 | assert CRS("+init=epsg:4328 +towgs84=0,0,0").source_crs.name == "unknown" | |
855 | 853 | |
856 | 854 | |
857 | 855 | def test_source_crs__missing(): |
859 | 857 | |
860 | 858 | |
861 | 859 | def test_target_crs__bound(): |
862 | assert CRS("+init=epsg:4328 +towgs84=0,0,0").target_crs.name == "WGS 84" | |
860 | with pytest.warns(DeprecationWarning): | |
861 | assert CRS("+init=epsg:4328 +towgs84=0,0,0").target_crs.name == "WGS 84" | |
863 | 862 | |
864 | 863 | |
865 | 864 | def test_target_crs__missing(): |
874 | 873 | "+proj=lcc +lat_1=30.0 +lat_2=35.0 +lat_0=30.0 " |
875 | 874 | "+lon_0=87.0 +x_0=0 +y_0=0 +type=crs" |
876 | 875 | ) |
876 | ||
877 | ||
878 | def test_to_dict_no_proj4(): | |
879 | crs = CRS( | |
880 | { | |
881 | "a": 6371229.0, | |
882 | "b": 6371229.0, | |
883 | "lon_0": -10.0, | |
884 | "o_lat_p": 30.0, | |
885 | "o_lon_p": 0.0, | |
886 | "o_proj": "longlat", | |
887 | "proj": "ob_tran", | |
888 | } | |
889 | ) | |
890 | assert crs.to_proj4() is None | |
891 | assert crs.to_dict() == {} |
6 | 6 | |
7 | 7 | def test_to_cf_transverse_mercator(): |
8 | 8 | crs = CRS( |
9 | init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62" | |
9 | proj="tmerc", | |
10 | lat_0=0, | |
11 | lon_0=15, | |
12 | k=0.9996, | |
13 | x_0=2520000, | |
14 | y_0=0, | |
15 | ellps="intl", | |
16 | units="m", | |
17 | towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62", | |
10 | 18 | ) |
11 | 19 | with pytest.warns(UserWarning): |
12 | 20 | cf_dict = crs.to_cf(errcheck=True) |
101 | 109 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") |
102 | 110 | assert cf_dict == { |
103 | 111 | "projected_crs_name": "WGS 84 / UTM zone 15N", |
104 | "grid_mapping_name": "unknown", | |
105 | "horizontal_datum_name": "WGS84", | |
112 | "latitude_of_projection_origin": 0.0, | |
113 | "longitude_of_central_meridian": -93.0, | |
114 | "scale_factor_at_central_meridian": 0.9996, | |
115 | "false_easting": 500000.0, | |
116 | "false_northing": 0.0, | |
117 | "grid_mapping_name": "transverse_mercator", | |
118 | "horizontal_datum_name": "WGS84", | |
119 | "unit": "m", | |
120 | } | |
121 | ||
122 | ||
123 | def test_cf_from_utm__nad83(): | |
124 | crs = CRS("epsg:26917") | |
125 | with pytest.warns(UserWarning): | |
126 | cf_dict = crs.to_cf(errcheck=True) | |
127 | assert cf_dict.pop("crs_wkt").startswith("PROJCRS[") | |
128 | assert cf_dict == { | |
129 | "projected_crs_name": "NAD83 / UTM zone 17N", | |
130 | "latitude_of_projection_origin": 0.0, | |
131 | "longitude_of_central_meridian": -81.0, | |
132 | "scale_factor_at_central_meridian": 0.9996, | |
133 | "false_easting": 500000.0, | |
134 | "false_northing": 0.0, | |
135 | "grid_mapping_name": "transverse_mercator", | |
136 | "horizontal_datum_name": "NAD83", | |
106 | 137 | "unit": "m", |
107 | 138 | } |
108 | 139 |
0 | import warnings | |
1 | ||
0 | 2 | from numpy.testing import assert_almost_equal |
1 | 3 | |
2 | from pyproj import Proj, transform | |
4 | from pyproj import Proj, proj_version_str, transform | |
3 | 5 | |
4 | 6 | # illustrates the use of the transform function to |
5 | 7 | # perform coordinate transformations with datum shifts. |
27 | 29 | UTM_z = WGS84_z = 52.8 # Ellipsoidical height in meters |
28 | 30 | WGS84_PROJ = Proj(proj="latlong", datum="WGS84") |
29 | 31 | UTM_33_PROJ = Proj(proj="utm", zone="33") |
30 | GAUSSSB_PROJ = Proj( | |
31 | init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62" | |
32 | ) | |
33 | print("proj4 library version = ", WGS84_PROJ.proj_version) | |
32 | with warnings.catch_warnings(): | |
33 | warnings.simplefilter("ignore", DeprecationWarning) | |
34 | GAUSSSB_PROJ = Proj( | |
35 | init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62" | |
36 | ) | |
37 | print("proj4 library version = ", proj_version_str) | |
34 | 38 | |
35 | 39 | |
36 | 40 | def test_shift_wgs84_to_utm33(): |
116 | 116 | # https://github.com/jswhit/pyproj/issues/8 |
117 | 117 | |
118 | 118 | def setUp(self): |
119 | self.p = Proj(init="epsg:4269") | |
119 | with pytest.warns(DeprecationWarning): | |
120 | self.p = Proj(init="epsg:4269") | |
120 | 121 | |
121 | 122 | def test_tranform_none_1st_parmeter(self): |
122 | 123 | # test should raise Type error if projections are not of Proj classes |
369 | 370 | |
370 | 371 | def test_proj_version(): |
371 | 372 | awips221 = Proj(proj="lcc", R=6371200, lat_1=50, lat_2=50, lon_0=-107) |
372 | with pytest.warns(UserWarning, matches="'Proj.proj_version' is deprecated"): | |
373 | with pytest.warns(DeprecationWarning, match="'Proj.proj_version' is deprecated"): | |
373 | 374 | assert type(awips221.proj_version) is int |
374 | 375 | |
375 | 376 |
0 | 0 | import numpy |
1 | 1 | from numpy.testing import assert_allclose |
2 | 2 | |
3 | from pyproj import Proj, transform | |
3 | from pyproj import Proj, proj_version_str, transform | |
4 | 4 | |
5 | 5 | |
6 | 6 | def test_transform(): |
11 | 11 | dx = 12190.58 |
12 | 12 | dy = dx |
13 | 13 | awips221 = Proj(proj="lcc", R=6371200, lat_1=50, lat_2=50, lon_0=-107) |
14 | print("proj4 library version = ", awips221.proj_version) | |
14 | print("proj4 library version = ", proj_version_str) | |
15 | 15 | llcrnrx, llcrnry = awips221(-145.5, 1) |
16 | 16 | awips221 = Proj( |
17 | 17 | proj="lcc", |
19 | 19 | |
20 | 20 | |
21 | 21 | def test_transform_wgs84_to_alaska(): |
22 | lat_lon_proj = pyproj.Proj(init="epsg:4326", preserve_units=False) | |
23 | alaska_aea_proj = pyproj.Proj(init="epsg:2964", preserve_units=False) | |
22 | with pytest.warns(DeprecationWarning): | |
23 | lat_lon_proj = pyproj.Proj(init="epsg:4326", preserve_units=False) | |
24 | alaska_aea_proj = pyproj.Proj(init="epsg:2964", preserve_units=False) | |
24 | 25 | test = (-179.72638, 49.752533) |
25 | 26 | xx, yy = pyproj.transform(lat_lon_proj, alaska_aea_proj, *test) |
26 | 27 | assert "{:.3f} {:.3f}".format(xx, yy) == "-1824924.495 330822.800" |
28 | 29 | |
29 | 30 | def test_illegal_transformation(): |
30 | 31 | # issue 202 |
31 | p1 = pyproj.Proj(init="epsg:4326") | |
32 | p2 = pyproj.Proj(init="epsg:3857") | |
32 | with pytest.warns(DeprecationWarning): | |
33 | p1 = pyproj.Proj(init="epsg:4326") | |
34 | p2 = pyproj.Proj(init="epsg:3857") | |
33 | 35 | xx, yy = pyproj.transform( |
34 | 36 | p1, p2, (-180, -180, 180, 180, -180), (-90, 90, 90, -90, -90) |
35 | 37 | ) |
43 | 45 | |
44 | 46 | def test_lambert_conformal_transform(): |
45 | 47 | # issue 207 |
46 | Midelt = pyproj.Proj(init="epsg:26191") | |
47 | WGS84 = pyproj.Proj(init="epsg:4326") | |
48 | with pytest.warns(DeprecationWarning): | |
49 | Midelt = pyproj.Proj(init="epsg:26191") | |
50 | WGS84 = pyproj.Proj(init="epsg:4326") | |
48 | 51 | |
49 | 52 | E = 567623.931 |
50 | 53 | N = 256422.787 |
76 | 79 | |
77 | 80 | |
78 | 81 | def test_equivalent_proj(): |
79 | transformer = Transformer.from_proj( | |
80 | "+init=epsg:4326", pyproj.Proj(4326).crs.to_proj4(), skip_equivalent=True | |
81 | ) | |
82 | with pytest.warns(DeprecationWarning): | |
83 | transformer = Transformer.from_proj( | |
84 | "+init=epsg:4326", pyproj.Proj(4326).crs.to_proj4(), skip_equivalent=True | |
85 | ) | |
82 | 86 | assert transformer._transformer.skip_equivalent |
83 | 87 | assert transformer._transformer.projections_equivalent |
84 | 88 | assert not transformer._transformer.projections_exact_same |
226 | 230 | |
227 | 231 | |
228 | 232 | def test_transform_no_error(): |
229 | pj = Proj(init="epsg:4555") | |
233 | with pytest.warns(DeprecationWarning): | |
234 | pj = Proj(init="epsg:4555") | |
230 | 235 | pjx, pjy = pj(116.366, 39.867) |
231 | 236 | transform(pj, Proj(4326), pjx, pjy, radians=True, errcheck=True) |
232 | 237 | |
233 | 238 | |
234 | 239 | def test_itransform_no_error(): |
235 | pj = Proj(init="epsg:4555") | |
240 | with pytest.warns(DeprecationWarning): | |
241 | pj = Proj(init="epsg:4555") | |
236 | 242 | pjx, pjy = pj(116.366, 39.867) |
237 | 243 | list(itransform(pj, Proj(4326), [(pjx, pjy)], radians=True, errcheck=True)) |
238 | 244 | |
239 | 245 | |
240 | 246 | def test_transform_no_exception(): |
241 | 247 | # issue 249 |
242 | transformer = Transformer.from_proj("+init=epsg:4326", "+init=epsg:27700") | |
248 | with pytest.warns(DeprecationWarning): | |
249 | transformer = Transformer.from_proj("+init=epsg:4326", "+init=epsg:27700") | |
243 | 250 | transformer.transform(1.716073972, 52.658007833, errcheck=True) |
244 | 251 | transformer.itransform([(1.716073972, 52.658007833)], errcheck=True) |
245 | 252 | |
246 | 253 | |
247 | 254 | def test_transform__out_of_bounds(): |
248 | transformer = Transformer.from_proj("+init=epsg:4326", "+init=epsg:27700") | |
255 | with pytest.warns(DeprecationWarning): | |
256 | transformer = Transformer.from_proj("+init=epsg:4326", "+init=epsg:27700") | |
249 | 257 | assert np.all(np.isinf(transformer.transform(100000, 100000, errcheck=True))) |
250 | 258 | |
251 | 259 | |
252 | 260 | def test_transform_radians(): |
253 | WGS84 = pyproj.Proj("+init=EPSG:4326") | |
261 | with pytest.warns(DeprecationWarning): | |
262 | WGS84 = pyproj.Proj("+init=EPSG:4326") | |
254 | 263 | ECEF = pyproj.Proj(proj="geocent", ellps="WGS84", datum="WGS84") |
255 | 264 | assert_almost_equal( |
256 | 265 | pyproj.transform( |
273 | 282 | |
274 | 283 | |
275 | 284 | def test_itransform_radians(): |
276 | WGS84 = pyproj.Proj("+init=EPSG:4326") | |
285 | with pytest.warns(DeprecationWarning): | |
286 | WGS84 = pyproj.Proj("+init=EPSG:4326") | |
277 | 287 | ECEF = pyproj.Proj(proj="geocent", ellps="WGS84", datum="WGS84") |
278 | 288 | assert_almost_equal( |
279 | 289 | list( |