Module: SpatialAdapter::Base::Mysql::Adapter

Included in:
ActiveRecord::ConnectionAdapters::Mysql2Adapter, ActiveRecord::ConnectionAdapters::MysqlAdapter
Defined in:
lib/spatial_adapter/base/mysql/adapter.rb

Constant Summary collapse

GEOMETRY_REGEXP =
/geometry|point|linestring|polygon|multipoint|multilinestring|multipolygon|geometrycollection/i

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/spatial_adapter/base/mysql/adapter.rb', line 9

def self.included klass
  klass.class_eval do
    def native_database_types
      (defined?(self.class::NATIVE_DATABASE_TYPES) ? self.class::NATIVE_DATABASE_TYPES : super) \
        .merge(SpatialAdapter.geometry_data_types)
    end

    # Redefines the quote method to add behaviour for when a Geometry is
    # encountered ; used when binding variables in find_by methods
    def quote(value, column = nil)
      if value.kind_of?(GeoRuby::SimpleFeatures::Geometry)
        "GeomFromWKB(0x#{value.as_hex_wkb},#{value.srid})"
      else
        super(value,column)
      end
    end

    #Redefines add_index to support the case where the index is spatial
    #If the :spatial key in the options table is true, then the sql string for a spatial index is created
    def add_index(table_name,column_name,options = {})
      index_name = options[:name] || index_name(table_name,:column => Array(column_name))

      if options[:spatial]
        execute "CREATE SPATIAL INDEX #{index_name} ON #{table_name} (#{Array(column_name).join(", ")})"
      else
        super
      end
    end
  end
end

Instance Method Details

#supports_geographic?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/spatial_adapter/base/mysql/adapter.rb', line 5

def supports_geographic?
  false
end