Skip to content

Commit

Permalink
TST: move tests using NADCON grids to test_transform (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Dec 21, 2022
1 parent c4cb8f0 commit 59d16f5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 34 deletions.
33 changes: 0 additions & 33 deletions pyproj/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,39 +1205,6 @@ def transform( # pylint: disable=invalid-name
geocentric coordinates, values of x and y are given in meters.
z is always meters.
Example usage:
>>> from pyproj import Proj, transform
>>> # projection 1: UTM zone 15, grs80 ellipse, NAD83 datum
>>> # (defined by epsg code 26915)
>>> p1 = Proj('epsg:26915', preserve_units=False)
>>> # projection 2: UTM zone 15, clrk66 ellipse, NAD27 datum
>>> 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.
>>> x2, y2 = transform(p1,p2,x1,y1)
>>> '%9.3f %11.3f' % (x1,y1)
'569704.566 4269024.671'
>>> '%9.3f %11.3f' % (x2,y2)
'569722.342 4268814.028'
>>> '%8.3f %5.3f' % p2(x2,y2,inverse=True)
' -92.200 38.567'
>>> # process 3 points at a time in a tuple
>>> lats = (38.83,39.32,38.75) # Columbia, KC and StL Missouri
>>> lons = (-92.22,-94.72,-90.37)
>>> x1, y1 = p1(lons,lats)
>>> x2, y2 = transform(p1,p2,x1,y1)
>>> xy = x1+y1
>>> '%9.3f %9.3f %9.3f %11.3f %11.3f %11.3f' % xy
'567703.344 351730.944 728553.093 4298200.739 4353698.725 4292319.005'
>>> xy = x2+y2
>>> '%9.3f %9.3f %9.3f %11.3f %11.3f %11.3f' % xy
'567721.149 351747.558 728569.133 4297989.112 4353489.645 4292106.305'
>>> lons, lats = p2(x2,y2,inverse=True)
>>> xy = lons+lats
>>> '%8.3f %8.3f %8.3f %5.3f %5.3f %5.3f' % xy
' -92.220 -94.720 -90.370 38.830 39.320 38.750'
"""
warnings.warn(
(
Expand Down
1 change: 1 addition & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
PROJ_GTE_901 = PROJ_LOOSE_VERSION >= version.parse("9.0.1")
PROJ_GTE_91 = PROJ_LOOSE_VERSION >= version.parse("9.1")
PROJ_GTE_911 = PROJ_LOOSE_VERSION >= version.parse("9.1.1")
PROJ_GTE_92 = PROJ_LOOSE_VERSION >= version.parse("9.2.0")


def unset_data_dir():
Expand Down
78 changes: 77 additions & 1 deletion test/test_transform.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy
import pytest
from numpy.testing import assert_allclose
from numpy.testing import assert_allclose, assert_almost_equal

from pyproj import Proj, __proj_version__, transform
from test.conftest import PROJ_GTE_92


def test_transform():
Expand Down Expand Up @@ -49,3 +50,78 @@ def test_transform():
assert_allclose(numpy.maximum.reduce(numpy.ravel(x3 - x1)), 0, atol=1e-4)
assert_allclose(numpy.minimum.reduce(numpy.ravel(y3 - y1)), 0, atol=1e-4)
assert_allclose(numpy.maximum.reduce(numpy.ravel(y3 - y1)), 0, atol=1e-4)


def test_transform_single_point_nad83_to_nad27():
# projection 1: UTM zone 15, grs80 ellipse, NAD83 datum
# (defined by epsg code 26915)
p1 = Proj("epsg:26915", preserve_units=False)
# projection 2: UTM zone 15, clrk66 ellipse, NAD27 datum
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.
x2, y2 = transform(p1, p2, x1, y1)
assert_almost_equal(
(x1, y1),
(569704.566, 4269024.671),
decimal=3,
)
assert_almost_equal(
(x2, y2),
(569722.394, 4268814.27) if PROJ_GTE_92 else (569722.342, 4268814.028),
decimal=3,
)
assert_almost_equal(
p2(x2, y2, inverse=True),
(-92.200, 38.567),
decimal=3,
)


def test_transform_tuple_nad83_to_nad27():
# projection 1: UTM zone 15, grs80 ellipse, NAD83 datum
# (defined by epsg code 26915)
p1 = Proj("epsg:26915", preserve_units=False)
# projection 2: UTM zone 15, clrk66 ellipse, NAD27 datum
p2 = Proj("epsg:26715", preserve_units=False)
# process 3 points at a time in a tuple
lats = (38.83, 39.32, 38.75) # Columbia, KC and StL Missouri
lons = (-92.22, -94.72, -90.37)
x1, y1 = p1(lons, lats)
x2, y2 = transform(p1, p2, x1, y1)
assert_almost_equal(
x1,
(567703.344, 351730.944, 728553.093),
decimal=3,
)
assert_almost_equal(
y1,
(4298200.739, 4353698.725, 4292319.005),
decimal=3,
)
assert_almost_equal(
x2,
(567721.401, 351747.526, 728569.212)
if PROJ_GTE_92
else (567721.149, 351747.558, 728569.133),
decimal=3,
)
assert_almost_equal(
y2,
(4297989.733, 4353489.752, 4292106.351)
if PROJ_GTE_92
else (4297989.112, 4353489.645, 4292106.305),
decimal=3,
)
lons2, lats2 = p2(x2, y2, inverse=True)
assert_almost_equal(
lons2,
(-92.220, -94.720, -90.370),
decimal=3,
)
assert_almost_equal(
lats2,
(38.830, 39.320, 38.750),
decimal=3,
)

0 comments on commit 59d16f5

Please sign in to comment.