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, #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.



331
332
333
334
# File 'lib/spatial_adapter/postgresql.rb', line 331

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



350
351
352
353
# File 'lib/spatial_adapter/postgresql.rb', line 350

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



346
347
348
# File 'lib/spatial_adapter/postgresql.rb', line 346

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.



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

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)


336
337
338
# File 'lib/spatial_adapter/postgresql.rb', line 336

def geographic?
  @geographic
end