diff options
| author | Luc Donnet | 2012-07-13 17:03:02 +0200 |
|---|---|---|
| committer | Luc Donnet | 2012-07-13 17:03:02 +0200 |
| commit | 6e742103cac4a749c26ea5e02a9e010fdc2a7815 (patch) | |
| tree | bd60a188e6e5b24340eec6241f00f35e18c14fe7 | |
| parent | 24fed642540fdf1171b8adeaba5fe7a6bc54a4f5 (diff) | |
| download | chouette-core-6e742103cac4a749c26ea5e02a9e010fdc2a7815.tar.bz2 | |
Add bounds for referential Refs #24
| -rw-r--r-- | app/models/referential.rb | 55 | ||||
| -rw-r--r-- | app/views/referentials/_form.erb | 18 | ||||
| -rw-r--r-- | config/locales/referentials.yml | 2 | ||||
| -rw-r--r-- | db/migrate/20120615102714_add_the_geom_to_referential.rb | 7 | ||||
| -rw-r--r-- | db/schema.rb | 28 |
5 files changed, 79 insertions, 31 deletions
diff --git a/app/models/referential.rb b/app/models/referential.rb index fd418a9ab..234c4a562 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- class Referential < ActiveRecord::Base - validates_presence_of :name validates_presence_of :slug validates_presence_of :prefix @@ -10,17 +9,13 @@ class Referential < ActiveRecord::Base validates_format_of :slug, :with => %r{\A[0-9a-z_]+\Z} validates_format_of :prefix, :with => %r{\A[0-9a-zA-Z_]+\Z} + attr_accessor :resources + attr_accessor :upper_corner + attr_accessor :lower_corner + has_many :imports, :dependent => :destroy has_many :exports, :dependent => :destroy - after_initialize :init_time_zone - - def init_time_zone - if time_zone.nil? - self.time_zone = "Paris" - end - end - def human_attribute_name(*args) self.class.human_attribute_name(*args) end @@ -72,29 +67,51 @@ class Referential < ActiveRecord::Base [ "NTF Lambert Zone 3 (27563)", 27563 ], [ "NTF Lambert Zone 4 (27564)", 27564 ], [ "NTF Lambert 2 étendu (27572)", 27582 ], - ["RGF 93 Lambert 93 (2154)", 2154 ] + [ "RGF 93 Lambert 93 (2154)", 2154 ] ] end before_create :create_schema - before_destroy :destroy_schema - - after_create :import_resources + def create_schema + Apartment::Database.create slug + end - attr_accessor :resources + before_destroy :destroy_schema + def destroy_schema + Apartment::Database.drop slug + end + after_create :import_resources def import_resources imports.create(:resources => resources) if resources end - def create_schema - Apartment::Database.create slug + before_save :update_envelope + before_create :update_envelope + def update_envelope + self.bounds = GeoRuby::SimpleFeatures::Envelope.from_coordinates([ [@lower_corner.x, @lower_corner.y], [ @upper_corner.x, @upper_corner.y ] ]).to_polygon.as_ewkt() + end + + def upper_corner + @upper_corner = "#{envelope.upper_corner.x}, #{envelope.upper_corner.y}" end - def destroy_schema - Apartment::Database.drop slug + def upper_corner=(upper_corner) + @upper_corner = GeoRuby::SimpleFeatures::Point.from_coordinates( upper_corner.split(",") ) end - + + def lower_corner + @lower_corner = "#{envelope.lower_corner.x}, #{envelope.lower_corner.y}" + end + + def lower_corner=(lower_corner) + @lower_corner = GeoRuby::SimpleFeatures::Point.from_coordinates( lower_corner.split(",") ) + end + + def envelope + GeoRuby::SimpleFeatures::Geometry.from_ewkt(read_attribute(:bounds)).envelope + end + end Rails.application.config.after_initialize do diff --git a/app/views/referentials/_form.erb b/app/views/referentials/_form.erb index f9beb480e..5b59ad5f8 100644 --- a/app/views/referentials/_form.erb +++ b/app/views/referentials/_form.erb @@ -11,15 +11,17 @@ <% end %> <%= form.input :prefix %> <%= form.input :projection_type, :as => :select, :collection => Referential.available_srids %> - <%= form.input :time_zone %> + <%= form.input :time_zone %> + <%= form.input :upper_corner %> + <%= form.input :lower_corner %> <% if @referential.new_record? %> - <%= form.input :resources, :as => :file %> + <%= form.input :resources, :as => :file %> <% end %> - <% end %> + <% end %> - <%= form.actions do %> - <%= form.action :submit, :as => :button %> - <%= form.action :cancel, :as => :link %> - <% end %> -<% end %> + <%= form.actions do %> + <%= form.action :submit, :as => :button %> + <%= form.action :cancel, :as => :link %> + <% end %> +<% end %>
\ No newline at end of file diff --git a/config/locales/referentials.yml b/config/locales/referentials.yml index 0d6327c6b..b5e882d3a 100644 --- a/config/locales/referentials.yml +++ b/config/locales/referentials.yml @@ -78,6 +78,8 @@ fr: prefix: Préfixe des identifiants Neptune projection_type: Système de référence spatiale optionnel (SRID) time_zone: Fuseau horaire + upper_corner: Point haut/droite emprise par défaut + lower_corner: Point bas/gauche emprise par défaut validity_period: Période de validité no_validity_period: non définie start_validity_period: du diff --git a/db/migrate/20120615102714_add_the_geom_to_referential.rb b/db/migrate/20120615102714_add_the_geom_to_referential.rb new file mode 100644 index 000000000..01dd74c88 --- /dev/null +++ b/db/migrate/20120615102714_add_the_geom_to_referential.rb @@ -0,0 +1,7 @@ +class AddTheGeomToReferential < ActiveRecord::Migration + + change_table :referentials do |t| + t.string :bounds + end + +end diff --git a/db/schema.rb b/db/schema.rb index 93b26a89f..944588d55 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -182,8 +182,8 @@ ActiveRecord::Schema.define(:version => 20120620081755) do t.string "arguments", :limit => 1000 t.integer "position" t.string "severity" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "file_validation_log_messages", ["file_validation_id"], :name => "index_file_validation_log_messages_on_file_validation_id" @@ -193,8 +193,18 @@ ActiveRecord::Schema.define(:version => 20120620081755) do t.string "options", :limit => 2000 t.string "file_name" t.string "file_type" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "geometry_columns", :id => false, :force => true do |t| + t.string "f_table_catalog", :limit => 256, :null => false + t.string "f_table_schema", :limit => 256, :null => false + t.string "f_table_name", :limit => 256, :null => false + t.string "f_geometry_column", :limit => 256, :null => false + t.integer "coord_dimension", :null => false + t.integer "srid", :null => false + t.string "type", :limit => 30, :null => false end create_table "group_of_lines", :force => true do |t| @@ -321,6 +331,8 @@ ActiveRecord::Schema.define(:version => 20120620081755) do t.string "prefix" t.string "projection_type" t.string "time_zone" + t.string "the_geom" + t.string "bounds" end create_table "routes", :force => true do |t| @@ -345,6 +357,14 @@ ActiveRecord::Schema.define(:version => 20120620081755) do t.integer "line_id", :limit => 8 end + create_table "spatial_ref_sys", :id => false, :force => true do |t| + t.integer "srid", :null => false + t.string "auth_name", :limit => 256 + t.integer "auth_srid" + t.string "srtext", :limit => 2048 + t.string "proj4text", :limit => 2048 + end + create_table "stop_areas", :force => true do |t| t.integer "parent_id", :limit => 8 t.string "objectid", :null => false |
