From 9afb35449b066fdef6b4af3b63e30e7f4eb4c5cf Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 18 Sep 2007 23:29:47 +0000 Subject: [PATCH] Change the gps_points table to store latitude and longitude values to seven decimal places to given a worse case precision of about 1cm. --- app/models/trace.rb | 8 ++++---- app/models/tracepoint.rb | 8 ++++---- db/functions/quadtile.c | 2 +- db/migrate/005_tile_tracepoints.rb | 2 +- lib/osm.rb | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/models/trace.rb b/app/models/trace.rb index a2bebf1dd..4cac233c2 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -204,10 +204,10 @@ class Trace < ActiveRecord::Base max_lon = Tracepoint.maximum('longitude', :conditions => ['gpx_id = ?', id]) min_lon = Tracepoint.minimum('longitude', :conditions => ['gpx_id = ?', id]) - max_lat = max_lat.to_f / 1000000 - min_lat = min_lat.to_f / 1000000 - max_lon = max_lon.to_f / 1000000 - min_lon = min_lon.to_f / 1000000 + max_lat = max_lat.to_f / 10000000 + min_lat = min_lat.to_f / 10000000 + max_lon = max_lon.to_f / 10000000 + min_lon = min_lon.to_f / 10000000 self.latitude = f_lat self.longitude = f_lon diff --git a/app/models/tracepoint.rb b/app/models/tracepoint.rb index e48a2748d..e0fcfbd97 100644 --- a/app/models/tracepoint.rb +++ b/app/models/tracepoint.rb @@ -22,19 +22,19 @@ class Tracepoint < ActiveRecord::Base end def lat=(l) - self.latitude = (l * 1000000).round + self.latitude = (l * 10000000).round end def lng=(l) - self.longitude = (l * 1000000).round + self.longitude = (l * 10000000).round end def lat - return self.latitude.to_f / 1000000 + return self.latitude.to_f / 10000000 end def lon - return self.longitude.to_f / 1000000 + return self.longitude.to_f / 10000000 end def to_xml_node diff --git a/db/functions/quadtile.c b/db/functions/quadtile.c index c0eb1ec3a..d60189245 100644 --- a/db/functions/quadtile.c +++ b/db/functions/quadtile.c @@ -27,5 +27,5 @@ long long tile_for_point(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char * long long lat = *(long long *)args->args[0]; long long lon = *(long long *)args->args[1]; - return xy2tile(lon2x(lon / 1000000.0), lat2y(lat / 1000000.0)); + return xy2tile(lon2x(lon / 10000000.0), lat2y(lat / 10000000.0)); } diff --git a/db/migrate/005_tile_tracepoints.rb b/db/migrate/005_tile_tracepoints.rb index 246f9b7b4..c0e6d8a61 100644 --- a/db/migrate/005_tile_tracepoints.rb +++ b/db/migrate/005_tile_tracepoints.rb @@ -4,7 +4,7 @@ class TileTracepoints < ActiveRecord::Migration add_index "gps_points", ["tile"], :name => "points_tile_idx" remove_index "gps_points", :name => "points_idx" - Tracepoint.update_all("tile = tile_for_point(latitude, longitude)") + Tracepoint.update_all("latitude = latitude * 10, longitude = longitude * 10, tile = tile_for_point(latitude * 10, longitude * 10)") end def self.down diff --git a/lib/osm.rb b/lib/osm.rb index 300d9fa7a..45c506e2e 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -414,10 +414,10 @@ module OSM # Return an SQL fragment to select a given area of the globe def self.sql_for_area(minlat, minlon, maxlat, maxlon, prefix = nil) tilesql = QuadTile.sql_for_area(minlat, minlon, maxlat, maxlon, prefix) - minlat = (minlat * 1000000).round - minlon = (minlon * 1000000).round - maxlat = (maxlat * 1000000).round - maxlon = (maxlon * 1000000).round + minlat = (minlat * 10000000).round + minlon = (minlon * 10000000).round + maxlat = (maxlat * 10000000).round + maxlon = (maxlon * 10000000).round return "#{tilesql} AND #{prefix}latitude BETWEEN #{minlat} AND #{maxlat} AND #{prefix}longitude BETWEEN #{minlon} AND #{maxlon}" end -- 2.43.2