1

Unfortunately, maths was never my strong point and I'm struggling with the best approach/formula to do the following (which I will then need to turn in to PHP code):

1). Start with a single large area (e.g. covering all of Europe)

2). Break this area down in to a series of smaller blocks (i.e. turn it into a grid of sorts)

3). Each grid block should have a width that roughly corresponds to a distance of 75km (taking into account the curvature of the earth).

4). Calculate the central lat/long point of each grid block

5). For each grid block's central point, run a search against a separate database of lat/long points (representing places of interest) to find a maximum of 5 closest points of interest to each grid block. The furthest point of interest must be no more than 150km away from the centre of the grid block.

Once all the above is done, I should end up with a database of grid blocks and their corresponding 5 closest places of interest.

My hope is that I should then be able take any random lat/long point and calculate (using an efficient math formula) which pre-computed grid block it falls within and thus be able to immediately return the 5 closest points of interest without having to do any expensive computing.

[ note: edited for clarity based on High Performance Mark's helpful response below ]

corford
  • 985
  • 10
  • 12
  • I think you want to define your squares in terms of spherical coordinates (ranges for the two angles) so they are all about the same size and find a way of converting between spherical coords and lat and long. Google should be able to tell you how to do this and it will make it easy to tell which point is in which square etc and measure distances etc. – Helen May 14 '12 at 15:35
  • Thanks for this Helen. I'm going to explore High Performance Mark's idea first as it seems marginally more within my means (the wikipedia entry for "spherical coordinates" baffled me...) – corford May 14 '12 at 17:38

1 Answers1

1

I think that your best bet would be to either use, or follow the example of, an existing approach to gridding an area, one such as UTM. Since you admit that your maths is weak, using is probably your better approach at this stage.

UTM will give you 1 and 2.

Nothing will give you 3 over an area as large as Europe. You won't be able to define an array of 75km squares which sum to a square, the Earth just isn't flat enough over such a large area.

UTM gives you 4.

Once you've got your head round all this, you shouldn't have too much trouble with 5, but post another question when you get there and you are having difficulties.

EDIT

To expand on point 3. I suggest that you find the middle latitude of the area you are interested in, that is the latitude half-way (in angular measure) between the northern and southern limits of your area of interest. Then Google around for the formula to convert the length of a degree of longitude to km at that latitude. Vertical lines at 75km spacing along that middle latitude will be the basis of your grid. These lines will be equally spaced in angular measure.

Next, figure out the distance (in km) between those vertical lines at the northern and southern limits of your area of interest -- same formula. If the linear measures are still within your boundaries of flexibility you've finished this step. If they are not (a) I'm surprised and (b) you're going to have to tackle some tricky maths and programming.

Next, and again bearing in mind your middle latitude, figure out the angular measurement which accords to 75km (of latitude) at that latitude. This will give you 2 horizontal (ie parallel to the equator) grid lines. Since the measurement in radians of 75km in latitude is far less variable than the linear measurement of longitude with changes in latitude you will probably be OK marking off the other squares with the same angular measurement.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
  • Thanks for such a quick response! In addition to my abysmal math ability, I also lack experience with geo related programming. For example, I wasn't aware of UTM (which I'm going to read up on now). Point 3 (or something similar) is unfortunately crucial to me i.e. I need to be able to roughly control how big each grid square is (it doesn't have to be fixed like 75km but it does need to fit within a boundary e.g. no less than 50km and no more than 100km). – corford May 14 '12 at 13:58
  • To further elaborate on point 3. Is there perhaps a formula or set of formulas I could investigate for taking a section of a sphere and breaking that down in to further smaller sections (of ideally controllable dimensions)? – corford May 14 '12 at 14:09
  • Well, as long as you don't expect to have squares of exactly 75km along each side, but are prepared, as you indicate, to be flexible to accommodate the fact that the Earth is a sphere (near-enough) you shouldn't have any problems. One thing's for certain though, you are going to have to be flexible, the surface of the Earth is going to remain (approximately) spherical. – High Performance Mark May 14 '12 at 14:09
  • Thanks for all your thoughts on this. I feel slightly less lost now :) – corford May 14 '12 at 17:53