Module: SpatialAdapter::SpatialColumn

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#geometry_typeObject (readonly)

Returns the value of attribute geometry_type.



3
4
5
# File 'lib/spatial_adapter/common/spatial_column.rb', line 3

def geometry_type
  @geometry_type
end

#sridObject (readonly)

Returns the value of attribute srid.



3
4
5
# File 'lib/spatial_adapter/common/spatial_column.rb', line 3

def srid
  @srid
end

#with_mObject (readonly)

Returns the value of attribute with_m.



3
4
5
# File 'lib/spatial_adapter/common/spatial_column.rb', line 3

def with_m
  @with_m
end

#with_zObject (readonly)

Returns the value of attribute with_z.



3
4
5
# File 'lib/spatial_adapter/common/spatial_column.rb', line 3

def with_z
  @with_z
end

Instance Method Details

#geographic?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/spatial_adapter/common/spatial_column.rb', line 17

def geographic?
  false
end

#initialize(name, default, sql_type = nil, null = true, srid = -1,, with_z = false, with_m = false) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/spatial_adapter/common/spatial_column.rb', line 5

def initialize(name, default, sql_type = nil, null = true, srid=-1, with_z=false, with_m=false)
  super(name, default, sql_type, null)
  @geometry_type = geometry_simplified_type(@sql_type)
  @srid = srid
  @with_z = with_z
  @with_m = with_m
end

#klassObject

Redefines klass to add support for geometries alias_method :klass_without_spatial, :klass



39
40
41
# File 'lib/spatial_adapter/common/spatial_column.rb', line 39

def klass
  spatial? ? GeoRuby::SimpleFeatures::Geometry : super
end

#spatial?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/spatial_adapter/common/spatial_column.rb', line 13

def spatial?
  !@geometry_type.nil?
end

#type_cast(value) ⇒ Object

Redefines type_cast to add support for geometries alias_method :type_cast_without_spatial, :type_cast



23
24
25
26
# File 'lib/spatial_adapter/common/spatial_column.rb', line 23

def type_cast(value)
  return nil if value.nil?
  spatial? ? self.class.string_to_geometry(value) : super
end

#type_cast_code(var_name) ⇒ Object

Redefines type_cast_code to add support for geometries.

WARNING : Since ActiveRecord keeps only the string values directly returned from the database, it translates from these to the correct types everytime an attribute is read (using the code returned by this method), which is probably ok for simple types, but might be less than efficient for geometries. Also you cannot modify the geometry object returned directly or your change will not be saved. alias_method :type_cast_code_without_spatial, :type_cast_code



32
33
34
# File 'lib/spatial_adapter/common/spatial_column.rb', line 32

def type_cast_code(var_name)
  spatial? ? "#{self.class.name}.string_to_geometry(#{var_name})" : super
end