Keep track of points outside a projection’s domain#
Transform a batch into Web Mercator coordinates while keeping the identity and outcome of every point. You’ll get one position to plot and a record of why each of the other two was rejected.
Keep an ID beside each input point#
In a CUDA-enabled cuGeo Proj Python environment, create these arrays on the default CuPy stream. The IDs stay on the host in the same order as the WGS 84 longitudes and latitudes, which are in degrees.
import numpy as np
import cupy as cp
from cugeo.proj import Transformer, RowStatus, RowFailure
ids = np.array(['A', 'B', 'C'])
lon = cp.array([3.0, 1.0, 1.0], dtype=cp.float64)
lat = cp.array([50.0, 89.5, 90.1], dtype=cp.float64)
Request an outcome for every point#
Request both status and failure arrays. Status identifies coordinates to keep, and the optional failure value identifies the check that failed. Once the call returns, copy all four arrays to the host for reporting.
t = Transformer.from_crs(4326, 3857, always_xy=True)
x, y, status, failure = t.transform_device(
lon, lat, return_status=True, return_failures=True
)
x, y, status, failure = map(cp.asnumpy, (x, y, status, failure))
Print the point to plot and retain the other outcomes#
Use RowStatus.OK to select usable positions. Print those coordinates in metres, and print the status and failure names for the remaining IDs.
ok = status == RowStatus.OK
for i in np.flatnonzero(ok):
print(ids[i], x[i], y[i])
for i in np.flatnonzero(~ok):
print(ids[i], RowStatus(int(status[i])).name, RowFailure(int(failure[i])).name)
Expect A near (333958.472380, 6446275.841017) m. Check its unrounded position against (333958.4723798207, 6446275.841017161) m with a Euclidean tolerance of 1e-6 m.
a = np.flatnonzero(ids == 'A')[0]
assert ok[a]
assert np.hypot(x[a] - 333958.4723798207, y[a] - 6446275.841017161) <= 1e-6
Expect B to report OUT_OF_DOMAIN and OUTSIDE_IMPLEMENTATION_LIMITS: its latitude of 89.5° exceeds cuGeo’s Web Mercator bound of ±85.0511287798066°, although pyproj still gives a finite position there. Expect C to report OUT_OF_DOMAIN and OUTSIDE_OPERATION_DOMAIN because its latitude of 90.1° lies beyond the pole.
Check that the usable group contains A once and the diagnostic group contains B and C once each. For a different failure in your own batch, see Diagnose a refused transform or failed coordinate.