Reputation: 1592
Given a bounding box, I would like to be able to calculate all possible latitude/longitude combinations within that box, to a certain accuracy e.g. 3 decimal places. At the moment the calculations are done is real time, which is very slow. To help speed things up I plan to use something like AppFabric Caching to cache a dataset of all points/distance combinations. If done correctly this should reduce the distance calculation to a lookup.
The only piece of the puzzle that I'm missing is an efficient way to calculate the combinations of lat/lon in the bounding box - can anyone help?
Mark
Upvotes: 0
Views: 2129
Reputation: 369
I would concur with the other answers that normally you wouldn't want to create a list of all latitude / longitude combinations.
If you're using SQL Server 2008 or 2012, using the STContains() or STIntersects() methods are pretty easy and with a spatial index, very fast.
Upvotes: 0
Reputation: 6834
Still a bit mystified as to why you want all such points rather than just checking a given point is in the box on the fly (this does not take much computation).
However, given a small box, we can treat is as locally flat.
That means we transform any point to new coordinates:
(llat, llong) -> (x = llong * cos(llat), y = llong)
[Note the cos() is not an expensive function - unless you are still on a 486!]
The problem then reduces to that for a cartesian plane.
Assuming that by "box" you mean a rectangle, not necessarily oriented.
The obvious thing to do is rasterize it.
Upvotes: 1
Reputation: 15233
My guess is that calculating "all of the latitude and longitude combinations" within a certain box shouldn't be sped up; it shouldn't be done at all. Instead, you should derive functions that run along the four edges of the bounding box. For instance, for varying x
and constant y_top
, derive functions lat(x)
and long(x)
. Given two functions for four edges = eight functions total, you should be able to develop fast logic that determines whether or not any given coordinate is in the bounding box.
Upvotes: 1