Class: ActiveRecord::ConnectionAdapters::PostGISAdapter
Constant Summary
collapse
- ADAPTER_NAME =
'PostGIS'
- SPATIAL_COLUMN_OPTIONS =
{
geography: { geographic: true },
geometry: {},
geometry_collection: {},
line_string: {},
multi_line_string: {},
multi_point: {},
multi_polygon: {},
spatial: {},
st_point: {},
st_polygon: {},
}
- DEFAULT_SRID =
0
Class Method Summary
collapse
Instance Method Summary
collapse
#truncate_tables
#create_table_definition, #new_column_from_field, #spatial_column_info
#type_cast
Class Method Details
.initialize_type_map(map = type_map) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 67
def initialize_type_map(map = type_map)
%w[
geography
geometry
geometry_collection
line_string
multi_line_string
multi_point
multi_polygon
st_point
st_polygon
].each do |geo_type|
map.register_type(geo_type) do |_, _, sql_type|
geo_type, srid, has_z, has_m, geographic = PostGIS::OID::Spatial.parse_sql_type(sql_type)
PostGIS::OID::Spatial.new(geo_type: geo_type, srid: srid, has_z: has_z, has_m: has_m, geographic: geographic)
end
end
super
end
|
.native_database_types ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 94
def native_database_types
@native_database_types ||= begin
default_types = PostgreSQLAdapter.native_database_types
default_types.merge({
geography: { name: "geography" },
geometry: { name: "geometry" },
geometry_collection: { name: "geometry_collection" },
line_string: { name: "line_string" },
multi_line_string: { name: "multi_line_string" },
multi_point: { name: "multi_point" },
multi_polygon: { name: "multi_polygon" },
spatial: { name: "geometry" },
st_point: { name: "st_point" },
st_polygon: { name: "st_polygon" }
})
end
end
|
.spatial_column_options(key) ⇒ Object
54
55
56
|
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 54
def self.spatial_column_options(key)
SPATIAL_COLUMN_OPTIONS[key]
end
|
Instance Method Details
#arel_visitor ⇒ Object
50
51
52
|
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 50
def arel_visitor Arel::Visitors::PostGIS.new(self)
end
|
#default_srid ⇒ Object
62
63
64
|
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 62
def default_srid
DEFAULT_SRID
end
|
#postgis_lib_version ⇒ Object
58
59
60
|
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 58
def postgis_lib_version
@postgis_lib_version ||= select_value("SELECT PostGIS_Lib_Version()")
end
|
#quote(value) ⇒ Object
122
123
124
125
126
127
128
129
130
|
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 122
def quote(value)
if RGeo::Feature::Geometry.check_type(value)
"'#{RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(value)}'"
elsif value.is_a?(RGeo::Cartesian::BoundingBox)
"'#{value.min_x},#{value.min_y},#{value.max_x},#{value.max_y}'::box"
else
super
end
end
|
#quote_default_expression(value, column) ⇒ Object
132
133
134
135
136
137
138
|
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 132
def quote_default_expression(value, column)
if column.type == :geography || column.type == :geometry
quote(value)
else
super
end
end
|
#srs_database_columns ⇒ Object
113
114
115
116
117
118
119
120
|
# File 'lib/active_record/connection_adapters/postgis_adapter.rb', line 113
def srs_database_columns
{
auth_name_column: "auth_name",
auth_srid_column: "auth_srid",
proj4text_column: "proj4text",
srtext_column: "srtext",
}
end
|