Skip to content

Commit

Permalink
Merge pull request #20 from tjdett/test-fixes
Browse files Browse the repository at this point in the history
Fixing GeoRSS namespace scoping and scoping use in specs
  • Loading branch information
nofxx committed Oct 31, 2012
2 parents 483882e + 71b9d6c commit 7b989f3
Show file tree
Hide file tree
Showing 27 changed files with 663 additions and 678 deletions.
16 changes: 1 addition & 15 deletions lib/geo_ruby.rb
@@ -1,21 +1,7 @@
# $:.unshift(File.dirname(__FILE__)) #unless # $:.unshift(File.dirname(__FILE__)) #unless
# $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) # $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))


require 'geo_ruby/simple_features/helper' require 'geo_ruby/simple_features'
require 'geo_ruby/simple_features/ewkt_parser'
require 'geo_ruby/simple_features/ewkb_parser'
require 'geo_ruby/simple_features/geometry'
require 'geo_ruby/simple_features/point'
require 'geo_ruby/simple_features/line_string'
require 'geo_ruby/simple_features/linear_ring'
require 'geo_ruby/simple_features/circle'
require 'geo_ruby/simple_features/polygon'
require 'geo_ruby/simple_features/multi_point'
require 'geo_ruby/simple_features/multi_line_string'
require 'geo_ruby/simple_features/multi_polygon'
require 'geo_ruby/simple_features/geometry_collection'
require 'geo_ruby/simple_features/envelope'
require 'geo_ruby/simple_features/geometry_factory'


# Require if you need # Require if you need
# require 'geo_ruby/shp4r/shp' # require 'geo_ruby/shp4r/shp'
Expand Down
2 changes: 2 additions & 0 deletions lib/geo_ruby/geojson.rb
Expand Up @@ -8,6 +8,7 @@
end end


module GeoRuby module GeoRuby

#Raised when an error in the GeoJSON string is detected #Raised when an error in the GeoJSON string is detected
class GeojsonFormatError < StandardError class GeojsonFormatError < StandardError
end end
Expand Down Expand Up @@ -73,6 +74,7 @@ def to_json(options = {})




class GeojsonParser class GeojsonParser
include GeoRuby::SimpleFeatures
attr_reader :geometry attr_reader :geometry


