-2

I have the following problem in my system : my system is client-server architectural . my application is about recognition building in a city .so i decide to separate the map of the city into grids each grid has an area equal 30 x 30 m . for each grid region i store the center point of the grid (lat,long) . so my question is if a user is located in a specific grid x it's location are send to the server how i can decide in which grid the user are located ?

Here's a photo clarify the problem:

City organization as grids

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
M.Abulsoud
  • 989
  • 7
  • 23

1 Answers1

1

I'm assuming your grids are all exactly the same size, and are arranged in a perfect rectangle, as indicated by your image. How about storing all grids in a simple 2D array? You can then find the index of any grid by doing

grid_size = 30; 
index_x = math.floor(user.x/grid_size); 
index_y = math.floor(user.y/grid_size);
Kevin
  • 74,910
  • 12
  • 133
  • 166
  • thanks Kevin wonderful trick ,how about if the situation is mess i.e the grids aren't Close proximity . i think i need to use the kd-tree in this situation right ? do you have another opinion? – M.Abulsoud Dec 30 '14 at 14:41
  • Yeah, kd-tree is probably appropriate when grids aren't nicely aligned. – Kevin Dec 30 '14 at 14:45
  • Thanks Kevin , one more question does the gps data need pre-processing (i.e quantize the lat & long ) to values or the original values ok ? – – M.Abulsoud Dec 30 '14 at 15:12
  • For kd trees, no processing should be necessary. For a 2d array, the coordinates should be translated so that the top left corner of the top left grid is (0,0). – Kevin Dec 30 '14 at 15:13