Class: GeographicAreasGeographicItem
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- GeographicAreasGeographicItem
- Includes:
- Shared::IsApplicationData, Shared::IsData
- Defined in:
- app/models/geographic_areas_geographic_item.rb
Overview
A GeographicAreaGeographicItem is an assertion that a GeographicArea was defined by a shape (GeographicItem) according to some source. The assertion may be bound by time.
Instance Attribute Summary collapse
-
#data_origin ⇒ String
The origin of this shape associations, take from SFGs /gaz data.
-
#date_valid_from ⇒ String
The verbatim value taken from the source data as to when this shape was first valid for the associated GeographicArea (name).
-
#date_valid_to ⇒ String
The verbatim data value taken from the source data as to when this shape was last valid for the associated GeographicArea (name).
-
#geographic_area_id ⇒ Integer
The id of a GeographicArea that represents the area of this association.
-
#geographic_item_id ⇒ Integer
The id of a GeographicItem that represents the geography of this association.
-
#origin_gid ⇒ String
The gid (row number) taken from the shape table from the source.
Class Method Summary collapse
- .default_geographic_item_data ⇒ Object
-
.ordered_by_data_origin ⇒ Object
# Postgis specific SQL scope :ordered_by_data_origin, lambda { order( “CASE geographic_areas_geographic_items.data_origin WHEN ‘ne_country’ THEN 1 WHEN ‘ne_state’ THEN 2 WHEN ‘gadm’ THEN 3 ELSE 4 END” ) }.
- .origin_order_clause(table_alias = nil) ⇒ Object
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods inherited from ApplicationRecord
Instance Attribute Details
#data_origin ⇒ String
The origin of this shape associations, take from SFGs /gaz data
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/geographic_areas_geographic_item.rb', line 31 class GeographicAreasGeographicItem < ApplicationRecord include Shared::IsData include Shared::IsApplicationData belongs_to :geographic_area, inverse_of: :geographic_areas_geographic_items belongs_to :geographic_item, inverse_of: :geographic_areas_geographic_items has_many :cached_map_item_translations, primary_key: :geographic_item_id, foreign_key: :translated_geographic_item_id validates :geographic_area, presence: true validates :geographic_item, presence: true unless ENV['NO_GEO_VALID'] # # Postgis specific SQL # scope :ordered_by_data_origin, lambda { # order( # "CASE geographic_areas_geographic_items.data_origin # WHEN 'ne_country' THEN 1 # WHEN 'ne_state' THEN 2 # WHEN 'gadm' THEN 3 # ELSE 4 # END" # ) # } # # https://github.com/DimaSavitsky/test-prototype/blob/df3c7c792331e19adfbb2065c7185623cabef24e/app/models/onet/occupation.rb#L61 def self.ordered_by_data_origin order(origin_order_clause) end def self.origin_order_clause(table_alias = nil) t = arel_table t = t.alias(table_alias) if table_alias.present? c = Arel::Nodes::Case.new(t[:data_origin]) c.when('gadm').then(1) c.when('ne_country').then(2) c.when('ne_state').then(3) c.else(4) c end def self.default_geographic_item_data q = "WITH summary AS ( SELECT p.id, p.geographic_area_id, p.geographic_item_id, ROW_NUMBER() OVER( PARTITION BY p.geographic_area_id ORDER BY #{origin_order_clause("p").to_sql}) AS rk FROM geographic_areas_geographic_items p) SELECT s.* FROM summary s WHERE s.rk = 1" GeographicAreasGeographicItem.joins( "JOIN (#{q}) as z ON geographic_areas_geographic_items.id = z.id" ) end end |
#date_valid_from ⇒ String
The verbatim value taken from the source data as to when this shape was first valid for the associated
GeographicArea (name)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/geographic_areas_geographic_item.rb', line 31 class GeographicAreasGeographicItem < ApplicationRecord include Shared::IsData include Shared::IsApplicationData belongs_to :geographic_area, inverse_of: :geographic_areas_geographic_items belongs_to :geographic_item, inverse_of: :geographic_areas_geographic_items has_many :cached_map_item_translations, primary_key: :geographic_item_id, foreign_key: :translated_geographic_item_id validates :geographic_area, presence: true validates :geographic_item, presence: true unless ENV['NO_GEO_VALID'] # # Postgis specific SQL # scope :ordered_by_data_origin, lambda { # order( # "CASE geographic_areas_geographic_items.data_origin # WHEN 'ne_country' THEN 1 # WHEN 'ne_state' THEN 2 # WHEN 'gadm' THEN 3 # ELSE 4 # END" # ) # } # # https://github.com/DimaSavitsky/test-prototype/blob/df3c7c792331e19adfbb2065c7185623cabef24e/app/models/onet/occupation.rb#L61 def self.ordered_by_data_origin order(origin_order_clause) end def self.origin_order_clause(table_alias = nil) t = arel_table t = t.alias(table_alias) if table_alias.present? c = Arel::Nodes::Case.new(t[:data_origin]) c.when('gadm').then(1) c.when('ne_country').then(2) c.when('ne_state').then(3) c.else(4) c end def self.default_geographic_item_data q = "WITH summary AS ( SELECT p.id, p.geographic_area_id, p.geographic_item_id, ROW_NUMBER() OVER( PARTITION BY p.geographic_area_id ORDER BY #{origin_order_clause("p").to_sql}) AS rk FROM geographic_areas_geographic_items p) SELECT s.* FROM summary s WHERE s.rk = 1" GeographicAreasGeographicItem.joins( "JOIN (#{q}) as z ON geographic_areas_geographic_items.id = z.id" ) end end |
#date_valid_to ⇒ String
The verbatim data value taken from the source data as to when this shape was last valid for the associated
GeographicArea (name)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/geographic_areas_geographic_item.rb', line 31 class GeographicAreasGeographicItem < ApplicationRecord include Shared::IsData include Shared::IsApplicationData belongs_to :geographic_area, inverse_of: :geographic_areas_geographic_items belongs_to :geographic_item, inverse_of: :geographic_areas_geographic_items has_many :cached_map_item_translations, primary_key: :geographic_item_id, foreign_key: :translated_geographic_item_id validates :geographic_area, presence: true validates :geographic_item, presence: true unless ENV['NO_GEO_VALID'] # # Postgis specific SQL # scope :ordered_by_data_origin, lambda { # order( # "CASE geographic_areas_geographic_items.data_origin # WHEN 'ne_country' THEN 1 # WHEN 'ne_state' THEN 2 # WHEN 'gadm' THEN 3 # ELSE 4 # END" # ) # } # # https://github.com/DimaSavitsky/test-prototype/blob/df3c7c792331e19adfbb2065c7185623cabef24e/app/models/onet/occupation.rb#L61 def self.ordered_by_data_origin order(origin_order_clause) end def self.origin_order_clause(table_alias = nil) t = arel_table t = t.alias(table_alias) if table_alias.present? c = Arel::Nodes::Case.new(t[:data_origin]) c.when('gadm').then(1) c.when('ne_country').then(2) c.when('ne_state').then(3) c.else(4) c end def self.default_geographic_item_data q = "WITH summary AS ( SELECT p.id, p.geographic_area_id, p.geographic_item_id, ROW_NUMBER() OVER( PARTITION BY p.geographic_area_id ORDER BY #{origin_order_clause("p").to_sql}) AS rk FROM geographic_areas_geographic_items p) SELECT s.* FROM summary s WHERE s.rk = 1" GeographicAreasGeographicItem.joins( "JOIN (#{q}) as z ON geographic_areas_geographic_items.id = z.id" ) end end |
#geographic_area_id ⇒ Integer
The id of a GeographicArea that represents the area of this association.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/geographic_areas_geographic_item.rb', line 31 class GeographicAreasGeographicItem < ApplicationRecord include Shared::IsData include Shared::IsApplicationData belongs_to :geographic_area, inverse_of: :geographic_areas_geographic_items belongs_to :geographic_item, inverse_of: :geographic_areas_geographic_items has_many :cached_map_item_translations, primary_key: :geographic_item_id, foreign_key: :translated_geographic_item_id validates :geographic_area, presence: true validates :geographic_item, presence: true unless ENV['NO_GEO_VALID'] # # Postgis specific SQL # scope :ordered_by_data_origin, lambda { # order( # "CASE geographic_areas_geographic_items.data_origin # WHEN 'ne_country' THEN 1 # WHEN 'ne_state' THEN 2 # WHEN 'gadm' THEN 3 # ELSE 4 # END" # ) # } # # https://github.com/DimaSavitsky/test-prototype/blob/df3c7c792331e19adfbb2065c7185623cabef24e/app/models/onet/occupation.rb#L61 def self.ordered_by_data_origin order(origin_order_clause) end def self.origin_order_clause(table_alias = nil) t = arel_table t = t.alias(table_alias) if table_alias.present? c = Arel::Nodes::Case.new(t[:data_origin]) c.when('gadm').then(1) c.when('ne_country').then(2) c.when('ne_state').then(3) c.else(4) c end def self.default_geographic_item_data q = "WITH summary AS ( SELECT p.id, p.geographic_area_id, p.geographic_item_id, ROW_NUMBER() OVER( PARTITION BY p.geographic_area_id ORDER BY #{origin_order_clause("p").to_sql}) AS rk FROM geographic_areas_geographic_items p) SELECT s.* FROM summary s WHERE s.rk = 1" GeographicAreasGeographicItem.joins( "JOIN (#{q}) as z ON geographic_areas_geographic_items.id = z.id" ) end end |
#geographic_item_id ⇒ Integer
The id of a GeographicItem that represents the geography of this association.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/geographic_areas_geographic_item.rb', line 31 class GeographicAreasGeographicItem < ApplicationRecord include Shared::IsData include Shared::IsApplicationData belongs_to :geographic_area, inverse_of: :geographic_areas_geographic_items belongs_to :geographic_item, inverse_of: :geographic_areas_geographic_items has_many :cached_map_item_translations, primary_key: :geographic_item_id, foreign_key: :translated_geographic_item_id validates :geographic_area, presence: true validates :geographic_item, presence: true unless ENV['NO_GEO_VALID'] # # Postgis specific SQL # scope :ordered_by_data_origin, lambda { # order( # "CASE geographic_areas_geographic_items.data_origin # WHEN 'ne_country' THEN 1 # WHEN 'ne_state' THEN 2 # WHEN 'gadm' THEN 3 # ELSE 4 # END" # ) # } # # https://github.com/DimaSavitsky/test-prototype/blob/df3c7c792331e19adfbb2065c7185623cabef24e/app/models/onet/occupation.rb#L61 def self.ordered_by_data_origin order(origin_order_clause) end def self.origin_order_clause(table_alias = nil) t = arel_table t = t.alias(table_alias) if table_alias.present? c = Arel::Nodes::Case.new(t[:data_origin]) c.when('gadm').then(1) c.when('ne_country').then(2) c.when('ne_state').then(3) c.else(4) c end def self.default_geographic_item_data q = "WITH summary AS ( SELECT p.id, p.geographic_area_id, p.geographic_item_id, ROW_NUMBER() OVER( PARTITION BY p.geographic_area_id ORDER BY #{origin_order_clause("p").to_sql}) AS rk FROM geographic_areas_geographic_items p) SELECT s.* FROM summary s WHERE s.rk = 1" GeographicAreasGeographicItem.joins( "JOIN (#{q}) as z ON geographic_areas_geographic_items.id = z.id" ) end end |
#origin_gid ⇒ String
The gid (row number) taken from the shape table from the source
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/geographic_areas_geographic_item.rb', line 31 class GeographicAreasGeographicItem < ApplicationRecord include Shared::IsData include Shared::IsApplicationData belongs_to :geographic_area, inverse_of: :geographic_areas_geographic_items belongs_to :geographic_item, inverse_of: :geographic_areas_geographic_items has_many :cached_map_item_translations, primary_key: :geographic_item_id, foreign_key: :translated_geographic_item_id validates :geographic_area, presence: true validates :geographic_item, presence: true unless ENV['NO_GEO_VALID'] # # Postgis specific SQL # scope :ordered_by_data_origin, lambda { # order( # "CASE geographic_areas_geographic_items.data_origin # WHEN 'ne_country' THEN 1 # WHEN 'ne_state' THEN 2 # WHEN 'gadm' THEN 3 # ELSE 4 # END" # ) # } # # https://github.com/DimaSavitsky/test-prototype/blob/df3c7c792331e19adfbb2065c7185623cabef24e/app/models/onet/occupation.rb#L61 def self.ordered_by_data_origin order(origin_order_clause) end def self.origin_order_clause(table_alias = nil) t = arel_table t = t.alias(table_alias) if table_alias.present? c = Arel::Nodes::Case.new(t[:data_origin]) c.when('gadm').then(1) c.when('ne_country').then(2) c.when('ne_state').then(3) c.else(4) c end def self.default_geographic_item_data q = "WITH summary AS ( SELECT p.id, p.geographic_area_id, p.geographic_item_id, ROW_NUMBER() OVER( PARTITION BY p.geographic_area_id ORDER BY #{origin_order_clause("p").to_sql}) AS rk FROM geographic_areas_geographic_items p) SELECT s.* FROM summary s WHERE s.rk = 1" GeographicAreasGeographicItem.joins( "JOIN (#{q}) as z ON geographic_areas_geographic_items.id = z.id" ) end end |
Class Method Details
.default_geographic_item_data ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/geographic_areas_geographic_item.rb', line 73 def self.default_geographic_item_data q = "WITH summary AS ( SELECT p.id, p.geographic_area_id, p.geographic_item_id, ROW_NUMBER() OVER( PARTITION BY p.geographic_area_id ORDER BY #{origin_order_clause("p").to_sql}) AS rk FROM geographic_areas_geographic_items p) SELECT s.* FROM summary s WHERE s.rk = 1" GeographicAreasGeographicItem.joins( "JOIN (#{q}) as z ON geographic_areas_geographic_items.id = z.id" ) end |
.ordered_by_data_origin ⇒ Object
# Postgis specific SQL scope :ordered_by_data_origin, lambda
order(
"CASE geographic_areas_geographic_items.data_origin
WHEN 'ne_country' THEN 1
WHEN 'ne_state' THEN 2
WHEN 'gadm' THEN 3
ELSE 4
END"
)
56 57 58 |
# File 'app/models/geographic_areas_geographic_item.rb', line 56 def self.ordered_by_data_origin order(origin_order_clause) end |
.origin_order_clause(table_alias = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/geographic_areas_geographic_item.rb', line 60 def self.origin_order_clause(table_alias = nil) t = arel_table t = t.alias(table_alias) if table_alias.present? c = Arel::Nodes::Case.new(t[:data_origin]) c.when('gadm').then(1) c.when('ne_country').then(2) c.when('ne_state').then(3) c.else(4) c end |