Upload
rupicon
View
51
Download
0
Embed Size (px)
Citation preview
Of course, for small cities...
we can ignore the fact the planet is sphericaland see it as flat.
6 / 27
To implement a distance converter module
module DistanceConverter # ...
# Convert Latitude distance from Kilometers to Degrees def to_deg_lat(km:, lat: 45) km / ONE_LAT_DEGREE[deg_approx_lat(lat)] end
# Convert Latitude distance from Degrees to Kilometers def to_km_lat(deg:, lat: 45) deg * ONE_LAT_DEGREE[deg_approx_lat(lat)] end
# Convert Longitude distance from Kilometers to Degrees def to_deg_lng(km:, lat: 45) km / ONE_LNG_DEGREE[deg_approx_lat(lat)] end
# Convert Longitude distance from Degrees to Kilometers def to_km_lng(deg:, lat: 45) deg * ONE_LNG_DEGREE[deg_approx_lat(lat)] end
private
# ...end
10 / 27
All is well, except...
This converter is Ruby. What if we need tocalculate distances in an SQL query?
11 / 27
A naive versionSELECT (sqrt((43.1234 - latitude)̂2 + (23.1234 - longitude)̂2)) AS distFROM areas;
That's just the linear distance between two points in a plane, so it's correctwith our assumtion when in a small city?But the problem is it is using degrees which is a bigger problem the closerwe are to the poles.One longitude degree will be worth less kilometers than a latitude degree.So, what now?
12 / 27
PostGIS version of the querySELECT ST_Distance_Sphere( ST_MakePoint(43.1234, 23.1234), ST_MakePoint(latitude, longitude)) AS distFROM areas;
For the example, the straight line distance with our Ruby converter: 4.5 kmPostGIS result: 6.5 kmWat
17 / 27
Being reminded about projectiondistortion
https://gmaps-samples.googlecode.com/svn/trunk/poly/puzzledrag.html
21 / 27
Even starting to doubt the Earth isactually a spheroid.
Why would they have more coordinatesystems??
22 / 27