Class: GeoRuby::SimpleFeatures::Geometry

Inherits:
Object
  • Object
show all
Defined in:
lib/geojson.rb

Class Method Summary collapse

Class Method Details

.from_geojson(data, srid = DEFAULT_SRID) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/geojson.rb', line 25

def self.from_geojson(data, srid=DEFAULT_SRID)
  data ||= {}
  if data.class==String
    require 'active_support' 
    data = ActiveSupport::JSON::decode(data)
  end
  coords = data['coordinates'] || data[:coordinates]
  case data['type'] || data[:type]
  when "Point"
    Point.from_coordinates(coords, srid)
  when "LineString"
    LineString.from_coordinates(coords, srid)
  when "Polygon"
    Polygon.from_coordinates(coords, srid)
  when "MultiPoint"
    MultiPoint.from_coordinates(coords, srid)
  when "MultiLineString"
    MultiLineString.from_coordinates(coords, srid)
  when "MultiPolygon"
    MultiPolygon.from_coordinates(coords, srid)
  when "GeometryCollection"
    geometriesJson=data['geometries'] || data[:geometries]
    geometries=geometriesJson.collect { |cur| from_geojson(cur, srid) }
    GeometryCollection.from_geometries(geometries, srid)
  when "Feature"
    geometryJson=data['geometry'] || data[:geometry]
    properties=data['properties'] || data[:properties]
    id=data['id'] || data[:id]
    Feature.new(from_geojson(geometryJson, srid), properties, id)
  when "FeatureCollection"
    features=data['features'] || data[:features]
    FeatureCollection.new(features.collect { |cur| from_geojson(cur, srid) })
  end
end