Permalink
Browse files

Merge pull request #20 from tjdett/test-fixes

Fixing GeoRSS namespace scoping and scoping use in specs
  • Loading branch information...
2 parents 483882e + 71b9d6c commit 7b989f3627f8e1d21b7260fc64be4cdd62b82173 @nofxx committed Oct 31, 2012
View
@@ -1,21 +1,7 @@
# $:.unshift(File.dirname(__FILE__)) #unless
# $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
-require 'geo_ruby/simple_features/helper'
-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 'geo_ruby/simple_features'
# Require if you need
# require 'geo_ruby/shp4r/shp'
View
@@ -8,6 +8,7 @@
end
module GeoRuby
+
#Raised when an error in the GeoJSON string is detected
class GeojsonFormatError < StandardError
end
@@ -73,6 +74,7 @@ def to_json(options = {})
class GeojsonParser
+ include GeoRuby::SimpleFeatures
attr_reader :geometry
def parse(geojson, srid=DEFAULT_SRID)
View
@@ -21,6 +21,7 @@ class GeorssTags < Struct.new(:featuretypetag,:relationshiptag,:elev,:floor,:rad
#Parses GeoRSS strings
#You can also use directly the static method Geometry.from_georss
class GeorssParser
+ include GeoRuby::SimpleFeatures
attr_reader :georss_tags, :geometry
#Parses the georss geometry passed as argument and notifies the factory of events
View
@@ -61,7 +61,7 @@ def accumulate_start(e)
def accumulate_end(e); @buffer << "</#{e[0]}>"; end
def parse_coordinates(buffer)
- if(buffer =~ /<coordinates>(.+)<\/coordinates>/)
+ if(buffer =~ /<coordinates>(.+)<\/coordinates>/m)
$1.gsub(/\n/, " ").strip.split(/\s+/).each do |coord|
x,y,z = coord.split(',')
if(x.nil? || y.nil?)
@@ -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
@@ -7,25 +7,25 @@
#
# TODO Refactor comon test approaches into methods
# 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 = Geometry.from_geojson(point_json)
- point.class.should eql(Point)
+ point = GeoRuby::SimpleFeatures::Geometry.from_geojson(point_json)
+ point.class.should eql(GeoRuby::SimpleFeatures::Point)
point_hash = JSON.parse(point_json)
point.to_coordinates.should eql(point_hash['coordinates'])
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] ]} }
- line_string = Geometry.from_geojson(ls_json)
- line_string.class.should eql(LineString)
+ line_string = GeoRuby::SimpleFeatures::Geometry.from_geojson(ls_json)
+ line_string.class.should eql(GeoRuby::SimpleFeatures::LineString)
ls_hash = JSON.parse(ls_json)
line_string.to_coordinates.should eql(ls_hash['coordinates'])
end
- it "should create a specified Polygon" do
+ it "should create a specified GeoRuby::SimpleFeatures::Polygon" do
poly_json = <<-EOJ
{ "type": "Polygon",
"coordinates": [
@@ -34,26 +34,26 @@
]
}
EOJ
- polygon = Geometry.from_geojson(poly_json)
- polygon.class.should eql(Polygon)
+ polygon = GeoRuby::SimpleFeatures::Geometry.from_geojson(poly_json)
+ polygon.class.should eql(GeoRuby::SimpleFeatures::Polygon)
polygon.rings.size.should eql(2)
poly_hash = JSON.parse(poly_json)
polygon.to_coordinates.should eql(poly_hash['coordinates'])
end
- it "should create a specified MultiPoint" do
+ it "should create a specified GeoRuby::SimpleFeatures::MultiPoint" do
mp_json = <<-EOJ
{ "type": "MultiPoint",
"coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
}
EOJ
- multi_point = Geometry.from_geojson(mp_json)
- multi_point.class.should eql(MultiPoint)
+ multi_point = GeoRuby::SimpleFeatures::Geometry.from_geojson(mp_json)
+ multi_point.class.should eql(GeoRuby::SimpleFeatures::MultiPoint)
mp_hash = JSON.parse(mp_json)
multi_point.to_coordinates.should eql(mp_hash['coordinates'])
end
- it "should create a specified MultiLineString" do
+ it "should create a specified GeoRuby::SimpleFeatures::MultiLineString" do
mls_json = <<-EOJ
{ "type": "MultiLineString",
"coordinates": [
@@ -62,13 +62,13 @@
]
}
EOJ
- multi_ls = Geometry.from_geojson(mls_json)
- multi_ls.class.should eql(MultiLineString)
+ multi_ls = GeoRuby::SimpleFeatures::Geometry.from_geojson(mls_json)
+ multi_ls.class.should eql(GeoRuby::SimpleFeatures::MultiLineString)
mls_hash = JSON.parse(mls_json)
multi_ls.to_coordinates.should eql(mls_hash['coordinates'])
end
- it "should create a specifiead MultiPolygon" do
+ it "should create a specifiead GeoRuby::SimpleFeatures::MultiPolygon" do
mpoly_json = <<-EOJ
{ "type": "MultiPolygon",
"coordinates": [
@@ -78,13 +78,13 @@
]
}
EOJ
- mpoly = Geometry.from_geojson(mpoly_json)
- mpoly.class.should eql(MultiPolygon)
+ mpoly = GeoRuby::SimpleFeatures::Geometry.from_geojson(mpoly_json)
+ mpoly.class.should eql(GeoRuby::SimpleFeatures::MultiPolygon)
mpoly_hash = JSON.parse(mpoly_json)
mpoly.to_coordinates.should eql(mpoly_hash['coordinates'])
end
- it "should create a specified GeometryCollection" do
+ it "should create a specified GeoRuby::SimpleFeatures::GeometryCollection" do
gcol_json = <<-EOJ
{ "type": "GeometryCollection",
"geometries": [
@@ -97,8 +97,8 @@
]
}
EOJ
- gcol = Geometry.from_geojson(gcol_json)
- gcol.class.should eql(GeometryCollection)
+ gcol = GeoRuby::SimpleFeatures::Geometry.from_geojson(gcol_json)
+ gcol.class.should eql(GeoRuby::SimpleFeatures::GeometryCollection)
gcol_hash = JSON.parse(gcol_json)
gcol.geometries.each_with_index do |g,i|
gh = gcol_hash['geometries'][i]
@@ -120,8 +120,8 @@
}
}
EOJ
- f = Geometry.from_geojson(feature_json)
- f.class.should eql(GeojsonFeature)
+ f = GeoRuby::SimpleFeatures::Geometry.from_geojson(feature_json)
+ f.class.should eql(GeoRuby::GeojsonFeature)
feature_hash = JSON.parse(feature_json)
f.id.should eql(feature_hash['id'])
f.properties.should eql(feature_hash['properties'])
@@ -131,8 +131,8 @@
it "should create a specified FeatureCollection" do
fcol_json = File.read(DATA_DIR + 'feature_collection.json')
- fcol = Geometry.from_geojson(fcol_json)
- fcol.class.should eql(GeojsonFeatureCollection)
+ fcol = GeoRuby::SimpleFeatures::Geometry.from_geojson(fcol_json)
+ fcol.class.should eql(GeoRuby::GeojsonFeatureCollection)
fcol_hash = JSON.parse(fcol_json)
fcol.features.each_with_index do |f,i|
fgh = fcol_hash['features'][i]['geometry']
Oops, something went wrong.

0 comments on commit 7b989f3

Please sign in to comment.