Class: ActiveRecord::ConnectionAdapters::PostGISAdapter

Inherits:
PostgreSQLAdapter
  • Object
show all
Includes:
ActiveRecord::ConnectionAdapters::PostGIS::DatabaseStatements, ActiveRecord::ConnectionAdapters::PostGIS::SchemaStatements
Defined in:
lib/active_record/connection_adapters/postgis_adapter.rb

Constant Summary collapse

ADAPTER_NAME =
'PostGIS'
SPATIAL_COLUMN_OPTIONS =
{
  geography:           { geographic: true },
  geometry:            {},
  geometry_collection: {},
  line_string:         {},
  multi_line_string:   {},
  multi_point:         {},
  multi_polygon:       {},
  spatial:             {},
  st_point:            {},
  st_polygon:          {},
}
DEFAULT_SRID =
0

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveRecord::ConnectionAdapters::PostGIS::DatabaseStatements

#truncate_tables

Methods included from ActiveRecord::ConnectionAdapters::PostGIS::SchemaStatements

#create_table_definition, #initialize_type_map, #native_database_types, #new_column_from_field, #spatial_column_info, #type_to_sql

Class Method Details

.spatial_column_options(key) ⇒ Object


63
64
65
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 63

def self.spatial_column_options(key)
  SPATIAL_COLUMN_OPTIONS[key]
end

Instance Method Details

#arel_visitorObject

:nodoc:


59
60
61
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 59

def arel_visitor # :nodoc:
  Arel::Visitors::PostGIS.new(self)
end

#default_sridObject


71
72
73
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 71

def default_srid
  DEFAULT_SRID
end

#postgis_lib_versionObject


67
68
69
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 67

def postgis_lib_version
  @postgis_lib_version ||= select_value("SELECT PostGIS_Lib_Version()")
end

#quote(value) ⇒ Object


84
85
86
87
88
89
90
91
92
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 84

def quote(value)
  if RGeo::Feature::Geometry.check_type(value)
    "'#{RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(value)}'"
  elsif value.is_a?(RGeo::Cartesian::BoundingBox)
    "'#{value.min_x},#{value.min_y},#{value.max_x},#{value.max_y}'::box"
  else
    super
  end
end

#quote_default_expression(value, column) ⇒ Object


94
95
96
97
98
99
100
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 94

def quote_default_expression(value, column)
  if column.type == :geography || column.type == :geometry
    quote(value)
  else
    super
  end
end

#srs_database_columnsObject


75
76
77
78
79
80
81
82
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 75

def srs_database_columns
  {
    auth_name_column: "auth_name",
    auth_srid_column: "auth_srid",
    proj4text_column: "proj4text",
    srtext_column:    "srtext",
  }
end