File size: 4,438 Bytes
44ac226 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | """Test_Pyproj.py - device test for pyproj 3.8.0 Android wheels.
Runs on-device via PipManager Scripts folder (needs PROJ native libs from
this wheel; needs `certifi` installed from its own package).
Exit-code contract: exit 0 iff every check PASSes, else exit 1.
Each check prints [PASS] / [FAIL] with the measured values.
Generated by RIMI
"""
import os
import sys
PASS = 0
FAIL = 0
def check(name, cond, detail=""):
global PASS, FAIL
if cond:
PASS += 1
print("[PASS] %s %s" % (name, detail))
else:
FAIL += 1
print("[FAIL] %s %s" % (name, detail))
def approx(a, b, tol):
return abs(a - b) <= tol
print("pyproj device test - python %s" % sys.version.split()[0])
# 1. import + version
try:
import pyproj
from pyproj import CRS, Geod, Transformer
from pyproj import datadir, proj_version_str
check("import pyproj", True, "version=%s" % pyproj.__version__)
except Exception as e:
check("import pyproj", False, repr(e))
print("RESULT: %d PASS, %d FAIL" % (PASS, FAIL))
sys.exit(1)
check("pyproj version 3.8.0", pyproj.__version__ == "3.8.0",
"got=%s" % pyproj.__version__)
# 2. runtime dep present
try:
import certifi
check("import certifi", True, certifi.where()[:60])
except Exception as e:
check("import certifi", False, repr(e))
# 3. PROJ version wired to our bundled 9.8.1
try:
check("PROJ version 9.8.1", proj_version_str == "9.8.1",
"got=%s" % proj_version_str)
except Exception as e:
check("PROJ version 9.8.1", False, repr(e))
# 4. datum DB vendored (internal proj_dir wins by default)
try:
ddir = datadir.get_data_dir()
db = os.path.join(ddir, "proj.db")
check("datum proj.db vendored",
os.path.isfile(db) and os.path.getsize(db) > 1000000,
"dir=%s size=%d" % (ddir, os.path.getsize(db) if os.path.isfile(db) else -1))
except Exception as e:
check("datum proj.db vendored", False, repr(e))
# 5. CRS object (needs proj.db)
try:
crs = CRS.from_epsg(4326)
check("CRS EPSG:4326", crs.to_epsg() == 4326 and "WGS" in crs.name,
"name=%s" % crs.name)
except Exception as e:
check("CRS EPSG:4326", False, repr(e))
# 6. CRS transform known answer: WGS84 lon/lat -> Web-Mercator (Copenhagen)
try:
t = Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True)
x, y = t.transform(12.0, 55.0)
ok = approx(x, 1335833.8895192828, 0.01) and approx(y, 7361866.113051185, 0.01)
check("transform 4326->3857", ok, "x=%.4f y=%.4f" % (x, y))
except Exception as e:
check("transform 4326->3857", False, repr(e))
# 7. transform origin + roundtrip
try:
t = Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True)
x0, y0 = t.transform(0.0, 0.0)
ti = Transformer.from_crs("EPSG:3857", "EPSG:4326", always_xy=True)
lon, lat = ti.transform(x0, y0)
check("transform origin+roundtrip",
approx(x0, 0.0, 1e-9) and approx(y0, 0.0, 1e-9)
and approx(lon, 0.0, 1e-9) and approx(lat, 0.0, 1e-9),
"x=%.3e y=%.3e" % (x0, y0))
except Exception as e:
check("transform origin+roundtrip", False, repr(e))
# 8. geodesic inverse known answer: 1 deg longitude on WGS84 equator
try:
g = Geod(ellps="WGS84")
az12, az21, dist = g.inv(0.0, 0.0, 1.0, 0.0)
ok = (approx(az12, 90.0, 1e-9) and approx(az21, -90.0, 1e-9)
and approx(dist, 111319.49079327357, 1e-6))
check("geodesic inverse equator", ok,
"az12=%.6f az21=%.6f dist=%.6f" % (az12, az21, dist))
except Exception as e:
check("geodesic inverse equator", False, repr(e))
# 9. geodesic forward consistency
try:
g = Geod(ellps="WGS84")
lon2, lat2, back = g.fwd(0.0, 0.0, 90.0, 111319.49079327357)
ok = approx(lon2, 1.0, 1e-9) and approx(lat2, 0.0, 1e-9)
check("geodesic forward", ok,
"lon=%.9f lat=%.9f backaz=%.6f" % (lon2, lat2, back))
except Exception as e:
check("geodesic forward", False, repr(e))
# 10. list API (needs proj.db tables)
try:
from pyproj import get_ellps_map
m = get_ellps_map()
check("get_ellps_map", isinstance(m, dict) and "WGS84" in m,
"entries=%d" % len(m))
except Exception as e:
check("get_ellps_map", False, repr(e))
print("RESULT: %d PASS, %d FAIL" % (PASS, FAIL))
sys.exit(0 if FAIL == 0 else 1)
|