lib/geo_ruby/geojson.rb in georuby-1.9.3 vs lib/geo_ruby/geojson.rb in georuby-1.9.5

- old
+ new

@@ -1,6 +1,13 @@ # GeoJSON parser based on the v1.0 spec at http://geojson.org/geojson-spec.html +require 'rubygems' +begin + require 'json' +rescue LoadError + puts "You've loaded GeoRuby GeoJSON Support." + puts "Please install any 'json' provider gem. `gem install json`" +end module GeoRuby #Raised when an error in the GeoJSON string is detected class GeojsonFormatError < StandardError end @@ -21,16 +28,20 @@ else (self.id == other.id) && (self.geometry == other.geometry) && (self.properties == other.properties) end end - def to_json(options={}) + def as_json(options={}) output = {} output[:type] = 'Feature' output[:geometry] = geometry output[:properties] = properties output[:id] = id unless id.nil? output.to_json(options) + end + + def to_json(options = {}) + as_json(options).to_json end alias :as_geojson :to_json end # Class added to support geojson 'Feature Collection' objects