I'm developing an app, that needs to calculate distances between my current position and different places in earth. I use PostGIS.
As my first solution I've stored all the positions as Geography, and I calculate distances easily. Everything is correct and working. However, I need to do this queries lots of times, so I want to speed up this calculation.
I have two premises:
- I store places around the world
- I only need to check distances between my current location and places that are near (100km distance max).
- some other variables
- We may have about 100-1000 places that match the distance
- places do not move
My idea is to use geometry instead of Geography.
- I was thinking on using UTM.
- For each place I'll store its position stored in its UTM zone projection
- Each place that is 100km near the border of the zone, I also calculate its position in the neighbor zone and store it (This may put some error in the distance, but I don't think will be much).
- When I want to look for distances I'll only check for the points that have the same zone, and calculate the distance.
As an example, I'll have a table like
| id | place_id | point | utm_zone | |---- |---------- |------- |---------- | | 1 | 1 | 1,1 | 24M | | 2 | 2 | 0,0 | 25M | | 3 | 2 | -1,-1 | 24M |
- Is this idea correct or I'm missing something?
- Is there any other better way to do this?