Skip to content

How to validate coordinates are in bounds? #67

Closed Answered by dvdoug
mkoskl asked this question in Q&A
Discussion options

You must be logged in to vote

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->con…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mkoskl
Comment options

@dvdoug
Comment options

@mkoskl
Comment options

Answer selected by mkoskl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants