Module: Gis::GeoJSON
- Defined in:
- lib/gis/geo_json.rb
Class Method Summary collapse
- .aggregation(objects, properties = nil) ⇒ JSON object
- .feature(object) ⇒ Hash
- .feature_collection(objects, properties = nil) ⇒ geo_JSON object
Class Method Details
.aggregation(objects, properties = nil) ⇒ JSON object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gis/geo_json.rb', line 43 def self.aggregation(objects, properties = nil) count = 0 result = { 'type' => 'Aggregation', 'features' => [] } objects.each_with_index do |object, i| unless object.nil? if object.class.to_s == 'Hash' json = object.merge('id' => i + 1) else json = object.to_geo_json_feature.merge('id' => i + 1) # offset by one, since google getFeatureById(0) fails end result['features'].push(json) count += 1 end end unless properties.nil? result['properties'] = {properties.to_s => count} end result end |
.feature(object) ⇒ Hash
94 95 96 97 98 99 100 101 |
# File 'lib/gis/geo_json.rb', line 94 def self.feature(object) result = { 'type' => 'FeatureCollection', 'features' => [] } result['features'].push(object.to_geo_json_feature) result end |
.feature_collection(objects, properties = nil) ⇒ geo_JSON object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/gis/geo_json.rb', line 69 def self.feature_collection(objects, properties = nil) count = 0 result = { 'type' => 'FeatureCollection', 'features' => [] } objects.each_with_index do |object, i| unless object.nil? if object.class.to_s == 'Hash' json = object.merge('id' => i + 1) else json = object.to_geo_json_feature.merge('id' => i + 1) # offset by one, since google getFeatureById(0) fails end result['features'].push(json) count += 1 end end unless properties.nil? result['properties'] = {properties => {'count' => count}} end result end |