Module: ActiveRecord::ConnectionAdapters::PostGIS::ColumnExtensions
- Defined in:
- lib/active_record/connection_adapters/postgis/column_extensions.rb
Instance Method Summary collapse
- #geographic? ⇒ Boolean
- #geometric_type ⇒ Object
- #has_m? ⇒ Boolean
- #has_z? ⇒ Boolean
- #spatial? ⇒ Boolean
- #srid ⇒ Object
Instance Method Details
#geographic? ⇒ Boolean
13 14 15 |
# File 'lib/active_record/connection_adapters/postgis/column_extensions.rb', line 13 def geographic? sql_type.start_with?("geography") || (spatial? && limit.is_a?(Hash) && limit[:geographic]) end |
#geometric_type ⇒ Object
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/column_extensions.rb', line 32 def geometric_type if spatial? case type.to_sym when :st_point then RGeo::Feature::Point when :st_line_string then RGeo::Feature::LineString when :st_polygon then RGeo::Feature::Polygon when :st_multi_point then RGeo::Feature::MultiPoint when :st_multi_line_string then RGeo::Feature::MultiLineString when :st_multi_polygon then RGeo::Feature::MultiPolygon when :st_geometry_collection then RGeo::Feature::GeometryCollection when :st_geometry then RGeo::Feature::Geometry when :st_geography then RGeo::Feature::Geometry # Legacy types when :geometry then RGeo::Feature::Geometry when :geography then RGeo::Feature::Geometry when :line_string then RGeo::Feature::LineString when :polygon then RGeo::Feature::Polygon when :multi_point then RGeo::Feature::MultiPoint when :multi_line_string then RGeo::Feature::MultiLineString when :multi_polygon then RGeo::Feature::MultiPolygon when :geometry_collection then RGeo::Feature::GeometryCollection else RGeo::Feature::Geometry end else nil end end |
#has_m? ⇒ Boolean
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/active_record/connection_adapters/postgis/column_extensions.rb', line 74 def has_m? if spatial? if limit.is_a?(Hash) && limit.key?(:has_m) limit[:has_m] elsif sql_type =~ /\b\w+M\b|\b\w+ZM\b/ true else false end else nil end end |
#has_z? ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/active_record/connection_adapters/postgis/column_extensions.rb', line 60 def has_z? if spatial? if limit.is_a?(Hash) && limit.key?(:has_z) limit[:has_z] elsif sql_type =~ /\b\w+Z\b|\b\w+ZM\b/ true else false end else nil end end |
#spatial? ⇒ Boolean
7 8 9 10 11 |
# File 'lib/active_record/connection_adapters/postgis/column_extensions.rb', line 7 def spatial? type.to_s.start_with?("st_") || [ :geography, :geometry, :geometry_collection, :line_string, :multi_line_string, :multi_point, :multi_polygon, :polygon ].include?(type.to_sym) end |
#srid ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_record/connection_adapters/postgis/column_extensions.rb', line 17 def srid if spatial? if limit.is_a?(Hash) && limit[:srid] limit[:srid] elsif sql_type =~ /,(\d+)\)/ $1.to_i else geographic? ? 4326 : 0 end else nil end end |