def parse(geojson, srid=DEFAULT_SRID) def parse(geojson, srid=DEFAULT_SRID)
Expand Down
1 change: 1 addition & 0 deletions lib/geo_ruby/georss.rb
Expand Up @@ -21,6 +21,7 @@ class GeorssTags < Struct.new(:featuretypetag,:relationshiptag,:elev,:floor,:rad
#Parses GeoRSS strings #Parses GeoRSS strings
#You can also use directly the static method Geometry.from_georss #You can also use directly the static method Geometry.from_georss
class GeorssParser class GeorssParser
include GeoRuby::SimpleFeatures
attr_reader :georss_tags, :geometry attr_reader :georss_tags, :geometry


#Parses the georss geometry passed as argument and notifies the factory of events #Parses the georss geometry passed as argument and notifies the factory of events
Expand Down
2 changes: 1 addition & 1 deletion lib/geo_ruby/kml.rb
Expand Up @@ -61,7 +61,7 @@ def accumulate_start(e)
def accumulate_end(e); @buffer << "</#{e[0]}>"; end def accumulate_end(e); @buffer << "</#{e[0]}>"; end


def parse_coordinates(buffer) def parse_coordinates(buffer)
if(buffer =~ /<coordinates>(.+)<\/coordinates>/) if(buffer =~ /<coordinates>(.+)<\/coordinates>/m)
$1.gsub(/\n/, " ").strip.split(/\s+/).each do |coord| $1.gsub(/\n/, " ").strip.split(/\s+/).each do |coord|
x,y,z = coord.split(',') x,y,z = coord.split(',')
if(x.nil? || y.nil?) if(x.nil? || y.nil?)
Expand Down
25 changes: 25 additions & 0 deletions lib/geo_ruby/simple_features.rb
@@ -0,0 +1,25 @@
module GeoRuby
module SimpleFeatures

%w[
geometry
circle
envelope
ewkb_parser
ewkt_parser
geometry_collection
geometry_factory
helper
line_string
linear_ring
multi_line_string
multi_point
multi_polygon
point
polygon
].each do |rel_file|
require File.join(File.dirname(__FILE__), 'simple_features', rel_file)
end

end
end
52 changes: 26 additions & 26 deletions spec/geo_ruby/geojson_spec.rb
Expand Up @@ -7,25 +7,25 @@
# #
# TODO Refactor comon test approaches into methods # TODO Refactor comon test approaches into methods
# TODO Add use of contexts? # TODO Add use of contexts?
describe GeojsonParser do describe GeoRuby::GeojsonParser do


it "should create a specified Point" do it "should create a specified GeoRuby::SimpleFeatures::Point" do
point_json = %{ { "type": "Point", "coordinates": [100.0, 0.0] } } point_json = %{ { "type": "Point", "coordinates": [100.0, 0.0] } }
point = Geometry.from_geojson(point_json) point = GeoRuby::SimpleFeatures::Geometry.from_geojson(point_json)
point.class.should eql(Point) point.class.should eql(GeoRuby::SimpleFeatures::Point)
point_hash = JSON.parse(point_json) point_hash = JSON.parse(point_json)
point.to_coordinates.should eql(point_hash['coordinates']) point.to_coordinates.should eql(point_hash['coordinates'])
end end


it "should create a specified LineString" do it "should create a specified GeoRuby::SimpleFeatures::LineString" do
ls_json = %{ { "type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]} } ls_json = %{ { "type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]} }
line_string = Geometry.from_geojson(ls_json) line_string = GeoRuby::SimpleFeatures::Geometry.from_geojson(ls_json)
line_string.class.should eql(LineString) line_string.class.should eql(GeoRuby::SimpleFeatures::LineString)
ls_hash = JSON.parse(ls_json) ls_hash = JSON.parse(ls_json)
line_string.to_coordinates.should eql(ls_hash['coordinates']) line_string.to_coordinates.should eql(ls_hash['coordinates'])
end end


it "should create a specified Polygon" do it "should create a specified GeoRuby::SimpleFeatures::Polygon" do
poly_json = <<-EOJ poly_json = <<-EOJ
{ "type": "Polygon", { "type": "Polygon",
"coordinates": [ "coordinates": [
Expand All @@ -34,26 +34,26 @@
] ]
} }
EOJ EOJ
polygon = Geometry.from_geojson(poly_json) polygon = GeoRuby::SimpleFeatures::Geometry.from_geojson(poly_json)
polygon.class.should eql(Polygon) polygon.class.should eql(GeoRuby::SimpleFeatures::Polygon)
polygon.rings.size.should eql(2) polygon.rings.size.should eql(2)
poly_hash = JSON.parse(poly_json) poly_hash = JSON.parse(poly_json)
polygon.to_coordinates.should eql(poly_hash['coordinates']) polygon.to_coordinates.should eql(poly_hash['coordinates'])
end end


it "should create a specified MultiPoint" do it "should create a specified GeoRuby::SimpleFeatures::MultiPoint" do
mp_json = <<-EOJ mp_json = <<-EOJ
{ "type": "MultiPoint", { "type": "MultiPoint",
"coordinates": [ [100.0, 0.0], [101.0, 1.0] ] "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
} }
EOJ EOJ
multi_point = Geometry.from_geojson(mp_json) multi_point = GeoRuby::SimpleFeatures::Geometry.from_geojson(mp_json)
multi_point.class.should eql(MultiPoint) multi_point.class.should eql(GeoRuby::SimpleFeatures::MultiPoint)
mp_hash = JSON.parse(mp_json) mp_hash = JSON.parse(mp_json)
multi_point.to_coordinates.should eql(mp_hash['coordinates']) multi_point.to_coordinates.should eql(mp_hash['coordinates'])
end end


