Skip to content
Commits on Source (4)
......@@ -11,7 +11,7 @@ env:
global:
- PROJ_BASE_DIR=$HOME/proj_install
- CYTHON_COVERAGE=True
- PROJSOURCE=6.1.0
- PROJSOURCE=6.1.1
# Following generated with
- WHEELHOUSE_UPLOADER_USERNAME=travis-worker
# Following generated by
......@@ -26,20 +26,23 @@ matrix:
os: osx
env:
- PYTHON=3.6.8
- PROJSOURCE=6.1.0
- PROJSOURCE=6.1.1
- python: 2.7
env:
- PROJSOURCE=6.1.0
- PROJSOURCE=6.1.1
- python: 3.5
env:
- PROJSOURCE=6.1.0
- PROJSOURCE=6.1.1
- python: 3.6
env:
- PROJSOURCE=6.1.0
- python: 3.6
env:
- PROJSOURCE=6.1.1
- python: 3.7
dist: xenial
env:
- PROJSOURCE=6.1.0
- PROJSOURCE=6.1.1
- DOC=true
- python: "nightly"
env:
......@@ -88,7 +91,7 @@ install:
- pip install coveralls
script:
- python -c "import pyproj; pyproj.Proj(init='epsg:4269')"
- python -c "import pyproj; pyproj.Proj('epsg:4269')"
- make test-coverage
# Building and uploading docs with doctr
- set -e
......
......@@ -27,13 +27,13 @@ environment:
PYTHON_ARCH: "64"
VS_VERSION: Visual Studio 14
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
PROJSOURCE: 6.1.0
PROJSOURCE: 6.1.1
# - PYTHON: "C:\\Python37-x64"
# PYTHON_VERSION: "3.7"
# PYTHON_ARCH: "64"
# VS_VERSION: Visual Studio 14
# APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
# PROJSOURCE: 6.1.0
# PROJSOURCE: 6.1.1
# - PYTHON: "C:\\Python36-x64"
# PYTHON_VERSION: "3.6"
# PYTHON_ARCH: "64"
......@@ -121,7 +121,7 @@ install:
test_script:
# Run the project tests
- "%CMD_IN_ENV% python -c \"import pyproj; pyproj.Proj(init='epsg:4269')\""
- "%CMD_IN_ENV% python -c \"import pyproj; pyproj.Proj('epsg:4269')\""
- "%CMD_IN_ENV% py.test --cov-report term-missing --cov=pyproj -v -s"
after_test:
......@@ -140,7 +140,7 @@ after_test:
# - "%CMD_IN_ENV% python setup.py bdist_msi"
# test wheel
- pip install pyproj --ignore-installed -f dist
- python -c "import pyproj; pyproj.Proj(init='epsg:4269')"
- python -c "import pyproj; pyproj.Proj('epsg:4269')"
# cleanup for test dir
- if %PROJSOURCE% == git del /F /Q dist\*
- ps: "ls dist"
......
python-pyproj (2.2.1+ds-1~exp2) UNRELEASED; urgency=medium
python-pyproj (2.2.2+ds-1~exp1) experimental; urgency=medium
* New upstream release.
* Update gbp.conf to use --source-only-changes by default.
* Bump Standards-Version to 4.4.0, no changes.
-- Bas Couwenberg <sebastic@debian.org> Sun, 07 Jul 2019 10:00:54 +0200
-- Bas Couwenberg <sebastic@debian.org> Sat, 13 Jul 2019 06:48:05 +0200
python-pyproj (2.2.1+ds-1~exp1) experimental; urgency=medium
......
......@@ -47,7 +47,7 @@ CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """
__version__ = "2.2.1"
__version__ = "2.2.2"
__all__ = [
"Proj",
"Geod",
......
include "proj.pxi"
cdef class Axis:
cdef public object name
cdef public object abbrev
cdef public object direction
cdef public double unit_conversion_factor
cdef public object unit_name
cdef public object unit_auth_code
cdef public object unit_code
cdef readonly object name
cdef readonly object abbrev
cdef readonly object direction
cdef readonly double unit_conversion_factor
cdef readonly object unit_name
cdef readonly object unit_auth_code
cdef readonly object unit_code
@staticmethod
cdef create(PJ_CONTEXT* projcontext, PJ* projobj, int index)
cdef class AreaOfUse:
cdef public double west
cdef public double south
cdef public double east
cdef public double north
cdef public object name
cdef readonly double west
cdef readonly double south
cdef readonly double east
cdef readonly double north
cdef readonly object name
@staticmethod
cdef create(PJ_CONTEXT* projcontext, PJ* projobj)
......@@ -26,81 +26,81 @@ cdef class AreaOfUse:
cdef class Base:
cdef PJ *projobj
cdef PJ_CONTEXT *projctx
cdef public object name
cdef readonly object name
cdef class Ellipsoid(Base):
cdef double _semi_major_metre
cdef double _semi_minor_metre
cdef public object is_semi_minor_computed
cdef readonly object is_semi_minor_computed
cdef double _inv_flattening
cdef public object ellipsoid_loaded
cdef readonly object ellipsoid_loaded
@staticmethod
cdef create(PJ* ellipsoid_pj)
cdef class PrimeMeridian(Base):
cdef public double longitude
cdef public double unit_conversion_factor
cdef public object unit_name
cdef readonly double longitude
cdef readonly double unit_conversion_factor
cdef readonly object unit_name
@staticmethod
cdef create(PJ* prime_meridian_pj)
cdef class Datum(Base):
cdef public object _ellipsoid
cdef public object _prime_meridian
cdef readonly object _ellipsoid
cdef readonly object _prime_meridian
@staticmethod
cdef create(PJ* datum_pj)
cdef class CoordinateSystem(Base):
cdef public object _axis_list
cdef readonly object _axis_list
@staticmethod
cdef create(PJ* coordinate_system_pj)
cdef class Param:
cdef public object name
cdef public object auth_name
cdef public object code
cdef public object value
cdef public double unit_conversion_factor
cdef public object unit_name
cdef public object unit_auth_name
cdef public object unit_code
cdef public object unit_category
cdef readonly object name
cdef readonly object auth_name
cdef readonly object code
cdef readonly object value
cdef readonly double unit_conversion_factor
cdef readonly object unit_name
cdef readonly object unit_auth_name
cdef readonly object unit_code
cdef readonly object unit_category
@staticmethod
cdef create(PJ_CONTEXT* projcontext, PJ* projobj, int param_idx)
cdef class Grid:
cdef public object short_name
cdef public object full_name
cdef public object package_name
cdef public object url
cdef public object direct_download
cdef public object open_license
cdef public object available
cdef readonly object short_name
cdef readonly object full_name
cdef readonly object package_name
cdef readonly object url
cdef readonly object direct_download
cdef readonly object open_license
cdef readonly object available
@staticmethod
cdef create(PJ_CONTEXT* projcontext, PJ* projobj, int grid_idx)
cdef class CoordinateOperation(Base):
cdef public object _params
cdef public object _grids
cdef public object method_name
cdef public object method_auth_name
cdef public object method_code
cdef public double accuracy
cdef public object is_instantiable
cdef public object has_ballpark_transformation
cdef public object _towgs84
cdef readonly object _params
cdef readonly object _grids
cdef readonly object method_name
cdef readonly object method_auth_name
cdef readonly object method_code
cdef readonly double accuracy
cdef readonly object is_instantiable
cdef readonly object has_ballpark_transformation
cdef readonly object _towgs84
@staticmethod
cdef create(PJ* coordinate_operation_pj)
......@@ -110,8 +110,8 @@ cdef class _CRS(Base):
cdef PJ_TYPE _type
cdef PJ_PROJ_INFO projpj_info
cdef char *pjinitstring
cdef public object srs
cdef public object type_name
cdef readonly object srs
cdef readonly object type_name
cdef object _ellipsoid
cdef object _area_of_use
cdef object _prime_meridian
......
......@@ -38,6 +38,22 @@ def is_wkt(proj_string):
return proj_context_guess_wkt_dialect(NULL, tmp_string) != PJ_GUESSED_NOT_WKT
def is_proj(proj_string):
"""
Check if the input projection string is in the PROJ format.
Parameters
----------
proj_string: str
The projection string.
Returns
-------
bool: True if the string is in the PROJ format
"""
return not is_wkt(proj_string) and "=" in proj_string
cdef _to_wkt(PJ_CONTEXT* projctx, PJ* projobj, version=WktVersion.WKT2_2018, pretty=False):
"""
Convert a PJ object to a wkt string.
......@@ -282,7 +298,7 @@ cdef class AreaOfUse:
cdef class Base:
def __cinit__(self):
self.projobj = NULL
self.projctx = get_pyproj_context()
self.projctx = NULL
self.name = "undefined"
def __dealloc__(self):
......@@ -292,6 +308,9 @@ cdef class Base:
if self.projctx != NULL:
proj_context_destroy(self.projctx)
def __init__(self):
self.projctx = get_pyproj_context()
def _set_name(self):
"""
Set the name of the PJ
......@@ -1286,6 +1305,7 @@ cdef class _CRS(Base):
self.type_name = "undefined"
def __init__(self, proj_string):
self.projctx = get_pyproj_context()
# initialize projection
self.projobj = proj_create(self.projctx, cstrencode(proj_string))
if self.projobj is NULL:
......@@ -1527,7 +1547,8 @@ cdef class _CRS(Base):
pyproj.CRS: The geodetic CRS from this CRS.
"""
warnings.warn(
"This method is deprecated an has been replaced with `CRS.geodetic_crs`."
"This method is deprecated an has been replaced with `CRS.geodetic_crs`.",
DeprecationWarning,
)
return self.geodetic_crs
......@@ -1547,7 +1568,7 @@ cdef class _CRS(Base):
the source CRS:
>>> from pyproj import CRS
>>> ccs = CRS("+init=epsg:4328 +towgs84=0,0,0")
>>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0")
>>> ccs.to_epsg()
>>> ccs.source_crs.to_epsg()
4978
......@@ -1587,7 +1608,7 @@ cdef class _CRS(Base):
the source CRS:
>>> from pyproj import CRS
>>> ccs = CRS("+init=epsg:4328 +towgs84=0,0,0")
>>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0")
>>> ccs.to_authority()
>>> ccs.source_crs.to_authority()
('EPSG', '4978')
......@@ -1765,7 +1786,10 @@ cdef class _CRS(Base):
-------
bool: True if CRS is valid.
"""
warnings.warn("CRS.is_valid is deprecated.")
warnings.warn(
"CRS.is_valid is deprecated.",
DeprecationWarning,
)
return self._type != PJ_TYPE_UNKNOWN
@property
......
include "proj.pxi"
cdef PJ_CONTEXT* get_pyproj_context()
\ No newline at end of file
cdef PJ_CONTEXT* get_pyproj_context() except *
......@@ -14,7 +14,7 @@ cdef void pyproj_log_function(void *user_data, int level, const char *error_msg)
ProjError.internal_proj_error = pystrdecode(error_msg)
cdef PJ_CONTEXT* get_pyproj_context():
cdef PJ_CONTEXT* get_pyproj_context() except *:
data_dir = get_data_dir()
data_dir_list = data_dir.split(os.pathsep)
cdef PJ_CONTEXT* pyproj_context = NULL
......
......@@ -23,9 +23,9 @@ cdef extern from "geodesic.h":
cdef class Geod:
cdef geod_geodesic _geod_geodesic
cdef public object initstring
cdef public object a
cdef public object b
cdef public object f
cdef public object es
cdef public object sphere
cdef readonly object initstring
cdef readonly object a
cdef readonly object b
cdef readonly object f
cdef readonly object es
cdef readonly object sphere
......@@ -41,7 +41,8 @@ cdef class Proj:
def proj_version(self):
warnings.warn(
"'Proj.proj_version' is deprecated. "
"Please use `pyproj.proj_version_str` instead."
"Please use `pyproj.proj_version_str` instead.",
DeprecationWarning,
)
return self._proj_version
......
include "base.pxi"
from pyproj._crs cimport Base, _CRS
from pyproj._datadir cimport get_pyproj_context
from pyproj.compat import cstrencode, pystrdecode
from pyproj.enums import ProjVersion, TransformDirection
from pyproj.exceptions import ProjError
......
......@@ -82,3 +82,21 @@ K_0_MAP = {
"DEFAULT": "scale_factor_at_projection_origin",
"transverse_mercator": "scale_factor_at_central_meridian",
}
METHOD_NAME_TO_CF_MAP = {"Transverse Mercator": "transverse_mercator"}
PARAM_TO_CF_MAP = {
"Latitude of natural origin": "latitude_of_projection_origin",
"Longitude of natural origin": "longitude_of_central_meridian",
"Latitude of false origin": "latitude_of_projection_origin",
"Longitude of false origin": "longitude_of_central_meridian",
"Scale factor at natural origin": "scale_factor_at_central_meridian",
"Easting at projection centre": "false_easting",
"Northing at projection centre": "false_northing",
"Easting at false origin": "fase_easting",
"Northing at false origin": "fase_northing",
"False easting": "false_easting",
"False northing": "false_northing",
}
......@@ -26,6 +26,7 @@ __all__ = [
"Ellipsoid",
"PrimeMeridian",
"is_wkt",
"is_proj",
]
import json
......@@ -36,7 +37,7 @@ from pyproj._crs import CoordinateOperation # noqa
from pyproj._crs import Datum # noqa
from pyproj._crs import Ellipsoid # noqa
from pyproj._crs import PrimeMeridian # noqa
from pyproj._crs import _CRS, is_wkt
from pyproj._crs import _CRS, is_proj, is_wkt
from pyproj.cf1x8 import (
GRID_MAPPING_NAME_MAP,
INVERSE_GRID_MAPPING_NAME_MAP,
......@@ -44,13 +45,15 @@ from pyproj.cf1x8 import (
K_0_MAP,
LON_0_MAP,
PROJ_PARAM_MAP,
PARAM_TO_CF_MAP,
METHOD_NAME_TO_CF_MAP,
)
from pyproj.compat import string_types
from pyproj.exceptions import CRSError
from pyproj.geod import Geod
def _from_dict(projparams):
def _prepare_from_dict(projparams):
# convert a dict to a proj string.
pjargs = []
for key, value in projparams.items():
......@@ -64,10 +67,10 @@ def _from_dict(projparams):
pass
else:
pjargs.append("+{key}={value}".format(key=key, value=value))
return _from_string(" ".join(pjargs))
return _prepare_from_string(" ".join(pjargs))
def _from_string(in_crs_string):
def _prepare_from_string(in_crs_string):
if not in_crs_string:
raise CRSError("CRS is empty or invalid: {!r}".format(in_crs_string))
elif "{" in in_crs_string:
......@@ -79,12 +82,12 @@ def _from_string(in_crs_string):
if not crs_dict:
raise CRSError("CRS is empty JSON")
return _from_dict(crs_dict)
elif not is_wkt(in_crs_string) and "=" in in_crs_string:
in_crs_string = re.sub(r"[\s+]?=[\s+]?", "=", in_crs_string)
return _prepare_from_dict(crs_dict)
elif is_proj(in_crs_string):
in_crs_string = re.sub(r"[\s+]?=[\s+]?", "=", in_crs_string.lstrip())
# make sure the projection starts with +proj or +init
starting_params = ("+init", "+proj", "init", "proj")
if not in_crs_string.lstrip().startswith(starting_params):
if not in_crs_string.startswith(starting_params):
kvpairs = []
first_item_inserted = False
for kvpair in in_crs_string.split():
......@@ -105,18 +108,21 @@ def _from_string(in_crs_string):
# look for EPSG, replace with epsg (EPSG only works
# on case-insensitive filesystems).
in_crs_string = in_crs_string.replace("+init=EPSG", "+init=epsg").strip()
# remove no_defs as it does nothing as of PROJ 6.0.0 and breaks
# initialization with +init=epsg:...
in_crs_string = re.sub(r"\s\+?no_defs([\w=]+)?", "", in_crs_string)
if in_crs_string.startswith(("+init", "init")):
warnings.warn(
"'+init=<authority>:<code>' syntax is deprecated."
" '<authority>:<code>' is the preferred initialization method.",
DeprecationWarning,
)
return in_crs_string
def _from_authority(auth_name, auth_code):
def _prepare_from_authority(auth_name, auth_code):
return "{}:{}".format(auth_name, auth_code)
def _from_epsg(auth_code):
return _from_authority("epsg", auth_code)
def _prepare_from_epsg(auth_code):
return _prepare_from_authority("epsg", auth_code)
class CRS(_CRS):
......@@ -281,15 +287,15 @@ class CRS(_CRS):
False
"""
if isinstance(projparams, string_types):
projstring = _from_string(projparams)
projstring = _prepare_from_string(projparams)
elif isinstance(projparams, dict):
projstring = _from_dict(projparams)
projstring = _prepare_from_dict(projparams)
elif kwargs:
projstring = _from_dict(kwargs)
projstring = _prepare_from_dict(kwargs)
elif isinstance(projparams, int):
projstring = _from_epsg(projparams)
projstring = _prepare_from_epsg(projparams)
elif isinstance(projparams, (list, tuple)) and len(projparams) == 2:
projstring = _from_authority(*projparams)
projstring = _prepare_from_authority(*projparams)
elif hasattr(projparams, "to_wkt"):
projstring = projparams.to_wkt()
else:
......@@ -312,7 +318,7 @@ class CRS(_CRS):
-------
CRS
"""
return cls(_from_authority(auth_name, code))
return cls(_prepare_from_authority(auth_name, code))
@classmethod
def from_epsg(cls, code):
......@@ -327,7 +333,7 @@ class CRS(_CRS):
-------
CRS
"""
return cls(_from_epsg(code))
return cls(_prepare_from_epsg(code))
@classmethod
def from_proj4(cls, in_proj_string):
......@@ -342,9 +348,9 @@ class CRS(_CRS):
-------
CRS
"""
if is_wkt(in_proj_string) or "=" not in in_proj_string:
if not is_proj(in_proj_string):
raise CRSError("Invalid PROJ string: {}".format(in_proj_string))
return cls(_from_string(in_proj_string))
return cls(_prepare_from_string(in_proj_string))
@classmethod
def from_wkt(cls, in_wkt_string):
......@@ -361,7 +367,7 @@ class CRS(_CRS):
"""
if not is_wkt(in_wkt_string):
raise CRSError("Invalid WKT string: {}".format(in_wkt_string))
return cls(_from_string(in_wkt_string))
return cls(_prepare_from_string(in_wkt_string))
@classmethod
def from_string(cls, in_crs_string):
......@@ -382,7 +388,7 @@ class CRS(_CRS):
-------
CRS
"""
return cls(_from_string(in_crs_string))
return cls(_prepare_from_string(in_crs_string))
def to_string(self):
"""Convert the CRS to a string.
......@@ -457,7 +463,7 @@ class CRS(_CRS):
-------
CRS
"""
return cls(_from_dict(proj_dict))
return cls(_prepare_from_dict(proj_dict))
def to_dict(self):
"""
......@@ -491,12 +497,13 @@ class CRS(_CRS):
val = [float(sval.strip()) for sval in val_split]
return val
proj_string = self.to_proj4()
if proj_string is None:
return {}
items = map(
lambda kv: len(kv) == 2 and (kv[0], parse(kv[1])) or (kv[0], None),
(
part.lstrip("+").split("=", 1)
for part in self.to_proj4().strip().split()
),
(part.lstrip("+").split("=", 1) for part in proj_string.strip().split()),
)
return {key: value for key, value in items if value is not False}
......@@ -541,6 +548,18 @@ class CRS(_CRS):
if proj_dict.pop("o_proj") not in lonlat_possible_names:
grid_mapping_name = "unknown"
# derive parameters from the coordinate operation
if (
grid_mapping_name == "unknown"
and self.coordinate_operation
and self.coordinate_operation.method_name in METHOD_NAME_TO_CF_MAP
):
grid_mapping_name = METHOD_NAME_TO_CF_MAP[
self.coordinate_operation.method_name
]
for param in self.coordinate_operation.params:
cf_dict[PARAM_TO_CF_MAP[param.name]] = param.value
cf_dict["grid_mapping_name"] = grid_mapping_name
# get best match for lon_0 value for projetion name
......
......@@ -129,14 +129,14 @@ class Proj(_proj.Proj):
>>> x,y = p2(-120.108, 34.36116666)
>>> 'x=%9.3f y=%11.3f' % (x,y)
'x=765975.641 y=3805993.134'
>>> p = Proj(init="epsg:32667", preserve_units=False)
>>> p = Proj("epsg:32667", preserve_units=False)
>>> 'x=%12.3f y=%12.3f (meters)' % p(-114.057222, 51.045)
'x=-1783506.250 y= 6193827.033 (meters)'
>>> p = Proj("+init=epsg:32667")
>>> p = Proj("epsg:32667")
>>> 'x=%12.3f y=%12.3f (feet)' % p(-114.057222, 51.045)
'x=-5851386.754 y=20320914.191 (feet)'
>>> # test data with radian inputs
>>> p1 = Proj(init="epsg:4214")
>>> p1 = Proj("epsg:4214")
>>> x1, y1 = p1(116.366, 39.867)
>>> '{:.3f} {:.3f}'.format(x1, y1)
'2.031 0.696'
......@@ -193,7 +193,7 @@ class Proj(_proj.Proj):
def definition_string(self):
"""Returns formal definition string for projection
>>> Proj('+init=epsg:4326').definition_string()
>>> Proj("epsg:4326").definition_string()
'proj=longlat datum=WGS84 no_defs ellps=WGS84 towgs84=0,0,0'
>>>
"""
......
......@@ -229,7 +229,8 @@ class Transformer(object):
'120.321 0.057'
>>> transproj = Transformer.from_crs(
... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'},
... '+init=EPSG:4326'
... "EPSG:4326",
... always_xy=True,
... )
>>> xpj, ypj, zpj = transproj.transform(
... -2704026.010,
......@@ -240,8 +241,9 @@ class Transformer(object):
>>> "%.3f %.3f %.3f" % (xpj, ypj, zpj)
'-2.137 0.661 -20.531'
>>> transprojr = Transformer.from_crs(
... '+init=EPSG:4326',
... "EPSG:4326",
... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'},
... always_xy=True,
... )
>>> xpjr, ypjr, zpjr = transprojr.transform(xpj, ypj, zpj, radians=True)
>>> "%.3f %.3f %.3f" % (xpjr, ypjr, zpjr)
......@@ -337,7 +339,8 @@ class Transformer(object):
'120.321 0.057'
>>> transproj = Transformer.from_crs(
... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'},
... '+init=EPSG:4326',
... "EPSG:4326",
... always_xy=True,
... )
>>> for pt in transproj.itransform(
... [(-2704026.010, -4253051.810, 3895878.820)],
......@@ -345,9 +348,10 @@ class Transformer(object):
... ):
... '{:.3f} {:.3f} {:.3f}'.format(*pt)
'-2.137 0.661 -20.531'
>>> transprojr = Transformer.from_proj(
... '+init=EPSG:4326',
>>> transprojr = Transformer.from_crs(
... "EPSG:4326",
... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'},
... always_xy=True,
... )
>>> for pt in transprojr.itransform(
... [(-2.137, 0.661, -20.531)],
......@@ -356,8 +360,9 @@ class Transformer(object):
... '{:.3f} {:.3f} {:.3f}'.format(*pt)
'-2704214.394 -4254414.478 3894270.731'
>>> transproj_eq = Transformer.from_proj(
... '+init=EPSG:4326',
... 'EPSG:4326',
... '+proj=longlat +datum=WGS84 +no_defs +type=crs',
... always_xy=True,
... skip_equivalent=True
... )
>>> for pt in transproj_eq.itransform([(-2.137, 0.661)]):
......@@ -494,9 +499,9 @@ def transform(
>>> from pyproj import Proj, transform
>>> # projection 1: UTM zone 15, grs80 ellipse, NAD83 datum
>>> # (defined by epsg code 26915)
>>> p1 = Proj(init='epsg:26915', preserve_units=False)
>>> p1 = Proj('epsg:26915', preserve_units=False)
>>> # projection 2: UTM zone 15, clrk66 ellipse, NAD27 datum
>>> p2 = Proj(init='epsg:26715', preserve_units=False)
>>> p2 = Proj('epsg:26715', preserve_units=False)
>>> # find x,y of Jefferson City, MO.
>>> x1, y1 = p1(-92.199881,38.56694)
>>> # transform this point to projection 2 coordinates.
......@@ -595,13 +600,13 @@ def itransform(
>>> from pyproj import Proj, itransform
>>> # projection 1: WGS84
>>> # (defined by epsg code 4326)
>>> p1 = Proj(init='epsg:4326', preserve_units=False)
>>> p1 = Proj('epsg:4326', preserve_units=False)
>>> # projection 2: GGRS87 / Greek Grid
>>> p2 = Proj(init='epsg:2100', preserve_units=False)
>>> p2 = Proj('epsg:2100', preserve_units=False)
>>> # Three points with coordinates lon, lat in p1
>>> points = [(22.95, 40.63), (22.81, 40.53), (23.51, 40.86)]
>>> # transform this point to projection 2 coordinates.
>>> for pt in itransform(p1,p2,points): '%6.3f %7.3f' % pt
>>> for pt in itransform(p1,p2,points, always_xy=True): '%6.3f %7.3f' % pt
'411050.470 4497928.574'
'399060.236 4486978.710'
'458553.243 4523045.485'
......
......@@ -3,7 +3,7 @@ import array
import numpy
from numpy.testing import assert_allclose
from pyproj import Proj
from pyproj import Proj, proj_version_str
try:
from time import perf_counter
......@@ -26,7 +26,7 @@ def test_awips221():
# awips221 = Proj(params)
# or keyword args
awips221 = Proj(proj="lcc", R=6371200, lat_1=50, lat_2=50, lon_0=-107)
print("proj4 library version = ", awips221.proj_version)
print("proj4 library version = ", proj_version_str)
# AWIPS grid 221 parameters
# (from http://www.nco.ncep.noaa.gov/pmb/docs/on388/tableb.html)
llcrnrx, llcrnry = awips221(-145.5, 1.0)
......
......@@ -56,6 +56,7 @@ def test_from_string():
assert wgs84_crs.to_proj4() == "+proj=longlat +datum=WGS84 +no_defs +type=crs"
# Make sure this doesn't get handled using the from_epsg()
# even though 'epsg' is in the string
with pytest.warns(DeprecationWarning):
epsg_init_crs = CRS.from_string("+init=epsg:26911 +units=m +no_defs=True")
assert (
epsg_init_crs.to_proj4()
......@@ -84,8 +85,8 @@ def test_bare_parameters():
def test_is_geographic():
assert CRS({"init": "EPSG:4326"}).is_geographic is True
assert CRS({"init": "EPSG:3857"}).is_geographic is False
assert CRS("EPSG:4326").is_geographic is True
assert CRS("EPSG:3857").is_geographic is False
wgs84_crs = CRS.from_string("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
assert wgs84_crs.is_geographic is True
......@@ -101,7 +102,7 @@ def test_is_geographic():
def test_is_projected():
assert CRS({"init": "EPSG:3857"}).is_projected is True
assert CRS("EPSG:3857").is_projected is True
lcc_crs = CRS.from_string(
"+lon_0=-95 +ellps=GRS80 +y_0=0 +no_defs=True +proj=lcc +x_0=0 "
......@@ -114,8 +115,8 @@ def test_is_projected():
def test_is_same_crs():
crs1 = CRS({"init": "EPSG:4326"})
crs2 = CRS({"init": "EPSG:3857"})
crs1 = CRS("urn:ogc:def:crs:OGC::CRS84")
crs2 = CRS("EPSG:3857")
assert crs1 == crs1
assert crs1 != crs2
......@@ -137,13 +138,12 @@ def test_is_same_crs():
def test_to_proj4():
assert (
CRS({"init": "EPSG:4326"}).to_proj4(4)
== "+proj=longlat +datum=WGS84 +no_defs +type=crs"
CRS("EPSG:4326").to_proj4(4) == "+proj=longlat +datum=WGS84 +no_defs +type=crs"
)
def test_is_valid():
with pytest.warns(UserWarning):
with pytest.warns(DeprecationWarning):
assert CRS(init="EPSG:4326").is_valid
......@@ -157,6 +157,7 @@ def test_empty_json():
def test_has_wkt_property():
with pytest.warns(DeprecationWarning):
assert (
CRS({"init": "EPSG:4326"})
.to_wkt("WKT1_GDAL")
......@@ -171,6 +172,7 @@ def test_to_wkt_pretty():
def test_repr():
with pytest.warns(DeprecationWarning):
assert repr(CRS({"init": "EPSG:4326"})) == (
"<Geographic 2D CRS: +init=epsg:4326 +type=crs>\n"
"Name: WGS 84\n"
......@@ -187,8 +189,10 @@ def test_repr():
def test_repr__long():
with pytest.warns(DeprecationWarning):
assert repr(CRS(CRS({"init": "EPSG:4326"}).to_wkt())) == (
'<Geographic 2D CRS: GEOGCRS["WGS 84",DATUM["World Geodetic System 1984 ...>\n'
'<Geographic 2D CRS: GEOGCRS["WGS 84",'
'DATUM["World Geodetic System 1984 ...>\n'
"Name: WGS 84\n"
"Axis Info [ellipsoidal]:\n"
"- lon[east]: Longitude (degree)\n"
......@@ -263,10 +267,12 @@ def test_repr_compound():
def test_dunder_str():
with pytest.warns(DeprecationWarning):
assert str(CRS({"init": "EPSG:4326"})) == CRS({"init": "EPSG:4326"}).srs
def test_epsg():
with pytest.warns(DeprecationWarning):
assert CRS({"init": "EPSG:4326"}).to_epsg(20) == 4326
assert CRS({"init": "EPSG:4326"}).to_epsg() is None
assert CRS.from_user_input(4326).to_epsg() == 4326
......@@ -316,6 +322,7 @@ def test_epsg__no_code_available():
def test_crs_OSR_equivalence():
crs1 = CRS.from_string("+proj=longlat +datum=WGS84 +no_defs")
crs2 = CRS.from_string("+proj=latlong +datum=WGS84 +no_defs")
with pytest.warns(DeprecationWarning):
crs3 = CRS({"init": "EPSG:4326"})
assert crs1 == crs2
# these are not equivalent in proj.4 now as one uses degrees and the othe radians
......@@ -613,7 +620,8 @@ def test_coordinate_operation_towgs84_three():
def test_coordinate_operation_towgs84_seven():
crs = CRS(
init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
"+proj=tmerc +lat_0=0 +lon_0=15 +k=0.9996 +x_0=2520000 +y_0=0 "
"+ellps=intl +towgs84=-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
)
assert crs.coordinate_operation.towgs84 == [
-122.74,
......@@ -627,7 +635,7 @@ def test_coordinate_operation_towgs84_seven():
def test_coordinate_operation_towgs84_missing():
crs = CRS(init="epsg:3004")
crs = CRS("epsg:3004")
assert crs.coordinate_operation.towgs84 == []
......@@ -717,7 +725,7 @@ def test_geodetic_crs():
def test_deprecated_to_geodetic():
cc = CRS("epsg:3004")
with pytest.warns(UserWarning):
with pytest.warns(DeprecationWarning):
assert cc.to_geodetic().to_epsg() == 4265
......@@ -791,23 +799,10 @@ def test_to_string__auth():
def test_srs__no_plus():
assert (
CRS("proj=longlat datum=WGS84 no_defs").srs
== "proj=longlat datum=WGS84 type=crs"
== "proj=longlat datum=WGS84 no_defs type=crs"
)
@pytest.mark.parametrize(
"init_string, expected_srs",
[
("+init=epsg:4326 +no_defs=True", "+init=epsg:4326 +type=crs"),
("init=epsg:4326 no_defs=True", "init=epsg:4326 type=crs"),
("+init=epsg:4326 +no_defs", "+init=epsg:4326 +type=crs"),
("init=epsg:4326 no_defs", "init=epsg:4326 type=crs"),
],
)
def test_removing_nodefs(init_string, expected_srs):
assert CRS(init_string).srs == expected_srs
def test_equals_different_type():
assert CRS("epsg:4326") != ""
......@@ -819,12 +814,14 @@ def test_is_exact_same_different_type():
def test_compare_crs_non_crs():
assert CRS.from_epsg(4326) != 4.2
assert CRS.from_epsg(4326) == 4326
with pytest.warns(DeprecationWarning):
assert CRS.from_dict({"init": "epsg:4326"}) == {"init": "epsg:4326"}
assert CRS.from_dict({"init": "epsg:4326"}) != "epsg:4326"
assert CRS("epsg:4326") == CustomCRS()
def test_is_geocentric__bound():
with pytest.warns(DeprecationWarning):
ccs = CRS("+init=epsg:4328 +towgs84=0,0,0")
assert ccs.is_geocentric
......@@ -852,6 +849,7 @@ def test_is_engineering():
def test_source_crs__bound():
with pytest.warns(DeprecationWarning):
assert CRS("+init=epsg:4328 +towgs84=0,0,0").source_crs.name == "unknown"
......@@ -860,6 +858,7 @@ def test_source_crs__missing():
def test_target_crs__bound():
with pytest.warns(DeprecationWarning):
assert CRS("+init=epsg:4328 +towgs84=0,0,0").target_crs.name == "WGS 84"
......@@ -875,3 +874,19 @@ def test_whitepace_between_equals():
"+proj=lcc +lat_1=30.0 +lat_2=35.0 +lat_0=30.0 "
"+lon_0=87.0 +x_0=0 +y_0=0 +type=crs"
)
def test_to_dict_no_proj4():
crs = CRS(
{
"a": 6371229.0,
"b": 6371229.0,
"lon_0": -10.0,
"o_lat_p": 30.0,
"o_lon_p": 0.0,
"o_proj": "longlat",
"proj": "ob_tran",
}
)
assert crs.to_proj4() is None
assert crs.to_dict() == {}
......@@ -7,7 +7,15 @@ from pyproj.exceptions import CRSError
def test_to_cf_transverse_mercator():
crs = CRS(
init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
proj="tmerc",
lat_0=0,
lon_0=15,
k=0.9996,
x_0=2520000,
y_0=0,
ellps="intl",
units="m",
towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62",
)
with pytest.warns(UserWarning):
cf_dict = crs.to_cf(errcheck=True)
......@@ -102,12 +110,35 @@ def test_cf_from_utm():
assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
assert cf_dict == {
"projected_crs_name": "WGS 84 / UTM zone 15N",
"grid_mapping_name": "unknown",
"latitude_of_projection_origin": 0.0,
"longitude_of_central_meridian": -93.0,
"scale_factor_at_central_meridian": 0.9996,
"false_easting": 500000.0,
"false_northing": 0.0,
"grid_mapping_name": "transverse_mercator",
"horizontal_datum_name": "WGS84",
"unit": "m",
}
def test_cf_from_utm__nad83():
crs = CRS("epsg:26917")
with pytest.warns(UserWarning):
cf_dict = crs.to_cf(errcheck=True)
assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
assert cf_dict == {
"projected_crs_name": "NAD83 / UTM zone 17N",
"latitude_of_projection_origin": 0.0,
"longitude_of_central_meridian": -81.0,
"scale_factor_at_central_meridian": 0.9996,
"false_easting": 500000.0,
"false_northing": 0.0,
"grid_mapping_name": "transverse_mercator",
"horizontal_datum_name": "NAD83",
"unit": "m",
}
def test_cf_rotated_latlon():
crs = CRS.from_cf(
dict(
......
import warnings
from numpy.testing import assert_almost_equal
from pyproj import Proj, transform
from pyproj import Proj, proj_version_str, transform
# illustrates the use of the transform function to
# perform coordinate transformations with datum shifts.
......@@ -28,10 +30,12 @@ WGS84_lon = 13.759554722 # Degrees
UTM_z = WGS84_z = 52.8 # Ellipsoidical height in meters
WGS84_PROJ = Proj(proj="latlong", datum="WGS84")
UTM_33_PROJ = Proj(proj="utm", zone="33")
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
GAUSSSB_PROJ = Proj(
init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
)
print("proj4 library version = ", WGS84_PROJ.proj_version)
print("proj4 library version = ", proj_version_str)
def test_shift_wgs84_to_utm33():
......