Codebase list python-pyproj / upstream/2.2.2+ds
New upstream version 2.2.2+ds Bas Couwenberg 4 years ago
22 changed file(s) with 348 addition(s) and 218 deletion(s). Raw diff Collapse all Expand all
1010 global:
1111 - PROJ_BASE_DIR=$HOME/proj_install
1212 - CYTHON_COVERAGE=True
13 - PROJSOURCE=6.1.0
13 - PROJSOURCE=6.1.1
1414 # Following generated with
1515 - WHEELHOUSE_UPLOADER_USERNAME=travis-worker
1616 # Following generated by
2525 os: osx
2626 env:
2727 - PYTHON=3.6.8
28 - PROJSOURCE=6.1.0
28 - PROJSOURCE=6.1.1
2929 - python: 2.7
3030 env:
31 - PROJSOURCE=6.1.0
31 - PROJSOURCE=6.1.1
3232 - python: 3.5
33 env:
34 - PROJSOURCE=6.1.1
35 - python: 3.6
3336 env:
3437 - PROJSOURCE=6.1.0
3538 - python: 3.6
3639 env:
37 - PROJSOURCE=6.1.0
40 - PROJSOURCE=6.1.1
3841 - python: 3.7
3942 dist: xenial
4043 env:
41 - PROJSOURCE=6.1.0
44 - PROJSOURCE=6.1.1
4245 - DOC=true
4346 - python: "nightly"
4447 env:
8790 - pip install coveralls
8891
8992 script:
90 - python -c "import pyproj; pyproj.Proj(init='epsg:4269')"
93 - python -c "import pyproj; pyproj.Proj('epsg:4269')"
9194 - make test-coverage
9295 # Building and uploading docs with doctr
9396 - set -e
2626 PYTHON_ARCH: "64"
2727 VS_VERSION: Visual Studio 14
2828 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
29 PROJSOURCE: 6.1.0
29 PROJSOURCE: 6.1.1
3030 # - PYTHON: "C:\\Python37-x64"
3131 # PYTHON_VERSION: "3.7"
3232 # PYTHON_ARCH: "64"
3333 # VS_VERSION: Visual Studio 14
3434 # APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
35 # PROJSOURCE: 6.1.0
35 # PROJSOURCE: 6.1.1
3636 # - PYTHON: "C:\\Python36-x64"
3737 # PYTHON_VERSION: "3.6"
3838 # PYTHON_ARCH: "64"
120120
121121 test_script:
122122 # Run the project tests
123 - "%CMD_IN_ENV% python -c \"import pyproj; pyproj.Proj(init='epsg:4269')\""
123 - "%CMD_IN_ENV% python -c \"import pyproj; pyproj.Proj('epsg:4269')\""
124124 - "%CMD_IN_ENV% py.test --cov-report term-missing --cov=pyproj -v -s"
125125
126126 after_test:
139139 # - "%CMD_IN_ENV% python setup.py bdist_msi"
140140 # test wheel
141141 - pip install pyproj --ignore-installed -f dist
142 - python -c "import pyproj; pyproj.Proj(init='epsg:4269')"
142 - python -c "import pyproj; pyproj.Proj('epsg:4269')"
143143 # cleanup for test dir
144144 - if %PROJSOURCE% == git del /F /Q dist\*
145145 - ps: "ls dist"
4646 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
4747 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
4848 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """
49 __version__ = "2.2.1"
49 __version__ = "2.2.2"
5050 __all__ = [
5151 "Proj",
5252 "Geod",
00 include "proj.pxi"
11
22 cdef class Axis:
3 cdef public object name
4 cdef public object abbrev
5 cdef public object direction
6 cdef public double unit_conversion_factor
7 cdef public object unit_name
8 cdef public object unit_auth_code
9 cdef public object unit_code
3 cdef readonly object name
4 cdef readonly object abbrev
5 cdef readonly object direction
6 cdef readonly double unit_conversion_factor
7 cdef readonly object unit_name
8 cdef readonly object unit_auth_code
9 cdef readonly object unit_code
1010
1111 @staticmethod
1212 cdef create(PJ_CONTEXT* projcontext, PJ* projobj, int index)
1313
1414 cdef class AreaOfUse:
15 cdef public double west
16 cdef public double south
17 cdef public double east
18 cdef public double north
19 cdef public object name
15 cdef readonly double west
16 cdef readonly double south
17 cdef readonly double east
18 cdef readonly double north
19 cdef readonly object name
2020
2121 @staticmethod
2222 cdef create(PJ_CONTEXT* projcontext, PJ* projobj)
2525 cdef class Base:
2626 cdef PJ *projobj
2727 cdef PJ_CONTEXT *projctx
28 cdef public object name
28 cdef readonly object name
2929
3030
3131 cdef class Ellipsoid(Base):
3232 cdef double _semi_major_metre
3333 cdef double _semi_minor_metre
34 cdef public object is_semi_minor_computed
34 cdef readonly object is_semi_minor_computed
3535 cdef double _inv_flattening
36 cdef public object ellipsoid_loaded
36 cdef readonly object ellipsoid_loaded
3737
3838 @staticmethod
3939 cdef create(PJ* ellipsoid_pj)
4040
4141 cdef class PrimeMeridian(Base):
42 cdef public double longitude
43 cdef public double unit_conversion_factor
44 cdef public object unit_name
42 cdef readonly double longitude
43 cdef readonly double unit_conversion_factor
44 cdef readonly object unit_name
4545
4646 @staticmethod
4747 cdef create(PJ* prime_meridian_pj)
4848
4949
5050 cdef class Datum(Base):
51 cdef public object _ellipsoid
52 cdef public object _prime_meridian
51 cdef readonly object _ellipsoid
52 cdef readonly object _prime_meridian
5353
5454 @staticmethod
5555 cdef create(PJ* datum_pj)
5656
5757
5858 cdef class CoordinateSystem(Base):
59 cdef public object _axis_list
59 cdef readonly object _axis_list
6060
6161 @staticmethod
6262 cdef create(PJ* coordinate_system_pj)
6363
6464
6565 cdef class Param:
66 cdef public object name
67 cdef public object auth_name
68 cdef public object code
69 cdef public object value
70 cdef public double unit_conversion_factor
71 cdef public object unit_name
72 cdef public object unit_auth_name
73 cdef public object unit_code
74 cdef public object unit_category
66 cdef readonly object name
67 cdef readonly object auth_name
68 cdef readonly object code
69 cdef readonly object value
70 cdef readonly double unit_conversion_factor
71 cdef readonly object unit_name
72 cdef readonly object unit_auth_name
73 cdef readonly object unit_code
74 cdef readonly object unit_category
7575
7676 @staticmethod
7777 cdef create(PJ_CONTEXT* projcontext, PJ* projobj, int param_idx)
7878
7979
8080 cdef class Grid:
81 cdef public object short_name
82 cdef public object full_name
83 cdef public object package_name
84 cdef public object url
85 cdef public object direct_download
86 cdef public object open_license
87 cdef public object available
81 cdef readonly object short_name
82 cdef readonly object full_name
83 cdef readonly object package_name
84 cdef readonly object url
85 cdef readonly object direct_download
86 cdef readonly object open_license
87 cdef readonly object available
8888
8989 @staticmethod
9090 cdef create(PJ_CONTEXT* projcontext, PJ* projobj, int grid_idx)
9191
9292
9393 cdef class CoordinateOperation(Base):
94 cdef public object _params
95 cdef public object _grids
96 cdef public object method_name
97 cdef public object method_auth_name
98 cdef public object method_code
99 cdef public double accuracy
100 cdef public object is_instantiable
101 cdef public object has_ballpark_transformation
102 cdef public object _towgs84
94 cdef readonly object _params
95 cdef readonly object _grids
96 cdef readonly object method_name
97 cdef readonly object method_auth_name
98 cdef readonly object method_code
99 cdef readonly double accuracy
100 cdef readonly object is_instantiable
101 cdef readonly object has_ballpark_transformation
102 cdef readonly object _towgs84
103103
104104 @staticmethod
105105 cdef create(PJ* coordinate_operation_pj)
109109 cdef PJ_TYPE _type
110110 cdef PJ_PROJ_INFO projpj_info
111111 cdef char *pjinitstring
112 cdef public object srs
113 cdef public object type_name
112 cdef readonly object srs
113 cdef readonly object type_name
114114 cdef object _ellipsoid
115115 cdef object _area_of_use
116116 cdef object _prime_meridian
3535 """
3636 tmp_string = cstrencode(proj_string)
3737 return proj_context_guess_wkt_dialect(NULL, tmp_string) != PJ_GUESSED_NOT_WKT
38
39
40 def is_proj(proj_string):
41 """
42 Check if the input projection string is in the PROJ format.
43
44 Parameters
45 ----------
46 proj_string: str
47 The projection string.
48
49 Returns
50 -------
51 bool: True if the string is in the PROJ format
52 """
53 return not is_wkt(proj_string) and "=" in proj_string
3854
3955
4056 cdef _to_wkt(PJ_CONTEXT* projctx, PJ* projobj, version=WktVersion.WKT2_2018, pretty=False):
281297 cdef class Base:
282298 def __cinit__(self):
283299 self.projobj = NULL
284 self.projctx = get_pyproj_context()
300 self.projctx = NULL
285301 self.name = "undefined"
286302
287303 def __dealloc__(self):
290306 proj_destroy(self.projobj)
291307 if self.projctx != NULL:
292308 proj_context_destroy(self.projctx)
309
310 def __init__(self):
311 self.projctx = get_pyproj_context()
293312
294313 def _set_name(self):
295314 """
12851304 self.type_name = "undefined"
12861305
12871306 def __init__(self, proj_string):
1307 self.projctx = get_pyproj_context()
12881308 # initialize projection
12891309 self.projobj = proj_create(self.projctx, cstrencode(proj_string))
12901310 if self.projobj is NULL:
15261546 pyproj.CRS: The geodetic CRS from this CRS.
15271547 """
15281548 warnings.warn(
1529 "This method is deprecated an has been replaced with `CRS.geodetic_crs`."
1549 "This method is deprecated an has been replaced with `CRS.geodetic_crs`.",
1550 DeprecationWarning,
15301551 )
15311552 return self.geodetic_crs
15321553
15461567 the source CRS:
15471568
15481569 >>> from pyproj import CRS
1549 >>> ccs = CRS("+init=epsg:4328 +towgs84=0,0,0")
1570 >>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0")
15501571 >>> ccs.to_epsg()
15511572 >>> ccs.source_crs.to_epsg()
15521573 4978
15861607 the source CRS:
15871608
15881609 >>> from pyproj import CRS
1589 >>> ccs = CRS("+init=epsg:4328 +towgs84=0,0,0")
1610 >>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0")
15901611 >>> ccs.to_authority()
15911612 >>> ccs.source_crs.to_authority()
15921613 ('EPSG', '4978')
17641785 -------
17651786 bool: True if CRS is valid.
17661787 """
1767 warnings.warn("CRS.is_valid is deprecated.")
1788 warnings.warn(
1789 "CRS.is_valid is deprecated.",
1790 DeprecationWarning,
1791 )
17681792 return self._type != PJ_TYPE_UNKNOWN
17691793
17701794 @property
00 include "proj.pxi"
11
2 cdef PJ_CONTEXT* get_pyproj_context()
2 cdef PJ_CONTEXT* get_pyproj_context() except *
1313 ProjError.internal_proj_error = pystrdecode(error_msg)
1414
1515
16 cdef PJ_CONTEXT* get_pyproj_context():
16 cdef PJ_CONTEXT* get_pyproj_context() except *:
1717 data_dir = get_data_dir()
1818 data_dir_list = data_dir.split(os.pathsep)
1919 cdef PJ_CONTEXT* pyproj_context = NULL
2222
2323 cdef class Geod:
2424 cdef geod_geodesic _geod_geodesic
25 cdef public object initstring
26 cdef public object a
27 cdef public object b
28 cdef public object f
29 cdef public object es
30 cdef public object sphere
25 cdef readonly object initstring
26 cdef readonly object a
27 cdef readonly object b
28 cdef readonly object f
29 cdef readonly object es
30 cdef readonly object sphere
4040 def proj_version(self):
4141 warnings.warn(
4242 "'Proj.proj_version' is deprecated. "
43 "Please use `pyproj.proj_version_str` instead."
43 "Please use `pyproj.proj_version_str` instead.",
44 DeprecationWarning,
4445 )
4546 return self._proj_version
4647
00 include "base.pxi"
11
22 from pyproj._crs cimport Base, _CRS
3 from pyproj._datadir cimport get_pyproj_context
43 from pyproj.compat import cstrencode, pystrdecode
54 from pyproj.enums import ProjVersion, TransformDirection
65 from pyproj.exceptions import ProjError
8181 "DEFAULT": "scale_factor_at_projection_origin",
8282 "transverse_mercator": "scale_factor_at_central_meridian",
8383 }
84
85
86 METHOD_NAME_TO_CF_MAP = {"Transverse Mercator": "transverse_mercator"}
87
88
89 PARAM_TO_CF_MAP = {
90 "Latitude of natural origin": "latitude_of_projection_origin",
91 "Longitude of natural origin": "longitude_of_central_meridian",
92 "Latitude of false origin": "latitude_of_projection_origin",
93 "Longitude of false origin": "longitude_of_central_meridian",
94 "Scale factor at natural origin": "scale_factor_at_central_meridian",
95 "Easting at projection centre": "false_easting",
96 "Northing at projection centre": "false_northing",
97 "Easting at false origin": "fase_easting",
98 "Northing at false origin": "fase_northing",
99 "False easting": "false_easting",
100 "False northing": "false_northing",
101 }
2525 "Ellipsoid",
2626 "PrimeMeridian",
2727 "is_wkt",
28 "is_proj",
2829 ]
2930
3031 import json
3536 from pyproj._crs import Datum # noqa
3637 from pyproj._crs import Ellipsoid # noqa
3738 from pyproj._crs import PrimeMeridian # noqa
38 from pyproj._crs import _CRS, is_wkt
39 from pyproj._crs import _CRS, is_proj, is_wkt
3940 from pyproj.cf1x8 import (
4041 GRID_MAPPING_NAME_MAP,
4142 INVERSE_GRID_MAPPING_NAME_MAP,
4344 K_0_MAP,
4445 LON_0_MAP,
4546 PROJ_PARAM_MAP,
47 PARAM_TO_CF_MAP,
48 METHOD_NAME_TO_CF_MAP,
4649 )
4750 from pyproj.compat import string_types
4851 from pyproj.exceptions import CRSError
4952 from pyproj.geod import Geod
5053
5154
52 def _from_dict(projparams):
55 def _prepare_from_dict(projparams):
5356 # convert a dict to a proj string.
5457 pjargs = []
5558 for key, value in projparams.items():
6366 pass
6467 else:
6568 pjargs.append("+{key}={value}".format(key=key, value=value))
66 return _from_string(" ".join(pjargs))
67
68
69 def _from_string(in_crs_string):
69 return _prepare_from_string(" ".join(pjargs))
70
71
72 def _prepare_from_string(in_crs_string):
7073 if not in_crs_string:
7174 raise CRSError("CRS is empty or invalid: {!r}".format(in_crs_string))
7275 elif "{" in in_crs_string:
7881
7982 if not crs_dict:
8083 raise CRSError("CRS is empty JSON")
81 return _from_dict(crs_dict)
82 elif not is_wkt(in_crs_string) and "=" in in_crs_string:
83 in_crs_string = re.sub(r"[\s+]?=[\s+]?", "=", in_crs_string)
84 return _prepare_from_dict(crs_dict)
85 elif is_proj(in_crs_string):
86 in_crs_string = re.sub(r"[\s+]?=[\s+]?", "=", in_crs_string.lstrip())
8487 # make sure the projection starts with +proj or +init
8588 starting_params = ("+init", "+proj", "init", "proj")
86 if not in_crs_string.lstrip().startswith(starting_params):
89 if not in_crs_string.startswith(starting_params):
8790 kvpairs = []
8891 first_item_inserted = False
8992 for kvpair in in_crs_string.split():
104107 # look for EPSG, replace with epsg (EPSG only works
105108 # on case-insensitive filesystems).
106109 in_crs_string = in_crs_string.replace("+init=EPSG", "+init=epsg").strip()
107 # remove no_defs as it does nothing as of PROJ 6.0.0 and breaks
108 # initialization with +init=epsg:...
109 in_crs_string = re.sub(r"\s\+?no_defs([\w=]+)?", "", in_crs_string)
110 if in_crs_string.startswith(("+init", "init")):
111 warnings.warn(
112 "'+init=<authority>:<code>' syntax is deprecated."
113 " '<authority>:<code>' is the preferred initialization method.",
114 DeprecationWarning,
115 )
110116 return in_crs_string
111117
112118
113 def _from_authority(auth_name, auth_code):
119 def _prepare_from_authority(auth_name, auth_code):
114120 return "{}:{}".format(auth_name, auth_code)
115121
116122
117 def _from_epsg(auth_code):
118 return _from_authority("epsg", auth_code)
123 def _prepare_from_epsg(auth_code):
124 return _prepare_from_authority("epsg", auth_code)
119125
120126
121127 class CRS(_CRS):
280286 False
281287 """
282288 if isinstance(projparams, string_types):
283 projstring = _from_string(projparams)
289 projstring = _prepare_from_string(projparams)
284290 elif isinstance(projparams, dict):
285 projstring = _from_dict(projparams)
291 projstring = _prepare_from_dict(projparams)
286292 elif kwargs:
287 projstring = _from_dict(kwargs)
293 projstring = _prepare_from_dict(kwargs)
288294 elif isinstance(projparams, int):
289 projstring = _from_epsg(projparams)
295 projstring = _prepare_from_epsg(projparams)
290296 elif isinstance(projparams, (list, tuple)) and len(projparams) == 2:
291 projstring = _from_authority(*projparams)
297 projstring = _prepare_from_authority(*projparams)
292298 elif hasattr(projparams, "to_wkt"):
293299 projstring = projparams.to_wkt()
294300 else:
311317 -------
312318 CRS
313319 """
314 return cls(_from_authority(auth_name, code))
320 return cls(_prepare_from_authority(auth_name, code))
315321
316322 @classmethod
317323 def from_epsg(cls, code):
326332 -------
327333 CRS
328334 """
329 return cls(_from_epsg(code))
335 return cls(_prepare_from_epsg(code))
330336
331337 @classmethod
332338 def from_proj4(cls, in_proj_string):
341347 -------
342348 CRS
343349 """
344 if is_wkt(in_proj_string) or "=" not in in_proj_string:
350 if not is_proj(in_proj_string):
345351 raise CRSError("Invalid PROJ string: {}".format(in_proj_string))
346 return cls(_from_string(in_proj_string))
352 return cls(_prepare_from_string(in_proj_string))
347353
348354 @classmethod
349355 def from_wkt(cls, in_wkt_string):
360366 """
361367 if not is_wkt(in_wkt_string):
362368 raise CRSError("Invalid WKT string: {}".format(in_wkt_string))
363 return cls(_from_string(in_wkt_string))
369 return cls(_prepare_from_string(in_wkt_string))
364370
365371 @classmethod
366372 def from_string(cls, in_crs_string):
381387 -------
382388 CRS
383389 """
384 return cls(_from_string(in_crs_string))
390 return cls(_prepare_from_string(in_crs_string))
385391
386392 def to_string(self):
387393 """Convert the CRS to a string.
456462 -------
457463 CRS
458464 """
459 return cls(_from_dict(proj_dict))
465 return cls(_prepare_from_dict(proj_dict))
460466
461467 def to_dict(self):
462468 """
490496 val = [float(sval.strip()) for sval in val_split]
491497 return val
492498
499 proj_string = self.to_proj4()
500 if proj_string is None:
501 return {}
502
493503 items = map(
494504 lambda kv: len(kv) == 2 and (kv[0], parse(kv[1])) or (kv[0], None),
495 (
496 part.lstrip("+").split("=", 1)
497 for part in self.to_proj4().strip().split()
498 ),
505 (part.lstrip("+").split("=", 1) for part in proj_string.strip().split()),
499506 )
500507
501508 return {key: value for key, value in items if value is not False}
539546 if grid_mapping_name == "rotated_latitude_longitude":
540547 if proj_dict.pop("o_proj") not in lonlat_possible_names:
541548 grid_mapping_name = "unknown"
549
550 # derive parameters from the coordinate operation
551 if (
552 grid_mapping_name == "unknown"
553 and self.coordinate_operation
554 and self.coordinate_operation.method_name in METHOD_NAME_TO_CF_MAP
555 ):
556 grid_mapping_name = METHOD_NAME_TO_CF_MAP[
557 self.coordinate_operation.method_name
558 ]
559 for param in self.coordinate_operation.params:
560 cf_dict[PARAM_TO_CF_MAP[param.name]] = param.value
542561
543562 cf_dict["grid_mapping_name"] = grid_mapping_name
544563
9595
9696 if _VALIDATED_PROJ_DATA is None:
9797 raise DataDirError(
98 "Valid PROJ data directory not found."
98 "Valid PROJ data directory not found. "
9999 "Either set the path using the environmental variable PROJ_LIB or "
100100 "with `pyproj.datadir.set_data_dir`."
101101 )
128128 >>> x,y = p2(-120.108, 34.36116666)
129129 >>> 'x=%9.3f y=%11.3f' % (x,y)
130130 'x=765975.641 y=3805993.134'
131 >>> p = Proj(init="epsg:32667", preserve_units=False)
131 >>> p = Proj("epsg:32667", preserve_units=False)
132132 >>> 'x=%12.3f y=%12.3f (meters)' % p(-114.057222, 51.045)
133133 'x=-1783506.250 y= 6193827.033 (meters)'
134 >>> p = Proj("+init=epsg:32667")
134 >>> p = Proj("epsg:32667")
135135 >>> 'x=%12.3f y=%12.3f (feet)' % p(-114.057222, 51.045)
136136 'x=-5851386.754 y=20320914.191 (feet)'
137137 >>> # test data with radian inputs
138 >>> p1 = Proj(init="epsg:4214")
138 >>> p1 = Proj("epsg:4214")
139139 >>> x1, y1 = p1(116.366, 39.867)
140140 >>> '{:.3f} {:.3f}'.format(x1, y1)
141141 '2.031 0.696'
192192 def definition_string(self):
193193 """Returns formal definition string for projection
194194
195 >>> Proj('+init=epsg:4326').definition_string()
195 >>> Proj("epsg:4326").definition_string()
196196 'proj=longlat datum=WGS84 no_defs ellps=WGS84 towgs84=0,0,0'
197197 >>>
198198 """
228228 '120.321 0.057'
229229 >>> transproj = Transformer.from_crs(
230230 ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'},
231 ... '+init=EPSG:4326'
231 ... "EPSG:4326",
232 ... always_xy=True,
232233 ... )
233234 >>> xpj, ypj, zpj = transproj.transform(
234235 ... -2704026.010,
239240 >>> "%.3f %.3f %.3f" % (xpj, ypj, zpj)
240241 '-2.137 0.661 -20.531'
241242 >>> transprojr = Transformer.from_crs(
242 ... '+init=EPSG:4326',
243 ... "EPSG:4326",
243244 ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'},
245 ... always_xy=True,
244246 ... )
245247 >>> xpjr, ypjr, zpjr = transprojr.transform(xpj, ypj, zpj, radians=True)
246248 >>> "%.3f %.3f %.3f" % (xpjr, ypjr, zpjr)
336338 '120.321 0.057'
337339 >>> transproj = Transformer.from_crs(
338340 ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'},
339 ... '+init=EPSG:4326',
341 ... "EPSG:4326",
342 ... always_xy=True,
340343 ... )
341344 >>> for pt in transproj.itransform(
342345 ... [(-2704026.010, -4253051.810, 3895878.820)],
344347 ... ):
345348 ... '{:.3f} {:.3f} {:.3f}'.format(*pt)
346349 '-2.137 0.661 -20.531'
347 >>> transprojr = Transformer.from_proj(
348 ... '+init=EPSG:4326',
350 >>> transprojr = Transformer.from_crs(
351 ... "EPSG:4326",
349352 ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'},
353 ... always_xy=True,
350354 ... )
351355 >>> for pt in transprojr.itransform(
352356 ... [(-2.137, 0.661, -20.531)],
355359 ... '{:.3f} {:.3f} {:.3f}'.format(*pt)
356360 '-2704214.394 -4254414.478 3894270.731'
357361 >>> transproj_eq = Transformer.from_proj(
358 ... '+init=EPSG:4326',
362 ... 'EPSG:4326',
359363 ... '+proj=longlat +datum=WGS84 +no_defs +type=crs',
364 ... always_xy=True,
360365 ... skip_equivalent=True
361366 ... )
362367 >>> for pt in transproj_eq.itransform([(-2.137, 0.661)]):
493498 >>> from pyproj import Proj, transform
494499 >>> # projection 1: UTM zone 15, grs80 ellipse, NAD83 datum
495500 >>> # (defined by epsg code 26915)
496 >>> p1 = Proj(init='epsg:26915', preserve_units=False)
501 >>> p1 = Proj('epsg:26915', preserve_units=False)
497502 >>> # projection 2: UTM zone 15, clrk66 ellipse, NAD27 datum
498 >>> p2 = Proj(init='epsg:26715', preserve_units=False)
503 >>> p2 = Proj('epsg:26715', preserve_units=False)
499504 >>> # find x,y of Jefferson City, MO.
500505 >>> x1, y1 = p1(-92.199881,38.56694)
501506 >>> # transform this point to projection 2 coordinates.
594599 >>> from pyproj import Proj, itransform
595600 >>> # projection 1: WGS84
596601 >>> # (defined by epsg code 4326)
597 >>> p1 = Proj(init='epsg:4326', preserve_units=False)
602 >>> p1 = Proj('epsg:4326', preserve_units=False)
598603 >>> # projection 2: GGRS87 / Greek Grid
599 >>> p2 = Proj(init='epsg:2100', preserve_units=False)
604 >>> p2 = Proj('epsg:2100', preserve_units=False)
600605 >>> # Three points with coordinates lon, lat in p1
601606 >>> points = [(22.95, 40.63), (22.81, 40.53), (23.51, 40.86)]
602607 >>> # transform this point to projection 2 coordinates.
603 >>> for pt in itransform(p1,p2,points): '%6.3f %7.3f' % pt
608 >>> for pt in itransform(p1,p2,points, always_xy=True): '%6.3f %7.3f' % pt
604609 '411050.470 4497928.574'
605610 '399060.236 4486978.710'
606611 '458553.243 4523045.485'
22 import numpy
33 from numpy.testing import assert_allclose
44
5 from pyproj import Proj
5 from pyproj import Proj, proj_version_str
66
77 try:
88 from time import perf_counter
2525 # awips221 = Proj(params)
2626 # or keyword args
2727 awips221 = Proj(proj="lcc", R=6371200, lat_1=50, lat_2=50, lon_0=-107)
28 print("proj4 library version = ", awips221.proj_version)
28 print("proj4 library version = ", proj_version_str)
2929 # AWIPS grid 221 parameters
3030 # (from http://www.nco.ncep.noaa.gov/pmb/docs/on388/tableb.html)
3131 llcrnrx, llcrnry = awips221(-145.5, 1.0)
5555 assert wgs84_crs.to_proj4() == "+proj=longlat +datum=WGS84 +no_defs +type=crs"
5656 # Make sure this doesn't get handled using the from_epsg()
5757 # even though 'epsg' is in the string
58 epsg_init_crs = CRS.from_string("+init=epsg:26911 +units=m +no_defs=True")
58 with pytest.warns(DeprecationWarning):
59 epsg_init_crs = CRS.from_string("+init=epsg:26911 +units=m +no_defs=True")
5960 assert (
6061 epsg_init_crs.to_proj4()
6162 == "+proj=utm +zone=11 +datum=NAD83 +units=m +no_defs +type=crs"
8384
8485
8586 def test_is_geographic():
86 assert CRS({"init": "EPSG:4326"}).is_geographic is True
87 assert CRS({"init": "EPSG:3857"}).is_geographic is False
87 assert CRS("EPSG:4326").is_geographic is True
88 assert CRS("EPSG:3857").is_geographic is False
8889
8990 wgs84_crs = CRS.from_string("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
9091 assert wgs84_crs.is_geographic is True
100101
101102
102103 def test_is_projected():
103 assert CRS({"init": "EPSG:3857"}).is_projected is True
104 assert CRS("EPSG:3857").is_projected is True
104105
105106 lcc_crs = CRS.from_string(
106107 "+lon_0=-95 +ellps=GRS80 +y_0=0 +no_defs=True +proj=lcc +x_0=0 "
113114
114115
115116 def test_is_same_crs():
116 crs1 = CRS({"init": "EPSG:4326"})
117 crs2 = CRS({"init": "EPSG:3857"})
117 crs1 = CRS("urn:ogc:def:crs:OGC::CRS84")
118 crs2 = CRS("EPSG:3857")
118119
119120 assert crs1 == crs1
120121 assert crs1 != crs2
136137
137138 def test_to_proj4():
138139 assert (
139 CRS({"init": "EPSG:4326"}).to_proj4(4)
140 == "+proj=longlat +datum=WGS84 +no_defs +type=crs"
140 CRS("EPSG:4326").to_proj4(4) == "+proj=longlat +datum=WGS84 +no_defs +type=crs"
141141 )
142142
143143
144144 def test_is_valid():
145 with pytest.warns(UserWarning):
145 with pytest.warns(DeprecationWarning):
146146 assert CRS(init="EPSG:4326").is_valid
147147
148148
156156
157157
158158 def test_has_wkt_property():
159 assert (
160 CRS({"init": "EPSG:4326"})
161 .to_wkt("WKT1_GDAL")
162 .startswith('GEOGCS["WGS 84",DATUM')
163 )
159 with pytest.warns(DeprecationWarning):
160 assert (
161 CRS({"init": "EPSG:4326"})
162 .to_wkt("WKT1_GDAL")
163 .startswith('GEOGCS["WGS 84",DATUM')
164 )
164165
165166
166167 def test_to_wkt_pretty():
170171
171172
172173 def test_repr():
173 assert repr(CRS({"init": "EPSG:4326"})) == (
174 "<Geographic 2D CRS: +init=epsg:4326 +type=crs>\n"
175 "Name: WGS 84\n"
176 "Axis Info [ellipsoidal]:\n"
177 "- lon[east]: Longitude (degree)\n"
178 "- lat[north]: Latitude (degree)\n"
179 "Area of Use:\n"
180 "- name: World\n"
181 "- bounds: (-180.0, -90.0, 180.0, 90.0)\n"
182 "Datum: World Geodetic System 1984\n"
183 "- Ellipsoid: WGS 84\n"
184 "- Prime Meridian: Greenwich\n"
185 )
174 with pytest.warns(DeprecationWarning):
175 assert repr(CRS({"init": "EPSG:4326"})) == (
176 "<Geographic 2D CRS: +init=epsg:4326 +type=crs>\n"
177 "Name: WGS 84\n"
178 "Axis Info [ellipsoidal]:\n"
179 "- lon[east]: Longitude (degree)\n"
180 "- lat[north]: Latitude (degree)\n"
181 "Area of Use:\n"
182 "- name: World\n"
183 "- bounds: (-180.0, -90.0, 180.0, 90.0)\n"
184 "Datum: World Geodetic System 1984\n"
185 "- Ellipsoid: WGS 84\n"
186 "- Prime Meridian: Greenwich\n"
187 )
186188
187189
188190 def test_repr__long():
189 assert repr(CRS(CRS({"init": "EPSG:4326"}).to_wkt())) == (
190 '<Geographic 2D CRS: GEOGCRS["WGS 84",DATUM["World Geodetic System 1984 ...>\n'
191 "Name: WGS 84\n"
192 "Axis Info [ellipsoidal]:\n"
193 "- lon[east]: Longitude (degree)\n"
194 "- lat[north]: Latitude (degree)\n"
195 "Area of Use:\n"
196 "- name: World\n"
197 "- bounds: (-180.0, -90.0, 180.0, 90.0)\n"
198 "Datum: World Geodetic System 1984\n"
199 "- Ellipsoid: WGS 84\n"
200 "- Prime Meridian: Greenwich\n"
201 )
191 with pytest.warns(DeprecationWarning):
192 assert repr(CRS(CRS({"init": "EPSG:4326"}).to_wkt())) == (
193 '<Geographic 2D CRS: GEOGCRS["WGS 84",'
194 'DATUM["World Geodetic System 1984 ...>\n'
195 "Name: WGS 84\n"
196 "Axis Info [ellipsoidal]:\n"
197 "- lon[east]: Longitude (degree)\n"
198 "- lat[north]: Latitude (degree)\n"
199 "Area of Use:\n"
200 "- name: World\n"
201 "- bounds: (-180.0, -90.0, 180.0, 90.0)\n"
202 "Datum: World Geodetic System 1984\n"
203 "- Ellipsoid: WGS 84\n"
204 "- Prime Meridian: Greenwich\n"
205 )
202206
203207
204208 def test_repr_epsg():
262266
263267
264268 def test_dunder_str():
265 assert str(CRS({"init": "EPSG:4326"})) == CRS({"init": "EPSG:4326"}).srs
269 with pytest.warns(DeprecationWarning):
270 assert str(CRS({"init": "EPSG:4326"})) == CRS({"init": "EPSG:4326"}).srs
266271
267272
268273 def test_epsg():
269 assert CRS({"init": "EPSG:4326"}).to_epsg(20) == 4326
270 assert CRS({"init": "EPSG:4326"}).to_epsg() is None
274 with pytest.warns(DeprecationWarning):
275 assert CRS({"init": "EPSG:4326"}).to_epsg(20) == 4326
276 assert CRS({"init": "EPSG:4326"}).to_epsg() is None
271277 assert CRS.from_user_input(4326).to_epsg() == 4326
272278 assert CRS.from_epsg(4326).to_epsg() == 4326
273279 assert CRS.from_user_input("epsg:4326").to_epsg() == 4326
315321 def test_crs_OSR_equivalence():
316322 crs1 = CRS.from_string("+proj=longlat +datum=WGS84 +no_defs")
317323 crs2 = CRS.from_string("+proj=latlong +datum=WGS84 +no_defs")
318 crs3 = CRS({"init": "EPSG:4326"})
324 with pytest.warns(DeprecationWarning):
325 crs3 = CRS({"init": "EPSG:4326"})
319326 assert crs1 == crs2
320327 # these are not equivalent in proj.4 now as one uses degrees and the othe radians
321328 assert crs1 == crs3
612619
613620 def test_coordinate_operation_towgs84_seven():
614621 crs = CRS(
615 init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
622 "+proj=tmerc +lat_0=0 +lon_0=15 +k=0.9996 +x_0=2520000 +y_0=0 "
623 "+ellps=intl +towgs84=-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
616624 )
617625 assert crs.coordinate_operation.towgs84 == [
618626 -122.74,
626634
627635
628636 def test_coordinate_operation_towgs84_missing():
629 crs = CRS(init="epsg:3004")
637 crs = CRS("epsg:3004")
630638 assert crs.coordinate_operation.towgs84 == []
631639
632640
716724
717725 def test_deprecated_to_geodetic():
718726 cc = CRS("epsg:3004")
719 with pytest.warns(UserWarning):
727 with pytest.warns(DeprecationWarning):
720728 assert cc.to_geodetic().to_epsg() == 4265
721729
722730
790798 def test_srs__no_plus():
791799 assert (
792800 CRS("proj=longlat datum=WGS84 no_defs").srs
793 == "proj=longlat datum=WGS84 type=crs"
794 )
795
796
797 @pytest.mark.parametrize(
798 "init_string, expected_srs",
799 [
800 ("+init=epsg:4326 +no_defs=True", "+init=epsg:4326 +type=crs"),
801 ("init=epsg:4326 no_defs=True", "init=epsg:4326 type=crs"),
802 ("+init=epsg:4326 +no_defs", "+init=epsg:4326 +type=crs"),
803 ("init=epsg:4326 no_defs", "init=epsg:4326 type=crs"),
804 ],
805 )
806 def test_removing_nodefs(init_string, expected_srs):
807 assert CRS(init_string).srs == expected_srs
801 == "proj=longlat datum=WGS84 no_defs type=crs"
802 )
808803
809804
810805 def test_equals_different_type():
818813 def test_compare_crs_non_crs():
819814 assert CRS.from_epsg(4326) != 4.2
820815 assert CRS.from_epsg(4326) == 4326
821 assert CRS.from_dict({"init": "epsg:4326"}) == {"init": "epsg:4326"}
822 assert CRS.from_dict({"init": "epsg:4326"}) != "epsg:4326"
816 with pytest.warns(DeprecationWarning):
817 assert CRS.from_dict({"init": "epsg:4326"}) == {"init": "epsg:4326"}
818 assert CRS.from_dict({"init": "epsg:4326"}) != "epsg:4326"
823819 assert CRS("epsg:4326") == CustomCRS()
824820
825821
826822 def test_is_geocentric__bound():
827 ccs = CRS("+init=epsg:4328 +towgs84=0,0,0")
823 with pytest.warns(DeprecationWarning):
824 ccs = CRS("+init=epsg:4328 +towgs84=0,0,0")
828825 assert ccs.is_geocentric
829826
830827
851848
852849
853850 def test_source_crs__bound():
854 assert CRS("+init=epsg:4328 +towgs84=0,0,0").source_crs.name == "unknown"
851 with pytest.warns(DeprecationWarning):
852 assert CRS("+init=epsg:4328 +towgs84=0,0,0").source_crs.name == "unknown"
855853
856854
857855 def test_source_crs__missing():
859857
860858
861859 def test_target_crs__bound():
862 assert CRS("+init=epsg:4328 +towgs84=0,0,0").target_crs.name == "WGS 84"
860 with pytest.warns(DeprecationWarning):
861 assert CRS("+init=epsg:4328 +towgs84=0,0,0").target_crs.name == "WGS 84"
863862
864863
865864 def test_target_crs__missing():
874873 "+proj=lcc +lat_1=30.0 +lat_2=35.0 +lat_0=30.0 "
875874 "+lon_0=87.0 +x_0=0 +y_0=0 +type=crs"
876875 )
876
877
878 def test_to_dict_no_proj4():
879 crs = CRS(
880 {
881 "a": 6371229.0,
882 "b": 6371229.0,
883 "lon_0": -10.0,
884 "o_lat_p": 30.0,
885 "o_lon_p": 0.0,
886 "o_proj": "longlat",
887 "proj": "ob_tran",
888 }
889 )
890 assert crs.to_proj4() is None
891 assert crs.to_dict() == {}
66
77 def test_to_cf_transverse_mercator():
88 crs = CRS(
9 init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
9 proj="tmerc",
10 lat_0=0,
11 lon_0=15,
12 k=0.9996,
13 x_0=2520000,
14 y_0=0,
15 ellps="intl",
16 units="m",
17 towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62",
1018 )
1119 with pytest.warns(UserWarning):
1220 cf_dict = crs.to_cf(errcheck=True)
101109 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
102110 assert cf_dict == {
103111 "projected_crs_name": "WGS 84 / UTM zone 15N",
104 "grid_mapping_name": "unknown",
105 "horizontal_datum_name": "WGS84",
112 "latitude_of_projection_origin": 0.0,
113 "longitude_of_central_meridian": -93.0,
114 "scale_factor_at_central_meridian": 0.9996,
115 "false_easting": 500000.0,
116 "false_northing": 0.0,
117 "grid_mapping_name": "transverse_mercator",
118 "horizontal_datum_name": "WGS84",
119 "unit": "m",
120 }
121
122
123 def test_cf_from_utm__nad83():
124 crs = CRS("epsg:26917")
125 with pytest.warns(UserWarning):
126 cf_dict = crs.to_cf(errcheck=True)
127 assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
128 assert cf_dict == {
129 "projected_crs_name": "NAD83 / UTM zone 17N",
130 "latitude_of_projection_origin": 0.0,
131 "longitude_of_central_meridian": -81.0,
132 "scale_factor_at_central_meridian": 0.9996,
133 "false_easting": 500000.0,
134 "false_northing": 0.0,
135 "grid_mapping_name": "transverse_mercator",
136 "horizontal_datum_name": "NAD83",
106137 "unit": "m",
107138 }
108139
0 import warnings
1
02 from numpy.testing import assert_almost_equal
13
2 from pyproj import Proj, transform
4 from pyproj import Proj, proj_version_str, transform
35
46 # illustrates the use of the transform function to
57 # perform coordinate transformations with datum shifts.
2729 UTM_z = WGS84_z = 52.8 # Ellipsoidical height in meters
2830 WGS84_PROJ = Proj(proj="latlong", datum="WGS84")
2931 UTM_33_PROJ = Proj(proj="utm", zone="33")
30 GAUSSSB_PROJ = Proj(
31 init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
32 )
33 print("proj4 library version = ", WGS84_PROJ.proj_version)
32 with warnings.catch_warnings():
33 warnings.simplefilter("ignore", DeprecationWarning)
34 GAUSSSB_PROJ = Proj(
35 init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
36 )
37 print("proj4 library version = ", proj_version_str)
3438
3539
3640 def test_shift_wgs84_to_utm33():
116116 # https://github.com/jswhit/pyproj/issues/8
117117
118118 def setUp(self):
119 self.p = Proj(init="epsg:4269")
119 with pytest.warns(DeprecationWarning):
120 self.p = Proj(init="epsg:4269")
120121
121122 def test_tranform_none_1st_parmeter(self):
122123 # test should raise Type error if projections are not of Proj classes
369370
370371 def test_proj_version():
371372 awips221 = Proj(proj="lcc", R=6371200, lat_1=50, lat_2=50, lon_0=-107)
372 with pytest.warns(UserWarning, matches="'Proj.proj_version' is deprecated"):
373 with pytest.warns(DeprecationWarning, match="'Proj.proj_version' is deprecated"):
373374 assert type(awips221.proj_version) is int
374375
375376
00 import numpy
11 from numpy.testing import assert_allclose
22
3 from pyproj import Proj, transform
3 from pyproj import Proj, proj_version_str, transform
44
55
66 def test_transform():
1111 dx = 12190.58
1212 dy = dx
1313 awips221 = Proj(proj="lcc", R=6371200, lat_1=50, lat_2=50, lon_0=-107)
14 print("proj4 library version = ", awips221.proj_version)
14 print("proj4 library version = ", proj_version_str)
1515 llcrnrx, llcrnry = awips221(-145.5, 1)
1616 awips221 = Proj(
1717 proj="lcc",
1919
2020
2121 def test_transform_wgs84_to_alaska():
22 lat_lon_proj = pyproj.Proj(init="epsg:4326", preserve_units=False)
23 alaska_aea_proj = pyproj.Proj(init="epsg:2964", preserve_units=False)
22 with pytest.warns(DeprecationWarning):
23 lat_lon_proj = pyproj.Proj(init="epsg:4326", preserve_units=False)
24 alaska_aea_proj = pyproj.Proj(init="epsg:2964", preserve_units=False)
2425 test = (-179.72638, 49.752533)
2526 xx, yy = pyproj.transform(lat_lon_proj, alaska_aea_proj, *test)
2627 assert "{:.3f} {:.3f}".format(xx, yy) == "-1824924.495 330822.800"
2829
2930 def test_illegal_transformation():
3031 # issue 202
31 p1 = pyproj.Proj(init="epsg:4326")
32 p2 = pyproj.Proj(init="epsg:3857")
32 with pytest.warns(DeprecationWarning):
33 p1 = pyproj.Proj(init="epsg:4326")
34 p2 = pyproj.Proj(init="epsg:3857")
3335 xx, yy = pyproj.transform(
3436 p1, p2, (-180, -180, 180, 180, -180), (-90, 90, 90, -90, -90)
3537 )
4345
4446 def test_lambert_conformal_transform():
4547 # issue 207
46 Midelt = pyproj.Proj(init="epsg:26191")
47 WGS84 = pyproj.Proj(init="epsg:4326")
48 with pytest.warns(DeprecationWarning):
49 Midelt = pyproj.Proj(init="epsg:26191")
50 WGS84 = pyproj.Proj(init="epsg:4326")
4851
4952 E = 567623.931
5053 N = 256422.787
7679
7780
7881 def test_equivalent_proj():
79 transformer = Transformer.from_proj(
80 "+init=epsg:4326", pyproj.Proj(4326).crs.to_proj4(), skip_equivalent=True
81 )
82 with pytest.warns(DeprecationWarning):
83 transformer = Transformer.from_proj(
84 "+init=epsg:4326", pyproj.Proj(4326).crs.to_proj4(), skip_equivalent=True
85 )
8286 assert transformer._transformer.skip_equivalent
8387 assert transformer._transformer.projections_equivalent
8488 assert not transformer._transformer.projections_exact_same
226230
227231
228232 def test_transform_no_error():
229 pj = Proj(init="epsg:4555")
233 with pytest.warns(DeprecationWarning):
234 pj = Proj(init="epsg:4555")
230235 pjx, pjy = pj(116.366, 39.867)
231236 transform(pj, Proj(4326), pjx, pjy, radians=True, errcheck=True)
232237
233238
234239 def test_itransform_no_error():
235 pj = Proj(init="epsg:4555")
240 with pytest.warns(DeprecationWarning):
241 pj = Proj(init="epsg:4555")
236242 pjx, pjy = pj(116.366, 39.867)
237243 list(itransform(pj, Proj(4326), [(pjx, pjy)], radians=True, errcheck=True))
238244
239245
240246 def test_transform_no_exception():
241247 # issue 249
242 transformer = Transformer.from_proj("+init=epsg:4326", "+init=epsg:27700")
248 with pytest.warns(DeprecationWarning):
249 transformer = Transformer.from_proj("+init=epsg:4326", "+init=epsg:27700")
243250 transformer.transform(1.716073972, 52.658007833, errcheck=True)
244251 transformer.itransform([(1.716073972, 52.658007833)], errcheck=True)
245252
246253
247254 def test_transform__out_of_bounds():
248 transformer = Transformer.from_proj("+init=epsg:4326", "+init=epsg:27700")
255 with pytest.warns(DeprecationWarning):
256 transformer = Transformer.from_proj("+init=epsg:4326", "+init=epsg:27700")
249257 assert np.all(np.isinf(transformer.transform(100000, 100000, errcheck=True)))
250258
251259
252260 def test_transform_radians():
253 WGS84 = pyproj.Proj("+init=EPSG:4326")
261 with pytest.warns(DeprecationWarning):
262 WGS84 = pyproj.Proj("+init=EPSG:4326")
254263 ECEF = pyproj.Proj(proj="geocent", ellps="WGS84", datum="WGS84")
255264 assert_almost_equal(
256265 pyproj.transform(
273282
274283
275284 def test_itransform_radians():
276 WGS84 = pyproj.Proj("+init=EPSG:4326")
285 with pytest.warns(DeprecationWarning):
286 WGS84 = pyproj.Proj("+init=EPSG:4326")
277287 ECEF = pyproj.Proj(proj="geocent", ellps="WGS84", datum="WGS84")
278288 assert_almost_equal(
279289 list(