]> git.openstreetmap.org Git - rails.git/commitdiff
rails_port_0.5: Merge rails_port.
authorGabriel Ebner <gabriel@svn.openstreetmap.org>
Sat, 29 Sep 2007 17:44:17 +0000 (17:44 +0000)
committerGabriel Ebner <gabriel@svn.openstreetmap.org>
Sat, 29 Sep 2007 17:44:17 +0000 (17:44 +0000)
app/models/trace.rb
app/models/tracepoint.rb
db/README
db/functions/Makefile
db/migrate/005_tile_tracepoints.rb
db/migrate/006_tile_nodes.rb

index 4cac233c2fd51c5147c627ba0c1f92606755cc9c..baf2ea7d27592dba4c88baebbfd734f1a8c0ed17 100644 (file)
@@ -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
index e0fcfbd9775858b48c5daf9b9d4a0959d6f3f215..1d9f1bd6bf5e57e24188a0ea83b1e724dc834c2a 100644 (file)
@@ -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
 
index f4530f09008b3fa2edef36816da7dd4ffb8ae007..d89a67bfb8bfb0603aac985e4dbd5295a3deff66 100644 (file)
--- 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 <uid> -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
 ===================================
 
index 6544db1ff12923e86653d848465522dd55b9e636..ce216e7655d59ce0a3923691aa4dac93547f1000 100644 (file)
@@ -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
index c0e6d8a61d5e25940a5e6e24023e356ef219a2fb..51a4d1376233c28ed88494b24f3c7eca71ee5a30 100644 (file)
@@ -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"
index 9624a0136b6ffacd12169db03d44f43c36a735d3..3a50cc9b05ff0372041681b8a16d2e12973556e5 100644 (file)
@@ -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