Class: ActiveRecord::ConnectionAdapters::PostGISAdapter::SpatialColumn
- Inherits:
-
ConnectionAdapters::PostgreSQLColumn
- Object
- ConnectionAdapters::PostgreSQLColumn
- ActiveRecord::ConnectionAdapters::PostGISAdapter::SpatialColumn
- Defined in:
- lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#geographic ⇒ Object
(also: #geographic?)
readonly
Returns the value of attribute geographic.
-
#geometric_type ⇒ Object
readonly
Returns the value of attribute geometric_type.
-
#has_m ⇒ Object
(also: #has_m?)
readonly
Returns the value of attribute has_m.
-
#has_z ⇒ Object
(also: #has_z?)
readonly
Returns the value of attribute has_z.
-
#srid ⇒ Object
readonly
Returns the value of attribute srid.
Instance Method Summary collapse
- #has_spatial_constraints? ⇒ Boolean
-
#initialize(factory_settings_, table_name_, name_, default_, oid_type_, sql_type_ = nil, null_ = true, opts_ = nil) ⇒ SpatialColumn
constructor
A new instance of SpatialColumn.
- #klass ⇒ Object
- #spatial? ⇒ Boolean
- #type_cast(value_) ⇒ Object
Constructor Details
#initialize(factory_settings_, table_name_, name_, default_, oid_type_, sql_type_ = nil, null_ = true, opts_ = nil) ⇒ SpatialColumn
Returns a new instance of SpatialColumn.
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb', line 11 def initialize(factory_settings_, table_name_, name_, default_, oid_type_, sql_type_=nil, null_=true, opts_=nil) @factory_settings = factory_settings_ @table_name = table_name_ @geographic = !!(sql_type_ =~ /geography/i) if opts_ # This case comes from an entry in the geometry_columns table @geometric_type = ::RGeo::ActiveRecord.geometric_type_from_name(opts_[:type]) || ::RGeo::Feature::Geometry @srid = opts_[:srid].to_i @has_z = !!opts_[:has_z] @has_m = !!opts_[:has_m] elsif @geographic # Geographic type information is embedded in the SQL type @geometric_type = ::RGeo::Feature::Geometry @srid = 4326 @has_z = @has_m = false if sql_type_ =~ /geography\((.*)\)$/i params_ = $1.split(',') if params_.size >= 2 if params_.first =~ /([a-z]+[^zm])(z?)(m?)/i @has_z = $2.length > 0 @has_m = $3.length > 0 @geometric_type = ::RGeo::ActiveRecord.geometric_type_from_name($1) end if params_.last =~ /(\d+)/ @srid = $1.to_i end end end elsif sql_type_ =~ /geography|geometry|point|linestring|polygon/i # Just in case there is a geometry column with no geometry_columns entry. @geometric_type = ::RGeo::Feature::Geometry @srid = @has_z = @has_m = nil else # Non-spatial column @geometric_type = @has_z = @has_m = @srid = nil end super(name_, default_, oid_type_, sql_type_, null_) if spatial? if @srid @limit = {:srid => @srid, :type => @geometric_type.type_name.underscore} @limit[:has_z] = true if @has_z @limit[:has_m] = true if @has_m @limit[:geographic] = true if @geographic else @limit = {:no_constraints => true} end end end |
Instance Attribute Details
#geographic ⇒ Object (readonly) Also known as: geographic?
Returns the value of attribute geographic.
61 62 63 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb', line 61 def geographic @geographic end |
#geometric_type ⇒ Object (readonly)
Returns the value of attribute geometric_type.
63 64 65 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb', line 63 def geometric_type @geometric_type end |
#has_m ⇒ Object (readonly) Also known as: has_m?
Returns the value of attribute has_m.
65 66 67 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb', line 65 def has_m @has_m end |
#has_z ⇒ Object (readonly) Also known as: has_z?
Returns the value of attribute has_z.
64 65 66 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb', line 64 def has_z @has_z end |
#srid ⇒ Object (readonly)
Returns the value of attribute srid.
62 63 64 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb', line 62 def srid @srid end |
Instance Method Details
#has_spatial_constraints? ⇒ Boolean
77 78 79 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb', line 77 def has_spatial_constraints? !@srid.nil? end |
#klass ⇒ Object
82 83 84 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb', line 82 def klass spatial? ? ::RGeo::Feature::Geometry : super end |
#spatial? ⇒ Boolean
72 73 74 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb', line 72 def spatial? type == :spatial || type == :geography end |
#type_cast(value_) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb', line 87 def type_cast(value_) if spatial? SpatialColumn.convert_to_geometry(value_, @factory_settings, @table_name, name, @geographic, @srid, @has_z, @has_m) else super end end |