Module: Gis::GeoJSON

Defined in:
lib/gis/geo_json.rb

Class Method Summary (collapse)

Class Method Details

+ (JSON object) aggregation(objects, properties = nil)

Parameters:

  • objects (Array feature_collections)

Returns:

  • (JSON object)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gis/geo_json.rb', line 42

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

+ (Object) feature(object)



91
92
93
94
95
96
97
98
# File 'lib/gis/geo_json.rb', line 91

def self.feature(object)
  result = {
    'type'     => 'FeatureCollection',
    'features' => []
  }
  result['features'].push(object.to_geo_json_feature)
  result
end

+ (geo_JSON object) feature_collection(objects, properties = nil)

Parameters:

  • objects (Array of instances that respond to .to_geo_json_feature)

Returns:

  • (geo_JSON object)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gis/geo_json.rb', line 68

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