From: Gabriel Ebner Date: Sat, 29 Sep 2007 17:44:17 +0000 (+0000) Subject: rails_port_0.5: Merge rails_port. X-Git-Tag: live~8121^2~3 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/26fb51c86e178a1c5bbe313c4688c623646173f8?hp=25ad9dd38cc0dacc1217ae8e415c2661a919c6a5 rails_port_0.5: Merge rails_port. --- diff --git a/app/models/trace.rb b/app/models/trace.rb index 4cac233c2..baf2ea7d2 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -190,7 +190,7 @@ class Trace < ActiveRecord::Base tp = Tracepoint.new tp.lat = point['latitude'].to_f - tp.lng = point['longitude'].to_f + tp.lon = point['longitude'].to_f tp.altitude = point['altitude'].to_f tp.timestamp = point['timestamp'] tp.gpx_id = id diff --git a/app/models/tracepoint.rb b/app/models/tracepoint.rb index e0fcfbd97..1d9f1bd6b 100644 --- a/app/models/tracepoint.rb +++ b/app/models/tracepoint.rb @@ -25,7 +25,7 @@ class Tracepoint < ActiveRecord::Base self.latitude = (l * 10000000).round end - def lng=(l) + def lon=(l) self.longitude = (l * 10000000).round end diff --git a/db/README b/db/README index f4530f090..d89a67bfb 100644 --- a/db/README +++ b/db/README @@ -29,6 +29,11 @@ Run this command in the db/functions directory: $ make +The above command should work for linux and most other Unix systems +that use ELF shared objects. For MacOS X you will need to do: + +$ make libquadtile.dylib + Make sure the db/functions directory is on the MySQL server's library path and restart the MySQL server. On linux the easiest way to do this is to create /etc/ld.so.conf.d/osm.conf and place the path to the @@ -45,6 +50,11 @@ $ mysql -u -p openstreetmap > create function tile_for_point returns integer soname 'libquadtile.so'; > exit +or, for MacOS X: + +> create function tile_for_point returns integer soname 'libquadtile.dylib'; +> exit + Creating database skeleton tables =================================== diff --git a/db/functions/Makefile b/db/functions/Makefile index 6544db1ff..ce216e765 100644 --- a/db/functions/Makefile +++ b/db/functions/Makefile @@ -1,4 +1,10 @@ QTDIR=../../lib/quad_tile -libquadtile.so: quadtile.c ${QTDIR}/quad_tile.h - cc `mysql_config --include` -I${QTDIR} -fPIC -O3 -shared -o libquadtile.so quadtile.c +libquadtile.so: quadtile.o + cc -shared -o libquadtile.so quadtile.o + +libquadtile.dylib: quadtile.o + libtool -dynamic quadtile.o -o libquadtile.dylib + +quadtile.o: quadtile.c ${QTDIR}/quad_tile.h + cc `mysql_config --include` -I${QTDIR} -fPIC -O3 -c -o quadtile.o quadtile.c diff --git a/db/migrate/005_tile_tracepoints.rb b/db/migrate/005_tile_tracepoints.rb index c0e6d8a61..51a4d1376 100644 --- a/db/migrate/005_tile_tracepoints.rb +++ b/db/migrate/005_tile_tracepoints.rb @@ -4,10 +4,20 @@ class TileTracepoints < ActiveRecord::Migration add_index "gps_points", ["tile"], :name => "points_tile_idx" remove_index "gps_points", :name => "points_idx" - Tracepoint.update_all("latitude = latitude * 10, longitude = longitude * 10, tile = tile_for_point(latitude * 10, longitude * 10)") + begin + Tracepoint.update_all("latitude = latitude * 10, longitude = longitude * 10, tile = tile_for_point(latitude * 10, longitude * 10)") + rescue ActiveRecord::StatementInvalid => ex + Tracepoint.find(:all).each do |tp| + tp.latitude = tp.latitude * 10 + tp.longitude = tp.longitude * 10 + tp.save! + end + end end def self.down + Tracepoint.update_all("latitude = latitude / 10, longitude = longitude / 10") + add_index "gps_points", ["latitude", "longitude"], :name => "points_idx" remove_index "gps_points", :name => "points_tile_idx" remove_column "gps_points", "tile" diff --git a/db/migrate/006_tile_nodes.rb b/db/migrate/006_tile_nodes.rb index 9624a0136..3a50cc9b0 100644 --- a/db/migrate/006_tile_nodes.rb +++ b/db/migrate/006_tile_nodes.rb @@ -1,13 +1,26 @@ class TileNodes < ActiveRecord::Migration - def self.upgrade_table(from_table, to_table) - execute <<-END_SQL - INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile) - SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000), - user_id, visible, tags, timestamp, - tile_for_point(CAST(ROUND(latitude * 10000000) AS UNSIGNED), - CAST(ROUND(longitude * 10000000) AS UNSIGNED)) - FROM #{from_table} - END_SQL + def self.upgrade_table(from_table, to_table, model) + begin + execute <<-END_SQL + INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile) + SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000), + user_id, visible, tags, timestamp, + tile_for_point(CAST(ROUND(latitude * 10000000) AS UNSIGNED), + CAST(ROUND(longitude * 10000000) AS UNSIGNED)) + FROM #{from_table} + END_SQL + rescue ActiveRecord::StatementInvalid => ex + execute <<-END_SQL + INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile) + SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000), + user_id, visible, tags, timestamp, 0 + FROM #{from_table} + END_SQL + + model.find(:all).each do |n| + n.save! + end + end end def self.downgrade_table(from_table, to_table) @@ -40,8 +53,8 @@ class TileNodes < ActiveRecord::Migration change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" change_column "current_nodes", "tile", :integer, :null => false, :unsigned => true - upgrade_table "current_nodes_v5", "current_nodes" - + upgrade_table "current_nodes_v5", "current_nodes", Node + drop_table "current_nodes_v5" rename_table "nodes", "nodes_v5" @@ -63,7 +76,7 @@ class TileNodes < ActiveRecord::Migration change_column "nodes", "tile", :integer, :null => false, :unsigned => true - upgrade_table "nodes_v5", "nodes" + upgrade_table "nodes_v5", "nodes", OldNode drop_table "nodes_v5" end