New upstream version 2.6.0+ds
Bas Couwenberg
4 years ago
18 | 18 | hooks: |
19 | 19 | - id: blacken-docs |
20 | 20 | args: [--skip-errors] |
21 | - repo: https://gitlab.com/pycqa/flake8 | |
22 | rev: 3.7.7 | |
23 | hooks: | |
24 | - id: flake8 | |
25 | additional_dependencies: [flake8-comprehensions>=3.1.0] | |
26 | args: [--max-line-length, '88', --ignore, "E225,W503,C408"] | |
27 | - id: flake8 | |
28 | name: flake8-pyx | |
29 | files: \.(pyx|pxd)$ | |
30 | types: | |
31 | - file | |
32 | args: [--append-config=flake8/cython.cfg] |
0 | Contact: Jeffrey Whitaker <jeffrey.s.whitaker@noaa.gov | |
0 | Copyright (c) 2006-2018, Jeffrey Whitaker. | |
1 | Copyright (c) 2019-2020, Open source contributors. | |
1 | 2 | |
2 | copyright (c) 2013 by Jeffrey Whitaker. | |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of | |
4 | this software and associated documentation files (the "Software"), to deal in | |
5 | the Software without restriction, including without limitation the rights to use, | |
6 | copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | |
7 | Software, and to permit persons to whom the Software is furnished to do so, | |
8 | subject to the following conditions: | |
3 | 9 | |
4 | Permission to use, copy, modify, and distribute this software | |
5 | and its documentation for any purpose and without fee is hereby | |
6 | granted, provided that the above copyright notice appear in all | |
7 | copies and that both the copyright notice and this permission | |
8 | notice appear in supporting documentation. THE AUTHOR DISCLAIMS | |
9 | ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL | |
10 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT | |
11 | SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |
12 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
13 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | |
14 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
15 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
10 | The above copyright notice and this permission notice shall be included in all | |
11 | copies or substantial portions of the Software. | |
12 | ||
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
14 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
15 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
16 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
17 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
18 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
61 | 61 | |
62 | 62 | lint: ## check style with flake8 |
63 | 63 | flake8 --max-line-length 88 setup.py pyproj/ test/ docs/ |
64 | flake8 --append-config=flake8/cython.cfg pyproj/ | |
64 | 65 | |
65 | 66 | check-type: |
66 | 67 | mypy pyproj |
0 | [flake8] | |
1 | filename = *.pyx,*.pxd | |
2 | max-line-length=88 | |
3 | select=E501,E302,E203,E111,E114,E221,E303,E128,E231,E126,E265,E305,E301,E127,E261,E271,E129,W291,E222,E241,E123,F403,C400,C401,C402,C403,C404,C405,C406,C407,C408,C409,C410,C411 |
0 | # -*- coding: utf-8 -*- | |
1 | 0 | """ |
2 | Cython wrapper to provide python interfaces to | |
3 | PROJ (https://proj.org) functions. | |
4 | ||
5 | Performs cartographic transformations and geodetic computations. | |
6 | ||
7 | The Proj class can convert from geographic (longitude,latitude) | |
8 | to native map projection (x,y) coordinates and vice versa, or | |
9 | from one map projection coordinate system directly to another. | |
10 | The module variable pj_list is a dictionary containing all the | |
11 | available projections and their descriptions. | |
12 | ||
13 | The Geod class can perform forward and inverse geodetic, or | |
14 | Great Circle, computations. The forward computation involves | |
15 | determining latitude, longitude and back azimuth of a terminus | |
16 | point given the latitude and longitude of an initial point, plus | |
17 | azimuth and distance. The inverse computation involves | |
18 | determining the forward and back azimuths and distance given the | |
19 | latitudes and longitudes of an initial and terminus point. | |
20 | ||
21 | Input coordinates can be given as python arrays, lists/tuples, | |
22 | scalars or numpy/Numeric/numarray arrays. Optimized for objects | |
23 | that support the Python buffer protocol (regular python and | |
24 | numpy array objects). | |
1 | Python interface to PROJ (https://proj.org), | |
2 | cartographic projections and coordinate transformations library. | |
25 | 3 | |
26 | 4 | Download: http://python.org/pypi/pyproj |
27 | 5 | |
28 | 6 | Requirements: Python 3.5+. |
29 | 7 | |
30 | Example scripts are in 'test' subdirectory of source distribution. | |
31 | The 'test()' function will run the examples in the docstrings. | |
8 | Contact: Jeffrey Whitaker <jeffrey.s.whitaker@noaa.gov> | |
32 | 9 | |
33 | Contact: Jeffrey Whitaker <jeffrey.s.whitaker@noaa.gov | |
10 | Copyright (c) 2006-2018, Jeffrey Whitaker. | |
11 | Copyright (c) 2019-2020, Open source contributors. | |
34 | 12 | |
35 | copyright (c) 2006 by Jeffrey Whitaker. | |
13 | Permission is hereby granted, free of charge, to any person obtaining a copy of | |
14 | this software and associated documentation files (the "Software"), to deal in | |
15 | the Software without restriction, including without limitation the rights to use, | |
16 | copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | |
17 | Software, and to permit persons to whom the Software is furnished to do so, | |
18 | subject to the following conditions: | |
36 | 19 | |
37 | Permission to use, copy, modify, and distribute this software | |
38 | and its documentation for any purpose and without fee is hereby | |
39 | granted, provided that the above copyright notice appear in all | |
40 | copies and that both the copyright notice and this permission | |
41 | notice appear in supporting documentation. THE AUTHOR DISCLAIMS | |
42 | ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL | |
43 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT | |
44 | SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |
45 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
46 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | |
47 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
48 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ | |
49 | __version__ = "2.6.0rc0" | |
20 | The above copyright notice and this permission notice shall be included in all | |
21 | copies or substantial portions of the Software. | |
22 | ||
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
24 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
25 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
26 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
27 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
28 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
29 | """ | |
30 | __version__ = "2.6.0" | |
50 | 31 | __all__ = [ |
51 | 32 | "Proj", |
52 | 33 | "Geod", |
529 | 529 | return self._is_exact_same(other) |
530 | 530 | |
531 | 531 | |
532 | ||
533 | 532 | cdef class _CRSParts(Base): |
534 | 533 | @classmethod |
535 | 534 | def from_user_input(cls, user_input): |
717 | 716 | ------- |
718 | 717 | CoordinateSystem |
719 | 718 | """ |
720 | return CoordinateSystem.from_json_dict(_load_proj_json(coordinate_system_json_str)) | |
719 | return CoordinateSystem.from_json_dict( | |
720 | _load_proj_json(coordinate_system_json_str) | |
721 | ) | |
721 | 722 | |
722 | 723 | |
723 | 724 | cdef class Ellipsoid(_CRSParts): |
970 | 971 | CRSError.clear() |
971 | 972 | return Ellipsoid.create(context, ellipsoid_pj) |
972 | 973 | |
973 | ||
974 | 974 | @staticmethod |
975 | 975 | def from_name( |
976 | 976 | ellipsoid_name, |
1268 | 1268 | return PrimeMeridian.create(context, prime_meridian_pj) |
1269 | 1269 | |
1270 | 1270 | |
1271 | ||
1272 | 1271 | _DATUM_TYPE_MAP = { |
1273 | 1272 | PJ_TYPE_GEODETIC_REFERENCE_FRAME: "Geodetic Reference Frame", |
1274 | 1273 | PJ_TYPE_DYNAMIC_GEODETIC_REFERENCE_FRAME: "Dynamic Geodetic Reference Frame", |
1279 | 1278 | |
1280 | 1279 | _PJ_DATUM_TYPE_MAP = { |
1281 | 1280 | DatumType.GEODETIC_REFERENCE_FRAME: PJ_TYPE_GEODETIC_REFERENCE_FRAME, |
1282 | DatumType.DYNAMIC_GEODETIC_REFERENCE_FRAME: PJ_TYPE_DYNAMIC_GEODETIC_REFERENCE_FRAME, | |
1281 | DatumType.DYNAMIC_GEODETIC_REFERENCE_FRAME: | |
1282 | PJ_TYPE_DYNAMIC_GEODETIC_REFERENCE_FRAME, | |
1283 | 1283 | DatumType.VERTICAL_REFERENCE_FRAME: PJ_TYPE_VERTICAL_REFERENCE_FRAME, |
1284 | DatumType.DYNAMIC_VERTICAL_REFERENCE_FRAME: PJ_TYPE_DYNAMIC_VERTICAL_REFERENCE_FRAME, | |
1284 | DatumType.DYNAMIC_VERTICAL_REFERENCE_FRAME: | |
1285 | PJ_TYPE_DYNAMIC_VERTICAL_REFERENCE_FRAME, | |
1285 | 1286 | DatumType.DATUM_ENSEMBLE: PJ_TYPE_DATUM_ENSEMBLE, |
1286 | 1287 | } |
1287 | 1288 | |
1731 | 1732 | |
1732 | 1733 | def __repr__(self): |
1733 | 1734 | return ("Param(name={name}, auth_name={auth_name}, code={code}, " |
1734 | "value={value}, unit_name={unit_name}, unit_auth_name={unit_auth_name}, " | |
1735 | "unit_code={unit_code}, unit_category={unit_category})").format( | |
1735 | "value={value}, unit_name={unit_name}, " | |
1736 | "unit_auth_name={unit_auth_name}, unit_code={unit_code}, " | |
1737 | "unit_category={unit_category})").format( | |
1736 | 1738 | name=self.name, |
1737 | 1739 | auth_name=self.auth_name, |
1738 | 1740 | code=self.code, |
1742 | 1744 | unit_code=self.unit_code, |
1743 | 1745 | unit_category=self.unit_category, |
1744 | 1746 | ) |
1745 | ||
1746 | 1747 | |
1747 | 1748 | |
1748 | 1749 | cdef class Grid: |
1814 | 1815 | return self.full_name |
1815 | 1816 | |
1816 | 1817 | def __repr__(self): |
1817 | return ("Grid(short_name={short_name}, full_name={full_name}, package_name={package_name}, " | |
1818 | "url={url}, direct_download={direct_download}, open_license={open_license}, " | |
1818 | return ("Grid(short_name={short_name}, full_name={full_name}, " | |
1819 | "package_name={package_name}, url={url}, " | |
1820 | "direct_download={direct_download}, open_license={open_license}, " | |
1819 | 1821 | "available={available})").format( |
1820 | 1822 | short_name=self.short_name, |
1821 | 1823 | full_name=self.full_name, |
1839 | 1841 | CoordinateOperationType.CONVERSION: PJ_TYPE_CONVERSION, |
1840 | 1842 | CoordinateOperationType.TRANSFORMATION: PJ_TYPE_TRANSFORMATION, |
1841 | 1843 | CoordinateOperationType.CONCATENATED_OPERATION: PJ_TYPE_CONCATENATED_OPERATION, |
1842 | CoordinateOperationType.OTHER_COORDINATE_OPERATION: PJ_TYPE_OTHER_COORDINATE_OPERATION, | |
1844 | CoordinateOperationType.OTHER_COORDINATE_OPERATION: | |
1845 | PJ_TYPE_OTHER_COORDINATE_OPERATION, | |
1843 | 1846 | } |
1844 | 1847 | |
1845 | 1848 | cdef class CoordinateOperation(_CRSParts): |
1883 | 1886 | |
1884 | 1887 | def __init__(self): |
1885 | 1888 | raise RuntimeError( |
1886 | "CoordinateOperation can only be initialized like 'CoordinateOperation.from_*()'." | |
1889 | "CoordinateOperation can only be initialized like " | |
1890 | "CoordinateOperation.from_*()'." | |
1887 | 1891 | ) |
1888 | 1892 | |
1889 | 1893 | @staticmethod |
2588 | 2592 | try: |
2589 | 2593 | self._sub_crs_list.append(_CRS(_to_wkt(self.context, projobj))) |
2590 | 2594 | finally: |
2591 | proj_destroy(projobj) # deallocate temp proj | |
2595 | proj_destroy(projobj) # deallocate temp proj | |
2592 | 2596 | iii += 1 |
2593 | 2597 | projobj = proj_crs_get_sub_crs( |
2594 | 2598 | self.context, |
2619 | 2623 | try: |
2620 | 2624 | self._geodetic_crs = _CRS(_to_wkt(self.context, projobj)) |
2621 | 2625 | finally: |
2622 | proj_destroy(projobj) # deallocate temp proj | |
2626 | proj_destroy(projobj) # deallocate temp proj | |
2623 | 2627 | return self._geodetic_crs |
2624 | 2628 | |
2625 | 2629 | def to_proj4(self, version=ProjVersion.PROJ_4): |
2628 | 2632 | |
2629 | 2633 | .. warning:: You will likely lose important projection |
2630 | 2634 | information when converting to a PROJ string from |
2631 | another format. See: https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems | |
2635 | another format. See: | |
2636 | https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems # noqa: E501 | |
2632 | 2637 | |
2633 | 2638 | Parameters |
2634 | 2639 | ---------- |
2741 | 2746 | user_auth_name = b_auth_name |
2742 | 2747 | |
2743 | 2748 | try: |
2744 | proj_list = proj_identify( | |
2749 | proj_list = proj_identify( | |
2745 | 2750 | self.context, |
2746 | 2751 | self.projobj, |
2747 | 2752 | user_auth_name, |
2758 | 2763 | CRSError.clear() |
2759 | 2764 | |
2760 | 2765 | # check to make sure that the projection found is valid |
2761 | if proj_list == NULL or num_proj_objects <= 0 or out_confidence < min_confidence: | |
2766 | if ( | |
2767 | proj_list == NULL | |
2768 | or num_proj_objects <= 0 | |
2769 | or out_confidence < min_confidence | |
2770 | ): | |
2762 | 2771 | if proj_list != NULL: |
2763 | 2772 | proj_list_destroy(proj_list) |
2764 | 2773 | return None |
0 | 0 | include "proj.pxi" |
1 | 1 | |
2 | cdef void pyproj_context_initialize(PJ_CONTEXT* context, bint free_context_on_error) except * | |
2 | cdef void pyproj_context_initialize( | |
3 | PJ_CONTEXT* context, | |
4 | bint free_context_on_error) except * | |
3 | 5 | |
4 | 6 | cdef class ContextManager: |
5 | 7 | cdef PJ_CONTEXT *context |
29 | 29 | free(c_data_dir) |
30 | 30 | |
31 | 31 | |
32 | cdef void pyproj_context_initialize(PJ_CONTEXT* context, bint free_context_on_error) except *: | |
32 | cdef void pyproj_context_initialize( | |
33 | PJ_CONTEXT* context, | |
34 | bint free_context_on_error, | |
35 | ) except *: | |
33 | 36 | """ |
34 | 37 | Setup the context for pyproj |
35 | 38 | """ |
40 | 43 | set_context_data_dir(context) |
41 | 44 | except DataDirError: |
42 | 45 | if free_context_on_error and context != NULL: |
43 | proj_context_destroy(context) | |
46 | proj_context_destroy(context) | |
44 | 47 | raise |
45 | 48 | |
46 | 49 |
0 | 0 | cdef extern from "geodesic.h": |
1 | struct geod_geodesic: | |
1 | struct geod_geodesic: | |
2 | 2 | pass |
3 | struct geod_geodesicline: | |
3 | struct geod_geodesicline: | |
4 | 4 | pass |
5 | void geod_init(geod_geodesic* g, double a, double f) | |
6 | void geod_direct(geod_geodesic* g, | |
7 | double lat1, double lon1, double azi1, double s12, | |
8 | double* plat2, double* plon2, double* pazi2) nogil | |
9 | void geod_inverse(geod_geodesic* g, | |
10 | double lat1, double lon1, double lat2, double lon2, | |
11 | double* ps12, double* pazi1, double* pazi2) nogil | |
12 | void geod_lineinit(geod_geodesicline* l, | |
13 | geod_geodesic* g, | |
14 | double lat1, double lon1, double azi1, unsigned caps) nogil | |
15 | void geod_position(geod_geodesicline* l, double s12, | |
16 | double* plat2, double* plon2, double* pazi2) nogil | |
17 | void geod_polygonarea(geod_geodesic* g, | |
18 | double lats[], double lons[], int n, | |
19 | double* pA, double* pP) nogil | |
5 | void geod_init(geod_geodesic* g, double a, double f) | |
6 | void geod_direct( | |
7 | geod_geodesic* g, | |
8 | double lat1, | |
9 | double lon1, | |
10 | double azi1, | |
11 | double s12, | |
12 | double* plat2, | |
13 | double* plon2, | |
14 | double* pazi2) nogil | |
15 | void geod_inverse( | |
16 | geod_geodesic* g, | |
17 | double lat1, | |
18 | double lon1, | |
19 | double lat2, | |
20 | double lon2, | |
21 | double* ps12, | |
22 | double* pazi1, | |
23 | double* pazi2) nogil | |
24 | void geod_lineinit( | |
25 | geod_geodesicline* l, | |
26 | geod_geodesic* g, | |
27 | double lat1, | |
28 | double lon1, | |
29 | double azi1, | |
30 | unsigned caps) nogil | |
31 | void geod_position( | |
32 | geod_geodesicline* l, | |
33 | double s12, | |
34 | double* plat2, | |
35 | double* plon2, | |
36 | double* pazi2) nogil | |
37 | void geod_polygonarea( | |
38 | geod_geodesic* g, | |
39 | double lats[], | |
40 | double lons[], | |
41 | int n, | |
42 | double* pA, | |
43 | double* pP) nogil | |
20 | 44 | |
21 | cdef enum: | |
22 | GEODESIC_VERSION_MAJOR | |
23 | GEODESIC_VERSION_MINOR | |
24 | GEODESIC_VERSION_PATCH | |
45 | cdef enum: | |
46 | GEODESIC_VERSION_MAJOR | |
47 | GEODESIC_VERSION_MINOR | |
48 | GEODESIC_VERSION_PATCH | |
25 | 49 | |
26 | 50 | |
27 | 51 | cdef class Geod: |
25 | 25 | |
26 | 26 | def __reduce__(self): |
27 | 27 | """special method that allows pyproj.Geod instance to be pickled""" |
28 | return self.__class__,(self.initstring,) | |
29 | ||
30 | @cython.boundscheck(False) | |
31 | @cython.wraparound(False) | |
32 | def _fwd(self, object lons, object lats, object az, object dist, bint radians=False): | |
28 | return self.__class__, (self.initstring,) | |
29 | ||
30 | @cython.boundscheck(False) | |
31 | @cython.wraparound(False) | |
32 | def _fwd( | |
33 | self, | |
34 | object lons, | |
35 | object lats, | |
36 | object az, | |
37 | object dist, | |
38 | bint radians=False, | |
39 | ): | |
33 | 40 | """ |
34 | 41 | forward transformation - determine longitude, latitude and back azimuth |
35 | 42 | of a terminus point given an initial point longitude and latitude, plus |
59 | 66 | lat1 = _RAD2DG * latbuff.data[iii] |
60 | 67 | az1 = _RAD2DG * azbuff.data[iii] |
61 | 68 | s12 = distbuff.data[iii] |
62 | geod_direct(&self._geod_geodesic, lat1, lon1, az1, s12,\ | |
63 | &plat2, &plon2, &pazi2) | |
69 | geod_direct( | |
70 | &self._geod_geodesic, | |
71 | lat1, | |
72 | lon1, | |
73 | az1, | |
74 | s12, | |
75 | &plat2, | |
76 | &plon2, | |
77 | &pazi2, | |
78 | ) | |
64 | 79 | # back azimuth needs to be flipped 180 degrees |
65 | 80 | # to match what PROJ geod utility produces. |
66 | 81 | if pazi2 > 0: |
78 | 93 | |
79 | 94 | @cython.boundscheck(False) |
80 | 95 | @cython.wraparound(False) |
81 | def _inv(self, object lons1, object lats1, object lons2, object lats2, bint radians=False): | |
96 | def _inv( | |
97 | self, | |
98 | object lons1, | |
99 | object lats1, | |
100 | object lons2, | |
101 | object lats2, | |
102 | bint radians=False, | |
103 | ): | |
82 | 104 | """ |
83 | 105 | inverse transformation - return forward and back azimuths, plus distance |
84 | 106 | between an initial and terminus lat/lon pair. |
129 | 151 | |
130 | 152 | @cython.boundscheck(False) |
131 | 153 | @cython.wraparound(False) |
132 | def _npts(self, double lon1, double lat1, double lon2, double lat2, int npts, bint radians=False): | |
154 | def _npts( | |
155 | self, | |
156 | double lon1, | |
157 | double lat1, | |
158 | double lon2, | |
159 | double lat2, | |
160 | int npts, | |
161 | bint radians=False, | |
162 | ): | |
133 | 163 | """ |
134 | 164 | given initial and terminus lat/lon, find npts intermediate points. |
135 | 165 | """ |
136 | 166 | cdef Py_ssize_t iii |
137 | cdef double del_s,ps12,pazi1,pazi2,s12,plon2,plat2 | |
167 | cdef double del_s | |
168 | cdef double ps12 | |
169 | cdef double pazi1 | |
170 | cdef double pazi2 | |
171 | cdef double s12 | |
172 | cdef double plon2 | |
173 | cdef double plat2 | |
138 | 174 | cdef geod_geodesicline line |
175 | ||
139 | 176 | if radians: |
140 | 177 | lon1 = _RAD2DG * lon1 |
141 | 178 | lat1 = _RAD2DG * lat1 |
277 | 314 | ) |
278 | 315 | return (polygon_area, polygon_perimeter) |
279 | 316 | |
280 | ||
281 | 317 | def __repr__(self): |
282 | 318 | return "{classname}({init!r})".format( |
283 | 319 | classname=self.__class__.__name__, |
5 | 5 | from pyproj.compat import cstrencode, pystrdecode |
6 | 6 | from pyproj.enums import PJType |
7 | 7 | from pyproj._datadir cimport pyproj_context_initialize |
8 | ||
8 | 9 | |
9 | 10 | def get_proj_operations_map(): |
10 | 11 | """ |
162 | 163 | PJType.OTHER_COORDINATE_OPERATION: PJ_TYPE_OTHER_COORDINATE_OPERATION, |
163 | 164 | } |
164 | 165 | |
166 | ||
165 | 167 | def get_codes(auth_name, pj_type, allow_deprecated=False): |
166 | 168 | """ |
167 | 169 | .. versionadded:: 2.4.0 |
17 | 17 | ) |
18 | 18 | |
19 | 19 | |
20 | Factors = namedtuple("Factors", | |
20 | Factors = namedtuple( | |
21 | "Factors", | |
21 | 22 | [ |
22 | 23 | "meridional_scale", |
23 | 24 | "parallel_scale", |
31 | 32 | "dx_dphi", |
32 | 33 | "dy_dlam", |
33 | 34 | "dy_dphi", |
34 | ] | |
35 | ], | |
35 | 36 | ) |
36 | 37 | Factors.__doc__ = """ |
37 | 38 | .. versionadded:: 2.6.0 |
38 | 39 | |
39 | 40 | These are the scaling and angular distortion factors. |
40 | 41 | |
41 | See `PJ_FACTORS documentation <https://proj.org/development/reference/datatypes.html?highlight=pj_factors#c.PJ_FACTORS>`__ | |
42 | See `PJ_FACTORS documentation <https://proj.org/development/reference/datatypes.html?highlight=pj_factors#c.PJ_FACTORS>`__ # noqa | |
42 | 43 | |
43 | 44 | Parameters |
44 | 45 | ---------- |
106 | 107 | def _fwd(self, object lons, object lats, bint errcheck=False): |
107 | 108 | """ |
108 | 109 | forward transformation - lons,lats to x,y (done in place). |
109 | if errcheck=True, an exception is raised if the forward transformation is invalid. | |
110 | if errcheck=False and the forward transformation is invalid, no exception is | |
111 | raised and 'inf' is returned. | |
110 | if errcheck=True, an exception is raised if the forward | |
111 | transformation is invalid. if errcheck=False and the forward | |
112 | transformation is invalid, no exception is raised and 'inf' is returned. | |
112 | 113 | """ |
113 | 114 | cdef PyBuffWriteManager lonbuff = PyBuffWriteManager(lons) |
114 | 115 | cdef PyBuffWriteManager latbuff = PyBuffWriteManager(lats) |
126 | 127 | proj_errno_reset(self.projobj) |
127 | 128 | for iii in range(latbuff.len): |
128 | 129 | # if inputs are nan's, return big number. |
129 | if lonbuff.data[iii] != lonbuff.data[iii] or latbuff.data[iii] != latbuff.data[iii]: | |
130 | if ( | |
131 | lonbuff.data[iii] != lonbuff.data[iii] | |
132 | or latbuff.data[iii] != latbuff.data[iii] | |
133 | ): | |
130 | 134 | lonbuff.data[iii] = HUGE_VAL |
131 | 135 | latbuff.data[iii] = HUGE_VAL |
132 | 136 | if errcheck: |
168 | 172 | latbuff.data[iii] = projxyout.xy.y |
169 | 173 | ProjError.clear() |
170 | 174 | |
171 | ||
172 | 175 | @cython.boundscheck(False) |
173 | 176 | @cython.wraparound(False) |
174 | 177 | def _inv(self, object xx, object yy, bint errcheck=False): |
175 | 178 | """ |
176 | 179 | inverse transformation - x,y to lons,lats (done in place). |
177 | if errcheck=True, an exception is raised if the inverse transformation is invalid. | |
178 | if errcheck=False and the inverse transformation is invalid, no exception is | |
180 | if errcheck=True, an exception is raised if the inverse | |
181 | transformation is invalid. if errcheck=False and the | |
182 | inverse transformation is invalid, no exception is | |
179 | 183 | raised and 'inf' is returned. |
180 | 184 | """ |
181 | 185 | if not self.has_inverse: |
198 | 202 | proj_errno_reset(self.projobj) |
199 | 203 | for iii in range(xbuff.len): |
200 | 204 | # if inputs are nan's, return big number. |
201 | if xbuff.data[iii] != xbuff.data[iii] or ybuff.data[iii] != ybuff.data[iii]: | |
205 | if ( | |
206 | xbuff.data[iii] != xbuff.data[iii] | |
207 | or ybuff.data[iii] != ybuff.data[iii] | |
208 | ): | |
202 | 209 | xbuff.data[iii] = HUGE_VAL |
203 | 210 | ybuff.data[iii] = HUGE_VAL |
204 | 211 | if errcheck: |
268 | 275 | dx_dphi = copy.copy(longitude) |
269 | 276 | dy_dlam = copy.copy(longitude) |
270 | 277 | dy_dphi = copy.copy(longitude) |
271 | cdef PyBuffWriteManager meridional_scale_buff = PyBuffWriteManager(meridional_scale) | |
272 | cdef PyBuffWriteManager parallel_scale_buff = PyBuffWriteManager(parallel_scale) | |
278 | cdef PyBuffWriteManager meridional_scale_buff = PyBuffWriteManager( | |
279 | meridional_scale) | |
280 | cdef PyBuffWriteManager parallel_scale_buff = PyBuffWriteManager( | |
281 | parallel_scale) | |
273 | 282 | cdef PyBuffWriteManager areal_scale_buff = PyBuffWriteManager(areal_scale) |
274 | cdef PyBuffWriteManager angular_distortion_buff = PyBuffWriteManager(angular_distortion) | |
275 | cdef PyBuffWriteManager meridian_parallel_angle_buff = PyBuffWriteManager(meridian_parallel_angle) | |
276 | cdef PyBuffWriteManager meridian_convergence_buff = PyBuffWriteManager(meridian_convergence) | |
277 | cdef PyBuffWriteManager tissot_semimajor_buff = PyBuffWriteManager(tissot_semimajor) | |
278 | cdef PyBuffWriteManager tissot_semiminor_buff = PyBuffWriteManager(tissot_semiminor) | |
283 | cdef PyBuffWriteManager angular_distortion_buff = PyBuffWriteManager( | |
284 | angular_distortion) | |
285 | cdef PyBuffWriteManager meridian_parallel_angle_buff = PyBuffWriteManager( | |
286 | meridian_parallel_angle) | |
287 | cdef PyBuffWriteManager meridian_convergence_buff = PyBuffWriteManager( | |
288 | meridian_convergence) | |
289 | cdef PyBuffWriteManager tissot_semimajor_buff = PyBuffWriteManager( | |
290 | tissot_semimajor) | |
291 | cdef PyBuffWriteManager tissot_semiminor_buff = PyBuffWriteManager( | |
292 | tissot_semiminor) | |
279 | 293 | cdef PyBuffWriteManager dx_dlam_buff = PyBuffWriteManager(dx_dlam) |
280 | 294 | cdef PyBuffWriteManager dx_dphi_buff = PyBuffWriteManager(dx_dphi) |
281 | 295 | cdef PyBuffWriteManager dy_dlam_buff = PyBuffWriteManager(dy_dlam) |
329 | 343 | meridional_scale_buff.data[iii] = pj_factors.meridional_scale |
330 | 344 | parallel_scale_buff.data[iii] = pj_factors.parallel_scale |
331 | 345 | areal_scale_buff.data[iii] = pj_factors.areal_scale |
332 | angular_distortion_buff.data[iii] = pj_factors.angular_distortion * _RAD2DG | |
333 | meridian_parallel_angle_buff.data[iii] = pj_factors.meridian_parallel_angle * _RAD2DG | |
334 | meridian_convergence_buff.data[iii] = pj_factors.meridian_convergence * _RAD2DG | |
346 | angular_distortion_buff.data[iii] = ( | |
347 | pj_factors.angular_distortion * _RAD2DG | |
348 | ) | |
349 | meridian_parallel_angle_buff.data[iii] = ( | |
350 | pj_factors.meridian_parallel_angle * _RAD2DG | |
351 | ) | |
352 | meridian_convergence_buff.data[iii] = ( | |
353 | pj_factors.meridian_convergence * _RAD2DG | |
354 | ) | |
335 | 355 | tissot_semimajor_buff.data[iii] = pj_factors.tissot_semimajor |
336 | 356 | tissot_semiminor_buff.data[iii] = pj_factors.tissot_semiminor |
337 | 357 | dx_dlam_buff.data[iii] = pj_factors.dx_dlam |
32 | 32 | } |
33 | 33 | |
34 | 34 | |
35 | AreaOfInterest = namedtuple("AreaOfInterest", | |
35 | AreaOfInterest = namedtuple( | |
36 | "AreaOfInterest", | |
36 | 37 | ["west_lon_degree", "south_lat_degree", "east_lon_degree", "north_lat_degree"] |
37 | 38 | ) |
38 | 39 | AreaOfInterest.__doc__ = """ |
98 | 99 | if area_of_interest is not None: |
99 | 100 | if not isinstance(area_of_interest, AreaOfInterest): |
100 | 101 | raise ProjError( |
101 | "Area of interest must be of the type pyproj.transformer.AreaOfInterest." | |
102 | "Area of interest must be of the type " | |
103 | "pyproj.transformer.AreaOfInterest." | |
102 | 104 | ) |
103 | 105 | west_lon_degree = area_of_interest.west_lon_degree |
104 | 106 | south_lat_degree = area_of_interest.south_lat_degree |
212 | 214 | def _initialize_from_projobj(self): |
213 | 215 | self.proj_info = proj_pj_info(self.projobj) |
214 | 216 | if self.proj_info.id == NULL: |
215 | raise ProjError("Input is not a transformation.") | |
217 | raise ProjError("Input is not a transformation.") | |
216 | 218 | cdef PJ_TYPE transformer_type = proj_get_type(self.projobj) |
217 | 219 | self.type_name = _TRANSFORMER_TYPE_MAP[transformer_type] |
218 | 220 | self._set_base_info() |
276 | 278 | Create a transformer from CRS objects |
277 | 279 | """ |
278 | 280 | cdef PJ_AREA *pj_area_of_interest = NULL |
279 | cdef double west_lon_degree, south_lat_degree, east_lon_degree, north_lat_degree | |
281 | cdef double west_lon_degree | |
282 | cdef double south_lat_degree | |
283 | cdef double east_lon_degree | |
284 | cdef double north_lat_degree | |
280 | 285 | cdef _Transformer transformer = _Transformer() |
281 | 286 | try: |
282 | 287 | if area_of_interest is not None: |
283 | 288 | if not isinstance(area_of_interest, AreaOfInterest): |
284 | 289 | raise ProjError( |
285 | "Area of interest must be of the type pyproj.transformer.AreaOfInterest." | |
290 | "Area of interest must be of the type " | |
291 | "pyproj.transformer.AreaOfInterest." | |
286 | 292 | ) |
287 | 293 | pj_area_of_interest = proj_area_create() |
288 | 294 | west_lon_degree = area_of_interest.west_lon_degree |
410 | 416 | bint radians, |
411 | 417 | bint errcheck, |
412 | 418 | ): |
413 | if self.projections_exact_same or (self.projections_equivalent and self.skip_equivalent): | |
419 | if ( | |
420 | self.projections_exact_same | |
421 | or (self.projections_equivalent and self.skip_equivalent) | |
422 | ): | |
414 | 423 | return |
415 | 424 | if radians and self.is_pipeline: |
416 | 425 | warnings.warn( |
506 | 515 | bint radians, |
507 | 516 | bint errcheck, |
508 | 517 | ): |
509 | if self.projections_exact_same or (self.projections_equivalent and self.skip_equivalent): | |
518 | if ( | |
519 | self.projections_exact_same | |
520 | or (self.projections_equivalent and self.skip_equivalent) | |
521 | ): | |
510 | 522 | return |
511 | 523 | tmp_pj_direction = _PJ_DIRECTION_MAP[TransformDirection.create(direction)] |
512 | 524 | cdef PJ_DIRECTION pj_direction = <PJ_DIRECTION>tmp_pj_direction |
575 | 587 | elif errcheck and ProjError.internal_proj_error is not None: |
576 | 588 | raise ProjError("itransform error") |
577 | 589 | |
578 | ||
579 | 590 | # radians to degrees |
580 | 591 | if not radians and self._output_radians[pj_direction]: |
581 | 592 | with nogil: |
0 | # -*- coding: utf-8 -*- | |
0 | """ | |
1 | This module is for compatibility between string types | |
2 | """ | |
1 | 3 | |
2 | 4 | |
3 | 5 | def cstrencode(pystr): |
0 | # -*- coding: utf-8 -*- | |
1 | 0 | """ |
2 | 1 | This module interfaces with PROJ to produce a pythonic interface |
3 | 2 | to the coordinate reference system (CRS) information through the CRS |
4 | 3 | class. |
5 | ||
6 | Original Author: Alan D. Snow [github.com/snowman2] (2019) | |
7 | 4 | """ |
8 | 5 | |
9 | 6 | from pyproj._crs import ( # noqa: F401 |
0 | """ | |
1 | This module is for building operations to be used when | |
2 | building a CRS. | |
3 | ||
4 | https://proj.org/operations/ | |
5 | """ | |
0 | 6 | import warnings |
1 | 7 | from distutils.version import LooseVersion |
2 | 8 | from typing import Any |
0 | """ | |
1 | This module is for building coordinate systems to be used when | |
2 | building a CRS. | |
3 | """ | |
0 | 4 | from typing import Union |
1 | 5 | |
2 | 6 | from pyproj._crs import CoordinateSystem |
0 | # -*- coding: utf-8 -*- | |
1 | 0 | """ |
2 | 1 | This module interfaces with PROJ to produce a pythonic interface |
3 | 2 | to the coordinate reference system (CRS) information. |
4 | ||
5 | Original Author: Alan D. Snow [github.com/snowman2] (2019) | |
6 | ||
7 | 3 | """ |
8 | 4 | import json |
9 | 5 | import re |
0 | """ | |
1 | This module is for building datums to be used when | |
2 | building a CRS. | |
3 | """ | |
0 | 4 | from typing import Any, Dict, Optional, Union |
1 | 5 | |
2 | 6 | from pyproj._crs import Datum, Ellipsoid, PrimeMeridian |
0 | 0 | """ |
1 | Set the datadir path to the local data directory | |
1 | Module for managing the PROJ data directory. | |
2 | 2 | """ |
3 | 3 | import os |
4 | 4 | import sys |
0 | 0 | """ |
1 | Cython wrapper to provide python interfaces to | |
2 | PROJ (https://proj.org) functions. | |
3 | ||
4 | Performs geodetic computations. | |
5 | ||
6 | 1 | The Geod class can perform forward and inverse geodetic, or |
7 | 2 | Great Circle, computations. The forward computation involves |
8 | 3 | determining latitude, longitude and back azimuth of a terminus |
10 | 5 | azimuth and distance. The inverse computation involves |
11 | 6 | determining the forward and back azimuths and distance given the |
12 | 7 | latitudes and longitudes of an initial and terminus point. |
13 | ||
14 | Contact: Jeffrey Whitaker <jeffrey.s.whitaker@noaa.gov | |
15 | ||
16 | copyright (c) 2006 by Jeffrey Whitaker. | |
17 | ||
18 | Permission to use, copy, modify, and distribute this software | |
19 | and its documentation for any purpose and without fee is hereby | |
20 | granted, provided that the above copyright notice appear in all | |
21 | copies and that both the copyright notice and this permission | |
22 | notice appear in supporting documentation. THE AUTHOR DISCLAIMS | |
23 | ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL | |
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT | |
25 | SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |
26 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
27 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | |
28 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
29 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ | |
8 | """ | |
30 | 9 | |
31 | 10 | __all__ = ["Geod", "pj_ellps", "geodesic_version_str"] |
32 | 11 |
0 | # -*- coding: utf-8 -*- | |
1 | 0 | """ |
2 | Cython wrapper to provide python interfaces to | |
3 | PROJ (https://proj.org) functions. | |
4 | ||
5 | Performs cartographic transformations and geodetic computations. | |
6 | ||
7 | The Proj class can convert from geographic (longitude,latitude) | |
8 | to native map projection (x,y) coordinates and vice versa, or | |
9 | from one map projection coordinate system directly to another. | |
10 | The module variable pj_list is a dictionary containing all the | |
11 | available projections and their descriptions. | |
12 | ||
13 | Input coordinates can be given as python arrays, lists/tuples, | |
14 | scalars or numpy/Numeric/numarray arrays. Optimized for objects | |
15 | that support the Python buffer protocol (regular python and | |
16 | numpy array objects). | |
17 | ||
18 | Download: http://python.org/pypi/pyproj | |
19 | ||
20 | Contact: Jeffrey Whitaker <jeffrey.s.whitaker@noaa.gov | |
21 | ||
22 | copyright (c) 2006 by Jeffrey Whitaker. | |
23 | ||
24 | Permission to use, copy, modify, and distribute this software | |
25 | and its documentation for any purpose and without fee is hereby | |
26 | granted, provided that the above copyright notice appear in all | |
27 | copies and that both the copyright notice and this permission | |
28 | notice appear in supporting documentation. THE AUTHOR DISCLAIMS | |
29 | ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL | |
30 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT | |
31 | SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |
32 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
33 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | |
34 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
35 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ | |
1 | Performs cartographic transformations (converts from | |
2 | longitude,latitude to native map projection x,y coordinates and | |
3 | vice versa) using PROJ (https://proj.org). | |
4 | ||
5 | A Proj class instance is initialized with proj map projection | |
6 | control parameter key/value pairs. The key/value pairs can | |
7 | either be passed in a dictionary, or as keyword arguments, | |
8 | or as a PROJ string (compatible with the proj command). See | |
9 | https://proj.org/operations/projections/index.html for examples of | |
10 | key/value pairs defining different map projections. | |
11 | ||
12 | Calling a Proj class instance with the arguments lon, lat will | |
13 | convert lon/lat (in degrees) to x/y native map projection | |
14 | coordinates (in meters). | |
15 | """ | |
36 | 16 | import re |
37 | 17 | import warnings |
38 | 18 | from typing import Any, Optional, Tuple, Type |
50 | 30 | """ |
51 | 31 | Performs cartographic transformations (converts from |
52 | 32 | longitude,latitude to native map projection x,y coordinates and |
53 | vice versa) using proj (https://proj.org). | |
33 | vice versa) using PROJ (https://proj.org). | |
54 | 34 | |
55 | 35 | A Proj class instance is initialized with proj map projection |
56 | 36 | control parameter key/value pairs. The key/value pairs can |
0 | # -*- coding: utf-8 -*- | |
1 | 0 | """ |
2 | 1 | The transformer module is for performing cartographic transformations. |
3 | ||
4 | Copyright (c) 2019 pyproj Contributors. | |
5 | ||
6 | Permission to use, copy, modify, and distribute this software | |
7 | and its documentation for any purpose and without fee is hereby | |
8 | granted, provided that the above copyright notice appear in all | |
9 | copies and that both the copyright notice and this permission | |
10 | notice appear in supporting documentation. THE AUTHOR DISCLAIMS | |
11 | ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL | |
12 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT | |
13 | SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |
14 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | |
16 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
17 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.""" | |
2 | """ | |
18 | 3 | |
19 | 4 | __all__ = [ |
20 | 5 | "transform", |
0 | """ | |
1 | Utility functions used within pyproj | |
2 | """ | |
0 | 3 | from array import array |
1 | 4 | from typing import Any, Tuple |
2 | 5 |
148 | 148 | include_dirs = get_proj_incdirs(proj_dir) |
149 | 149 | |
150 | 150 | # setup extension options |
151 | ext_options = dict( | |
152 | include_dirs=include_dirs, | |
153 | library_dirs=library_dirs, | |
154 | runtime_library_dirs=library_dirs if os.name != "nt" else None, | |
155 | libraries=get_libraries(library_dirs), | |
156 | ) | |
151 | ext_options = { | |
152 | "include_dirs": include_dirs, | |
153 | "library_dirs": library_dirs, | |
154 | "runtime_library_dirs": library_dirs if os.name != "nt" else None, | |
155 | "libraries": get_libraries(library_dirs), | |
156 | } | |
157 | 157 | # setup cythonized modules |
158 | 158 | return cythonize( |
159 | 159 | [ |
222 | 222 | author="Jeff Whitaker", |
223 | 223 | author_email="jeffrey.s.whitaker@noaa.gov", |
224 | 224 | platforms=["any"], |
225 | license="OSI Approved", | |
225 | license="MIT", | |
226 | 226 | keywords=["python", "map projections", "GIS", "mapping", "maps"], |
227 | 227 | classifiers=[ |
228 | 228 | "Development Status :: 4 - Beta", |
229 | 229 | "Intended Audience :: Science/Research", |
230 | "License :: OSI Approved", | |
231 | 230 | "Programming Language :: Python :: 3", |
232 | 231 | "Programming Language :: Python :: 3.5", |
233 | 232 | "Programming Language :: Python :: 3.6", |
32 | 32 | ) |
33 | 33 | awips221_from_dict = Proj(params, preserve_units=False) |
34 | 34 | |
35 | items = sorted([val for val in awips221.crs.srs.split() if val]) | |
36 | items_dict = sorted([val for val in awips221_from_dict.crs.srs.split() if val]) | |
35 | items = sorted(val for val in awips221.crs.srs.split() if val) | |
36 | items_dict = sorted(val for val in awips221_from_dict.crs.srs.split() if val) | |
37 | 37 | self.assertEqual(items, items_dict) |
38 | 38 | |
39 | 39 | expected = sorted( |