it "should create a specified MultiLineString" do it "should create a specified GeoRuby::SimpleFeatures::MultiLineString" do
mls_json = <<-EOJ mls_json = <<-EOJ
{ "type": "MultiLineString", { "type": "MultiLineString",
"coordinates": [ "coordinates": [
Expand All @@ -62,13 +62,13 @@
] ]
} }
EOJ EOJ
multi_ls = Geometry.from_geojson(mls_json) multi_ls = GeoRuby::SimpleFeatures::Geometry.from_geojson(mls_json)
multi_ls.class.should eql(MultiLineString) multi_ls.class.should eql(GeoRuby::SimpleFeatures::MultiLineString)
mls_hash = JSON.parse(mls_json) mls_hash = JSON.parse(mls_json)
multi_ls.to_coordinates.should eql(mls_hash['coordinates']) multi_ls.to_coordinates.should eql(mls_hash['coordinates'])
end end


it "should create a specifiead MultiPolygon" do it "should create a specifiead GeoRuby::SimpleFeatures::MultiPolygon" do
mpoly_json = <<-EOJ mpoly_json = <<-EOJ
{ "type": "MultiPolygon", { "type": "MultiPolygon",
"coordinates": [ "coordinates": [
Expand All @@ -78,13 +78,13 @@
] ]
} }
EOJ EOJ
mpoly = Geometry.from_geojson(mpoly_json) mpoly = GeoRuby::SimpleFeatures::Geometry.from_geojson(mpoly_json)
mpoly.class.should eql(MultiPolygon) mpoly.class.should eql(GeoRuby::SimpleFeatures::MultiPolygon)
mpoly_hash = JSON.parse(mpoly_json) mpoly_hash = JSON.parse(mpoly_json)
mpoly.to_coordinates.should eql(mpoly_hash['coordinates']) mpoly.to_coordinates.should eql(mpoly_hash['coordinates'])
end end


it "should create a specified GeometryCollection" do it "should create a specified GeoRuby::SimpleFeatures::GeometryCollection" do
gcol_json = <<-EOJ gcol_json = <<-EOJ
{ "type": "GeometryCollection", { "type": "GeometryCollection",
"geometries": [ "geometries": [
Expand All @@ -97,8 +97,8 @@
] ]
} }
EOJ EOJ
gcol = Geometry.from_geojson(gcol_json) gcol = GeoRuby::SimpleFeatures::Geometry.from_geojson(gcol_json)
gcol.class.should eql(GeometryCollection) gcol.class.should eql(GeoRuby::SimpleFeatures::GeometryCollection)
gcol_hash = JSON.parse(gcol_json) gcol_hash = JSON.parse(gcol_json)
gcol.geometries.each_with_index do |g,i| gcol.geometries.each_with_index do |g,i|
gh = gcol_hash['geometries'][i] gh = gcol_hash['geometries'][i]
Expand All @@ -120,8 +120,8 @@
} }
} }
EOJ EOJ
f = Geometry.from_geojson(feature_json) f = GeoRuby::SimpleFeatures::Geometry.from_geojson(feature_json)
f.class.should eql(GeojsonFeature) f.class.should eql(GeoRuby::GeojsonFeature)
feature_hash = JSON.parse(feature_json) feature_hash = JSON.parse(feature_json)
f.id.should eql(feature_hash['id']) f.id.should eql(feature_hash['id'])
f.properties.should eql(feature_hash['properties']) f.properties.should eql(feature_hash['properties'])
Expand All @@ -131,8 +131,8 @@


it "should create a specified FeatureCollection" do it "should create a specified FeatureCollection" do
fcol_json = File.read(DATA_DIR + 'feature_collection.json') fcol_json = File.read(DATA_DIR + 'feature_collection.json')
fcol = Geometry.from_geojson(fcol_json) fcol = GeoRuby::SimpleFeatures::Geometry.from_geojson(fcol_json)
fcol.class.should eql(GeojsonFeatureCollection) fcol.class.should eql(GeoRuby::GeojsonFeatureCollection)
fcol_hash = JSON.parse(fcol_json) fcol_hash = JSON.parse(fcol_json)
fcol.features.each_with_index do |f,i| fcol.features.each_with_index do |f,i|
fgh = fcol_hash['features'][i]['geometry'] fgh = fcol_hash['features'][i]['geometry']
Expand Down

0 comments on commit 7b989f3

Please sign in to comment.