-
Hello! How can I validate coordinates are in bounds of specified CRS? E.g. if I have URN for the coordinate system and latitude / longitude pair, how can I check if the latitude and longitude are valid for specified CRS? Br, Miika |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Interesting, that's not a use case I've ever considered - I've always assumed that you've got the lat/long it must be valid 😱 It depends how accurate you need the check to be. The bounding areas for all CRS types (even non-geographic ones) are defined in WGS84 coordinates so the most accurate way that works for all point types would be this (slightly clunky API): $crs = Geographic2D::fromSRID(Geographic2D::EPSG_ED50);
$point = GeographicPoint::create( // New York, will fail
latitude: new Degree(40.689167),
longitude: new Degree(-74.044444),
crs: $crs
);
$wgs84 = Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84);
$isInsideCRS = $crs->getBoundingArea()->containsPoint($point->convert($wgs84)->asGeographicValue()); |
Beta Was this translation helpful? Give feedback.
Interesting, that's not a use case I've ever considered - I've always assumed that you've got the lat/long it must be valid 😱
It depends how accurate you need the check to be. The bounding areas for all CRS types (even non-geographic ones) are defined in WGS84 coordinates so the most accurate way that works for all point types would be this (slightly clunky API):