module DbSerializer::GeoJSON
JSON Serializer
Public Instance Methods
db_serializer(field = :geometry)
click to toggle source
Allows to set the options for this gem @param field [Symbol] name of the attribute containing geometry @return [Hash]
# File lib/db_serializer/geo_json.rb, line 37 def db_serializer(field = :geometry) @db_serializer_options = {} @db_serializer_options[:field] = field.to_sym db_serializer_options end
db_serializer_options()
click to toggle source
Allows to get the options for this gem @return [Hash] contains keys :field
# File lib/db_serializer/geo_json.rb, line 46 def db_serializer_options if defined?(@db_serializer_options) @db_serializer_options elsif superclass.respond_to?(:db_serializer_options) superclass.db_serializer_options || {} else {} end end
to_geojson(columns = nil)
click to toggle source
Creates a json serialized FeatureCollection of the ActiveRecord::Relation.
FeatureCollection specs: wiki.geojson.org/GeoJSON_draft_version_6#FeatureCollection
It is already serialized so there is no need to apply .to_json
.
@param columns [Array<Symbol, String>] @return [String] JSON serialized FeatureCollection
# File lib/db_serializer/geo_json.rb, line 65 def to_geojson(columns = nil) features = set_geojson_attribute(columns) query = DbSerializer::Utilities::SQL.feature_collection(features) ActiveRecord::Base.connection.query_value(query) end