| """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])
|
|
|
|
|
| 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__)
|
|
|
|
|
| try:
|
| import certifi
|
| check("import certifi", True, certifi.where()[:60])
|
| except Exception as e:
|
| check("import certifi", False, repr(e))
|
|
|
|
|
| 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))
|
|
|
|
|
| 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))
|
|
|
|
|
| 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))
|
|
|
|
|
| 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))
|
|
|
|
|
| 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))
|
|
|
|
|
| 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))
|
|
|
|
|
| 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))
|
|
|
|
|
| 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)
|
|
|