Class: ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn

Inherits:
PostgreSQLColumn
  • Object
show all
Includes:
SpatialAdapter::SpatialColumn
Defined in:
lib/spatial_adapter/postgresql.rb

Instance Attribute Summary

Attributes included from SpatialAdapter::SpatialColumn

#geometry_type, #srid, #with_m, #with_z

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SpatialAdapter::SpatialColumn

#klass, #spatial?, #type_cast, #type_cast_code

Constructor Details

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

Returns a new instance of SpatialPostgreSQLColumn.



323
324
325
326
# File 'lib/spatial_adapter/postgresql.rb', line 323

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

Class Method Details

.create_from_geography(name, default, sql_type, null = true) ⇒ Object



342
343
344
345
# File 'lib/spatial_adapter/postgresql.rb', line 342

def self.create_from_geography(name, default, sql_type, null = true)
  params = extract_geography_params(sql_type)
  new(name, default, sql_type, null, params[:srid], params[:with_z], params[:with_m], true)
end

.create_simplified(name, default, null = true) ⇒ Object



338
339
340
# File 'lib/spatial_adapter/postgresql.rb', line 338

def self.create_simplified(name, default, null = true)
  new(name, default, "geometry", null)
end

.string_to_geometry(string) ⇒ Object

Transforms a string to a geometry. PostGIS returns a HewEWKB string.



333
334
335
336
# File 'lib/spatial_adapter/postgresql.rb', line 333

def self.string_to_geometry(string)
  return string unless string.is_a?(String)
  GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(string) rescue nil
end

Instance Method Details

#geographic?Boolean

Returns:

  • (Boolean)


328
329
330
# File 'lib/spatial_adapter/postgresql.rb', line 328

def geographic?
  @geographic
end