Skip to content

Commit 59d16f5

Browse files
authored
TST: move tests using NADCON grids to test_transform (#1211)
1 parent c4cb8f0 commit 59d16f5

File tree

3 files changed

+78
-34
lines changed

3 files changed

+78
-34
lines changed

pyproj/transformer.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,39 +1205,6 @@ def transform( # pylint: disable=invalid-name
12051205
geocentric coordinates, values of x and y are given in meters.
12061206
z is always meters.
12071207
1208-
Example usage:
1209-
1210-
>>> from pyproj import Proj, transform
1211-
>>> # projection 1: UTM zone 15, grs80 ellipse, NAD83 datum
1212-
>>> # (defined by epsg code 26915)
1213-
>>> p1 = Proj('epsg:26915', preserve_units=False)
1214-
>>> # projection 2: UTM zone 15, clrk66 ellipse, NAD27 datum
1215-
>>> p2 = Proj('epsg:26715', preserve_units=False)
1216-
>>> # find x,y of Jefferson City, MO.
1217-
>>> x1, y1 = p1(-92.199881,38.56694)
1218-
>>> # transform this point to projection 2 coordinates.
1219-
>>> x2, y2 = transform(p1,p2,x1,y1)
1220-
>>> '%9.3f %11.3f' % (x1,y1)
1221-
'569704.566 4269024.671'
1222-
>>> '%9.3f %11.3f' % (x2,y2)
1223-
'569722.342 4268814.028'
1224-
>>> '%8.3f %5.3f' % p2(x2,y2,inverse=True)
1225-
' -92.200 38.567'
1226-
>>> # process 3 points at a time in a tuple
1227-
>>> lats = (38.83,39.32,38.75) # Columbia, KC and StL Missouri
1228-
>>> lons = (-92.22,-94.72,-90.37)
1229-
>>> x1, y1 = p1(lons,lats)
1230-
>>> x2, y2 = transform(p1,p2,x1,y1)
1231-
>>> xy = x1+y1
1232-
>>> '%9.3f %9.3f %9.3f %11.3f %11.3f %11.3f' % xy
1233-
'567703.344 351730.944 728553.093 4298200.739 4353698.725 4292319.005'
1234-
>>> xy = x2+y2
1235-
>>> '%9.3f %9.3f %9.3f %11.3f %11.3f %11.3f' % xy
1236-
'567721.149 351747.558 728569.133 4297989.112 4353489.645 4292106.305'
1237-
>>> lons, lats = p2(x2,y2,inverse=True)
1238-
>>> xy = lons+lats
1239-
>>> '%8.3f %8.3f %8.3f %5.3f %5.3f %5.3f' % xy
1240-
' -92.220 -94.720 -90.370 38.830 39.320 38.750'
12411208
"""
12421209
warnings.warn(
12431210
(

test/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
PROJ_GTE_901 = PROJ_LOOSE_VERSION >= version.parse("9.0.1")
1515
PROJ_GTE_91 = PROJ_LOOSE_VERSION >= version.parse("9.1")
1616
PROJ_GTE_911 = PROJ_LOOSE_VERSION >= version.parse("9.1.1")
17+
PROJ_GTE_92 = PROJ_LOOSE_VERSION >= version.parse("9.2.0")
1718

1819

1920
def unset_data_dir():

test/test_transform.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import numpy
22
import pytest
3-
from numpy.testing import assert_allclose
3+
from numpy.testing import assert_allclose, assert_almost_equal
44

55
from pyproj import Proj, __proj_version__, transform
6+
from test.conftest import PROJ_GTE_92
67

78

89
def test_transform():
@@ -49,3 +50,78 @@ def test_transform():
4950
assert_allclose(numpy.maximum.reduce(numpy.ravel(x3 - x1)), 0, atol=1e-4)
5051
assert_allclose(numpy.minimum.reduce(numpy.ravel(y3 - y1)), 0, atol=1e-4)
5152
assert_allclose(numpy.maximum.reduce(numpy.ravel(y3 - y1)), 0, atol=1e-4)
53+
54+
55+
def test_transform_single_point_nad83_to_nad27():
56+
# projection 1: UTM zone 15, grs80 ellipse, NAD83 datum
57+
# (defined by epsg code 26915)
58+
p1 = Proj("epsg:26915", preserve_units=False)
59+
# projection 2: UTM zone 15, clrk66 ellipse, NAD27 datum
60+
p2 = Proj("epsg:26715", preserve_units=False)
61+
# find x,y of Jefferson City, MO.
62+
x1, y1 = p1(-92.199881, 38.56694)
63+
# transform this point to projection 2 coordinates.
64+
x2, y2 = transform(p1, p2, x1, y1)
65+
assert_almost_equal(
66+
(x1, y1),
67+
(569704.566, 4269024.671),
68+
decimal=3,
69+
)
70+
assert_almost_equal(
71+
(x2, y2),
72+
(569722.394, 4268814.27) if PROJ_GTE_92 else (569722.342, 4268814.028),
73+
decimal=3,
74+
)
75+
assert_almost_equal(
76+
p2(x2, y2, inverse=True),
77+
(-92.200, 38.567),
78+
decimal=3,
79+
)
80+
81+
82+
def test_transform_tuple_nad83_to_nad27():
83+
# projection 1: UTM zone 15, grs80 ellipse, NAD83 datum
84+
# (defined by epsg code 26915)
85+
p1 = Proj("epsg:26915", preserve_units=False)
86+
# projection 2: UTM zone 15, clrk66 ellipse, NAD27 datum
87+
p2 = Proj("epsg:26715", preserve_units=False)
88+
# process 3 points at a time in a tuple
89+
lats = (38.83, 39.32, 38.75) # Columbia, KC and StL Missouri
90+
lons = (-92.22, -94.72, -90.37)
91+
x1, y1 = p1(lons, lats)
92+
x2, y2 = transform(p1, p2, x1, y1)
93+
assert_almost_equal(
94+
x1,
95+
(567703.344, 351730.944, 728553.093),
96+
decimal=3,
97+
)
98+
assert_almost_equal(
99+
y1,
100+
(4298200.739, 4353698.725, 4292319.005),
101+
decimal=3,
102+
)
103+
assert_almost_equal(
104+
x2,
105+
(567721.401, 351747.526, 728569.212)
106+
if PROJ_GTE_92
107+
else (567721.149, 351747.558, 728569.133),
108+
decimal=3,
109+
)
110+
assert_almost_equal(
111+
y2,
112+
(4297989.733, 4353489.752, 4292106.351)
113+
if PROJ_GTE_92
114+
else (4297989.112, 4353489.645, 4292106.305),
115+
decimal=3,
116+
)
117+
lons2, lats2 = p2(x2, y2, inverse=True)
118+
assert_almost_equal(
119+
lons2,
120+
(-92.220, -94.720, -90.370),
121+
decimal=3,
122+
)
123+
assert_almost_equal(
124+
lats2,
125+
(38.830, 39.320, 38.750),
126+
decimal=3,
127+
)

0 commit comments

Comments
 (0)