class ActiveRecord::ConnectionAdapters::PostGISAdapter

Constants

ADAPTER_NAME
DEFAULT_SRID

postgis.17.x6.nabble.com/Default-SRID-td5001115.html

SPATIAL_COLUMN_OPTIONS

Public Class Methods

initialize_type_map(map = type_map) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/postgis_adapter.rb, line 67
def initialize_type_map(map = type_map)
  %w[
    geography
    geometry
    geometry_collection
    line_string
    multi_line_string
    multi_point
    multi_polygon
    st_point
    st_polygon
  ].each do |geo_type|
    map.register_type(geo_type) do |_, _, sql_type|
      # sql_type is a string that comes from the database definition
      # examples:
      #   "geometry(Point,4326)"
      #   "geography(Point,4326)"
      #   "geometry(Polygon,4326) NOT NULL"
      #   "geometry(Geography,4326)"
      geo_type, srid, has_z, has_m, geographic = PostGIS::OID::Spatial.parse_sql_type(sql_type)
      PostGIS::OID::Spatial.new(geo_type: geo_type, srid: srid, has_z: has_z, has_m: has_m, geographic: geographic)
    end
  end

  super
end
native_database_types() click to toggle source
# File lib/active_record/connection_adapters/postgis_adapter.rb, line 94
def native_database_types
  @native_database_types ||= begin
    default_types = PostgreSQLAdapter.native_database_types
    default_types.merge({
      geography:           { name: "geography" },
      geometry:            { name: "geometry" },
      geometry_collection: { name: "geometry_collection" },
      line_string:         { name: "line_string" },
      multi_line_string:   { name: "multi_line_string" },
      multi_point:         { name: "multi_point" },
      multi_polygon:       { name: "multi_polygon" },
      spatial:             { name: "geometry" },
      st_point:            { name: "st_point" },
      st_polygon:          { name: "st_polygon" }
    })
  end
end
spatial_column_options(key) click to toggle source
# File lib/active_record/connection_adapters/postgis_adapter.rb, line 54
def self.spatial_column_options(key)
  SPATIAL_COLUMN_OPTIONS[key]
end

Public Instance Methods

default_srid() click to toggle source
# File lib/active_record/connection_adapters/postgis_adapter.rb, line 62
def default_srid
  DEFAULT_SRID
end
postgis_lib_version() click to toggle source
# File lib/active_record/connection_adapters/postgis_adapter.rb, line 58
def postgis_lib_version
  @postgis_lib_version ||= select_value("SELECT PostGIS_Lib_Version()")
end
quote(value) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/postgis_adapter.rb, line 122
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) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/postgis_adapter.rb, line 132
def quote_default_expression(value, column)
  if column.type == :geography || column.type == :geometry
    quote(value)
  else
    super
  end
end
srs_database_columns() click to toggle source
# File lib/active_record/connection_adapters/postgis_adapter.rb, line 113
def srs_database_columns
  {
    auth_name_column: "auth_name",
    auth_srid_column: "auth_srid",
    proj4text_column: "proj4text",
    srtext_column:    "srtext",
  }
end