Module: Underpass::GeoJSON

Defined in:
lib/underpass/geo_json.rb

Overview

Encodes Feature arrays as GeoJSON FeatureCollections.

Examples:

Export query results to GeoJSON

features = Underpass::QL::Query.perform(bbox, query)
geojson = Underpass::GeoJSON.encode(features)

Class Method Summary collapse

Class Method Details

.encode(features) ⇒ Hash

Encodes an array of features as a GeoJSON FeatureCollection hash.

Parameters:

  • features (Array<Feature>)

    the features to encode

Returns:

  • (Hash)

    a GeoJSON FeatureCollection



16
17
18
19
20
21
# File 'lib/underpass/geo_json.rb', line 16

def self.encode(features)
  geo_features = features.map do |f|
    RGeo::GeoJSON::Feature.new(f.geometry, f.id, f.properties)
  end
  RGeo::GeoJSON.encode(RGeo::GeoJSON::FeatureCollection.new(geo_features))
end