Module: ActiveRecord::ConnectionAdapters::PostGIS::ColumnDefinitionUtils

Defined in:
lib/active_record/connection_adapters/postgis/table_definition.rb

Class Method Summary collapse

Class Method Details

.default_srid(options) ⇒ Object



136
137
138
139
# File 'lib/active_record/connection_adapters/postgis/table_definition.rb', line 136

def default_srid(options)
  # Geography columns default to SRID 4326, geometry columns to 0
  options[:geographic] ? 4326 : 0
end

.geo_type(type = "GEOMETRY") ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/active_record/connection_adapters/postgis/table_definition.rb', line 111

def geo_type(type = "GEOMETRY")
  g_type = type.to_s.delete("_").upcase
  case g_type
  when "STPOINT" then "POINT"
  when "STPOLYGON" then "POLYGON"
  when "STLINESTRING" then "LINESTRING"
  when "STMULTIPOINT" then "MULTIPOINT"
  when "STMULTILINESTRING" then "MULTILINESTRING"
  when "STMULTIPOLYGON" then "MULTIPOLYGON"
  when "STGEOMETRYCOLLECTION" then "GEOMETRYCOLLECTION"
  when "STGEOMETRY" then "GEOMETRY"
  when "STGEOGRAPHY" then "GEOGRAPHY"
  else
    "GEOMETRY"  # Default fallback
  end
end

.limit_from_options(type, options = {}) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/active_record/connection_adapters/postgis/table_definition.rb', line 128

def limit_from_options(type, options = {})
  has_z = options[:has_z] ? "Z" : ""
  has_m = options[:has_m] ? "M" : ""
  srid = options[:srid] || default_srid(options)
  field_type = [ type, has_z, has_m ].compact.join
  "#{field_type},#{srid}"
end