检测坐标是否落在经度和纬度边界框内 [英] Detect if a co-ordinate falls within a longitude and latitude boundary box
问题描述
数学从来都不是我的强项,我正努力完成一项任务.
Maths has never been my strong point and I'm struggling with a task.
我需要确定一组经度和纬度坐标是否落在已给出最大/最小经度和最大/最小纬度的框中.
I need to determine if a set of longitude and latitude co-ordinates fall inside a box, where the max/min longitude and max/min latitude have been given.
任何帮助将不胜感激.
**编辑**
我正在使用GPS坐标,因此最小经度可能大于最大经度.也就是说,如果该框在日期行上方.
I'm using GPS co-ordinates, so the minimum longitude could be larger than the maximum longitude. i.e if the box is over date line.
推荐答案
给出minlat
,maxlat
,minlong
和maxlong
(即盒子的四个角),那么确定是否您的lat
位于minlat
和maxlat
之间,而您的long
位于minlong
和maxlong
之间.
Given minlat
, maxlat
, minlong
and maxlong
(ie the 4 corners of your box) then it's a simple matter of determining whether your lat
lies between minlat
and maxlat
and your long
between minlong
and maxlong
.
如果框跨过180°
,则可以通过添加(或减去)相同的偏移量来偏移所有经度(请注意符号),或者将框沿经度分为两部分,并分别测试两个半部.
If the box straddles 180°
either shift all your longitudes by adding (or subtracting) the same offset (take care with signs) or split the box into two along longitude 180°
and test both halves separately.
这篇关于检测坐标是否落在经度和纬度边界框内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!