Codebase list python-pyproj / 076e847
Update upstream source from tag 'upstream/3.2.1_rc0' Update to upstream version '3.2.1~rc0' with Debian dir a27601f6a95c5dee4768b6c49a0e8c82795f9327 Bas Couwenberg 2 years ago
26 changed file(s) with 428 addition(s) and 305 deletion(s). Raw diff Collapse all Expand all
00 Change Log
11 ==========
22
3 3.2.1
4 ------
5 - REF: declare specific python types in cython (pull #928)
6 - REF: Use cython string decoding (pull #929)
7 - BUG: Return multiple authorities with :attr:`pyproj.crs.CRS.list_authority` (pull #943)
8 - BUG: CRS CF conversions ensure lon_0 = north_pole_grid_longitude + 180 (issue #927)
9 - BUG: CRS CF conversions ensure Pole rotation (netCDF CF convention) conversion works (issue #927)
10
311 3.2.0
412 ------
5 * WHL: Wheels contain PROJ 8.1.1
13 - WHL: Wheels contain PROJ 8.1.1
614 - DOC: Add new pyproj logo (issue #700)
715 - REF: Handle deprecation of proj_context_set_autoclose_database (issue #866)
816 - REF: Make CRS methods inheritable (issue #847)
00 Documentation Archive
11 =====================
22
3 - `3.2.0 <https://pyproj4.github.io/pyproj/3.2.0/>`_
34 - `3.1.0 <https://pyproj4.github.io/pyproj/3.1.0/>`_
45 - `3.0.1 <https://pyproj4.github.io/pyproj/3.0.1/>`_
56 - `2.6.1 <https://pyproj4.github.io/pyproj/v2.6.1rel/>`_
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__ = "3.2.0"
30 __version__ = "3.2.1.rc0"
3131 __all__ = [
3232 "Proj",
3333 "Geod",
0 from pyproj.compat import pystrdecode
0 cdef str cstrdecode(const char *instring)
1 cpdef bytes cstrencode(str pystr)
12
3 IF CTE_PYTHON_IMPLEMENTATION == "CPython":
4 from cpython cimport array
5 cdef array.array empty_array(int npts)
26
3 cdef cstrdecode(const char *instring)
7 ELSE:
8 # https://github.com/pyproj4/pyproj/issues/854
9 cdef empty_array(int npts)
0 def cstrencode(pystr: str) -> bytes: ...
00 import array
11
2 from pyproj.compat import pystrdecode
2
3 cpdef bytes cstrencode(str pystr):
4 """
5 Encode a string into bytes.
6 """
7 try:
8 return pystr.encode("utf-8")
9 except UnicodeDecodeError:
10 return pystr.decode("utf-8").encode("utf-8")
311
412
5 cdef cstrdecode(const char *instring):
13 cdef str cstrdecode(const char *instring):
614 if instring != NULL:
7 return pystrdecode(instring)
15 return instring
816 return None
917
1018
1321
1422 cdef array.array _ARRAY_TEMPLATE = array.array("d", [])
1523
16 def empty_array(int npts):
24 cdef array.array empty_array(int npts):
1725 return array.clone(_ARRAY_TEMPLATE, npts, zero=False)
1826
1927 ELSE:
2028 # https://github.com/pyproj4/pyproj/issues/854
21 def empty_array(int npts):
29 cdef empty_array(int npts):
2230 return array.array("d", [float("NaN")] * npts)
55 const PJ* crs_2D)
66
77
8 cdef _get_concatenated_operations(PJ_CONTEXT*context, PJ*concatenated_operation)
8 cdef tuple _get_concatenated_operations(PJ_CONTEXT*context, PJ*concatenated_operation)
99 cdef _to_proj4(
1010 PJ_CONTEXT* context,
1111 PJ* projobj,
12 version,
13 pretty,
12 object version,
13 bint pretty,
1414 )
1515
1616 cdef class Axis:
17 cdef readonly object name
18 cdef readonly object abbrev
19 cdef readonly object direction
17 cdef readonly str name
18 cdef readonly str abbrev
19 cdef readonly str direction
2020 cdef readonly double unit_conversion_factor
21 cdef readonly object unit_name
22 cdef readonly object unit_auth_code
23 cdef readonly object unit_code
21 cdef readonly str unit_name
22 cdef readonly str unit_auth_code
23 cdef readonly str unit_code
2424
2525 @staticmethod
2626 cdef Axis create(PJ_CONTEXT* context, PJ* projobj, int index)
3030 cdef class Base:
3131 cdef PJ *projobj
3232 cdef PJ_CONTEXT* context
33 cdef readonly object name
34 cdef readonly object _remarks
35 cdef readonly object _scope
33 cdef readonly str name
34 cdef readonly str _remarks
35 cdef readonly str _scope
3636 cdef _set_base_info(self)
3737
3838 cdef class _CRSParts(Base):
4242 cdef class Ellipsoid(_CRSParts):
4343 cdef readonly double semi_major_metre
4444 cdef readonly double semi_minor_metre
45 cdef readonly object is_semi_minor_computed
45 cdef readonly bint is_semi_minor_computed
4646 cdef readonly double inverse_flattening
4747
4848 @staticmethod
5252 cdef class PrimeMeridian(_CRSParts):
5353 cdef readonly double longitude
5454 cdef readonly double unit_conversion_factor
55 cdef readonly object unit_name
55 cdef readonly str unit_name
5656
5757 @staticmethod
5858 cdef PrimeMeridian create(PJ_CONTEXT* context, PJ* prime_meridian_pj)
5959
6060
6161 cdef class Datum(_CRSParts):
62 cdef readonly object type_name
62 cdef readonly str type_name
6363 cdef readonly object _ellipsoid
6464 cdef readonly object _prime_meridian
6565
6868
6969
7070 cdef class CoordinateSystem(_CRSParts):
71 cdef readonly object _axis_list
71 cdef readonly list _axis_list
7272
7373 @staticmethod
7474 cdef CoordinateSystem create(PJ_CONTEXT* context, PJ* coordinate_system_pj)
7575
7676
7777 cdef class Param:
78 cdef readonly object name
79 cdef readonly object auth_name
80 cdef readonly object code
78 cdef readonly str name
79 cdef readonly str auth_name
80 cdef readonly str code
8181 cdef readonly object value
8282 cdef readonly double unit_conversion_factor
83 cdef readonly object unit_name
84 cdef readonly object unit_auth_name
85 cdef readonly object unit_code
86 cdef readonly object unit_category
83 cdef readonly str unit_name
84 cdef readonly str unit_auth_name
85 cdef readonly str unit_code
86 cdef readonly str unit_category
8787
8888 @staticmethod
8989 cdef Param create(PJ_CONTEXT* context, PJ* projobj, int param_idx)
9090
9191
9292 cdef class Grid:
93 cdef readonly object short_name
94 cdef readonly object full_name
95 cdef readonly object package_name
96 cdef readonly object url
97 cdef readonly object direct_download
98 cdef readonly object open_license
99 cdef readonly object available
93 cdef readonly str short_name
94 cdef readonly str full_name
95 cdef readonly str package_name
96 cdef readonly str url
97 cdef readonly bint direct_download
98 cdef readonly bint open_license
99 cdef readonly bint available
100100
101101 @staticmethod
102102 cdef Grid create(PJ_CONTEXT* context, PJ* projobj, int grid_idx)
103103
104104
105105 cdef class CoordinateOperation(_CRSParts):
106 cdef readonly object _params
107 cdef readonly object _grids
106 cdef readonly list _params
107 cdef readonly list _grids
108108 cdef readonly object _area_of_use
109 cdef readonly object method_name
110 cdef readonly object method_auth_name
111 cdef readonly object method_code
109 cdef readonly str method_name
110 cdef readonly str method_auth_name
111 cdef readonly str method_code
112112 cdef readonly double accuracy
113 cdef readonly object is_instantiable
114 cdef readonly object has_ballpark_transformation
115 cdef readonly object _towgs84
116 cdef readonly object _operations
117 cdef readonly type_name
113 cdef readonly bint is_instantiable
114 cdef readonly bint has_ballpark_transformation
115 cdef readonly list _towgs84
116 cdef readonly tuple _operations
117 cdef readonly str type_name
118118
119119 @staticmethod
120120 cdef CoordinateOperation create(PJ_CONTEXT* context, PJ* coordinate_operation_pj)
123123 cdef class _CRS(Base):
124124 cdef PJ_TYPE _type
125125 cdef PJ_PROJ_INFO projpj_info
126 cdef readonly object srs
127 cdef readonly object type_name
128 cdef readonly object _ellipsoid
126 cdef readonly str srs
127 cdef readonly str type_name
128 cdef readonly Ellipsoid _ellipsoid
129129 cdef readonly object _area_of_use
130 cdef readonly object _prime_meridian
131 cdef readonly object _datum
132 cdef readonly object _sub_crs_list
133 cdef readonly object _source_crs
134 cdef readonly object _target_crs
135 cdef readonly object _geodetic_crs
136 cdef readonly object _coordinate_system
137 cdef readonly object _coordinate_operation
130 cdef readonly PrimeMeridian _prime_meridian
131 cdef readonly Datum _datum
132 cdef readonly list _sub_crs_list
133 cdef readonly _CRS _source_crs
134 cdef readonly _CRS _target_crs
135 cdef readonly _CRS _geodetic_crs
136 cdef readonly CoordinateSystem _coordinate_system
137 cdef readonly CoordinateOperation _coordinate_operation
184184 ] = CoordinateOperationType.CONVERSION,
185185 ) -> "CoordinateOperation": ...
186186
187
188187 class AuthorityMatchInfo(NamedTuple):
189188 auth_name: str
190189 code: str
191190 confidence: int
192
193191
194192 class _CRS(Base):
195193 srs: str
22 import warnings
33 from collections import OrderedDict, namedtuple
44
5 from pyproj._compat cimport cstrdecode
5 from pyproj._compat cimport cstrdecode, cstrencode
66 from pyproj._datadir cimport pyproj_context_create, pyproj_context_destroy
77
88 from pyproj.aoi import AreaOfUse
9 from pyproj.compat import cstrencode, pystrdecode
109 from pyproj.crs.datum import CustomEllipsoid
1110 from pyproj.crs.enums import CoordinateOperationType, DatumType
1211 from pyproj.enums import ProjVersion, WktVersion
1413 from pyproj.geod import pj_ellps
1514 from pyproj.utils import NumpyEncoder
1615
16
1717 # This is for looking up the ellipsoid parameters
1818 # based on the long name
19 _PJ_ELLPS_NAME_MAP = {
19 cdef dict _PJ_ELLPS_NAME_MAP = {
2020 ellps["description"]: ellps_id for ellps_id, ellps in pj_ellps.items()
2121 }
2222
2323
24 cdef decode_or_undefined(const char* instring):
24 cdef str decode_or_undefined(const char* instring):
2525 pystr = cstrdecode(instring)
2626 if pystr is None:
2727 return "undefined"
2828 return pystr
2929
3030
31 def is_wkt(proj_string):
31 def is_wkt(str proj_string not None):
3232 """
3333 .. versionadded:: 2.0.0
3434
4343 -------
4444 bool: True if the string is in the Well-Known Text format
4545 """
46 tmp_string = cstrencode(proj_string)
47 return proj_context_guess_wkt_dialect(NULL, tmp_string) != PJ_GUESSED_NOT_WKT
48
49
50 def is_proj(proj_string):
46 cdef bytes b_proj_string = cstrencode(proj_string)
47 return proj_context_guess_wkt_dialect(NULL, b_proj_string) != PJ_GUESSED_NOT_WKT
48
49
50 def is_proj(str proj_string not None):
5151 """
5252 .. versionadded:: 2.2.2
5353
6868 cdef _to_wkt(
6969 PJ_CONTEXT* context,
7070 PJ* projobj,
71 version=WktVersion.WKT2_2019,
72 pretty=False
71 object version=WktVersion.WKT2_2019,
72 bint pretty=False
7373 ):
7474 """
7575 Convert a PJ object to a wkt string.
100100 wkt_out_type = supported_wkt_types[WktVersion.create(version)]
101101
102102 cdef const char* options_wkt[2]
103 multiline = b"MULTILINE=NO"
103 cdef bytes multiline = b"MULTILINE=NO"
104104 if pretty:
105105 multiline = b"MULTILINE=YES"
106106 options_wkt[0] = multiline
119119 cdef _to_proj4(
120120 PJ_CONTEXT* context,
121121 PJ* projobj,
122 version,
123 pretty,
122 object version,
123 bint pretty,
124124 ):
125125 """
126126 Convert the projection to a PROJ string.
146146 proj_out_type = supported_prj_types[ProjVersion.create(version)]
147147
148148 cdef const char* options[2]
149 multiline = b"MULTILINE=NO"
149 cdef bytes multiline = b"MULTILINE=NO"
150150 if pretty:
151151 multiline = b"MULTILINE=YES"
152152 options[0] = multiline
164164 return cstrdecode(proj_string)
165165
166166
167 cdef _get_concatenated_operations(PJ_CONTEXT* context, PJ* concatenated_operation):
167 cdef tuple _get_concatenated_operations(
168 PJ_CONTEXT* context, PJ* concatenated_operation
169 ):
168170 """
169171 For a PJ* of type concatenated operation, get the operations
170172 """
189191
190192 cdef PJ * _from_name(
191193 PJ_CONTEXT* context,
192 name_string,
193 auth_name,
194 str name_string,
195 str auth_name,
194196 PJ_TYPE pj_type,
195197 ):
196198 """
214216 """
215217 cdef PJ_TYPE[1] pj_types = [pj_type]
216218 cdef char* c_auth_name = NULL
219 cdef bytes b_auth_name
217220 if auth_name is not None:
218221 b_auth_name = cstrencode(auth_name)
219222 c_auth_name = b_auth_name
236239 return datum_pj
237240
238241
239 def _load_proj_json(in_proj_json):
242 def _load_proj_json(str in_proj_json):
240243 try:
241244 return json.loads(in_proj_json)
242245 except ValueError:
356359 cdef const char* proj_name = proj_get_name(self.projobj)
357360 self.name = decode_or_undefined(proj_name)
358361 cdef const char* scope = proj_get_scope(self.projobj)
359 if scope != NULL:
360 py_scope = pystrdecode(scope)
361 self._scope = py_scope if py_scope else self._scope
362 if scope != NULL and scope != "":
363 self._scope = scope
362364 cdef const char* remarks = proj_get_remarks(self.projobj)
363 if remarks != NULL:
364 py_remarks = pystrdecode(remarks)
365 self._remarks = py_remarks if py_remarks else self._remarks
365 if remarks != NULL and remarks != "":
366 self._remarks = remarks
366367
367368 @property
368369 def remarks(self):
414415 """
415416 return _to_wkt(self.context, self.projobj, version, pretty=pretty)
416417
417 def to_json(self, pretty=False, indentation=2):
418 def to_json(self, bint pretty=False, int indentation=2):
418419 """
419420 .. versionadded:: 2.4.0
420421
535536 return self._is_equivalent(other)
536537
537538
538 _COORD_SYSTEM_TYPE_MAP = {
539 cdef dict _COORD_SYSTEM_TYPE_MAP = {
539540 PJ_CS_TYPE_UNKNOWN: "unknown",
540541 PJ_CS_TYPE_CARTESIAN: "cartesian",
541542 PJ_CS_TYPE_ELLIPSOIDAL: "ellipsoidal",
606607 return self._axis_list
607608
608609 @staticmethod
609 def from_string(coordinate_system_string):
610 def from_string(str coordinate_system_string not None):
610611 """
611612 .. versionadded:: 2.5.0
612613
636637 pyproj_context_destroy(context)
637638 raise CRSError(
638639 "Invalid coordinate system string: "
639 f"{pystrdecode(coordinate_system_string)}"
640 f"{coordinate_system_string}"
640641 )
641642 CRSError.clear()
642643 return CoordinateSystem.create(context, coordinate_system_pj)
643644
644645 @staticmethod
645 def from_json_dict(coordinate_system_dict):
646 def from_json_dict(dict coordinate_system_dict not None):
646647 """
647648 .. versionadded:: 2.5.0
648649
662663 )
663664
664665 @staticmethod
665 def from_json(coordinate_system_json_str):
666 def from_json(str coordinate_system_json_str not None):
666667 """
667668 .. versionadded:: 2.5.0
668669
681682 _load_proj_json(coordinate_system_json_str)
682683 )
683684
684 def to_cf(self, rotated_pole=False):
685 def to_cf(self, bint rotated_pole=False):
685686 """
686687 .. versionadded:: 3.0.0
687688
815816 return ellips
816817
817818 @staticmethod
818 def from_authority(auth_name, code):
819 def from_authority(str auth_name not None, code not None):
819820 """
820821 .. versionadded:: 2.2.0
821822
849850 return Ellipsoid.create(context, ellipsoid_pj)
850851
851852 @staticmethod
852 def from_epsg(code):
853 def from_epsg(code not None):
853854 """
854855 .. versionadded:: 2.2.0
855856
867868 return Ellipsoid.from_authority("EPSG", code)
868869
869870 @staticmethod
870 def _from_string(ellipsoid_string):
871 def _from_string(str ellipsoid_string not None):
871872 """
872873 Create an Ellipsoid from a string.
873874
895896 proj_destroy(ellipsoid_pj)
896897 pyproj_context_destroy(context)
897898 raise CRSError(
898 f"Invalid ellipsoid string: {pystrdecode(ellipsoid_string)}"
899 f"Invalid ellipsoid string: {ellipsoid_string}"
899900 )
900901 CRSError.clear()
901902 return Ellipsoid.create(context, ellipsoid_pj)
902903
903904 @staticmethod
904 def from_string(ellipsoid_string):
905 def from_string(str ellipsoid_string not None):
905906 """
906907 .. versionadded:: 2.2.0
907908
932933 raise crs_err
933934
934935 @staticmethod
935 def from_json_dict(ellipsoid_dict):
936 def from_json_dict(dict ellipsoid_dict not None):
936937 """
937938 .. versionadded:: 2.4.0
938939
950951 return Ellipsoid._from_string(json.dumps(ellipsoid_dict, cls=NumpyEncoder))
951952
952953 @staticmethod
953 def from_json(ellipsoid_json_str):
954 def from_json(str ellipsoid_json_str not None):
954955 """
955956 .. versionadded:: 2.4.0
956957
969970
970971 @staticmethod
971972 def _from_name(
972 ellipsoid_name,
973 auth_name,
973 str ellipsoid_name,
974 str auth_name,
974975 ):
975976 """
976977 .. versionadded:: 2.5.0
998999 )
9991000 if ellipsoid_pj == NULL:
10001001 pyproj_context_destroy(context)
1001 raise CRSError(f"Invalid ellipsoid name: {pystrdecode(ellipsoid_name)}")
1002 raise CRSError(f"Invalid ellipsoid name: {ellipsoid_name}")
10021003 CRSError.clear()
10031004 return Ellipsoid.create(context, ellipsoid_pj)
10041005
10051006 @staticmethod
10061007 def from_name(
1007 ellipsoid_name,
1008 auth_name=None,
1008 str ellipsoid_name not None,
1009 str auth_name=None,
10091010 ):
10101011 """
10111012 .. versionadded:: 2.5.0
10931094 return prime_meridian
10941095
10951096 @staticmethod
1096 def from_authority(auth_name, code):
1097 def from_authority(str auth_name not None, code not None):
10971098 """
10981099 .. versionadded:: 2.2.0
10991100
11271128 return PrimeMeridian.create(context, prime_meridian_pj)
11281129
11291130 @staticmethod
1130 def from_epsg(code):
1131 def from_epsg(code not None):
11311132 """
11321133 .. versionadded:: 2.2.0
11331134
11451146 return PrimeMeridian.from_authority("EPSG", code)
11461147
11471148 @staticmethod
1148 def _from_string(prime_meridian_string):
1149 def _from_string(str prime_meridian_string not None):
11491150 """
11501151 Create an PrimeMeridian from a string.
11511152
11761177 proj_destroy(prime_meridian_pj)
11771178 pyproj_context_destroy(context)
11781179 raise CRSError(
1179 f"Invalid prime meridian string: {pystrdecode(prime_meridian_string)}"
1180 f"Invalid prime meridian string: {prime_meridian_string}"
11801181 )
11811182 CRSError.clear()
11821183 return PrimeMeridian.create(context, prime_meridian_pj)
11831184
11841185 @staticmethod
1185 def from_string(prime_meridian_string):
1186 def from_string(str prime_meridian_string not None):
11861187 """
11871188 .. versionadded:: 2.2.0
11881189
12131214 raise crs_err
12141215
12151216 @staticmethod
1216 def from_json_dict(prime_meridian_dict):
1217 def from_json_dict(dict prime_meridian_dict not None):
12171218 """
12181219 .. versionadded:: 2.4.0
12191220
12331234 )
12341235
12351236 @staticmethod
1236 def from_json(prime_meridian_json_str):
1237 def from_json(str prime_meridian_json_str not None):
12371238 """
12381239 .. versionadded:: 2.4.0
12391240
12521253
12531254 @staticmethod
12541255 def from_name(
1255 prime_meridian_name,
1256 auth_name=None,
1256 str prime_meridian_name not None,
1257 str auth_name=None,
12571258 ):
12581259 """
12591260 .. versionadded:: 2.5.0
12851286 if prime_meridian_pj == NULL:
12861287 pyproj_context_destroy(context)
12871288 raise CRSError(
1288 f"Invalid prime meridian name: {pystrdecode(prime_meridian_name)}"
1289 f"Invalid prime meridian name: {prime_meridian_name}"
12891290 )
12901291 CRSError.clear()
12911292 return PrimeMeridian.create(context, prime_meridian_pj)
12921293
12931294
1294 _DATUM_TYPE_MAP = {
1295 cdef dict _DATUM_TYPE_MAP = {
12951296 PJ_TYPE_GEODETIC_REFERENCE_FRAME: "Geodetic Reference Frame",
12961297 PJ_TYPE_DYNAMIC_GEODETIC_REFERENCE_FRAME: "Dynamic Geodetic Reference Frame",
12971298 PJ_TYPE_VERTICAL_REFERENCE_FRAME: "Vertical Reference Frame",
13021303 PJ_TYPE_PARAMETRIC_DATUM: "Parametric Datum",
13031304 }
13041305
1305 _PJ_DATUM_TYPE_MAP = {
1306 cdef dict _PJ_DATUM_TYPE_MAP = {
13061307 DatumType.DATUM_ENSEMBLE: PJ_TYPE_DATUM_ENSEMBLE,
13071308 DatumType.GEODETIC_REFERENCE_FRAME: PJ_TYPE_GEODETIC_REFERENCE_FRAME,
13081309 DatumType.DYNAMIC_GEODETIC_REFERENCE_FRAME:
13441345 return datum
13451346
13461347 @staticmethod
1347 def _from_authority(auth_name, code, PJ_CATEGORY category):
1348 def _from_authority(str auth_name not None, code not None, PJ_CATEGORY category):
13481349 """
13491350 Create a Datum from an authority code.
13501351
13631364
13641365 cdef PJ* datum_pj = proj_create_from_database(
13651366 context,
1366 cstrencode(str(auth_name)),
1367 cstrencode(auth_name),
13671368 cstrencode(str(code)),
13681369 category,
13691370 False,
13771378 return Datum.create(context, datum_pj)
13781379
13791380 @staticmethod
1380 def from_authority(auth_name, code):
1381 def from_authority(str auth_name not None, code not None):
13811382 """
13821383 Create a Datum from an authority code.
13831384
13981399 return Datum._from_authority(auth_name, code, PJ_CATEGORY_DATUM)
13991400
14001401 @staticmethod
1401 def from_epsg(code):
1402 def from_epsg(code not None):
14021403 """
14031404 Create a Datum from an EPSG code.
14041405
14141415 return Datum.from_authority("EPSG", code)
14151416
14161417 @staticmethod
1417 def _from_string(datum_string):
1418 def _from_string(str datum_string not None):
14181419 """
14191420 Create a Datum from a string.
14201421
14451446 ):
14461447 proj_destroy(datum_pj)
14471448 pyproj_context_destroy(context)
1448 raise CRSError(f"Invalid datum string: {pystrdecode(datum_string)}")
1449 raise CRSError(f"Invalid datum string: {datum_string}")
14491450 CRSError.clear()
14501451 return Datum.create(context, datum_pj)
14511452
14521453 @staticmethod
1453 def from_string(datum_string):
1454 def from_string(str datum_string not None):
14541455 """
14551456 Create a Datum from a string.
14561457
14811482
14821483 @staticmethod
14831484 def _from_name(
1484 datum_name,
1485 auth_name,
1486 datum_type,
1485 str datum_name,
1486 str auth_name,
1487 object datum_type,
14871488 ):
14881489 """
14891490 .. versionadded:: 2.5.0
15141515 )
15151516 if datum_pj == NULL:
15161517 pyproj_context_destroy(context)
1517 raise CRSError(f"Invalid datum name: {pystrdecode(datum_name)}")
1518 raise CRSError(f"Invalid datum name: {datum_name}")
15181519 CRSError.clear()
15191520 return Datum.create(context, datum_pj)
15201521
15211522 @staticmethod
15221523 def from_name(
1523 datum_name,
1524 auth_name=None,
1524 str datum_name not None,
1525 str auth_name=None,
15251526 datum_type=None,
15261527 ):
15271528 """
15701571 )
15711572
15721573 @staticmethod
1573 def from_json_dict(datum_dict):
1574 def from_json_dict(dict datum_dict not None):
15741575 """
15751576 .. versionadded:: 2.4.0
15761577
15881589 return Datum._from_string(json.dumps(datum_dict, cls=NumpyEncoder))
15891590
15901591 @staticmethod
1591 def from_json(datum_json_str):
1592 def from_json(str datum_json_str not None):
15921593 """
15931594 .. versionadded:: 2.4.0
15941595
18231824 )
18241825
18251826
1826 _COORDINATE_OPERATION_TYPE_MAP = {
1827 cdef dict _COORDINATE_OPERATION_TYPE_MAP = {
18271828 PJ_TYPE_UNKNOWN: "Unknown",
18281829 PJ_TYPE_CONVERSION: "Conversion",
18291830 PJ_TYPE_TRANSFORMATION: "Transformation",
18311832 PJ_TYPE_OTHER_COORDINATE_OPERATION: "Other Coordinate Operation",
18321833 }
18331834
1834 _PJ_COORDINATE_OPERATION_TYPE_MAP = {
1835 cdef dict _PJ_COORDINATE_OPERATION_TYPE_MAP = {
18351836 CoordinateOperationType.CONVERSION: PJ_TYPE_CONVERSION,
18361837 CoordinateOperationType.TRANSFORMATION: PJ_TYPE_TRANSFORMATION,
18371838 CoordinateOperationType.CONCATENATED_OPERATION: PJ_TYPE_CONCATENATED_OPERATION,
19241925 return coord_operation
19251926
19261927 @staticmethod
1927 def from_authority(auth_name, code, use_proj_alternative_grid_names=False):
1928 def from_authority(
1929 str auth_name not None,
1930 code not None,
1931 bint use_proj_alternative_grid_names=False,
1932 ):
19281933 """
19291934 Create a CoordinateOperation from an authority code.
19301935
19581963 return CoordinateOperation.create(context, coord_operation_pj)
19591964
19601965 @staticmethod
1961 def from_epsg(code, use_proj_alternative_grid_names=False):
1966 def from_epsg(code not None, bint use_proj_alternative_grid_names= False):
19621967 """
19631968 Create a CoordinateOperation from an EPSG code.
19641969
19781983 )
19791984
19801985 @staticmethod
1981 def _from_string(coordinate_operation_string):
1986 def _from_string(str coordinate_operation_string not None):
19821987 """
19831988 Create a CoordinateOperation from a string.
19841989
20122017 pyproj_context_destroy(context)
20132018 raise CRSError(
20142019 "Invalid coordinate operation string: "
2015 f"{pystrdecode(coordinate_operation_string)}"
2020 f"{coordinate_operation_string}"
20162021 )
20172022 CRSError.clear()
20182023 return CoordinateOperation.create(context, coord_operation_pj)
20192024
20202025 @staticmethod
2021 def from_string(coordinate_operation_string):
2026 def from_string(str coordinate_operation_string not None):
20222027 """
20232028 Create a CoordinateOperation from a string.
20242029
20452050 raise crs_err
20462051
20472052 @staticmethod
2048 def from_json_dict(coordinate_operation_dict):
2053 def from_json_dict(dict coordinate_operation_dict not None):
20492054 """
20502055 Create CoordinateOperation from a JSON dictionary.
20512056
20652070 )
20662071
20672072 @staticmethod
2068 def from_json(coordinate_operation_json_str):
2073 def from_json(str coordinate_operation_json_str not None):
20692074 """
20702075 Create CoordinateOperation from a JSON string.
20712076
20862091
20872092 @staticmethod
20882093 def from_name(
2089 coordinate_operation_name,
2090 auth_name=None,
2091 coordinate_operation_type=CoordinateOperationType.CONVERSION,
2094 str coordinate_operation_name not None,
2095 str auth_name=None,
2096 coordinate_operation_type not None=CoordinateOperationType.CONVERSION,
20922097 ):
20932098 """
20942099 .. versionadded:: 2.5.0
21272132 pyproj_context_destroy(context)
21282133 raise CRSError(
21292134 "Invalid coordinate operation name: "
2130 f"{pystrdecode(coordinate_operation_name)}"
2135 f"{coordinate_operation_name}"
21312136 )
21322137 CRSError.clear()
21332138 return CoordinateOperation.create(context, coordinate_operation_pj)
21992204 self._area_of_use = create_area_of_use(self.context, self.projobj)
22002205 return self._area_of_use
22012206
2202 def to_proj4(self, version=ProjVersion.PROJ_5, pretty=False):
2207 def to_proj4(self, version not None=ProjVersion.PROJ_5, bint pretty=False):
22032208 """
22042209 Convert the projection to a PROJ string.
22052210
22972302 """
22982303
22992304
2300 _CRS_TYPE_MAP = {
2305 cdef dict _CRS_TYPE_MAP = {
23012306 PJ_TYPE_UNKNOWN: "Unknown CRS",
23022307 PJ_TYPE_CRS: "CRS",
23032308 PJ_TYPE_GEODETIC_CRS: "Geodetic CRS",
23352340 self._coordinate_operation = None
23362341 self.type_name = "undefined"
23372342
2338 def __init__(self, proj_string):
2343 def __init__(self, const char *proj_string):
23392344 self.context = pyproj_context_create()
23402345 # initialize projection
23412346 self.projobj = proj_create(
23422347 self.context,
2343 cstrencode(proj_string),
2348 proj_string,
23442349 )
23452350 if self.projobj == NULL:
2346 raise CRSError(f"Invalid projection: {pystrdecode(proj_string)}")
2351 raise CRSError(f"Invalid projection: {proj_string}")
23472352 # make sure the input is a CRS
23482353 if not proj_is_crs(self.projobj):
23492354 raise CRSError(f"Input is not a CRS: {proj_string}")
23502355 # set proj information
2351 self.srs = pystrdecode(proj_string)
2356 self.srs = proj_string
23522357 self._type = proj_get_type(self.projobj)
23532358 self.type_name = _CRS_TYPE_MAP[self._type]
23542359 self._set_base_info()
26662671 )
26672672 return _to_proj4(self.context, self.projobj, version=version, pretty=False)
26682673
2669 def to_epsg(self, min_confidence=70):
2674 def to_epsg(self, int min_confidence=70):
26702675 """
26712676 Return the EPSG code best matching the CRS
26722677 or None if it a match is not found.
27092714 return int(auth_info[1])
27102715 return None
27112716
2712 def to_authority(self, auth_name=None, min_confidence=70):
2717 def to_authority(self, str auth_name=None, int min_confidence=70):
27132718 """
27142719 .. versionadded:: 2.2.0
27152720
27552760 except IndexError:
27562761 return None
27572762
2758 def list_authority(self, auth_name=None, min_confidence=70):
2763 def list_authority(self, str auth_name=None, int min_confidence=70):
27592764 """
27602765 .. versionadded:: 3.2.0
27612766
27962801 # get list of possible matching projections
27972802 cdef PJ_OBJ_LIST *proj_list = NULL
27982803 cdef int *c_out_confidence_list = NULL
2799 cdef int out_confidence = -9999
28002804 cdef int num_proj_objects = -9999
2805 cdef bytes b_auth_name
28012806 cdef char *user_auth_name = NULL
28022807 cdef int iii = 0
28032808
28352840 if out_confidence_list[iii] < min_confidence:
28362841 continue
28372842 proj = proj_list_get(self.context, proj_list, iii)
2838 code = proj_get_id_code(proj, iii)
2839 out_auth_name = proj_get_id_auth_name(proj, iii)
2843 code = proj_get_id_code(proj, 0)
2844 out_auth_name = proj_get_id_auth_name(proj, 0)
28402845 if out_auth_name != NULL and code != NULL:
28412846 authority_list.append(
28422847 AuthorityMatchInfo(
2843 pystrdecode(out_auth_name),
2844 pystrdecode(code),
2848 out_auth_name,
2849 code,
28452850 out_confidence_list[iii]
28462851 )
28472852 )
28522857 CRSError.clear()
28532858 return authority_list
28542859
2855 def to_3d(self, name=None):
2860 def to_3d(self, str name=None):
28562861 """
28572862 .. versionadded:: 3.1.0
28582863
28722877 -------
28732878 _CRS
28742879 """
2875 cdef char* name_3D = NULL
2880 cdef char* c_name = NULL
2881 cdef bytes b_name
28762882 if name is not None:
28772883 b_name = cstrencode(name)
2878 name_3D = b_name
2884 c_name = b_name
28792885
28802886 cdef PJ * projobj = proj_crs_promote_to_3D(
2881 self.context, name_3D, self.projobj
2887 self.context, c_name, self.projobj
28822888 )
28832889 CRSError.clear()
28842890 if projobj == NULL:
28892895 proj_destroy(projobj)
28902896 return crs_3d
28912897
2892 def _is_crs_property(self, property_name, property_types, sub_crs_index=0):
2898 def _is_crs_property(
2899 self, str property_name, tuple property_types, int sub_crs_index=0
2900 ):
28932901 """
28942902 .. versionadded:: 2.2.0
28952903
11 import os
22 import warnings
33
4 from libc.stdlib cimport free, malloc
5
6 from pyproj._compat cimport cstrencode
7
8 from pyproj.exceptions import DataDirError, ProjError
49 from pyproj.utils import strtobool
5
6 from libc.stdlib cimport free, malloc
7
8 from pyproj.compat import cstrencode, pystrdecode
9 from pyproj.exceptions import DataDirError, ProjError
1010
1111 # for logging the internal PROJ messages
1212 # https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
8484 str:
8585 The user writable data directory.
8686 """
87 return pystrdecode(proj_context_get_user_writable_directory(
87 return proj_context_get_user_writable_directory(
8888 PYPROJ_GLOBAL_CONTEXT, bool(create)
89 ))
89 )
9090
9191
9292 cdef void pyproj_log_function(void *user_data, int level, const char *error_msg) nogil:
9898 # PROJ_DEBUG environment variable.
9999 if level == PJ_LOG_ERROR:
100100 with gil:
101 ProjError.internal_proj_error = pystrdecode(error_msg)
101 ProjError.internal_proj_error = error_msg
102102 _LOGGER.debug(f"PROJ_ERROR: {ProjError.internal_proj_error}")
103103 elif level == PJ_LOG_DEBUG:
104104 with gil:
105 _LOGGER.debug(f"PROJ_DEBUG: {pystrdecode(error_msg)}")
105 _LOGGER.debug(f"PROJ_DEBUG: {error_msg}")
106106 elif level == PJ_LOG_TRACE:
107107 with gil:
108 _LOGGER.debug(f"PROJ_TRACE: {pystrdecode(error_msg)}")
108 _LOGGER.debug(f"PROJ_TRACE: {error_msg}")
109109
110110
111111 cdef void set_context_data_dir(PJ_CONTEXT* context) except *:
116116
117117 data_dir_list = get_data_dir().split(os.pathsep)
118118 # the first path will always have the database
119 b_database_path = cstrencode(os.path.join(data_dir_list[0], "proj.db"))
119 cdef bytes b_database_path = cstrencode(os.path.join(data_dir_list[0], "proj.db"))
120120 cdef const char* c_database_path = b_database_path
121121 if not proj_context_set_database_path(context, c_database_path, NULL, NULL):
122122 warnings.warn("pyproj unable to set database path.")
124124 cdef const char **c_data_dir = <const char **>malloc(
125125 (dir_list_len + 1) * sizeof(const char*)
126126 )
127 cdef bytes b_data_dir
127128 try:
128129 for iii in range(dir_list_len):
129130 b_data_dir = cstrencode(data_dir_list[iii])
191192 proj_context_destroy(context)
192193
193194
194 def _pyproj_global_context_initialize():
195 cpdef _pyproj_global_context_initialize():
195196 pyproj_context_initialize(PYPROJ_GLOBAL_CONTEXT)
196197
197198
198 def _global_context_set_data_dir():
199 cpdef _global_context_set_data_dir():
199200 set_context_data_dir(PYPROJ_GLOBAL_CONTEXT)
22 cimport cython
33 from libc.math cimport ceil, isnan, round
44
5 from pyproj._compat cimport cstrencode, empty_array
6
57 from collections import namedtuple
68
7 from pyproj._compat import empty_array
8 from pyproj.compat import cstrencode, pystrdecode
99 from pyproj.enums import GeodIntermediateFlag
1010 from pyproj.exceptions import GeodError
1111
7272 # convert 'a' only for initstring
7373 a_str = int(a) if a.is_integer() else a
7474 f_str = int(f) if f.is_integer() else f
75 self.initstring = pystrdecode(cstrencode(f"+a={a_str} +f={f_str}"))
75 self.initstring = f"+a={a_str} +f={f_str}"
7676 self.sphere = sphere
7777 self.b = b
7878 self.es = es
33
44 from pyproj.utils import strtobool
55
6 from pyproj._compat cimport cstrencode
67 from pyproj._datadir cimport PYPROJ_GLOBAL_CONTEXT
78
8 from pyproj.compat import cstrencode
99
10
11 def _set_ca_bundle_path(ca_bundle_path):
10 def _set_ca_bundle_path(str ca_bundle_path):
1211 """
1312 Sets the path to the CA Bundle used by the `curl`
1413 built into PROJ.
00 include "proj.pxi"
1
2 from pyproj.compat import pystrdecode
31
42 from pyproj._datadir cimport PYPROJ_GLOBAL_CONTEXT
53
119 str:
1210 URL of the endpoint where PROJ grids are stored.
1311 """
14 return pystrdecode(proj_context_get_url_endpoint(PYPROJ_GLOBAL_CONTEXT))
12 return proj_context_get_url_endpoint(PYPROJ_GLOBAL_CONTEXT)
00 include "proj.pxi"
11
2 from pyproj._crs cimport _CRS, Base
2 from pyproj._crs cimport Base
33
44
55 cdef class _TransformerGroup:
66 cdef PJ_CONTEXT* context
7 cdef readonly _transformers
8 cdef readonly _unavailable_operations
9 cdef readonly _best_available
7 cdef readonly list _transformers
8 cdef readonly list _unavailable_operations
9 cdef readonly list _best_available
1010
1111 cdef class _Transformer(Base):
1212 cdef PJ_PROJ_INFO proj_info
1313 cdef readonly _area_of_use
14 cdef readonly type_name
15 cdef readonly object _operations
14 cdef readonly str type_name
15 cdef readonly tuple _operations
1616
1717 @staticmethod
1818 cdef _Transformer _from_pj(
1919 PJ_CONTEXT* context,
2020 PJ *transform_pj,
21 always_xy,
21 bint always_xy,
2222 )
6565 ) -> str: ...
6666 @staticmethod
6767 def from_crs(
68 crs_from: str,
69 crs_to: str,
68 crs_from: bytes,
69 crs_to: bytes,
7070 always_xy: bool = False,
7171 area_of_interest: Optional[AreaOfInterest] = None,
7272 authority: Optional[str] = None,
73 accuracy: Optional[float] = None,
73 accuracy: Optional[str] = None,
7474 allow_ballpark: Optional[bool] = None,
7575 ) -> "_Transformer": ...
7676 @staticmethod
77 def from_pipeline(proj_pipeline: str) -> "_Transformer": ...
77 def from_pipeline(proj_pipeline: bytes) -> "_Transformer": ...
7878 def _transform(
7979 self,
8080 inx: Any,
77 import warnings
88 from collections import namedtuple
99
10 from pyproj._compat cimport cstrencode
1011 from pyproj._crs cimport (
1112 _CRS,
1213 Base,
1920
2021 from pyproj._datadir import _LOGGER
2122 from pyproj.aoi import AreaOfInterest
22 from pyproj.compat import cstrencode, pystrdecode
2323 from pyproj.enums import ProjVersion, TransformDirection
2424 from pyproj.exceptions import ProjError
2525
2828 _AUTH_CODE_RE = re.compile(r"(?P<authority>\w+)\:(?P<code>\w+)")
2929
3030
31 cdef pyproj_errno_string(PJ_CONTEXT* ctx, int err):
31 cdef str pyproj_errno_string(PJ_CONTEXT* ctx, int err):
3232 # https://github.com/pyproj4/pyproj/issues/760
3333 IF CTE_PROJ_VERSION_MAJOR >= 8:
34 return pystrdecode(proj_context_errno_string(ctx, err))
34 return proj_context_errno_string(ctx, err)
3535 ELSE:
36 return pystrdecode(proj_errno_string(err))
37
38
39 _PJ_DIRECTION_MAP = {
36 return proj_errno_string(err)
37
38
39 cdef dict _PJ_DIRECTION_MAP = {
4040 TransformDirection.FORWARD: PJ_FWD,
4141 TransformDirection.INVERSE: PJ_INV,
4242 TransformDirection.IDENT: PJ_IDENT,
4343 }
4444
45 _TRANSFORMER_TYPE_MAP = {
45 cdef dict _TRANSFORMER_TYPE_MAP = {
4646 PJ_TYPE_UNKNOWN: "Unknown Transformer",
4747 PJ_TYPE_CONVERSION: "Conversion Transformer",
4848 PJ_TYPE_TRANSFORMATION: "Transformation Transformer",
119119
120120 def __init__(
121121 self,
122 _CRS crs_from,
123 _CRS crs_to,
124 always_xy=False,
122 _CRS crs_from not None,
123 _CRS crs_to not None,
124 bint always_xy=False,
125125 area_of_interest=None,
126126 ):
127127 """
236236 const char *source_crs_str,
237237 const char *target_crs_str,
238238 PJ_AREA *area,
239 authority,
240 accuracy,
239 str authority,
240 str accuracy,
241241 allow_ballpark,
242242 ):
243243 """
262262 return NULL
263263
264264 cdef const char* options[4]
265 cdef bytes b_authority
266 cdef bytes b_accuracy
265267 cdef int options_index = 0
266268 options[0] = NULL
267269 options[1] = NULL
511513
512514 @property
513515 def id(self):
514 return pystrdecode(self.proj_info.id)
516 return self.proj_info.id
515517
516518 @property
517519 def description(self):
518 return pystrdecode(self.proj_info.description)
520 return self.proj_info.description
519521
520522 @property
521523 def definition(self):
522 return pystrdecode(self.proj_info.definition)
524 return self.proj_info.definition
523525
524526 @property
525527 def has_inverse(self):
565567 """
566568 return proj_context_is_network_enabled(self.context) == 1
567569
568 def to_proj4(self, version=ProjVersion.PROJ_5, pretty=False):
570 def to_proj4(self, version=ProjVersion.PROJ_5, bint pretty=False):
569571 """
570572 Convert the projection to a PROJ string.
571573
590592 def from_crs(
591593 const char* crs_from,
592594 const char* crs_to,
593 always_xy=False,
595 bint always_xy=False,
594596 area_of_interest=None,
595 authority=None,
596 accuracy=None,
597 str authority=None,
598 str accuracy=None,
597599 allow_ballpark=None,
598600 ):
599601 """
648650 cdef _Transformer _from_pj(
649651 PJ_CONTEXT* context,
650652 PJ *transform_pj,
651 always_xy,
653 bint always_xy,
652654 ):
653655 """
654656 Create a Transformer from a PJ* object
671673 cdef _Transformer transformer = _Transformer()
672674 transformer.context = pyproj_context_create()
673675
674 auth_match = _AUTH_CODE_RE.match(pystrdecode(proj_pipeline.strip()))
676 auth_match = _AUTH_CODE_RE.match(proj_pipeline.strip())
675677 if auth_match:
676678 # attempt to create coordinate operation from AUTH:CODE
677679 match_data = auth_match.groupdict()
705707 proj_destroy(self.projobj)
706708 self.projobj = always_xy_pj
707709
708 def _init_from_crs(self, always_xy):
710 def _init_from_crs(self, bint always_xy):
709711 """
710712 Finish initializing transformer properties from CRS objects
711713 """
+0
-25
pyproj/compat.py less more
0 """
1 This module is for compatibility between string types
2 """
3
4
5 def cstrencode(pystr):
6 """
7 encode a string into bytes. If already bytes, do nothing.
8 """
9 try:
10 return pystr.encode("utf-8")
11 except UnicodeDecodeError:
12 return pystr.decode("utf-8").encode("utf-8")
13 except AttributeError:
14 return pystr # already bytes
15
16
17 def pystrdecode(cstr):
18 """
19 Decode a string to a python string.
20 """
21 try:
22 return cstr.decode("utf-8")
23 except AttributeError:
24 return cstr
335335 return RotatedLatitudeLongitudeConversion(
336336 o_lat_p=cf_params["grid_north_pole_latitude"],
337337 o_lon_p=cf_params["grid_north_pole_longitude"],
338 lon_0=cf_params.get("north_pole_grid_longitude", 0.0),
338 # https://github.com/pyproj4/pyproj/issues/927
339 lon_0=cf_params.get("north_pole_grid_longitude", 0.0) + 180,
339340 )
340341
341342
625626 "grid_mapping_name": "rotated_latitude_longitude",
626627 "grid_north_pole_latitude": params["o_lat_p"],
627628 "grid_north_pole_longitude": params["o_lon_p"],
628 "north_pole_grid_longitude": params["lon_0"],
629 # https://github.com/pyproj4/pyproj/issues/927
630 "north_pole_grid_longitude": params["lon_0"] - 180,
631 }
632
633
634 def _pole_rotation_netcdf__to_cf(conversion):
635 """
636 http://cfconventions.org/cf-conventions/cf-conventions.html#_rotated_pole
637
638 https://github.com/OSGeo/PROJ/pull/2835
639 """
640 params = _to_dict(conversion)
641 return {
642 "grid_mapping_name": "rotated_latitude_longitude",
643 "grid_north_pole_latitude": params[
644 "grid_north_pole_latitude_(netcdf_cf_convention)"
645 ],
646 "grid_north_pole_longitude": params[
647 "grid_north_pole_longitude_(netcdf_cf_convention)"
648 ],
649 "north_pole_grid_longitude": params[
650 "north_pole_grid_longitude_(netcdf_cf_convention)"
651 ],
629652 }
630653
631654
655678 "proj ob_tran o_proj=lonlat": _rotated_latitude_longitude__to_cf,
656679 "proj ob_tran o_proj=latlon": _rotated_latitude_longitude__to_cf,
657680 "proj ob_tran o_proj=latlong": _rotated_latitude_longitude__to_cf,
681 "pole rotation (netcdf cf convention)": _pole_rotation_netcdf__to_cf,
658682 }
55
66 from libc.stdlib cimport free, malloc
77
8 from pyproj._compat cimport cstrdecode
8 from pyproj._compat cimport cstrdecode, cstrencode
99 from pyproj._datadir cimport pyproj_context_create, pyproj_context_destroy
1010
1111 from pyproj.aoi import AreaOfUse
12 from pyproj.compat import cstrencode, pystrdecode
1312 from pyproj.enums import PJType
1413
15 _PJ_TYPE_MAP = {
14
15 cdef dict _PJ_TYPE_MAP = {
1616 PJType.UNKNOWN: PJ_TYPE_UNKNOWN,
1717 PJType.ELLIPSOID: PJ_TYPE_ELLIPSOID,
1818 PJType.PRIME_MERIDIAN: PJ_TYPE_PRIME_MERIDIAN,
3939 PJType.CONCATENATED_OPERATION: PJ_TYPE_CONCATENATED_OPERATION,
4040 PJType.OTHER_COORDINATE_OPERATION: PJ_TYPE_OTHER_COORDINATE_OPERATION,
4141 }
42 _INV_PJ_TYPE_MAP = {value: key for key, value in _PJ_TYPE_MAP.items()}
42 cdef dict _INV_PJ_TYPE_MAP = {value: key for key, value in _PJ_TYPE_MAP.items()}
4343
4444
4545 def get_authorities():
6060 try:
6161 auth_list = []
6262 while proj_auth_list[iii] != NULL:
63 auth_list.append(pystrdecode(proj_auth_list[iii]))
63 auth_list.append(proj_auth_list[iii])
6464 iii += 1
6565 finally:
6666 pyproj_context_destroy(context)
6868 return auth_list
6969
7070
71 def get_codes(auth_name, pj_type, allow_deprecated=False):
71 def get_codes(str auth_name not None, pj_type not None, bint allow_deprecated=False):
7272 """
7373 .. versionadded:: 2.4.0
7474
105105 try:
106106 code_list = []
107107 while proj_code_list[iii] != NULL:
108 code_list.append(pystrdecode(proj_code_list[iii]))
108 code_list.append(proj_code_list[iii])
109109 iii += 1
110110 finally:
111111 proj_string_list_destroy(proj_code_list)
149149
150150
151151 def query_crs_info(
152 auth_name=None,
152 str auth_name=None,
153153 pj_types=None,
154154 area_of_interest=None,
155 contains=False,
156 allow_deprecated=False,
155 bint contains=False,
156 bint allow_deprecated=False,
157157 ):
158158 """
159159 .. versionadded:: 3.0.0
190190 cdef int result_count = 0
191191 cdef int pj_type_count = 0
192192 cdef int iii = 0
193 cdef bytes b_auth_name
193194 if auth_name is not None:
194195 b_auth_name = cstrencode(auth_name)
195196 c_auth_name = b_auth_name
244245 name=cstrdecode(crs_info_list[iii].area_name),
245246 )
246247 code_list.append(CRSInfo(
247 auth_name=pystrdecode(crs_info_list[iii].auth_name),
248 code=pystrdecode(crs_info_list[iii].code),
249 name=pystrdecode(crs_info_list[iii].name),
248 auth_name=crs_info_list[iii].auth_name,
249 code=crs_info_list[iii].code,
250 name=crs_info_list[iii].name,
250251 type=_INV_PJ_TYPE_MAP[crs_info_list[iii].type],
251252 deprecated=bool(crs_info_list[iii].deprecated),
252253 area_of_use=area_of_use,
261262
262263
263264 def query_utm_crs_info(
264 datum_name=None,
265 str datum_name=None,
265266 area_of_interest=None,
266 contains=False,
267 bint contains=False,
267268 ):
268269 """
269270 .. versionadded:: 3.0.0
340341 """
341342
342343
343 def get_units_map(auth_name=None, category=None, allow_deprecated=False):
344 def get_units_map(str auth_name=None, str category=None, bint allow_deprecated=False):
344345 """
345346 .. versionadded:: 2.2.0
346347 .. versionadded:: 3.0.0 query PROJ database.
363364 """
364365 cdef const char* c_auth_name = NULL
365366 cdef const char* c_category = NULL
367 cdef bytes b_auth_name
368 cdef bytes b_category
366369 if auth_name is not None:
367 auth_name = cstrencode(auth_name)
368 c_auth_name = auth_name
370 b_auth_name = cstrencode(auth_name)
371 c_auth_name = b_auth_name
369372 if category is not None:
370 category = cstrencode(category)
371 c_category = category
373 b_category = cstrencode(category)
374 c_category = b_category
372375
373376 cdef int num_units = 0
374377 cdef PJ_CONTEXT* context = pyproj_context_create()
384387 for iii in range(num_units):
385388 proj_short_name = None
386389 if db_unit_list[iii].proj_short_name != NULL:
387 proj_short_name = pystrdecode(db_unit_list[iii].proj_short_name)
388 name = pystrdecode(db_unit_list[iii].name)
390 proj_short_name = db_unit_list[iii].proj_short_name
391 name = db_unit_list[iii].name
389392 units_map[name] = Unit(
390 auth_name=pystrdecode(db_unit_list[iii].auth_name),
391 code=pystrdecode(db_unit_list[iii].code),
393 auth_name=db_unit_list[iii].auth_name,
394 code=db_unit_list[iii].code,
392395 name=name,
393 category=pystrdecode(db_unit_list[iii].category),
396 category=db_unit_list[iii].category,
394397 conv_factor=db_unit_list[iii].conv_factor,
395398 proj_short_name=proj_short_name,
396399 deprecated=bool(db_unit_list[iii].deprecated),
00 include "proj.pxi"
1
2 from pyproj.compat import pystrdecode
31
42
53 def get_proj_operations_map():
1311 cdef int iii = 0
1412 operations_map = {}
1513 while proj_operations[iii].id != NULL:
16 operations_map[pystrdecode(proj_operations[iii].id)] = \
17 pystrdecode(proj_operations[iii].descr[0]).split("\n\t")[0]
14 operations_map[proj_operations[iii].id] = \
15 proj_operations[iii].descr[0].split("\n\t")[0]
1816 iii += 1
1917 return operations_map
2018
3028 cdef int iii = 0
3129 ellps_map = {}
3230 while proj_ellps[iii].id != NULL:
33 major_key, major_val = pystrdecode(proj_ellps[iii].major).split("=")
34 ell_key, ell_val = pystrdecode(proj_ellps[iii].ell).split("=")
35 ellps_map[pystrdecode(proj_ellps[iii].id)] = {
31 major_key, major_val = proj_ellps[iii].major.split("=")
32 ell_key, ell_val = proj_ellps[iii].ell.split("=")
33 ellps_map[proj_ellps[iii].id] = {
3634 major_key: float(major_val),
3735 ell_key: float(ell_val),
38 "description": pystrdecode(proj_ellps[iii].name)
36 "description": proj_ellps[iii].name
3937 }
4038 iii += 1
4139 return ellps_map
5250 cdef int iii = 0
5351 prime_meridians_map = {}
5452 while prime_meridians[iii].id != NULL:
55 prime_meridians_map[pystrdecode(prime_meridians[iii].id)] = \
56 pystrdecode(prime_meridians[iii].defn)
53 prime_meridians_map[prime_meridians[iii].id] = \
54 prime_meridians[iii].defn
5755 iii += 1
5856 return prime_meridians_map
1717 import warnings
1818 from typing import Any, Optional, Tuple, Type
1919
20 from pyproj._compat import cstrencode
2021 from pyproj._transformer import Factors
21 from pyproj.compat import pystrdecode
2222 from pyproj.crs import CRS
2323 from pyproj.enums import TransformDirection
2424 from pyproj.list import get_proj_operations_map
130130 projstring = self.crs.to_proj4() or self.crs.srs
131131
132132 self.srs = re.sub(r"\s\+?type=crs", "", projstring).strip()
133 super().__init__(TransformerFromPipeline(self.srs))
133 super().__init__(TransformerFromPipeline(cstrencode(self.srs)))
134134
135135 def __call__(
136136 self,
255255 >>> Proj("epsg:4326").definition_string()
256256 'proj=longlat datum=WGS84 no_defs ellps=WGS84 towgs84=0,0,0'
257257 """
258 return pystrdecode(self.definition)
258 return self.definition
259259
260260 def to_latlong_def(self) -> Optional[str]:
261261 """return the definition string of the geographic (lat/lon)
1717 from typing import Any, Iterable, Iterator, List, Optional, Tuple, Union, overload
1818
1919 from pyproj import CRS
20 from pyproj._compat import cstrencode
2021 from pyproj._crs import AreaOfUse, CoordinateOperation
2122 from pyproj._transformer import ( # noqa: F401 pylint: disable=unused-import
2223 AreaOfInterest,
2425 _TransformerGroup,
2526 proj_version_str,
2627 )
27 from pyproj.compat import cstrencode
2828 from pyproj.datadir import get_user_data_dir
2929 from pyproj.enums import ProjVersion, TransformDirection, WktVersion
3030 from pyproj.exceptions import ProjError
7979 Generates a Cython _Transformer class from input CRS data.
8080 """
8181
82 crs_from: str
83 crs_to: str
82 crs_from: bytes
83 crs_to: bytes
8484 always_xy: bool
8585 area_of_interest: Optional[AreaOfInterest]
8686 authority: Optional[str]
87 accuracy: Optional[float]
87 accuracy: Optional[str]
8888 allow_ballpark: Optional[bool]
8989
9090 def __call__(self) -> _Transformer:
9494 _Transformer
9595 """
9696 return _Transformer.from_crs(
97 cstrencode(self.crs_from),
98 cstrencode(self.crs_to),
97 self.crs_from,
98 self.crs_to,
9999 always_xy=self.always_xy,
100100 area_of_interest=self.area_of_interest,
101101 authority=self.authority,
112112 Generates a Cython _Transformer class from input pipeline data.
113113 """
114114
115 proj_pipeline: str
115 proj_pipeline: bytes
116116
117117 def __call__(self) -> _Transformer:
118118 """
120120 -------
121121 _Transformer
122122 """
123 return _Transformer.from_pipeline(cstrencode(self.proj_pipeline))
123 return _Transformer.from_pipeline(self.proj_pipeline)
124124
125125
126126 class TransformerGroup(_TransformerGroup):
532532
533533 return Transformer(
534534 TransformerFromCRS(
535 CRS.from_user_input(crs_from).srs,
536 CRS.from_user_input(crs_to).srs,
535 cstrencode(CRS.from_user_input(crs_from).srs),
536 cstrencode(CRS.from_user_input(crs_to).srs),
537537 always_xy=always_xy,
538538 area_of_interest=area_of_interest,
539539 authority=authority,
540 accuracy=accuracy,
540 accuracy=accuracy if accuracy is None else str(accuracy),
541541 allow_ballpark=allow_ballpark,
542542 )
543543 )
573573 Transformer
574574
575575 """
576 return Transformer(TransformerFromPipeline(proj_pipeline))
576 return Transformer(TransformerFromPipeline(cstrencode(proj_pipeline)))
577577
578578 @overload
579579 def transform( # pylint: disable=invalid-name
658658 instead of returning a new array. This will fail if the input
659659 is not an array in C order with the double data type.
660660
661 Example:
661 Example
662 --------
662663
663664 >>> from pyproj import Transformer
664665 >>> transformer = Transformer.from_crs("epsg:4326", "epsg:3857")
768769 Default is :attr:`pyproj.enums.TransformDirection.FORWARD`.
769770
770771
771 Example:
772 Example
773 --------
772774
773775 >>> from pyproj import Transformer
774776 >>> transformer = Transformer.from_crs(4326, 2100)
874876 Transform boundary densifying the edges to account for nonlinear
875877 transformations along these edges and extracting the outermost bounds.
876878
879 If the destination CRS is geographic and right < left then the bounds
880 crossed the antimeridian. In this scenario there are two polygons,
881 one on each side of the antimeridian. The first polygon should be
882 constructed with (left, bottom, 180, top) and the second with
883 (-180, bottom, top, right).
884
885 To construct the bounding polygons with shapely::
886
887 def bounding_polygon(left, bottom, right, top):
888 if right < left:
889 return shapely.geometry.MultiPolygon(
890 [
891 shapely.geometry.box(left, bottom, 180, top),
892 shapely.geometry.box(-180, bottom, right, top),
893 ]
894 )
895 return shapely.geometry.box(left, bottom, right, top)
896
897
877898 Parameters
878899 ----------
879900 left: float
55 author = Jeff Whitaker
66 author_email = jeffrey.s.whitaker@noaa.gov
77 license = MIT
8 license-file = LICENSE
8 license_file = LICENSE
99 platform = any
1010 keywords = GIS, map, geospatial, coordinate-systems, coordinate-transformation, cartographic-projection, geodesic
1111 classifiers =
109109 # Configure optional Cython coverage.
110110 cythonize_options = {
111111 "language_level": sys.version_info[0],
112 "compiler_directives": {"embedsignature": True},
112 "compiler_directives": {
113 "c_string_type": "str",
114 "c_string_encoding": "utf-8",
115 "embedsignature": True,
116 },
113117 }
114118 if os.environ.get("PYPROJ_FULL_COVERAGE"):
115119 cythonize_options["compiler_directives"].update(linetrace=True)
14411441 pass
14421442
14431443
1444 def test_crs_multiprocess():
1445 # https://github.com/pyproj4/pyproj/issues/933
1446 with concurrent.futures.ProcessPoolExecutor(max_workers=2) as executor:
1447 for result in executor.map(CRS, [4326 for _ in range(10)]):
1448 pass
1449
1450
14441451 def test_coordinate_operation__to_proj4():
14451452 operation = CoordinateOperation.from_string(
14461453 "+proj=pipeline +step +proj=axisswap +order=2,1 +step "
15281535 assert CRS("+proj=utm +zone=15").list_authority() == [
15291536 AuthorityMatchInfo(auth_name="EPSG", code="32615", confidence=70)
15301537 ]
1538
1539
1540 def test_list_authority__multiple():
1541 auth_list = CRS("+proj=longlat").list_authority()
1542 assert AuthorityMatchInfo(auth_name="OGC", code="CRS84", confidence=70) in auth_list
1543 assert AuthorityMatchInfo(auth_name="EPSG", code="4326", confidence=70) in auth_list
391391 "o_proj": "longlat",
392392 "o_lat_p": 32.5,
393393 "o_lon_p": 170.0,
394 "lon_0": 0,
394 "lon_0": 180,
395395 "datum": "WGS84",
396396 "no_defs": None,
397397 "type": "crs",
414414 "o_proj": "longlat",
415415 "o_lat_p": 32.5,
416416 "o_lon_p": 170.0,
417 "lon_0": 1.0,
417 "lon_0": 181.0,
418418 "datum": "WGS84",
419419 "no_defs": None,
420420 "type": "crs",
421421 }
422
423
424 def test_rotated_pole_to_cf():
425 rotated_pole_wkt = (
426 'GEOGCRS["undefined",\n'
427 ' BASEGEOGCRS["Unknown datum based upon the GRS 1980 ellipsoid",\n'
428 ' DATUM["Not specified (based on GRS 1980 ellipsoid)",\n'
429 ' ELLIPSOID["GRS 1980",6378137,298.257222101,\n'
430 ' LENGTHUNIT["metre",1]]],\n'
431 ' PRIMEM["Greenwich",0,\n'
432 ' ANGLEUNIT["degree",0.0174532925199433]]],\n'
433 ' DERIVINGCONVERSION["Pole rotation (netCDF CF convention)",\n'
434 ' METHOD["Pole rotation (netCDF CF convention)"],\n'
435 ' PARAMETER["Grid north pole latitude (netCDF CF '
436 'convention)",2,\n'
437 ' ANGLEUNIT["degree",0.0174532925199433,\n'
438 ' ID["EPSG",9122]]],\n'
439 ' PARAMETER["Grid north pole longitude (netCDF CF '
440 'convention)",3,\n'
441 ' ANGLEUNIT["degree",0.0174532925199433,\n'
442 ' ID["EPSG",9122]]],\n'
443 ' PARAMETER["North pole grid longitude (netCDF CF '
444 'convention)",4,\n'
445 ' ANGLEUNIT["degree",0.0174532925199433,\n'
446 ' ID["EPSG",9122]]]],\n'
447 " CS[ellipsoidal,2],\n"
448 ' AXIS["geodetic latitude (Lat)",north,\n'
449 " ORDER[1],\n"
450 ' ANGLEUNIT["degree",0.0174532925199433,\n'
451 ' ID["EPSG",9122]]],\n'
452 ' AXIS["geodetic longitude (Lon)",east,\n'
453 " ORDER[2],\n"
454 ' ANGLEUNIT["degree",0.0174532925199433,\n'
455 ' ID["EPSG",9122]]]]'
456 )
457 crs = CRS(rotated_pole_wkt)
458 expected_cf = {
459 "semi_major_axis": 6378137.0,
460 "semi_minor_axis": 6356752.314140356,
461 "inverse_flattening": 298.257222101,
462 "reference_ellipsoid_name": "GRS 1980",
463 "longitude_of_prime_meridian": 0.0,
464 "prime_meridian_name": "Greenwich",
465 "geographic_crs_name": "undefined",
466 "grid_mapping_name": "rotated_latitude_longitude",
467 "grid_north_pole_latitude": 2.0,
468 "grid_north_pole_longitude": 3.0,
469 "north_pole_grid_longitude": 4.0,
470 "horizontal_datum_name": "Not specified (based on GRS 1980 ellipsoid)",
471 }
472 cf_dict = crs.to_cf()
473 assert cf_dict.pop("crs_wkt").startswith("GEOGCRS[")
474 assert cf_dict == expected_cf
475 # test roundtrip
476 _test_roundtrip(expected_cf, "GEOGCRS[")
422477
423478
424479 def test_cf_lambert_conformal_conic_1sp():