|
1 | 1 | import numpy
|
2 | 2 | import pytest
|
3 |
| -from numpy.testing import assert_allclose |
| 3 | +from numpy.testing import assert_allclose, assert_almost_equal |
4 | 4 |
|
5 | 5 | from pyproj import Proj, __proj_version__, transform
|
| 6 | +from test.conftest import PROJ_GTE_92 |
6 | 7 |
|
7 | 8 |
|
8 | 9 | def test_transform():
|
@@ -49,3 +50,78 @@ def test_transform():
|
49 | 50 | assert_allclose(numpy.maximum.reduce(numpy.ravel(x3 - x1)), 0, atol=1e-4)
|
50 | 51 | assert_allclose(numpy.minimum.reduce(numpy.ravel(y3 - y1)), 0, atol=1e-4)
|
51 | 52 | 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