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
-
.quick_geo_json(geographic_item_id) ⇒ GeoJSON
Content for geometry.
Class Method Details
.aggregation(objects, properties = nil) ⇒ JSON object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gis/geo_json.rb', line 6 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
56 57 58 59 60 61 62 63 |
# File 'lib/gis/geo_json.rb', line 56 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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gis/geo_json.rb', line 31 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 |
.quick_geo_json(geographic_item_id) ⇒ GeoJSON
Returns content for geometry.
66 67 68 |
# File 'lib/gis/geo_json.rb', line 66 def self.quick_geo_json(geographic_item_id) GeographicItem.find(geographic_item_id).to_geo_json end |