diff --git a/lib/geo_ruby.rb b/lib/geo_ruby.rb index ae712cb..703bd55 100644 --- a/lib/geo_ruby.rb +++ b/lib/geo_ruby.rb @@ -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' diff --git a/lib/geo_ruby/geojson.rb b/lib/geo_ruby/geojson.rb index e71a432..076db6c 100644 --- a/lib/geo_ruby/geojson.rb +++ b/lib/geo_ruby/geojson.rb @@ -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) diff --git a/lib/geo_ruby/georss.rb b/lib/geo_ruby/georss.rb index 186681d..360f5de 100644 --- a/lib/geo_ruby/georss.rb +++ b/lib/geo_ruby/georss.rb @@ -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 diff --git a/lib/geo_ruby/kml.rb b/lib/geo_ruby/kml.rb index c111bf9..4e33cb0 100644 --- a/lib/geo_ruby/kml.rb +++ b/lib/geo_ruby/kml.rb @@ -61,7 +61,7 @@ def accumulate_start(e) def accumulate_end(e); @buffer << ""; end def parse_coordinates(buffer) - if(buffer =~ /(.+)<\/coordinates>/) + if(buffer =~ /(.+)<\/coordinates>/m) $1.gsub(/\n/, " ").strip.split(/\s+/).each do |coord| x,y,z = coord.split(',') if(x.nil? || y.nil?) diff --git a/lib/geo_ruby/simple_features.rb b/lib/geo_ruby/simple_features.rb new file mode 100644 index 0000000..ce69513 --- /dev/null +++ b/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 diff --git a/spec/geo_ruby/geojson_spec.rb b/spec/geo_ruby/geojson_spec.rb index 9cc30e5..020a9a8 100644 --- a/spec/geo_ruby/geojson_spec.rb +++ b/spec/geo_ruby/geojson_spec.rb @@ -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'] diff --git a/spec/geo_ruby/georss.rb b/spec/geo_ruby/georss.rb deleted file mode 100644 index 43e9914..0000000 --- a/spec/geo_ruby/georss.rb +++ /dev/null @@ -1,218 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') - -describe GeorssParser do - it "test_point_creation" do - point = Point.from_x_y(3,4) - - point.as_georss(:dialect => :simple, :elev => 45.7, :featuretypetag => "hoyoyo").gsub("\n","").should eql("4 3") - point.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("43") - point.as_georss(:dialect => :gml).gsub("\n","").should eql("4 3") - - point.as_kml(:id => "HOYOYO-42").gsub("\n","").should eql("3,4") - end - - it "test_line_string" do - ls = LineString.from_points([Point.from_lon_lat_z(12.4,-45.3,56),Point.from_lon_lat_z(45.4,41.6,45)],123,true) - - ls.as_georss.gsub("\n","").should eql("-45.3 12.4 41.6 45.4") - ls.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("-45.312.4") - ls.as_georss(:dialect => :gml).gsub("\n","").should eql("-45.3 12.4 41.6 45.4") - - ls.as_kml(:extrude => 1, :altitude_mode => "absolute").gsub("\n","").should eql("1absolute12.4,-45.3,56 45.4,41.6,45") - end - - it "test_polygon" do - linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256) - linear_ring2 = LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256) - polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256) - - polygon.as_georss(:georss_ns => "hoyoyo").gsub("\n","").should eql("-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4") - polygon.as_georss(:dialect => :w3cgeo, :w3cgeo_ns => "bouyoul").gsub("\n","").should eql("-45.312.4") - polygon.as_georss(:dialect => :gml).gsub("\n","").should eql("-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4") - - polygon.as_kml.gsub("\n","").should eql("12.4,-45.3 45.4,41.6 4.456,1.0698 12.4,-45.32.4,5.3 5.4,1.4263 14.46,1.06 2.4,5.3") - end - - it "test_geometry_collection" do - gc = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) - - #only the first geometry is output - gc.as_georss(:dialect => :simple,:floor => 4).gsub("\n","").should eql("45.4 4.67") - gc.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("45.44.67") - gc.as_georss(:dialect => :gml).gsub("\n","").should eql("45.4 4.67") - - gc.as_kml(:id => "HOYOYO-42").gsub("\n","").should eql("4.67,45.45.7,12.45 67.55,54") - end - - it "test_envelope" do - linear_ring1 = LinearRing.from_coordinates([[12,-45,5],[45,41,6],[4,1,8],[12.4,-45,3]],256,true) - linear_ring2 = LinearRing.from_coordinates([[2,5,9],[5.4,1,-5.4],[14,1,34],[2,5,3]],256,true) - polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256,true) - - e = polygon.envelope - - e.as_georss(:dialect => :simple).gsub("\n","").should eql("-45 4 41 45") - #center - e.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("-224") - e.as_georss(:dialect => :gml).gsub("\n","").should eql("-45 441 45") - - e.as_kml.gsub("\n","").should eql("41-45454-5.434") - end - - it "test_point_georss_read" do - #W3CGeo - str = " 12.3\n\t 4.56 " - geom = Geometry.from_georss(str) - geom.class.should eql(Point) - geom.lat.should eql(12.3) - geom.lon.should eql(4.56) - - str = " \n \t 4.56 \n\t 12.3 " - geom = Geometry.from_georss(str) - geom.class.should eql(Point) - geom.lat.should eql(12.3) - geom.lon.should eql(4.56) - - #gml - str = " \t\r \t 4 \t 3 " - geom = Geometry.from_georss(str) - geom.class.should eql(Point) - geom.lat.should eql(4.0) - geom.lon.should eql(3.0) - - #simple - str = " 4 \r\t 3 \t" - geom = Geometry.from_georss(str) - geom.class.should eql(Point) - geom.lat.should eql(4.0) - geom.lon.should eql(3.0) - - #simple with tags - str = " 4 \n 3 \t" - geom,tags = Geometry.from_georss_with_tags(str) - geom.class.should eql(Point) - geom.lat.should eql(4.0) - geom.lon.should eql(3.0) - tags.featuretypetag.should eql("hoyoyo") - tags.elev.should eql(45.7) - tags.relationshiptag.should eql("puyopuyo") - tags.floor.should eql(2) - tags.radius.should eql(42.0) - end - - it "test_line_string_georss_read" do - ls = LineString.from_points([Point.from_lon_lat(12.4,-45.3),Point.from_lon_lat(45.4,41.6)]) - - str = " -45.3 12.4 \n \r41.6\t 45.4" - geom = Geometry.from_georss(str) - geom.class.should eql(LineString) - ls.should == geom - - str = "-45.3 12.4 41.6 45.4" - geom = Geometry.from_georss(str) - geom.class.should eql(LineString) - ls.should == geom - end - - it "test_polygon_georss_read" do - linear_ring = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]]) - polygon = Polygon.from_linear_rings([linear_ring]) - - str = " -45.3 12.4 41.6 \n\r 45.4 1.0698 \r 4.456 -45.3 12.4 " - geom = Geometry.from_georss(str) - geom.class.should eql(Polygon) - polygon.should == geom - - str = "\r\t \n -45.3 \n\r 12.4 41.6 \n\t 45.4 1.0698 4.456 -45.3 12.4" - geom = Geometry.from_georss(str) - geom.class.should eql(Polygon) - polygon.should == geom - end - - it "test_envelope_georss_read" do - e = Envelope.from_coordinates([[4.456,-45.3],[45.4,41.6]]) - - str = "-45.3 4.456 \n41.6 45.4" - geom = Geometry.from_georss(str) - geom.class.should eql(Envelope) - geom.should == e - - str = "-45.3 \n 4.45641.6 \t\n 45.4" - geom = Geometry.from_georss(str) - geom.class.should eql(Envelope) - geom.should == e - end - - it "test_kml_read" do - g = Geometry.from_kml("45,12,25") - g.should be_a Point - g.should == Point.from_x_y_z(45,12,25) - - g = Geometry.from_kml(" - 1 - 1 - - -122.364383,37.824664,0 -122.364152,37.824322,0 - - ") - g.should be_a LineString - g.length.should eql(2) - g.should == LineString.from_points([Point.from_x_y_z(-122.364383,37.824664,0),Point.from_x_y_z(-122.364152,37.824322,0)],4326,true) - - g = Geometry.from_kml(" - 1 - relativeToGround - - - - -122.366278,37.818844,30 - -122.365248,37.819267,30 - -122.365640,37.819861,30 - -122.366669,37.819429,30 - -122.366278,37.818844,30 - - - - - - - -122.366212,37.818977,30 - -122.365424,37.819294,30 - -122.365704,37.819731,30 - -122.366488,37.819402,30 - -122.366212,37.818977,30 - - - - - - - -122.366212,37.818977,30 - -122.365424,37.819294,30 - -122.365704,37.819731,30 - -122.366488,37.819402,30 - -122.366212,37.818977,30 - - - - ") - g.should be_a Polygon - g.length.should eql(3) - end - - it "test_to_kml_for_point_does_not_raise_type_error_if_geom_data_not_provided" do - point = Point.from_coordinates([1.6,2.8],123) - lambda { point.kml_representation }.should_not raise_error(TypeError) - end - - it "test_to_kml_for_polygon_does_not_raise_type_error_if_geom_data_not_provided" do - polygon = Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) - lambda { polygon.kml_representation }.should_not raise_error(TypeError) - end - - it "test_to_kml_for_line_string_does_not_raise_type_error_if_geom_data_not_provided" do - ls = LineString.from_coordinates([[5.7,12.45],[67.55,54]],256) - lambda { ls.kml_representation }.should_not raise_error(TypeError) - end - -end diff --git a/spec/geo_ruby/georss_spec.rb b/spec/geo_ruby/georss_spec.rb index 27365c4..46c3156 100644 --- a/spec/geo_ruby/georss_spec.rb +++ b/spec/geo_ruby/georss_spec.rb @@ -2,13 +2,225 @@ RSS_DATA_DIR = File.dirname(__FILE__) + '/../data/georss/' -describe GeorssParser do +describe GeoRuby::GeorssParser do it "should parse an rss file" do - geo = GeorssParser.new.parse(File.read(RSS_DATA_DIR + "/w3c.xml")) - geo.should be_a Point + geo = subject.parse(File.read(RSS_DATA_DIR + "/w3c.xml")) + geo.should be_a GeoRuby::SimpleFeatures::Point end + it "test_point_creation" do + point = GeoRuby::SimpleFeatures::Point.from_x_y(3,4) + point.as_georss(:dialect => :simple, :elev => 45.7, :featuretypetag => "hoyoyo").gsub("\n","").should eql("4 3") + point.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("43") + point.as_georss(:dialect => :gml).gsub("\n","").should eql("4 3") + + point.as_kml(:id => "HOYOYO-42").gsub("\n","").should eql("3,4") + end + + it "test_line_string" do + ls = GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.from_lon_lat_z(12.4,-45.3,56),GeoRuby::SimpleFeatures::Point.from_lon_lat_z(45.4,41.6,45)],123,true) + + ls.as_georss.gsub("\n","").should eql("-45.3 12.4 41.6 45.4") + ls.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("-45.312.4") + ls.as_georss(:dialect => :gml).gsub("\n","").should eql("-45.3 12.4 41.6 45.4") + + ls.as_kml(:extrude => 1, :altitude_mode => "absolute").gsub("\n","").should eql("1absolute12.4,-45.3,56 45.4,41.6,45") + end + + it "test_polygon" do + linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256) + linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256) + polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring1,linear_ring2],256) + + polygon.as_georss(:georss_ns => "hoyoyo").gsub("\n","").should eql("-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4") + polygon.as_georss(:dialect => :w3cgeo, :w3cgeo_ns => "bouyoul").gsub("\n","").should eql("-45.312.4") + polygon.as_georss(:dialect => :gml).gsub("\n","").should eql("-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4") + + polygon.as_kml.gsub("\n","").should eql("12.4,-45.3 45.4,41.6 4.456,1.0698 12.4,-45.32.4,5.3 5.4,1.4263 14.46,1.06 2.4,5.3") + end + + it "test_geometry_collection" do + gc = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) + + #only the first geometry is output + gc.as_georss(:dialect => :simple,:floor => 4).gsub("\n","").should eql("45.4 4.67") + gc.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("45.44.67") + gc.as_georss(:dialect => :gml).gsub("\n","").should eql("45.4 4.67") + + gc.as_kml(:id => "HOYOYO-42").gsub("\n","").should eql("4.67,45.45.7,12.45 67.55,54") + end + + it "test_envelope" do + linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12,-45,5],[45,41,6],[4,1,8],[12.4,-45,3]],256,true) + linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2,5,9],[5.4,1,-5.4],[14,1,34],[2,5,3]],256,true) + polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring1,linear_ring2],256,true) + + e = polygon.envelope + + e.as_georss(:dialect => :simple).gsub("\n","").should eql("-45 4 41 45") + #center + e.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("-224") + e.as_georss(:dialect => :gml).gsub("\n","").should eql("-45 441 45") + + e.as_kml.gsub("\n","").should eql("41-45454-5.434") + end + + it "test_point_georss_read" do + #W3CGeo + str = " 12.3\n\t 4.56 " + geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str) + geom.class.should eql(GeoRuby::SimpleFeatures::Point) + geom.lat.should eql(12.3) + geom.lon.should eql(4.56) + + str = " \n \t 4.56 \n\t 12.3 " + geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str) + geom.class.should eql(GeoRuby::SimpleFeatures::Point) + geom.lat.should eql(12.3) + geom.lon.should eql(4.56) + + #gml + str = " \t\r \t 4 \t 3 " + geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str) + geom.class.should eql(GeoRuby::SimpleFeatures::Point) + geom.lat.should eql(4.0) + geom.lon.should eql(3.0) + + #simple + str = " 4 \r\t 3 \t" + geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str) + geom.class.should eql(GeoRuby::SimpleFeatures::Point) + geom.lat.should eql(4.0) + geom.lon.should eql(3.0) + + #simple with tags + str = " 4 \n 3 \t" + geom,tags = GeoRuby::SimpleFeatures::Geometry.from_georss_with_tags(str) + geom.class.should eql(GeoRuby::SimpleFeatures::Point) + geom.lat.should eql(4.0) + geom.lon.should eql(3.0) + tags.featuretypetag.should eql("hoyoyo") + tags.elev.should eql(45.7) + tags.relationshiptag.should eql("puyopuyo") + tags.floor.should eql(2) + tags.radius.should eql(42.0) + end + + it "test_line_string_georss_read" do + ls = GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.from_lon_lat(12.4,-45.3),GeoRuby::SimpleFeatures::Point.from_lon_lat(45.4,41.6)]) + + str = " -45.3 12.4 \n \r41.6\t 45.4" + geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str) + geom.class.should eql(GeoRuby::SimpleFeatures::LineString) + ls.should == geom + + str = "-45.3 12.4 41.6 45.4" + geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str) + geom.class.should eql(GeoRuby::SimpleFeatures::LineString) + ls.should == geom + end + + it "test_polygon_georss_read" do + linear_ring = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]]) + polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring]) + + str = " -45.3 12.4 41.6 \n\r 45.4 1.0698 \r 4.456 -45.3 12.4 " + geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str) + geom.class.should eql(GeoRuby::SimpleFeatures::Polygon) + polygon.should == geom + + str = "\r\t \n -45.3 \n\r 12.4 41.6 \n\t 45.4 1.0698 4.456 -45.3 12.4" + geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str) + geom.class.should eql(GeoRuby::SimpleFeatures::Polygon) + polygon.should == geom + end + + it "test_envelope_georss_read" do + e = GeoRuby::SimpleFeatures::Envelope.from_coordinates([[4.456,-45.3],[45.4,41.6]]) + + str = "-45.3 4.456 \n41.6 45.4" + geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str) + geom.class.should eql(GeoRuby::SimpleFeatures::Envelope) + geom.should == e + + str = "-45.3 \n 4.45641.6 \t\n 45.4" + geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str) + geom.class.should eql(GeoRuby::SimpleFeatures::Envelope) + geom.should == e + end + + it "test_kml_read" do + g = GeoRuby::SimpleFeatures::Geometry.from_kml("45,12,25") + g.should be_a GeoRuby::SimpleFeatures::Point + g.should == GeoRuby::SimpleFeatures::Point.from_x_y_z('45','12','25') + + g = GeoRuby::SimpleFeatures::Geometry.from_kml(" + 1 + 1 + + -122.364383,37.824664,0 -122.364152,37.824322,0 + + ") + g.should be_a GeoRuby::SimpleFeatures::LineString + g.length.should eql(2) + g.should == GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.from_x_y_z('-122.364383','37.824664','0'),GeoRuby::SimpleFeatures::Point.from_x_y_z('-122.364152','37.824322','0')],4326,true) + + g = GeoRuby::SimpleFeatures::Geometry.from_kml(" + 1 + relativeToGround + + + + -122.366278,37.818844,30 + -122.365248,37.819267,30 + -122.365640,37.819861,30 + -122.366669,37.819429,30 + -122.366278,37.818844,30 + + + + + + + -122.366212,37.818977,30 + -122.365424,37.819294,30 + -122.365704,37.819731,30 + -122.366488,37.819402,30 + -122.366212,37.818977,30 + + + + + + + -122.366212,37.818977,30 + -122.365424,37.819294,30 + -122.365704,37.819731,30 + -122.366488,37.819402,30 + -122.366212,37.818977,30 + + + + ") + g.should be_a GeoRuby::SimpleFeatures::Polygon + g.length.should eql(3) + end + + it "test_to_kml_for_point_does_not_raise_type_error_if_geom_data_not_provided" do + point = GeoRuby::SimpleFeatures::Point.from_coordinates([1.6,2.8],123) + lambda { point.kml_representation }.should_not raise_error(TypeError) + end + + it "test_to_kml_for_polygon_does_not_raise_type_error_if_geom_data_not_provided" do + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) + lambda { polygon.kml_representation }.should_not raise_error(TypeError) + end + + it "test_to_kml_for_line_string_does_not_raise_type_error_if_geom_data_not_provided" do + ls = GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256) + lambda { ls.kml_representation }.should_not raise_error(TypeError) + end end diff --git a/spec/geo_ruby/gpx4r/gpx_spec.rb b/spec/geo_ruby/gpx4r/gpx_spec.rb index a7087b7..5c24ea7 100644 --- a/spec/geo_ruby/gpx4r/gpx_spec.rb +++ b/spec/geo_ruby/gpx4r/gpx_spec.rb @@ -1,23 +1,20 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -include GeoRuby::Gpx4r -include GeoRuby::SimpleFeatures - -describe Gpx4r do +describe GeoRuby::Gpx4r do it "should add gpx extension and raise if doesn't exists" do lambda do File.should_receive(:exists?).with("short.gpx").and_return(false) - GpxFile.open('short').should be_true - end.should raise_error MalformedGpxException + GeoRuby::Gpx4r::GpxFile.open('short').should be_true + end.should raise_error GeoRuby::Gpx4r::MalformedGpxException end describe "Waypoints" do before(:all) do - @gpxfile = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/short.gpx', :with_z => true, :with_m => true) - @gpxfile2 = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/fells_loop', :with_z => true, :with_m => true) - @gpxfile3 = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/tracktreks.gpx', :with_z => true) + @gpxfile = GeoRuby::Gpx4r::GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/short.gpx', :with_z => true, :with_m => true) + @gpxfile2 = GeoRuby::Gpx4r::GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/fells_loop', :with_z => true, :with_m => true) + @gpxfile3 = GeoRuby::Gpx4r::GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/tracktreks.gpx', :with_z => true) end it "should open and parse" do @@ -63,43 +60,43 @@ end it "should return it as a linestring" do - @gpxfile.as_line_string.should be_instance_of LineString - @gpxfile.as_polyline.should be_instance_of LineString + @gpxfile.as_line_string.should be_instance_of GeoRuby::SimpleFeatures::LineString + @gpxfile.as_polyline.should be_instance_of GeoRuby::SimpleFeatures::LineString end it "should return it as a linestring 3" do - @gpxfile3.as_line_string.should be_instance_of LineString - @gpxfile3.as_polyline.should be_instance_of LineString + @gpxfile3.as_line_string.should be_instance_of GeoRuby::SimpleFeatures::LineString + @gpxfile3.as_polyline.should be_instance_of GeoRuby::SimpleFeatures::LineString end it "should return a envelope" do - @gpxfile.envelope.should be_instance_of Envelope + @gpxfile.envelope.should be_instance_of GeoRuby::SimpleFeatures::Envelope @gpxfile.envelope.lower_corner.x.should be_within(0.001).of(9.08128) @gpxfile.envelope.lower_corner.y.should be_within(0.001).of(48.7169) end it "should return a envelope 3" do - @gpxfile3.envelope.should be_instance_of Envelope + @gpxfile3.envelope.should be_instance_of GeoRuby::SimpleFeatures::Envelope @gpxfile3.envelope.lower_corner.x.should be_within(0.001).of(-149.8422613) @gpxfile3.envelope.lower_corner.y.should be_within(0.001).of(-17.547636) end it "should return it as a polygon" do [@gpxfile, @gpxfile2, @gpxfile3].each do |g| - g.as_polygon.should be_instance_of Polygon - g.as_polygon[0].should be_instance_of LinearRing + g.as_polygon.should be_instance_of GeoRuby::SimpleFeatures::Polygon + g.as_polygon[0].should be_instance_of GeoRuby::SimpleFeatures::LinearRing g.as_polygon[0].should be_closed g.as_polygon[1].should be_nil end end it "should close the polygon" do - se = Point.from_x_y(-44, -23) - sw = Point.from_x_y(-42, -22) - nw = Point.from_x_y(-42, -25) - ne = Point.from_x_y(-44, -21) + se = GeoRuby::SimpleFeatures::Point.from_x_y(-44, -23) + sw = GeoRuby::SimpleFeatures::Point.from_x_y(-42, -22) + nw = GeoRuby::SimpleFeatures::Point.from_x_y(-42, -25) + ne = GeoRuby::SimpleFeatures::Point.from_x_y(-44, -21) @gpxfile.instance_variable_set(:@points, [se,sw,nw,ne]) - @gpxfile.as_polygon.should == Polygon.from_points([[se,sw,nw,ne,se]]) + @gpxfile.as_polygon.should == GeoRuby::SimpleFeatures::Polygon.from_points([[se,sw,nw,ne,se]]) end end diff --git a/spec/geo_ruby/kml_spec.rb b/spec/geo_ruby/kml_spec.rb index 0ebd805..72ef6c5 100644 --- a/spec/geo_ruby/kml_spec.rb +++ b/spec/geo_ruby/kml_spec.rb @@ -1,6 +1,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe KmlParser do +describe GeoRuby::KmlParser do before(:all) do POINT = "-82.4898187291883,34.2473206042649" LINESTRING = "-122.365662,37.826988 -122.365202,37.826302 -122.364581,37.82655 -122.365038,37.827237" @@ -14,11 +14,11 @@ end before(:each) do - @factory = GeometryFactory.new - @kml_parser = KmlParser.new(@factory) + @factory = GeoRuby::SimpleFeatures::GeometryFactory.new + @kml_parser = described_class.new(@factory) end - it "should parse a Point correctly" do + it "should parse a GeoRuby::SimpleFeatures::Point correctly" do @kml_parser.parse(POINT) g = @factory.geometry g.should_not eql(nil) @@ -26,7 +26,7 @@ g.as_kml.gsub(/\n/,'').should eql(POINT) end - it "should parse a LineString correctly" do + it "should parse a GeoRuby::SimpleFeatures::LineString correctly" do @kml_parser.parse(LINESTRING) g = @factory.geometry g.should_not eql(nil) @@ -40,7 +40,7 @@ g.as_kml.gsub(/\n/,'').should eql(LINEARRING) end - it "should parse a Polygon correctly" do + it "should parse a GeoRuby::SimpleFeatures::Polygon correctly" do @kml_parser.parse(POLYGON) g = @factory.geometry g.should_not eql(nil) diff --git a/spec/geo_ruby/shp4r/shp_spec.rb b/spec/geo_ruby/shp4r/shp_spec.rb index c6648e9..cc59bad 100644 --- a/spec/geo_ruby/shp4r/shp_spec.rb +++ b/spec/geo_ruby/shp4r/shp_spec.rb @@ -1,18 +1,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -include GeoRuby::Shp4r - -describe Shp4r do +describe GeoRuby::Shp4r do describe "Point" do before(:each) do - @shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/point.shp') + @shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/point.shp') end it "should parse ok" do @shpfile.record_count.should eql(2) @shpfile.should have(1).fields - @shpfile.shp_type.should eql(ShpType::POINT) + @shpfile.shp_type.should eql(GeoRuby::Shp4r::ShpType::POINT) end it "should parse fields" do @@ -23,7 +21,7 @@ it "should parse record 1" do rec = @shpfile[0] - rec.geometry.should be_kind_of Point + rec.geometry.should be_kind_of GeoRuby::SimpleFeatures::Point rec.geometry.x.should be_within(0.00001).of(-90.08375) rec.geometry.y.should be_within(0.00001).of(34.39996) rec.data["Hoyoyo"].should eql(6) @@ -31,7 +29,7 @@ it "should parse record 2" do rec = @shpfile[1] - rec.geometry.should be_kind_of Point + rec.geometry.should be_kind_of GeoRuby::SimpleFeatures::Point rec.geometry.x.should be_within(0.00001).of(-87.82580) rec.geometry.y.should be_within(0.00001).of(33.36416) rec.data["Hoyoyo"].should eql(9) @@ -41,26 +39,26 @@ describe "Polyline" do before(:each) do - @shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polyline.shp') + @shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/polyline.shp') end it "should parse ok" do @shpfile.record_count.should eql(1) @shpfile.should have(1).fields - @shpfile.shp_type.should eql(ShpType::POLYLINE) + @shpfile.shp_type.should eql(GeoRuby::Shp4r::ShpType::POLYLINE) end it "should parse fields" do field = @shpfile.fields.first field.name.should eql("Chipoto") - # Dbf now uses the decimal to choose between int and float + # GeoRuby::Shp4r::Dbf now uses the decimal to choose between int and float # So here is N instead of F field.type.should eql("N") end it "should parse record 1" do rec = @shpfile[0] - rec.geometry.should be_kind_of MultiLineString + rec.geometry.should be_kind_of GeoRuby::SimpleFeatures::MultiLineString rec.geometry.length.should eql(1) rec.geometry[0].length.should eql(6) rec.data["Chipoto"].should eql(5.678) @@ -70,13 +68,13 @@ describe "Polygon" do before(:each) do - @shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon.shp') + @shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon.shp') end it "should parse ok" do @shpfile.record_count.should eql(1) @shpfile.should have(1).fields - @shpfile.shp_type.should eql(ShpType::POLYGON) + @shpfile.shp_type.should eql(GeoRuby::Shp4r::ShpType::POLYGON) end it "should parse fields" do @@ -87,7 +85,7 @@ it "should parse record 1" do rec = @shpfile[0] - rec.geometry.should be_kind_of MultiPolygon + rec.geometry.should be_kind_of GeoRuby::SimpleFeatures::MultiPolygon rec.geometry.length.should eql(1) rec.geometry[0].length.should eql(1) rec.geometry[0][0].length.should eql(7) @@ -111,12 +109,12 @@ def rm_all_shp(file) it "test_point" do cp_all_shp(File.dirname(__FILE__) + '/../../data/point', File.dirname(__FILE__) + '/../../data/point2') - shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/point2.shp') + shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/point2.shp') shpfile.transaction do |tr| - tr.should be_instance_of ShpTransaction - tr.add(ShpRecord.new(Point.from_x_y(123.4,123.4),'Hoyoyo' => 5)) - tr.add(ShpRecord.new(Point.from_x_y(-16.67,16.41),'Hoyoyo' => -7)) + tr.should be_instance_of GeoRuby::Shp4r::ShpTransaction + tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Point.from_x_y(123.4,123.4),'Hoyoyo' => 5)) + tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Point.from_x_y(-16.67,16.41),'Hoyoyo' => -7)) tr.delete(1) end @@ -130,12 +128,12 @@ def rm_all_shp(file) cp_all_shp(File.dirname(__FILE__) + '/../../data/polyline', File.dirname(__FILE__) + '/../../data/polyline2') - shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polyline2.shp') + shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/polyline2.shp') shpfile.transaction do |tr| - tr.should be_instance_of ShpTransaction - tr.add(ShpRecord.new(LineString.from_coordinates([[123.4,123.4],[45.6,12.3]]),'Chipoto' => 5.6778)) - tr.add(ShpRecord.new(LineString.from_coordinates([[23.4,13.4],[45.6,12.3],[12,-67]]),'Chipoto' => -7.1)) + tr.should be_instance_of GeoRuby::Shp4r::ShpTransaction + tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::LineString.from_coordinates([[123.4,123.4],[45.6,12.3]]),'Chipoto' => 5.6778)) + tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::LineString.from_coordinates([[23.4,13.4],[45.6,12.3],[12,-67]]),'Chipoto' => -7.1)) tr.delete(0) end @@ -147,12 +145,12 @@ def rm_all_shp(file) it "test_polygon" do cp_all_shp(File.dirname(__FILE__) + '/../../data/polygon', File.dirname(__FILE__) + '/../../data/polygon2') - shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon2.shp') + shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon2.shp') shpfile.transaction do |tr| - tr.should be_instance_of ShpTransaction + tr.should be_instance_of GeoRuby::Shp4r::ShpTransaction tr.delete(0) - tr.add(ShpRecord.new(Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]]),'Hello' => "oook")) + tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]]),'Hello' => "oook")) end shpfile.record_count.should eql(1) @@ -164,11 +162,11 @@ def rm_all_shp(file) it "test_multipoint" do cp_all_shp(File.dirname(__FILE__) + '/../../data/multipoint', File.dirname(__FILE__) + '/../../data/multipoint2') - shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/multipoint2.shp') + shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/multipoint2.shp') shpfile.transaction do |tr| - tr.should be_instance_of ShpTransaction - tr.add(ShpRecord.new(MultiPoint.from_coordinates([[45.6,-45.1],[12.4,98.2],[51.2,-0.12],[156.12345,56.109]]),'Hello' => 5,"Hoyoyo" => "AEZAE")) + tr.should be_instance_of GeoRuby::Shp4r::ShpTransaction + tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[45.6,-45.1],[12.4,98.2],[51.2,-0.12],[156.12345,56.109]]),'Hello' => 5,"Hoyoyo" => "AEZAE")) end shpfile.record_count.should eql(2) @@ -181,11 +179,11 @@ def rm_all_shp(file) cp_all_shp(File.dirname(__FILE__) + '/../../data/polygon', File.dirname(__FILE__) + '/../../data/polygon4') - shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon4.shp') + shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon4.shp') shpfile.transaction do |tr| - tr.should be_instance_of ShpTransaction - tr.add(ShpRecord.new(MultiPolygon.from_polygons([Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]])]),'Hello' => "oook")) + tr.should be_instance_of GeoRuby::Shp4r::ShpTransaction + tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]])]),'Hello' => "oook")) end shpfile.record_count.should eql(2) @@ -199,11 +197,11 @@ def rm_all_shp(file) cp_all_shp(File.dirname(__FILE__) + '/../../data/polygon', File.dirname(__FILE__) + '/../../data/polygon5') - shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon5.shp') + shpfile = GeoRuby::Shp4r::ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon5.shp') shpfile.transaction do |tr| - tr.should be_instance_of ShpTransaction - tr.add(ShpRecord.new(MultiPolygon.from_polygons([Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]])]),'Hello' => "oook")) + tr.should be_instance_of GeoRuby::Shp4r::ShpTransaction + tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]])]),'Hello' => "oook")) tr.rollback end shpfile.record_count.should eql(1) @@ -215,9 +213,9 @@ def rm_all_shp(file) end it "test_creation" do - shpfile = ShpFile.create(File.dirname(__FILE__) + '/../../data/point3.shp',ShpType::POINT,[Dbf::Field.new("Hoyoyo","C",10,0)]) + shpfile = GeoRuby::Shp4r::ShpFile.create(File.dirname(__FILE__) + '/../../data/point3.shp',GeoRuby::Shp4r::ShpType::POINT,[GeoRuby::Shp4r::Dbf::Field.new("Hoyoyo","C",10,0)]) shpfile.transaction do |tr| - tr.add(ShpRecord.new(Point.from_x_y(123,123.4),'Hoyoyo' => "HJHJJ")) + tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::Point.from_x_y(123,123.4),'Hoyoyo' => "HJHJJ")) end shpfile.record_count.should eql(1) shpfile.close @@ -225,9 +223,9 @@ def rm_all_shp(file) end it "test_creation_multipoint" do - shpfile = ShpFile.create(File.dirname(__FILE__) + '/../../data/multipoint3.shp',ShpType::MULTIPOINT,[Dbf::Field.new("Hoyoyo","C",10),Dbf::Field.new("Hello","N",10)]) + shpfile = GeoRuby::Shp4r::ShpFile.create(File.dirname(__FILE__) + '/../../data/multipoint3.shp',GeoRuby::Shp4r::ShpType::MULTIPOINT,[GeoRuby::Shp4r::Dbf::Field.new("Hoyoyo","C",10),GeoRuby::Shp4r::Dbf::Field.new("Hello","N",10)]) shpfile.transaction do |tr| - tr.add(ShpRecord.new(MultiPoint.from_coordinates([[123,123.4],[345,12.2]]),'Hoyoyo' => "HJHJJ","Hello" => 5)) + tr.add(GeoRuby::Shp4r::ShpRecord.new(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[123,123.4],[345,12.2]]),'Hoyoyo' => "HJHJJ","Hello" => 5)) end shpfile.record_count.should eql(1) shpfile.close diff --git a/spec/geo_ruby/simple_features/circle_spec.rb b/spec/geo_ruby/simple_features/circle_spec.rb index 35132f9..a0acaff 100644 --- a/spec/geo_ruby/simple_features/circle_spec.rb +++ b/spec/geo_ruby/simple_features/circle_spec.rb @@ -1,16 +1,14 @@ # -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe Circle do +describe GeoRuby::SimpleFeatures::Circle do it "should instantiate" do - Circle.new.should be_kind_of Geometry + subject.should be_kind_of GeoRuby::SimpleFeatures::Geometry end - describe "Instance" do - let(:circle) { Circle.new(4326) } + let(:circle) { GeoRuby::SimpleFeatures::Circle.new(4326) } end - end diff --git a/spec/geo_ruby/simple_features/envelope_spec.rb b/spec/geo_ruby/simple_features/envelope_spec.rb index 185a259..9d1b0ba 100644 --- a/spec/geo_ruby/simple_features/envelope_spec.rb +++ b/spec/geo_ruby/simple_features/envelope_spec.rb @@ -1,29 +1,29 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe Envelope do +describe GeoRuby::SimpleFeatures::Envelope do before(:each) do @srid = 4269 - @env = Envelope.from_points([Point.from_x_y(10,20, @srid),Point.from_x_y(20,30, @srid)], @srid) + @env = GeoRuby::SimpleFeatures::Envelope.from_points([GeoRuby::SimpleFeatures::Point.from_x_y(10,20, @srid),GeoRuby::SimpleFeatures::Point.from_x_y(20,30, @srid)], @srid) end it "should initialize" do - @env.should be_instance_of(Envelope) + @env.should be_instance_of(GeoRuby::SimpleFeatures::Envelope) end it "converted tu" do - linear_ring = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256) - polygon = Polygon.from_linear_rings([linear_ring],256) + linear_ring = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256) + polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring],256) e = polygon.envelope - e.lower_corner.class.should eql(Point) - e.upper_corner.class.should eql(Point) + e.lower_corner.class.should eql(GeoRuby::SimpleFeatures::Point) + e.upper_corner.class.should eql(GeoRuby::SimpleFeatures::Point) e.lower_corner.x.should eql(4.456) e.lower_corner.y.should eql(-45.3) e.upper_corner.x.should eql(45.4) e.upper_corner.y.should eql(41.6) - line_string = LineString.from_coordinates([[13.6,-49.3],[45.4,44.6],[14.2,1.09],[13.6,-49.3]],256) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[13.6,-49.3],[45.4,44.6],[14.2,1.09],[13.6,-49.3]],256) e2 = line_string.envelope e3 = e.extend(e2) diff --git a/spec/geo_ruby/simple_features/ewkb_parser_spec.rb b/spec/geo_ruby/simple_features/ewkb_parser_spec.rb index 3973576..d504e14 100644 --- a/spec/geo_ruby/simple_features/ewkb_parser_spec.rb +++ b/spec/geo_ruby/simple_features/ewkb_parser_spec.rb @@ -1,106 +1,106 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe EWKBParser do +describe GeoRuby::SimpleFeatures::EWKBParser do before(:each) do - @factory = GeometryFactory::new - @hex_ewkb_parser = HexEWKBParser::new(@factory) + @factory = GeoRuby::SimpleFeatures::GeometryFactory::new + @hex_ewkb_parser = GeoRuby::SimpleFeatures::HexEWKBParser::new(@factory) end it "test_point2d" do @hex_ewkb_parser.parse("01010000207B000000CDCCCCCCCCCC28406666666666A64640") point = @factory.geometry - point.should be_instance_of Point - point.should == Point.from_x_y(12.4,45.3,123) + point.should be_instance_of GeoRuby::SimpleFeatures::Point + point.should == GeoRuby::SimpleFeatures::Point.from_x_y(12.4,45.3,123) end it "test_point2d_BigEndian" do @hex_ewkb_parser.parse("00000000014013A035BD512EC7404A3060C38F3669") point = @factory.geometry - point.should be_instance_of Point - point.should == Point.from_x_y(4.906455,52.377953) + point.should be_instance_of GeoRuby::SimpleFeatures::Point + point.should == GeoRuby::SimpleFeatures::Point.from_x_y(4.906455,52.377953) end it "test_point3dz" do @hex_ewkb_parser.parse("01010000A07B000000CDCCCCCCCCCC28406666666666A646400000000000000CC0") point = @factory.geometry - point.should be_instance_of Point - point.should == Point.from_x_y_z(12.4,45.3,-3.5,123) + point.should be_instance_of GeoRuby::SimpleFeatures::Point + point.should == GeoRuby::SimpleFeatures::Point.from_x_y_z(12.4,45.3,-3.5,123) end it "test_point4d" do @hex_ewkb_parser.parse("01010000E07B000000CDCCCCCCCCCC28406666666666A646400000000000000CC00000000000002E40") point = @factory.geometry - point.should be_instance_of Point - point.should == Point.from_x_y_z_m(12.4,45.3,-3.5,15,123) + point.should be_instance_of GeoRuby::SimpleFeatures::Point + point.should == GeoRuby::SimpleFeatures::Point.from_x_y_z_m(12.4,45.3,-3.5,15,123) end it "test_line_string" do @hex_ewkb_parser.parse("01020000200001000002000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC4440") line_string = @factory.geometry - line_string.should be_instance_of LineString - line_string.should == LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256) + line_string.should be_instance_of GeoRuby::SimpleFeatures::LineString + line_string.should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256) @hex_ewkb_parser.parse("01020000A00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A641403333333333B34640CDCCCCCCCCCC44409A99999999992840") line_string = @factory.geometry - line_string.should be_instance_of LineString - line_string.should == LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true) + line_string.should be_instance_of GeoRuby::SimpleFeatures::LineString + line_string.should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true) @hex_ewkb_parser.parse("01020000E00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A64140CDCCCCCCCC8C46403333333333B34640CDCCCCCCCCCC44409A999999999928403D0AD7A3701D4440") line_string = @factory.geometry - line_string.should be_instance_of LineString - line_string.should == LineString.from_coordinates([[12.4,-45.3,35.3,45.1],[45.4,41.6,12.3,40.23]],256,true,true) + line_string.should be_instance_of GeoRuby::SimpleFeatures::LineString + line_string.should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3,45.1],[45.4,41.6,12.3,40.23]],256,true,true) end it "test_polygon" do @hex_ewkb_parser.parse("0103000020000100000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F") polygon = @factory.geometry - polygon.should be_instance_of Polygon - polygon.should == Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) + polygon.should be_instance_of GeoRuby::SimpleFeatures::Polygon + polygon.should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) @hex_ewkb_parser.parse("01030000A000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040") polygon = @factory.geometry - polygon.should be_instance_of Polygon - polygon.should == Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true) + polygon.should be_instance_of GeoRuby::SimpleFeatures::Polygon + polygon.should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true) @hex_ewkb_parser.parse("010300006000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040") polygon = @factory.geometry - polygon.should be_instance_of Polygon - polygon.should == Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true) + polygon.should be_instance_of GeoRuby::SimpleFeatures::Polygon + polygon.should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true) @hex_ewkb_parser.parse("01030000E0000100000200000005000000000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C00000000000001040000000000000000000000000000000400000000000001440000000000000104000000000000010400000000000000040AE47E17A14AE1240000000000000000000000000000010400000000000000040713D0AD7A370F53F000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C005000000000000000000F03F000000000000F03F00000000000000409A999999999928400000000000000840000000000000F03F00000000000000400000000000C05E400000000000000840000000000000084000000000000000406666666666662840000000000000F03F000000000000084000000000000000400000000000002840000000000000F03F000000000000F03F00000000000000409A99999999992840") polygon = @factory.geometry - polygon.should be_instance_of Polygon - polygon.should == Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true) + polygon.should be_instance_of GeoRuby::SimpleFeatures::Polygon + polygon.should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true) end it "test_geometry_collection" do @hex_ewkb_parser.parse("010700002000010000020000000101000000AE47E17A14AE12403333333333B34640010200000002000000CDCCCCCCCCCC16406666666666E628403333333333E350400000000000004B40") geometry_collection = @factory.geometry - geometry_collection.should be_instance_of GeometryCollection + geometry_collection.should be_instance_of GeoRuby::SimpleFeatures::GeometryCollection - geometry_collection.should == GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) + geometry_collection.should == GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) geometry_collection[0].srid.should eql(256) @hex_ewkb_parser.parse("01070000E0000100000200000001010000C0AE47E17A14AE12403333333333B34640F6285C8FC2D54640666666666666024001020000C002000000CDCCCCCCCCCC16406666666666E628403D0AD7A3703D124033333333339358403333333333E350400000000000004B4066666666666628403333333333330B40") geometry_collection = @factory.geometry - geometry_collection.should be_instance_of GeometryCollection - geometry_collection.should == GeometryCollection.from_geometries([Point.from_x_y_z_m(4.67,45.4,45.67,2.3,256),LineString.from_coordinates([[5.7,12.45,4.56,98.3],[67.55,54,12.2,3.4]],256,true, true)],256,true, true) + geometry_collection.should be_instance_of GeoRuby::SimpleFeatures::GeometryCollection + geometry_collection.should == GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y_z_m(4.67,45.4,45.67,2.3,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45,4.56,98.3],[67.55,54,12.2,3.4]],256,true, true)],256,true, true) geometry_collection[0].srid.should eql(256) end it "test_multi_point" do @hex_ewkb_parser.parse("0104000020BC010000030000000101000000CDCCCCCCCCCC28403333333333D35EC0010100000066666666664650C09A99999999D95E4001010000001F97DD388EE35E400000000000C05E40") multi_point = @factory.geometry - multi_point.should be_instance_of MultiPoint - multi_point.should == MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) + multi_point.should be_instance_of GeoRuby::SimpleFeatures::MultiPoint + multi_point.should == GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) multi_point.srid.should eql(444) multi_point[0].srid.should eql(444) @hex_ewkb_parser.parse("01040000A0BC010000030000000101000080CDCCCCCCCCCC28403333333333D35EC00000000000001240010100008066666666664650C09A99999999D95E40333333333333F33F01010000801F97DD388EE35E400000000000C05E406666666666660240") multi_point = @factory.geometry - multi_point.should be_instance_of MultiPoint - multi_point.should == MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,1.2],[123.55555555,123,2.3]],444,true) + multi_point.should be_instance_of GeoRuby::SimpleFeatures::MultiPoint + multi_point.should == GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,1.2],[123.55555555,123,2.3]],444,true) multi_point.srid.should eql(444) multi_point[0].srid.should eql(444) end @@ -108,15 +108,15 @@ it "test_multi_line_string" do @hex_ewkb_parser.parse("01050000200001000002000000010200000002000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF010200000003000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF39B4C876BE8F46403333333333D35E40") multi_line_string = @factory.geometry - multi_line_string.should be_instance_of MultiLineString - multi_line_string.should == MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) + multi_line_string.should be_instance_of GeoRuby::SimpleFeatures::MultiLineString + multi_line_string.should == GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) multi_line_string.srid.should eql(256) multi_line_string[0].srid.should eql(256) @hex_ewkb_parser.parse("0105000020000100000200000001020000C002000000000000000000F83F9A99999999994640CDCCCCCCCCCCF43F333333333333F33FE4BD6A65C20F4BC0FA7E6ABC749388BF333333333333F33F000000000000124001020000C003000000000000000000F83F9A99999999994640666666666666144000000000000012C0E4BD6A65C20F4BC0FA7E6ABC749388BF3333333333331BC03333333333330B4039B4C876BE8F46403333333333D35E40000000000000124033333333333315C0") multi_line_string = @factory.geometry - multi_line_string.should be_instance_of MultiLineString - multi_line_string.should == MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true) + multi_line_string.should be_instance_of GeoRuby::SimpleFeatures::MultiLineString + multi_line_string.should == GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true) multi_line_string.srid.should eql(256) multi_line_string[0].srid.should eql(256) end @@ -124,15 +124,15 @@ it "test_multi_polygon" do @hex_ewkb_parser.parse("0106000020000100000200000001030000000200000004000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC44406DE7FBA9F1D211403D2CD49AE61DF13FCDCCCCCCCCCC28406666666666A646C004000000333333333333034033333333333315409A999999999915408A8EE4F21FD2F63FEC51B81E85EB2C40F6285C8FC2F5F03F3333333333330340333333333333154001030000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F") multi_polygon = @factory.geometry - multi_polygon.should be_instance_of MultiPolygon - multi_polygon.should == MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) + multi_polygon.should be_instance_of GeoRuby::SimpleFeatures::MultiPolygon + multi_polygon.should == GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) multi_polygon.srid.should eql(256) multi_polygon[0].srid.should eql(256) @hex_ewkb_parser.parse("0106000020000100000200000001030000400200000004000000CDCCCCCCCCCC28406666666666A646C0333333333333F33F3333333333B34640CDCCCCCCCCCC4440333333333333F33F6DE7FBA9F1D211403D2CD49AE61DF13F333333333333F33FCDCCCCCCCCCC28406666666666A646C0333333333333F33F0400000033333333333303403333333333331540333333333333F33F9A999999999915408A8EE4F21FD2F63F333333333333F33FEC51B81E85EB2C40F6285C8FC2F5F03F333333333333F33F33333333333303403333333333331540333333333333F33F0103000040020000000500000000000000000000000000000000000000333333333333F33F00000000000010400000000000000000333333333333F33F00000000000010400000000000001040666666666666024000000000000000000000000000001040333333333333F33F00000000000000000000000000000000333333333333F33F05000000000000000000F03F000000000000F03F9A999999999901400000000000000840000000000000F03F6666666666660A40000000000000084000000000000008409A9999999999F13F000000000000F03F00000000000008403333333333330340000000000000F03F000000000000F03F9A99999999990140") multi_polygon = @factory.geometry - multi_polygon.should be_instance_of MultiPolygon - multi_polygon.should == MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3,1.2],[45.4,41.6,1.2],[4.456,1.0698,1.2],[12.4,-45.3,1.2]],[[2.4,5.3,1.2],[5.4,1.4263,1.2],[14.46,1.06,1.2],[2.4,5.3,1.2]]],256,false,true),Polygon.from_coordinates([[[0,0,1.2],[4,0,1.2],[4,4,2.3],[0,4,1.2],[0,0,1.2]],[[1,1,2.2],[3,1,3.3],[3,3,1.1],[1,3,2.4],[1,1,2.2]]],256,false,true)],256,false,true) + multi_polygon.should be_instance_of GeoRuby::SimpleFeatures::MultiPolygon + multi_polygon.should == GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3,1.2],[45.4,41.6,1.2],[4.456,1.0698,1.2],[12.4,-45.3,1.2]],[[2.4,5.3,1.2],[5.4,1.4263,1.2],[14.46,1.06,1.2],[2.4,5.3,1.2]]],256,false,true),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,1.2],[4,0,1.2],[4,4,2.3],[0,4,1.2],[0,0,1.2]],[[1,1,2.2],[3,1,3.3],[3,3,1.1],[1,3,2.4],[1,1,2.2]]],256,false,true)],256,false,true) multi_polygon.srid.should eql(256) multi_polygon[0].srid.should eql(256) end @@ -140,19 +140,19 @@ it "test_failure_trailing_data" do #added A345 at the end - lambda {@hex_ewkb_parser.parse("01010000207B000000CDCCCCCCCCCC28406666666666A64640A345")}.should raise_error(EWKBFormatError) + lambda {@hex_ewkb_parser.parse("01010000207B000000CDCCCCCCCCCC28406666666666A64640A345")}.should raise_error(GeoRuby::SimpleFeatures::EWKBFormatError) end it "test_failure_unknown_geometry_type" do - lambda {@hex_ewkb_parser.parse("01090000207B000000CDCCCCCCCCCC28406666666666A64640")}.should raise_error(EWKBFormatError) + lambda {@hex_ewkb_parser.parse("01090000207B000000CDCCCCCCCCCC28406666666666A64640")}.should raise_error(GeoRuby::SimpleFeatures::EWKBFormatError) end it "test_failure_m" do - lambda {@hex_ewkb_parser.parse("01010000607B000000CDCCCCCCCCCC28406666666666A64640")}.should raise_error(EWKBFormatError) + lambda {@hex_ewkb_parser.parse("01010000607B000000CDCCCCCCCCCC28406666666666A64640")}.should raise_error(GeoRuby::SimpleFeatures::EWKBFormatError) end it "test_failure_truncated_data" do - lambda {@hex_ewkb_parser.parse("01010000207B000000CDCCCCCCCCCC2840666666")}.should raise_error(EWKBFormatError) + lambda {@hex_ewkb_parser.parse("01010000207B000000CDCCCCCCCCCC2840666666")}.should raise_error(GeoRuby::SimpleFeatures::EWKBFormatError) end end diff --git a/spec/geo_ruby/simple_features/ewkt_parser_spec.rb b/spec/geo_ruby/simple_features/ewkt_parser_spec.rb index 39b77ba..8c5ec0c 100644 --- a/spec/geo_ruby/simple_features/ewkt_parser_spec.rb +++ b/spec/geo_ruby/simple_features/ewkt_parser_spec.rb @@ -1,26 +1,26 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe EWKTParser do +describe GeoRuby::SimpleFeatures::EWKTParser do before(:each) do - @factory = GeometryFactory::new - @ewkt_parser = EWKTParser::new(@factory) + @factory = GeoRuby::SimpleFeatures::GeometryFactory::new + @ewkt_parser = GeoRuby::SimpleFeatures::EWKTParser::new(@factory) end it "test_point" do ewkt="POINT( 3.456 0.123)" @ewkt_parser.parse(ewkt) point = @factory.geometry - point.should be_instance_of Point - point.should == Point.from_x_y(3.456,0.123) + point.should be_instance_of GeoRuby::SimpleFeatures::Point + point.should == GeoRuby::SimpleFeatures::Point.from_x_y(3.456,0.123) end it "test_point_with_srid" do ewkt="SRID=245;POINT(0.0 2.0)" @ewkt_parser.parse(ewkt) point = @factory.geometry - point.should be_instance_of Point - point.should == Point.from_x_y(0,2,245) + point.should be_instance_of GeoRuby::SimpleFeatures::Point + point.should == GeoRuby::SimpleFeatures::Point.from_x_y(0,2,245) point.srid.should eql(245) ewkt.should == point.as_ewkt(true,false) end @@ -29,8 +29,8 @@ ewkt="POINT(3.456 0.123 123.667)" @ewkt_parser.parse(ewkt) point = @factory.geometry - point.should be_instance_of Point - point.should == Point.from_x_y_z(3.456,0.123,123.667) + point.should be_instance_of GeoRuby::SimpleFeatures::Point + point.should == GeoRuby::SimpleFeatures::Point.from_x_y_z(3.456,0.123,123.667) ewkt.should == point.as_ewkt(false) end @@ -38,8 +38,8 @@ ewkt="POINTM(3.456 0.123 123.667)" @ewkt_parser.parse(ewkt) point = @factory.geometry - point.should be_instance_of Point - point.should == Point.from_x_y_m(3.456,0.123,123.667) + point.should be_instance_of GeoRuby::SimpleFeatures::Point + point.should == GeoRuby::SimpleFeatures::Point.from_x_y_m(3.456,0.123,123.667) ewkt.should == point.as_ewkt(false) end @@ -47,8 +47,8 @@ ewkt="POINT(3.456 0.123 123.667 15.0)" @ewkt_parser.parse(ewkt) point = @factory.geometry - point.should be_instance_of Point - point.should == Point.from_x_y_z_m(3.456,0.123,123.667,15.0) + point.should be_instance_of GeoRuby::SimpleFeatures::Point + point.should == GeoRuby::SimpleFeatures::Point.from_x_y_z_m(3.456,0.123,123.667,15.0) ewkt.should == point.as_ewkt(false) end @@ -56,73 +56,73 @@ it "test_linestring" do @ewkt_parser.parse("LINESTRING(3.456 0.123,123.44 123.56,54555.22 123.3)") line_string = @factory.geometry - line_string.should be_instance_of LineString - line_string.should == LineString.from_coordinates([[3.456,0.123],[123.44,123.56],[54555.22,123.3]]) + line_string.should be_instance_of GeoRuby::SimpleFeatures::LineString + line_string.should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[3.456,0.123],[123.44,123.56],[54555.22,123.3]]) @ewkt_parser.parse("SRID=256;LINESTRING(12.4 -45.3,45.4 41.6)") line_string = @factory.geometry - line_string.should be_instance_of LineString - line_string.should == LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256) + line_string.should be_instance_of GeoRuby::SimpleFeatures::LineString + line_string.should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256) @ewkt_parser.parse("SRID=256;LINESTRING(12.4 -45.3 35.3,45.4 41.6 12.3)") line_string = @factory.geometry - line_string.should be_instance_of LineString - line_string.should == LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true) + line_string.should be_instance_of GeoRuby::SimpleFeatures::LineString + line_string.should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true) @ewkt_parser.parse("SRID=256;LINESTRINGM(12.4 -45.3 35.3,45.4 41.6 12.3)") line_string = @factory.geometry - line_string.should be_instance_of LineString - line_string.should == LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,false,true) + line_string.should be_instance_of GeoRuby::SimpleFeatures::LineString + line_string.should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,false,true) @ewkt_parser.parse("SRID=256;LINESTRING(12.4 -45.3 35.3 25.2,45.4 41.6 12.3 13.75)") line_string = @factory.geometry - line_string.should be_instance_of LineString - line_string.should == LineString.from_coordinates([[12.4,-45.3,35.3,25.2],[45.4,41.6,12.3,13.75]],256,true,true) + line_string.should be_instance_of GeoRuby::SimpleFeatures::LineString + line_string.should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3,25.2],[45.4,41.6,12.3,13.75]],256,true,true) end it "test_polygon" do @ewkt_parser.parse("POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1))") polygon = @factory.geometry - polygon.should be_instance_of Polygon - polygon.should == Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) + polygon.should be_instance_of GeoRuby::SimpleFeatures::Polygon + polygon.should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) @ewkt_parser.parse("SRID=256;POLYGON( ( 0 0 2,4 0 2,4 4 2,0 4 2,0 0 2),(1 1 2,3 1 2,3 3 2,1 3 2,1 1 2))") polygon = @factory.geometry - polygon.should be_instance_of Polygon - polygon.should == Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true) + polygon.should be_instance_of GeoRuby::SimpleFeatures::Polygon + polygon.should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true) @ewkt_parser.parse("SRID=256;POLYGONM((0 0 2,4 0 2,4 4 2,0 4 2,0 0 2),(1 1 2,3 1 2,3 3 2,1 3 2,1 1 2))") polygon = @factory.geometry - polygon.should be_instance_of Polygon - polygon.should == Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true) + polygon.should be_instance_of GeoRuby::SimpleFeatures::Polygon + polygon.should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true) @ewkt_parser.parse("SRID=256;POLYGON((0 0 2 -45.1,4 0 2 5,4 4 2 4.67,0 4 2 1.34,0 0 2 -45.1),(1 1 2 12.3,3 1 2 123,3 3 2 12.2,1 3 2 12,1 1 2 12.3))") polygon = @factory.geometry - polygon.should be_instance_of Polygon - polygon.should == Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true) + polygon.should be_instance_of GeoRuby::SimpleFeatures::Polygon + polygon.should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true) end it "test_multi_point" do #Form output by the current version of PostGIS. Future versions will output the one in the specification @ewkt_parser.parse("SRID=444;MULTIPOINT(12.4 -123.3,-65.1 123.4,123.55555555 123)") multi_point = @factory.geometry - multi_point.should be_instance_of MultiPoint - multi_point.should == MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) + multi_point.should be_instance_of GeoRuby::SimpleFeatures::MultiPoint + multi_point.should == GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) multi_point.srid.should eql(444) multi_point[0].srid.should eql(444) @ewkt_parser.parse("SRID=444;MULTIPOINT(12.4 -123.3 4.5,-65.1 123.4 6.7,123.55555555 123 7.8)") multi_point = @factory.geometry - multi_point.should be_instance_of MultiPoint - multi_point.should == MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,6.7],[123.55555555,123,7.8]],444,true) + multi_point.should be_instance_of GeoRuby::SimpleFeatures::MultiPoint + multi_point.should == GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,6.7],[123.55555555,123,7.8]],444,true) multi_point.srid.should eql(444) multi_point[0].srid.should eql(444) #Form in the EWKT specification (from the OGC) @ewkt_parser.parse("SRID=444;MULTIPOINT( ( 12.4 -123.3 4.5 ) , (-65.1 123.4 6.7),(123.55555555 123 7.8))") multi_point = @factory.geometry - multi_point.should be_instance_of MultiPoint - multi_point.should == MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,6.7],[123.55555555,123,7.8]],444,true) + multi_point.should be_instance_of GeoRuby::SimpleFeatures::MultiPoint + multi_point.should == GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,6.7],[123.55555555,123,7.8]],444,true) multi_point.srid.should eql(444) multi_point[0].srid.should eql(444) end @@ -130,15 +130,15 @@ it "test_multi_line_string" do @ewkt_parser.parse("SRID=256;MULTILINESTRING((1.5 45.2,-54.12312 -0.012),(1.5 45.2,-54.12312 -0.012,45.123 123.3))") multi_line_string = @factory.geometry - multi_line_string.should be_instance_of MultiLineString - multi_line_string.should == MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) + multi_line_string.should be_instance_of GeoRuby::SimpleFeatures::MultiLineString + multi_line_string.should == GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) multi_line_string.srid.should eql(256) multi_line_string[0].srid.should eql(256) @ewkt_parser.parse("SRID=256;MULTILINESTRING((1.5 45.2 1.3 1.2,-54.12312 -0.012 1.2 4.5),(1.5 45.2 5.1 -4.5,-54.12312 -0.012 -6.8 3.4,45.123 123.3 4.5 -5.3))") multi_line_string = @factory.geometry - multi_line_string.should be_instance_of MultiLineString - multi_line_string.should == MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true) + multi_line_string.should be_instance_of GeoRuby::SimpleFeatures::MultiLineString + multi_line_string.should == GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true) multi_line_string.srid.should eql(256) multi_line_string[0].srid.should eql(256) end @@ -147,8 +147,8 @@ ewkt="SRID=256;MULTIPOLYGON(((12.4 -45.3,45.4 41.6,4.456 1.0698,12.4 -45.3),(2.4 5.3,5.4 1.4263,14.46 1.06,2.4 5.3)),((0.0 0.0,4.0 0.0,4.0 4.0,0.0 4.0,0.0 0.0),(1.0 1.0,3.0 1.0,3.0 3.0,1.0 3.0,1.0 1.0)))" @ewkt_parser.parse(ewkt) multi_polygon = @factory.geometry - multi_polygon.should be_instance_of MultiPolygon - multi_polygon.should == MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) + multi_polygon.should be_instance_of GeoRuby::SimpleFeatures::MultiPolygon + multi_polygon.should == GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) multi_polygon.srid.should eql(256) multi_polygon[0].srid.should eql(256) ewkt.should == multi_polygon.as_ewkt @@ -156,8 +156,8 @@ ewkt="MULTIPOLYGON(((12.4 -45.3 2,45.4 41.6 3,4.456 1.0698 4,12.4 -45.3 2),(2.4 5.3 1,5.4 1.4263 3.44,14.46 1.06 4.5,2.4 5.3 1)),((0 0 5.6,4 0 5.4,4 4 1,0 4 23,0 0 5.6),(1 1 2.3,3 1 4,3 3 5,1 3 6,1 1 2.3)))" @ewkt_parser.parse(ewkt) multi_polygon = @factory.geometry - multi_polygon.should be_instance_of MultiPolygon - multi_polygon.should == MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3,2],[45.4,41.6,3],[4.456,1.0698,4],[12.4,-45.3,2]],[[2.4,5.3,1],[5.4,1.4263,3.44],[14.46,1.06,4.5],[2.4,5.3,1]]],4326,true),Polygon.from_coordinates([[[0,0,5.6],[4,0,5.4],[4,4,1],[0,4,23],[0,0,5.6]],[[1,1,2.3],[3,1,4],[3,3,5],[1,3,6],[1,1,2.3]]],4326,true)],4326,true) + multi_polygon.should be_instance_of GeoRuby::SimpleFeatures::MultiPolygon + multi_polygon.should == GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3,2],[45.4,41.6,3],[4.456,1.0698,4],[12.4,-45.3,2]],[[2.4,5.3,1],[5.4,1.4263,3.44],[14.46,1.06,4.5],[2.4,5.3,1]]],4326,true),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,5.6],[4,0,5.4],[4,4,1],[0,4,23],[0,0,5.6]],[[1,1,2.3],[3,1,4],[3,3,5],[1,3,6],[1,1,2.3]]],4326,true)],4326,true) multi_polygon.srid.should eql(4326) multi_polygon[0].srid.should eql(4326) end @@ -165,14 +165,14 @@ it "test_geometry_collection" do @ewkt_parser.parse("SRID=256;GEOMETRYCOLLECTION(POINT(4.67 45.4),LINESTRING(5.7 12.45,67.55 54),POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1)))") geometry_collection = @factory.geometry - geometry_collection.should be_instance_of GeometryCollection - geometry_collection.should == GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) + geometry_collection.should be_instance_of GeoRuby::SimpleFeatures::GeometryCollection + geometry_collection.should == GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) geometry_collection[0].srid.should eql(256) @ewkt_parser.parse("SRID=256;GEOMETRYCOLLECTIONM(POINTM(4.67 45.4 45.6),LINESTRINGM(5.7 12.45 5.6,67.55 54 6.7))") geometry_collection = @factory.geometry - geometry_collection.should be_instance_of GeometryCollection - geometry_collection.should == GeometryCollection.from_geometries([Point.from_x_y_m(4.67,45.4,45.6,256),LineString.from_coordinates([[5.7,12.45,5.6],[67.55,54,6.7]],256,false,true)],256,false,true) + geometry_collection.should be_instance_of GeoRuby::SimpleFeatures::GeometryCollection + geometry_collection.should == GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y_m(4.67,45.4,45.6,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45,5.6],[67.55,54,6.7]],256,false,true)],256,false,true) geometry_collection[0].srid.should eql(256) end diff --git a/spec/geo_ruby/simple_features/geometry_collection_spec.rb b/spec/geo_ruby/simple_features/geometry_collection_spec.rb index 310f7ea..a5eab5c 100644 --- a/spec/geo_ruby/simple_features/geometry_collection_spec.rb +++ b/spec/geo_ruby/simple_features/geometry_collection_spec.rb @@ -1,54 +1,54 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe GeometryCollection do +describe GeoRuby::SimpleFeatures::GeometryCollection do it "should test_geometry_collection_creation" do - geometry_collection = GeometryCollection::new(256) - geometry_collection << Point.from_x_y(4.67,45.4,256) + geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection::new(256) + geometry_collection << GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256) geometry_collection.length.should eql(1) - geometry_collection[0].should == Point.from_x_y(4.67,45.4,256) + geometry_collection[0].should == GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256) - geometry_collection[0]=LineString.from_coordinates([[5.7,12.45],[67.55,54]],256) - geometry_collection << Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) + geometry_collection[0]=GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256) + geometry_collection << GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) geometry_collection.length.should eql(2) - geometry_collection[0].should == LineString.from_coordinates([[5.7,12.45],[67.55,54]],256) + geometry_collection[0].should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256) - geometry_collection = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) - geometry_collection.class.should eql(GeometryCollection) + geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) + geometry_collection.class.should eql(GeoRuby::SimpleFeatures::GeometryCollection) geometry_collection.srid.should eql(256) geometry_collection.length.should eql(2) - geometry_collection[1].should == LineString.from_coordinates([[5.7,12.45],[67.55,54]],256) + geometry_collection[1].should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256) bbox = geometry_collection.bounding_box bbox.length.should eql(2) - bbox[0].should == Point.from_x_y(4.67,12.45) - bbox[1].should == Point.from_x_y(67.55,54) + bbox[0].should == GeoRuby::SimpleFeatures::Point.from_x_y(4.67,12.45) + bbox[1].should == GeoRuby::SimpleFeatures::Point.from_x_y(67.55,54) end it "test_geometry_collection_equal" do - geometry_collection1 = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) - geometry_collection2 = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256),Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256)],256,true) - line_string=LineString.from_coordinates([[5.7,12.45],[67.55,54]],256) + geometry_collection1 = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) + geometry_collection2 = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256)],256,true) + line_string=GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256) - geometry_collection1.should == GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) + geometry_collection1.should == GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) geometry_collection2.should_not == geometry_collection1 line_string.should_not == geometry_collection1 end it "test_geometry_collection_binary" do - geometry_collection = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) + geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) geometry_collection.as_hex_ewkb.should eql("010700002000010000020000000101000000AE47E17A14AE12403333333333B34640010200000002000000CDCCCCCCCCCC16406666666666E628403333333333E350400000000000004B40") - geometry_collection = GeometryCollection.from_geometries([Point.from_x_y_z_m(4.67,45.4,45.67,2.3,256),LineString.from_coordinates([[5.7,12.45,4.56,98.3],[67.55,54,12.2,3.4]],256,true, true)],256,true, true) + geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y_z_m(4.67,45.4,45.67,2.3,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45,4.56,98.3],[67.55,54,12.2,3.4]],256,true, true)],256,true, true) geometry_collection.as_hex_ewkb.should eql("01070000E0000100000200000001010000C0AE47E17A14AE12403333333333B34640F6285C8FC2D54640666666666666024001020000C002000000CDCCCCCCCCCC16406666666666E628403D0AD7A3703D124033333333339358403333333333E350400000000000004B4066666666666628403333333333330B40") end it "should test_geometry_collection_text" do - geometry_collection = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) + geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) geometry_collection.as_ewkt.should eql("SRID=256;GEOMETRYCOLLECTION(POINT(4.67 45.4),LINESTRING(5.7 12.45,67.55 54))") - geometry_collection = GeometryCollection.from_geometries([Point.from_x_y_m(4.67,45.4,45.6,256),LineString.from_coordinates([[5.7,12.45,5.6],[67.55,54,6.7]],256,false,true)],256,false,true) + geometry_collection = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y_m(4.67,45.4,45.6,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45,5.6],[67.55,54,6.7]],256,false,true)],256,false,true) geometry_collection.as_ewkt.should eql("SRID=256;GEOMETRYCOLLECTIONM(POINTM(4.67 45.4 45.6),LINESTRINGM(5.7 12.45 5.6,67.55 54 6.7))") end diff --git a/spec/geo_ruby/simple_features/geometry_factory_spec.rb b/spec/geo_ruby/simple_features/geometry_factory_spec.rb index 2affa91..0106351 100644 --- a/spec/geo_ruby/simple_features/geometry_factory_spec.rb +++ b/spec/geo_ruby/simple_features/geometry_factory_spec.rb @@ -1,8 +1,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe GeometryFactory do +describe GeoRuby::SimpleFeatures::GeometryFactory do # before(:each) do -# @po = MultiPolygon.new +# @po = GeoRuby::SimpleFeatures::MultiPolygon.new # end #it "should f" do diff --git a/spec/geo_ruby/simple_features/geometry_spec.rb b/spec/geo_ruby/simple_features/geometry_spec.rb index ef6e100..0713cf2 100644 --- a/spec/geo_ruby/simple_features/geometry_spec.rb +++ b/spec/geo_ruby/simple_features/geometry_spec.rb @@ -1,32 +1,29 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe Geometry do - before(:each) do - @geo = Geometry.new - end +describe GeoRuby::SimpleFeatures::Geometry do it "should instantiate" do - violated unless @geo + violated unless subject end it "should have a default srid" do - @geo.srid.should eql(4326) #Geometry.default_srid) + subject.srid.should eql(4326) #Geometry.default_srid) end it "should change srid" do - geo = Geometry.new(225) + geo = GeoRuby::SimpleFeatures::Geometry.new(225) geo.srid.should eql(225) end it "should instantiate from hex ewkb" do - point = Geometry.from_hex_ewkb("01010000207B000000CDCCCCCCCCCC28406666666666A64640") - point.class.should == Point + point = GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb("01010000207B000000CDCCCCCCCCCC28406666666666A64640") + point.class.should == GeoRuby::SimpleFeatures::Point point.x.should be_within(0.1).of(12.4) end it "should output as_ewkb" do - @geo.stub!(:binary_geometry_type).and_return(1) - @geo.stub!(:binary_representation).and_return(1) - @geo.as_ewkb.should eql("\001\001\000\000 \346\020\000\000\001") + subject.stub!(:binary_geometry_type).and_return(1) + subject.stub!(:binary_representation).and_return(1) + subject.as_ewkb.should eql("\001\001\000\000 \346\020\000\000\001") end end diff --git a/spec/geo_ruby/simple_features/line_string_spec.rb b/spec/geo_ruby/simple_features/line_string_spec.rb index 08c6db8..b69d073 100644 --- a/spec/geo_ruby/simple_features/line_string_spec.rb +++ b/spec/geo_ruby/simple_features/line_string_spec.rb @@ -2,22 +2,22 @@ module LineSpecHelper def mock_points(num) -# @point = mock(Point, :x => 1.0, :y => 2.0) +# @point = mock(GeoRuby::SimpleFeatures::Point, :x => 1.0, :y => 2.0) Array.new(num) { |i| mock_point(i,i) } end def mock_point(x=1,y=2) - mock(Point, :x => x, :y => y, :text_representation => "#{x} #{y}") + mock(GeoRuby::SimpleFeatures::Point, :x => x, :y => y, :text_representation => "#{x} #{y}") end end -describe LineString do +describe GeoRuby::SimpleFeatures::LineString do include LineSpecHelper describe "Instance Methods" do - let(:line) { LineString.from_points([mock(Point)]) } + let(:line) { GeoRuby::SimpleFeatures::LineString.from_points([mock(GeoRuby::SimpleFeatures::Point)]) } it "should instantiate" do violated unless line @@ -37,16 +37,16 @@ def mock_point(x=1,y=2) end - describe "Valid LineString" do + describe "Valid GeoRuby::SimpleFeatures::LineString" do - let(:line) { LineString.from_points([Point.xy(1,1), Point.xy(2,2), Point.xy(3,3)]) } + let(:line) { GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.xy(1,1), GeoRuby::SimpleFeatures::Point.xy(2,2), GeoRuby::SimpleFeatures::Point.xy(3,3)]) } it "should check orientation" do line.should_not be_clockwise end it "should check orientation" do - l = LineString.from_points([Point.from_x_y(20,20), Point.from_x_y(10,10), Point.from_x_y(-10,10)]) + l = GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.from_x_y(20,20), GeoRuby::SimpleFeatures::Point.from_x_y(10,10), GeoRuby::SimpleFeatures::Point.from_x_y(-10,10)]) l.should be_clockwise end @@ -55,107 +55,107 @@ def mock_point(x=1,y=2) describe "tu converted" do it "should concat points" do - line_string = LineString::new - line_string.concat([Point.from_x_y(12.4,45.3),Point.from_x_y(45.4,41.6)]) + line_string = GeoRuby::SimpleFeatures::LineString::new + line_string.concat([GeoRuby::SimpleFeatures::Point.from_x_y(12.4,45.3),GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6)]) line_string.length.should eql(2) - line_string[0].should == Point.from_x_y(12.4,45.3) + line_string[0].should == GeoRuby::SimpleFeatures::Point.from_x_y(12.4,45.3) - point=Point.from_x_y(123,45.8777) + point=GeoRuby::SimpleFeatures::Point.from_x_y(123,45.8777) line_string[0]=point line_string[0].should == point - points=[Point.from_x_y(123,45.8777),Point.from_x_y(45.4,41.6)] + points=[GeoRuby::SimpleFeatures::Point.from_x_y(123,45.8777),GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6)] line_string.each_index {|i| line_string[i].should == points[i] } - point=Point.from_x_y(22.4,13.56) + point=GeoRuby::SimpleFeatures::Point.from_x_y(22.4,13.56) line_string << point line_string.length.should eql(3) line_string[2].should eql(point) end it "should create" do - line_string = LineString.from_points([Point.from_x_y(12.4,-45.3),Point.from_x_y(45.4,41.6)],123) - line_string.class.should eql(LineString) + line_string = GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3),GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6)],123) + line_string.class.should eql(GeoRuby::SimpleFeatures::LineString) line_string.length.should eql(2) - line_string[0].should == Point.from_x_y(12.4,-45.3) - line_string[1].should == Point.from_x_y(45.4,41.6) + line_string[0].should == GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3) + line_string[1].should == GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6) - line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123) - line_string.class.should eql(LineString) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123) + line_string.class.should eql(GeoRuby::SimpleFeatures::LineString) line_string.length.should eql(3) - line_string[0].should == Point.from_x_y(12.4,-45.3) - line_string[1].should == Point.from_x_y(45.4,41.6) + line_string[0].should == GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3) + line_string[1].should == GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6) - line_string = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true) - line_string.class.should eql(LineString) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true) + line_string.class.should eql(GeoRuby::SimpleFeatures::LineString) line_string.length.should eql(3) - line_string[0].should == Point.from_x_y_z(12.4,-45.3,123,123) + line_string[0].should == GeoRuby::SimpleFeatures::Point.from_x_y_z(12.4,-45.3,123,123) - line_string = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true) - line_string.class.should eql(LineString) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true) + line_string.class.should eql(GeoRuby::SimpleFeatures::LineString) line_string.length.should eql(3) - line_string[0].should == Point.from_x_y_z(12.4,-45.3,123,123) + line_string[0].should == GeoRuby::SimpleFeatures::Point.from_x_y_z(12.4,-45.3,123,123) end it "should bbox it" do - bbox = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true).bounding_box + bbox = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true).bounding_box bbox.length.should eql(2) - bbox[0].should == Point.from_x_y_z(4.456,-45.3,123) - bbox[1].should == Point.from_x_y_z(45.4,41.6,987) + bbox[0].should == GeoRuby::SimpleFeatures::Point.from_x_y_z(4.456,-45.3,123) + bbox[1].should == GeoRuby::SimpleFeatures::Point.from_x_y_z(45.4,41.6,987) end it "should test_line_string_equal" do - line_string1 = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123) - line_string2 = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],123) - point = Point.from_x_y(12.4,-45.3,123) + line_string1 = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123) + line_string2 = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],123) + point = GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3,123) - line_string1.should == LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123) + line_string1.should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123) line_string1.should_not == line_string2 line_string1.should_not == point end it "should test_line_string_binary" do - line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256) line_string.as_hex_ewkb.should eql("01020000200001000002000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC4440") - line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true) line_string.as_hex_ewkb.should eql("01020000A00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A641403333333333B34640CDCCCCCCCCCC44409A99999999992840") - line_string = LineString.from_coordinates([[12.4,-45.3,35.3,45.1],[45.4,41.6,12.3,40.23]],256,true,true) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3,45.1],[45.4,41.6,12.3,40.23]],256,true,true) line_string.as_hex_ewkb.should eql("01020000E00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A64140CDCCCCCCCC8C46403333333333B34640CDCCCCCCCCCC44409A999999999928403D0AD7A3701D4440") end it "test_line_string_text" do - line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256) line_string.as_ewkt.should eql("SRID=256;LINESTRING(12.4 -45.3,45.4 41.6)") - line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true) line_string.as_ewkt.should eql("SRID=256;LINESTRING(12.4 -45.3 35.3,45.4 41.6 12.3)") - line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,false,true) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,false,true) line_string.as_ewkt.should eql("SRID=256;LINESTRINGM(12.4 -45.3 35.3,45.4 41.6 12.3)") - line_string = LineString.from_coordinates([[12.4,-45.3,35.3,25.2],[45.4,41.6,12.3,13.75]],256,true,true) + line_string = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4,-45.3,35.3,25.2],[45.4,41.6,12.3,13.75]],256,true,true) line_string.as_ewkt.should eql("SRID=256;LINESTRING(12.4 -45.3 35.3 25.2,45.4 41.6 12.3 13.75)") end it "should test_linear_ring_creation" do #testing just the constructor helpers since the rest is the same as for line_string - linear_ring = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],345) - linear_ring.class.should eql(LinearRing) + linear_ring = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],345) + linear_ring.class.should eql(GeoRuby::SimpleFeatures::LinearRing) linear_ring.length.should eql(4) linear_ring.should be_closed - linear_ring[1].should == Point.from_x_y(45.4,41.6,345) + linear_ring[1].should == GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6,345) end end describe "> Coordinates" do before(:each) do - Point.should_receive(:from_coordinates). + GeoRuby::SimpleFeatures::Point.should_receive(:from_coordinates). exactly(4).with(anything, 4326, false, false).and_return(mock_point) - @line = LineString.from_coordinates([1.2,2.5,2.2,4.5]) + @line = GeoRuby::SimpleFeatures::LineString.from_coordinates([1.2,2.5,2.2,4.5]) end it "should instantiate from coordinates" do @@ -166,7 +166,7 @@ def mock_point(x=1,y=2) describe "> Instantiated" do - let (:line) { LineString.from_points(mock_points(7)) } + let (:line) { GeoRuby::SimpleFeatures::LineString.from_points(mock_points(7)) } it "should be closed if the last point equals the first" do line.push(line.first) @@ -203,10 +203,10 @@ def mock_point(x=1,y=2) describe "> Distances..." do before(:each) do - @p1 = mock(Point) - @p2 = mock(Point) - @p3 = mock(Point) - @line = LineString.from_points([@p1,@p2,@p3]) + @p1 = mock(GeoRuby::SimpleFeatures::Point) + @p2 = mock(GeoRuby::SimpleFeatures::Point) + @p3 = mock(GeoRuby::SimpleFeatures::Point) + @line = GeoRuby::SimpleFeatures::LineString.from_points([@p1,@p2,@p3]) end it "should print the length with haversine" do @@ -224,10 +224,10 @@ def mock_point(x=1,y=2) describe "Simplify" do - let(:line) { LineString.from_coordinates([[6,0],[4,1],[3,4],[4,6],[5,8],[5,9],[4,10],[6,15]], 4326) } + let(:line) { GeoRuby::SimpleFeatures::LineString.from_coordinates([[6,0],[4,1],[3,4],[4,6],[5,8],[5,9],[4,10],[6,15]], 4326) } it "should simplify a simple linestring" do - line = LineString.from_coordinates([[12,15],[14,17],[17, 20]], 4326) + line = GeoRuby::SimpleFeatures::LineString.from_coordinates([[12,15],[14,17],[17, 20]], 4326) line.simplify.should have(2).points end diff --git a/spec/geo_ruby/simple_features/linear_ring_spec.rb b/spec/geo_ruby/simple_features/linear_ring_spec.rb index 1dad5aa..8c814de 100644 --- a/spec/geo_ruby/simple_features/linear_ring_spec.rb +++ b/spec/geo_ruby/simple_features/linear_ring_spec.rb @@ -1,22 +1,22 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe LinearRing do +describe GeoRuby::SimpleFeatures::LinearRing do it "should instantiate" do - lr = LinearRing.new(4326) - lr.should be_instance_of(LinearRing) + lr = GeoRuby::SimpleFeatures::LinearRing.new(4326) + lr.should be_instance_of(GeoRuby::SimpleFeatures::LinearRing) end describe "Instance" do - let(:lr) { LinearRing.from_coordinates([[10,10],[20,45],[45,10],[10, 10]],256) } + let(:lr) { GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[10,10],[20,45],[45,10],[10, 10]],256) } it "should test if contains a point" do - lr.contains_point?(Point.from_x_y(21,21)).should be_true + lr.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(21,21)).should be_true end it "should test if not contains a point" do - lr.contains_point?(Point.from_x_y(21,51)).should be_false + lr.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(21,51)).should be_false end end diff --git a/spec/geo_ruby/simple_features/multi_line_string_spec.rb b/spec/geo_ruby/simple_features/multi_line_string_spec.rb index a22ddf4..9d31246 100644 --- a/spec/geo_ruby/simple_features/multi_line_string_spec.rb +++ b/spec/geo_ruby/simple_features/multi_line_string_spec.rb @@ -1,40 +1,40 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe MultiLineString do +describe GeoRuby::SimpleFeatures::MultiLineString do it "test_multi_line_string_creation" do - multi_line_string1 = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) - multi_line_string1.should be_instance_of(MultiLineString) + multi_line_string1 = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) + multi_line_string1.should be_instance_of(GeoRuby::SimpleFeatures::MultiLineString) multi_line_string1.length.should eql(2) - multi_line_string1[0].should == LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256) + multi_line_string1[0].should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256) - multi_line_string2= MultiLineString.from_coordinates([[[1.5,45.2],[-54.12312,-0.012]],[[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]]],256); - multi_line_string1.should be_instance_of(MultiLineString) + multi_line_string2= GeoRuby::SimpleFeatures::MultiLineString.from_coordinates([[[1.5,45.2],[-54.12312,-0.012]],[[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]]],256); + multi_line_string1.should be_instance_of(GeoRuby::SimpleFeatures::MultiLineString) multi_line_string1.length.should eql(2) - multi_line_string2[0].should == LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256) + multi_line_string2[0].should == GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256) multi_line_string2.should == multi_line_string2 end it "test_multi_line_string_binary" do - multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) + multi_line_string = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) multi_line_string.as_hex_ewkb.should eql("01050000200001000002000000010200000002000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF010200000003000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF39B4C876BE8F46403333333333D35E40") - multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true) + multi_line_string = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true) multi_line_string.as_hex_ewkb.should eql("0105000020000100000200000001020000C002000000000000000000F83F9A99999999994640CDCCCCCCCCCCF43F333333333333F33FE4BD6A65C20F4BC0FA7E6ABC749388BF333333333333F33F000000000000124001020000C003000000000000000000F83F9A99999999994640666666666666144000000000000012C0E4BD6A65C20F4BC0FA7E6ABC749388BF3333333333331BC03333333333330B4039B4C876BE8F46403333333333D35E40000000000000124033333333333315C0") end it "test_multi_line_string_text" do - multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) + multi_line_string = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) multi_line_string.as_ewkt.should eql("SRID=256;MULTILINESTRING((1.5 45.2,-54.12312 -0.012),(1.5 45.2,-54.12312 -0.012,45.123 123.3))") - multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true) + multi_line_string = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true) multi_line_string.as_ewkt.should eql("SRID=256;MULTILINESTRING((1.5 45.2 1.3 1.2,-54.12312 -0.012 1.2 4.5),(1.5 45.2 5.1 -4.5,-54.12312 -0.012 -6.8 3.4,45.123 123.3 4.5 -5.3))") end describe "Some More" do before do - @mls = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) + @mls = GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256) end it "should have a accessor to all points" do @@ -47,7 +47,7 @@ it "should simplify to linestring" do ls = @mls.to_line_string - ls.should be_instance_of(LineString) + ls.should be_instance_of(GeoRuby::SimpleFeatures::LineString) ls.should have(5).points end end diff --git a/spec/geo_ruby/simple_features/multi_point_spec.rb b/spec/geo_ruby/simple_features/multi_point_spec.rb index cd28e22..5664cd7 100644 --- a/spec/geo_ruby/simple_features/multi_point_spec.rb +++ b/spec/geo_ruby/simple_features/multi_point_spec.rb @@ -1,33 +1,33 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe MultiPoint do +describe GeoRuby::SimpleFeatures::MultiPoint do it "test_multi_point_creation" do - multi_point = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) - multi_point.should be_instance_of(MultiPoint) + multi_point = GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) + multi_point.should be_instance_of(GeoRuby::SimpleFeatures::MultiPoint) multi_point.length.should eql(3) - multi_point[0].should == Point.from_x_y(12.4,-123.3,444) - multi_point[2].should == Point.from_x_y(123.55555555,123,444) + multi_point[0].should == GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-123.3,444) + multi_point[2].should == GeoRuby::SimpleFeatures::Point.from_x_y(123.55555555,123,444) end it "test_multi_point_binary" do - multi_point = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) + multi_point = GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) multi_point.as_hex_ewkb.should eql("0104000020BC010000030000000101000000CDCCCCCCCCCC28403333333333D35EC0010100000066666666664650C09A99999999D95E4001010000001F97DD388EE35E400000000000C05E40") - multi_point = MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,1.2],[123.55555555,123,2.3]],444,true) + multi_point = GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,1.2],[123.55555555,123,2.3]],444,true) multi_point.as_hex_ewkb.should eql("01040000A0BC010000030000000101000080CDCCCCCCCCCC28403333333333D35EC00000000000001240010100008066666666664650C09A99999999D95E40333333333333F33F01010000801F97DD388EE35E400000000000C05E406666666666660240") end it "test_multi_point_text" do - multi_point = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) + multi_point = GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) multi_point.as_ewkt.should eql("SRID=444;MULTIPOINT((12.4 -123.3),(-65.1 123.4),(123.55555555 123))") - multi_point = MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,6.7],[123.55555555,123,7.8]],444,true) + multi_point = GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,6.7],[123.55555555,123,7.8]],444,true) multi_point.as_ewkt.should eql("SRID=444;MULTIPOINT((12.4 -123.3 4.5),(-65.1 123.4 6.7),(123.55555555 123 7.8))") end it "should respond to points" do - mp = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) + mp = GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444) mp.should have(3).geometries mp.should have(3).points end diff --git a/spec/geo_ruby/simple_features/multi_polygon_spec.rb b/spec/geo_ruby/simple_features/multi_polygon_spec.rb index a7b8e46..25effce 100644 --- a/spec/geo_ruby/simple_features/multi_polygon_spec.rb +++ b/spec/geo_ruby/simple_features/multi_polygon_spec.rb @@ -1,45 +1,45 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe MultiPolygon do +describe GeoRuby::SimpleFeatures::MultiPolygon do it "test_multi_polygon_creation" do - multi_polygon1 = MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) - multi_polygon1.should be_instance_of(MultiPolygon) + multi_polygon1 = GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) + multi_polygon1.should be_instance_of(GeoRuby::SimpleFeatures::MultiPolygon) multi_polygon1.length.should eql(2) - multi_polygon1[0].should == Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) + multi_polygon1[0].should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) - multi_polygon2 = MultiPolygon.from_coordinates([[[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],[[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]]],256) - multi_polygon1.should be_instance_of(MultiPolygon) + multi_polygon2 = GeoRuby::SimpleFeatures::MultiPolygon.from_coordinates([[[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],[[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]]],256) + multi_polygon1.should be_instance_of(GeoRuby::SimpleFeatures::MultiPolygon) multi_polygon1.length.should eql(2) - multi_polygon2[0].should == Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) + multi_polygon2[0].should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) multi_polygon1.should == multi_polygon2 end it "test_multi_polygon_binary" do - multi_polygon = MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) + multi_polygon = GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) multi_polygon.as_hex_ewkb.should eql("0106000020000100000200000001030000000200000004000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC44406DE7FBA9F1D211403D2CD49AE61DF13FCDCCCCCCCCCC28406666666666A646C004000000333333333333034033333333333315409A999999999915408A8EE4F21FD2F63FEC51B81E85EB2C40F6285C8FC2F5F03F3333333333330340333333333333154001030000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F") - multi_polygon = MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3,1.2],[45.4,41.6,1.2],[4.456,1.0698,1.2],[12.4,-45.3,1.2]],[[2.4,5.3,1.2],[5.4,1.4263,1.2],[14.46,1.06,1.2],[2.4,5.3,1.2]]],256,false,true),Polygon.from_coordinates([[[0,0,1.2],[4,0,1.2],[4,4,2.3],[0,4,1.2],[0,0,1.2]],[[1,1,2.2],[3,1,3.3],[3,3,1.1],[1,3,2.4],[1,1,2.2]]],256,false,true)],256,false,true) + multi_polygon = GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3,1.2],[45.4,41.6,1.2],[4.456,1.0698,1.2],[12.4,-45.3,1.2]],[[2.4,5.3,1.2],[5.4,1.4263,1.2],[14.46,1.06,1.2],[2.4,5.3,1.2]]],256,false,true),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,1.2],[4,0,1.2],[4,4,2.3],[0,4,1.2],[0,0,1.2]],[[1,1,2.2],[3,1,3.3],[3,3,1.1],[1,3,2.4],[1,1,2.2]]],256,false,true)],256,false,true) multi_polygon.as_hex_ewkb.should eql("0106000020000100000200000001030000400200000004000000CDCCCCCCCCCC28406666666666A646C0333333333333F33F3333333333B34640CDCCCCCCCCCC4440333333333333F33F6DE7FBA9F1D211403D2CD49AE61DF13F333333333333F33FCDCCCCCCCCCC28406666666666A646C0333333333333F33F0400000033333333333303403333333333331540333333333333F33F9A999999999915408A8EE4F21FD2F63F333333333333F33FEC51B81E85EB2C40F6285C8FC2F5F03F333333333333F33F33333333333303403333333333331540333333333333F33F0103000040020000000500000000000000000000000000000000000000333333333333F33F00000000000010400000000000000000333333333333F33F00000000000010400000000000001040666666666666024000000000000000000000000000001040333333333333F33F00000000000000000000000000000000333333333333F33F05000000000000000000F03F000000000000F03F9A999999999901400000000000000840000000000000F03F6666666666660A40000000000000084000000000000008409A9999999999F13F000000000000F03F00000000000008403333333333330340000000000000F03F000000000000F03F9A99999999990140") end it "test_multi_polygon_text" do - multi_polygon = MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) + multi_polygon = GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) multi_polygon.as_ewkt.should eql("SRID=256;MULTIPOLYGON(((12.4 -45.3,45.4 41.6,4.456 1.0698,12.4 -45.3),(2.4 5.3,5.4 1.4263,14.46 1.06,2.4 5.3)),((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1)))") - multi_polygon = MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3,2],[45.4,41.6,3],[4.456,1.0698,4],[12.4,-45.3,2]],[[2.4,5.3,1],[5.4,1.4263,3.44],[14.46,1.06,4.5],[2.4,5.3,1]]],4326,true),Polygon.from_coordinates([[[0,0,5.6],[4,0,5.4],[4,4,1],[0,4,23],[0,0,5.6]],[[1,1,2.3],[3,1,4],[3,3,5],[1,3,6],[1,1,2.3]]],4326,true)],4326,true) + multi_polygon = GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3,2],[45.4,41.6,3],[4.456,1.0698,4],[12.4,-45.3,2]],[[2.4,5.3,1],[5.4,1.4263,3.44],[14.46,1.06,4.5],[2.4,5.3,1]]],4326,true),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,5.6],[4,0,5.4],[4,4,1],[0,4,23],[0,0,5.6]],[[1,1,2.3],[3,1,4],[3,3,5],[1,3,6],[1,1,2.3]]],4326,true)],4326,true) multi_polygon.as_ewkt.should eql("SRID=4326;MULTIPOLYGON(((12.4 -45.3 2,45.4 41.6 3,4.456 1.0698 4,12.4 -45.3 2),(2.4 5.3 1,5.4 1.4263 3.44,14.46 1.06 4.5,2.4 5.3 1)),((0 0 5.6,4 0 5.4,4 4 1,0 4 23,0 0 5.6),(1 1 2.3,3 1 4,3 3 5,1 3 6,1 1 2.3)))") end describe "Counting" do before do - @mp = MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) + @mp = GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256),GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256) end it "should have a points method" do - @mp.points[0].should be_instance_of(Point) + @mp.points[0].should be_instance_of(GeoRuby::SimpleFeatures::Point) end it "should flatten it right" do diff --git a/spec/geo_ruby/simple_features/point_spec.rb b/spec/geo_ruby/simple_features/point_spec.rb index ef6cbf9..30567de 100644 --- a/spec/geo_ruby/simple_features/point_spec.rb +++ b/spec/geo_ruby/simple_features/point_spec.rb @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe Point do - let(:point) { Point.new(4326) } +describe GeoRuby::SimpleFeatures::Point do + let(:point) { GeoRuby::SimpleFeatures::Point.new(4326) } it "should instantiatember" do violated unless point - point.should be_instance_of(Point) + point.should be_instance_of(GeoRuby::SimpleFeatures::Point) end it "should have a nice matcher" do @@ -18,15 +18,15 @@ end it "should have a very nice matcher" do - Point.from_x_y_z_m(1,2,3.33,"t").should be_a_point(1, 2, 3.33, "t") + GeoRuby::SimpleFeatures::Point.from_x_y_z_m(1,2,3.33,"t").should be_a_point(1, 2, 3.33, "t") end it "should have a dumb matcher" do - Point.should be_geometric + GeoRuby::SimpleFeatures::Point.should be_geometric end it "should be subclassable" do - place = Class.new(Point) + place = Class.new(GeoRuby::SimpleFeatures::Point) p = place.from_x_y(1,2) p.should be_a place end @@ -54,18 +54,18 @@ end it "should compare ok" do - point1= Point::new + point1= GeoRuby::SimpleFeatures::Point::new point1.set_x_y(1.5,45.4) - point2= Point::new + point2= GeoRuby::SimpleFeatures::Point::new point2.set_x_y(1.5,45.4) - point3= Point::new + point3= GeoRuby::SimpleFeatures::Point::new point3.set_x_y(4.5,12.3) - point4= Point::new + point4= GeoRuby::SimpleFeatures::Point::new point4.set_x_y_z(1.5,45.4,423) - point5= Point::new + point5= GeoRuby::SimpleFeatures::Point::new point5.set_x_y(1.5,45.4) point5.m=15 - geometry= Geometry::new + geometry= GeoRuby::SimpleFeatures::Geometry::new point1.should == point2 point1.should_not == point3 @@ -77,7 +77,7 @@ describe "> Instantiation" do it "should instantiate a 2d point" do - point = Point.from_x_y(10,20,123) + point = GeoRuby::SimpleFeatures::Point.from_x_y(10,20,123) point.x.should eql(10) point.y.should eql(20) point.srid.should eql(123) @@ -85,21 +85,21 @@ end it "should instantiate a 2d easily" do - point = Point.xy(10,20,123) + point = GeoRuby::SimpleFeatures::Point.xy(10,20,123) point.x.should eql(10) point.y.should eql(20) point.srid.should eql(123) end it "should instantiate a 3d point" do - point = Point.from_x_y_z(-10,-20,-30) + point = GeoRuby::SimpleFeatures::Point.from_x_y_z(-10,-20,-30) point.x.should eql(-10) point.y.should eql(-20) point.z.should eql(-30) end it "should instantiate a 3d(m) point" do - point = Point.from_x_y_m(10,20,30) + point = GeoRuby::SimpleFeatures::Point.from_x_y_m(10,20,30) point.x.should eql(10) point.y.should eql(20) point.m.should eql(30) @@ -107,7 +107,7 @@ end it "should instantiate a 4d point" do - point = Point.from_x_y_z_m(10,20,30,40,123) + point = GeoRuby::SimpleFeatures::Point.from_x_y_z_m(10,20,30,40,123) point.x.should eql(10) point.y.should eql(20) point.z.should eql(30) @@ -116,13 +116,13 @@ end it "should instantiate a point from polar coordinates" do - point = Point.from_r_t(1.4142,45) + point = GeoRuby::SimpleFeatures::Point.from_r_t(1.4142,45) point.y.should be_within(0.1).of(1) point.x.should be_within(0.1).of(1) end it "should instantiate from coordinates x,y" do - point = Point.from_coordinates([1.6,2.8],123) + point = GeoRuby::SimpleFeatures::Point.from_coordinates([1.6,2.8],123) point.x.should eql(1.6) point.y.should eql(2.8) point.should_not be_with_z @@ -131,7 +131,7 @@ end it "should instantiate from coordinates x,y,z" do - point = Point.from_coordinates([1.6,2.8,3.4],123, true) + point = GeoRuby::SimpleFeatures::Point.from_coordinates([1.6,2.8,3.4],123, true) point.x.should eql(1.6) point.y.should eql(2.8) point.z.should eql(3.4) @@ -140,7 +140,7 @@ end it "should instantiate from coordinates x,y,z,m" do - point = Point.from_coordinates([1.6,2.8,3.4,15],123, true, true) + point = GeoRuby::SimpleFeatures::Point.from_coordinates([1.6,2.8,3.4,15],123, true, true) point.x.should eql(1.6) point.y.should eql(2.8) point.z.should eql(3.4) @@ -151,65 +151,65 @@ end it "should have a bbox" do - bbox = Point.from_x_y_z_m(-1.6,2.8,-3.4,15,123).bounding_box + bbox = GeoRuby::SimpleFeatures::Point.from_x_y_z_m(-1.6,2.8,-3.4,15,123).bounding_box bbox.length.should eql(2) - bbox[0].should == Point.from_x_y_z(-1.6,2.8,-3.4) - bbox[1].should == Point.from_x_y_z(-1.6,2.8,-3.4) + bbox[0].should == GeoRuby::SimpleFeatures::Point.from_x_y_z(-1.6,2.8,-3.4) + bbox[1].should == GeoRuby::SimpleFeatures::Point.from_x_y_z(-1.6,2.8,-3.4) end it "should parse lat long" do - Point.from_latlong("-20° 47' 26.37","-20° 47' 26.37").x.should be_within(0.00001).of(-20.790658) - Point.from_latlong("20° 47' 26.378","20° 47' 26.378").y.should be_within(0.00001).of(20.790658) + GeoRuby::SimpleFeatures::Point.from_latlong("-20° 47' 26.37","-20° 47' 26.37").x.should be_within(0.00001).of(-20.790658) + GeoRuby::SimpleFeatures::Point.from_latlong("20° 47' 26.378","20° 47' 26.378").y.should be_within(0.00001).of(20.790658) end it "should parse lat long w/o sec" do - Point.from_latlong("-20°47′26″","-20°47′26″").x.should be_within(0.00001).of(-20.790555) - Point.from_latlong("20°47′26″","20°47′26″").y.should be_within(0.00001).of(20.790555) + GeoRuby::SimpleFeatures::Point.from_latlong("-20°47′26″","-20°47′26″").x.should be_within(0.00001).of(-20.790555) + GeoRuby::SimpleFeatures::Point.from_latlong("20°47′26″","20°47′26″").y.should be_within(0.00001).of(20.790555) end it "should accept with W or S notation" do - Point.from_latlong("20° 47' 26.37 W","20° 47' 26.37 S").x.should be_within(0.00001).of(-20.790658) - Point.from_latlong("20° 47' 26.37 W","20° 47' 26.37 S").y.should be_within(0.00001).of(-20.790658) + GeoRuby::SimpleFeatures::Point.from_latlong("20° 47' 26.37 W","20° 47' 26.37 S").x.should be_within(0.00001).of(-20.790658) + GeoRuby::SimpleFeatures::Point.from_latlong("20° 47' 26.37 W","20° 47' 26.37 S").y.should be_within(0.00001).of(-20.790658) end it "should instantiate a point from positive degrees" do - point = Point.from_latlong('47`20 06.09E','22`50 77.35N') + point = GeoRuby::SimpleFeatures::Point.from_latlong('47`20 06.09E','22`50 77.35N') point.y.should be_within(0.000001).of(22.8548194) point.x.should be_within(0.000001).of(47.335025) end it "should instantiate a point from negative degrees" do - point = Point.from_latlong('47`20 06.09W','22`50 77.35S') + point = GeoRuby::SimpleFeatures::Point.from_latlong('47`20 06.09W','22`50 77.35S') point.y.should be_within(0.000001).of(-22.8548194) point.x.should be_within(0.000001).of(-47.335025) end it "should print out nicely" do - Point.from_x_y(47.88, -20.1).as_latlong.should eql("47°52′48″, -20°06′00″") + GeoRuby::SimpleFeatures::Point.from_x_y(47.88, -20.1).as_latlong.should eql("47°52′48″, -20°06′00″") end it "should print out nicely" do - Point.from_x_y(-20.78, 20.78).as_latlong(:full => true).should eql("-20°46′48.00″, 20°46′48.00″") + GeoRuby::SimpleFeatures::Point.from_x_y(-20.78, 20.78).as_latlong(:full => true).should eql("-20°46′48.00″, 20°46′48.00″") end it "should print out nicely" do - Point.from_x_y(47.11, -20.2).as_latlong(:full => true).should eql("47°06′36.00″, -20°11′60.00″") + GeoRuby::SimpleFeatures::Point.from_x_y(47.11, -20.2).as_latlong(:full => true).should eql("47°06′36.00″, -20°11′60.00″") end it "should print out nicely" do - Point.from_x_y(47.11, -20.2).as_latlong(:coord => true).should eql("47°06′36″N, 20°11′60″W") + GeoRuby::SimpleFeatures::Point.from_x_y(47.11, -20.2).as_latlong(:coord => true).should eql("47°06′36″N, 20°11′60″W") end it "should print out nicely" do - Point.from_x_y(-47.11, 20.2).as_latlong(:full => true,:coord => true).should eql("47°06′36.00″S, 20°11′60.00″E") + GeoRuby::SimpleFeatures::Point.from_x_y(-47.11, 20.2).as_latlong(:full => true,:coord => true).should eql("47°06′36.00″S, 20°11′60.00″E") end end describe " > Distance & Bearing" do - let(:p1) { Point.from_x_y(1,1) } - let(:p2) { Point.from_x_y(2,2) } + let(:p1) { GeoRuby::SimpleFeatures::Point.from_x_y(1,1) } + let(:p2) { GeoRuby::SimpleFeatures::Point.from_x_y(2,2) } it "and a 3th grade child should calculate euclidian distance" do p1.euclidian_distance(p2). @@ -227,8 +227,8 @@ end describe "Orthogonal Distance" do - let(:line) { LineString.from_coordinates([[0,0],[1,3]], 4326) } - let(:line2) { LineString.from_coordinates([[1,1],[1,2]], 4326) } + let(:line) { GeoRuby::SimpleFeatures::LineString.from_coordinates([[0,0],[1,3]], 4326) } + let(:line2) { GeoRuby::SimpleFeatures::LineString.from_coordinates([[1,1],[1,2]], 4326) } it "should calcula orthogonal distance from a line (90 deg)" do p1.orthogonal_distance(line).should be_within(0.001).of(1.414) @@ -257,22 +257,22 @@ end it "should calculate the bearing from apoint to another in degrees" do - p3 = Point.from_x_y(1,-1) + p3 = GeoRuby::SimpleFeatures::Point.from_x_y(1,-1) p1.bearing_to(p3).should be_within(0.01).of(180.0) end it "should calculate the bearing from apoint to another in degrees" do - p3 = Point.from_x_y(-1,-1) + p3 = GeoRuby::SimpleFeatures::Point.from_x_y(-1,-1) p1.bearing_to(p3).should be_within(0.01).of(225.0) end it "should calculate the bearing from apoint to another in degrees" do - p3 = Point.from_x_y(-1,1) + p3 = GeoRuby::SimpleFeatures::Point.from_x_y(-1,1) p1.bearing_to(p3).should be_within(0.01).of(270.0) end it "should calculate the bearing from apoint to another in degrees" do - p3 = Point.from_x_y(2,-1) + p3 = GeoRuby::SimpleFeatures::Point.from_x_y(2,-1) p1.bearing_to(p3).should be_within(0.0001).of(153.4349488) end @@ -285,7 +285,7 @@ end it "should calculate the bearing from apoint to another in degrees" do - p3 = Point.from_x_y(-1,1) + p3 = GeoRuby::SimpleFeatures::Point.from_x_y(-1,1) p1.bearing_text(p3).should eql(:w) end @@ -293,7 +293,7 @@ describe "> Export Formats" do - let(:point) { Point.from_x_y( -11.2431, 32.3141 ) } + let(:point) { GeoRuby::SimpleFeatures::Point.from_x_y( -11.2431, 32.3141 ) } it "should print out as array" do @@ -304,19 +304,19 @@ end it "should printoout as binary" do - Point.from_x_y(12.4,45.3,123).as_hex_ewkb.should eql("01010000207B000000CDCCCCCCCCCC28406666666666A64640") - point = Point.from_x_y_z_m(12.4,45.3,-3.5,15,123) + GeoRuby::SimpleFeatures::Point.from_x_y(12.4,45.3,123).as_hex_ewkb.should eql("01010000207B000000CDCCCCCCCCCC28406666666666A64640") + point = GeoRuby::SimpleFeatures::Point.from_x_y_z_m(12.4,45.3,-3.5,15,123) point.as_hex_ewkb.should eql("01010000E07B000000CDCCCCCCCCCC28406666666666A646400000000000000CC00000000000002E40") point.as_hex_wkb.should eql("0101000000CDCCCCCCCCCC28406666666666A64640") end it "should printoout as text" do - Point.from_x_y(12.4,45.3,123).as_ewkt.should eql("SRID=123;POINT(12.4 45.3)") - point = Point.from_x_y_z(12.4,45.3,-3.5,123) + GeoRuby::SimpleFeatures::Point.from_x_y(12.4,45.3,123).as_ewkt.should eql("SRID=123;POINT(12.4 45.3)") + point = GeoRuby::SimpleFeatures::Point.from_x_y_z(12.4,45.3,-3.5,123) point.as_ewkt.should eql("SRID=123;POINT(12.4 45.3 -3.5)") point.as_wkt.should eql("POINT(12.4 45.3)") point.as_ewkt(false,true).should eql("POINT(12.4 45.3 -3.5)") - point = Point.from_x_y_m(12.4,45.3,-3.5,123) + point = GeoRuby::SimpleFeatures::Point.from_x_y_m(12.4,45.3,-3.5,123) point.as_ewkt.should eql("SRID=123;POINTM(12.4 45.3 -3.5)") point.as_ewkt(true,true,false).should eql("SRID=123;POINT(12.4 45.3)") end diff --git a/spec/geo_ruby/simple_features/polygon_spec.rb b/spec/geo_ruby/simple_features/polygon_spec.rb index 5a99fe8..d5c72fd 100644 --- a/spec/geo_ruby/simple_features/polygon_spec.rb +++ b/spec/geo_ruby/simple_features/polygon_spec.rb @@ -1,17 +1,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe Polygon do +describe GeoRuby::SimpleFeatures::Polygon do describe "Instance Methods" do - let(:poly) { Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) } + let(:poly) { GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) } it "should check if contains point" do - poly.contains_point?(Point.from_x_y(3, 3)).should be_true + poly.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(3, 3)).should be_true end it "should check if not contains point" do - poly.contains_point?(Point.from_x_y(5, 5)).should be_false + poly.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(5, 5)).should be_false end end @@ -19,18 +19,18 @@ describe "tu converted" do #no test of the binary representation for linear_rings : always with polygons and like line_string it "should test_polygon_creation" do - linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256) - linear_ring2 = LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256) - point1 = Point.from_x_y(12.4,-45.3,256) - point2 = Point.from_x_y(45.4,41.6,256) - point3 = Point.from_x_y(4.456,1.0698,256) - point4 = Point.from_x_y(12.4,-45.3,256) - point5 = Point.from_x_y(2.4,5.3,256) - point6 = Point.from_x_y(5.4,1.4263,256) - point7 = Point.from_x_y(14.46,1.06,256) - point8 = Point.from_x_y(2.4,5.3,256) - - polygon = Polygon::new(256) + linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256) + linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256) + point1 = GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3,256) + point2 = GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6,256) + point3 = GeoRuby::SimpleFeatures::Point.from_x_y(4.456,1.0698,256) + point4 = GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3,256) + point5 = GeoRuby::SimpleFeatures::Point.from_x_y(2.4,5.3,256) + point6 = GeoRuby::SimpleFeatures::Point.from_x_y(5.4,1.4263,256) + point7 = GeoRuby::SimpleFeatures::Point.from_x_y(14.46,1.06,256) + point8 = GeoRuby::SimpleFeatures::Point.from_x_y(2.4,5.3,256) + + polygon = GeoRuby::SimpleFeatures::Polygon::new(256) polygon.length.should be_zero polygon << linear_ring1 @@ -42,78 +42,78 @@ polygon.length.should eql(2) polygon[1].should == linear_ring2 - polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256) - polygon.class.should eql(Polygon) + polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring1,linear_ring2],256) + polygon.class.should eql(GeoRuby::SimpleFeatures::Polygon) polygon.length.should eql(2) polygon[0].should == linear_ring1 polygon[1].should == linear_ring2 - polygon = Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) - polygon.class.should eql(Polygon) + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) + polygon.class.should eql(GeoRuby::SimpleFeatures::Polygon) polygon.length.should eql(2) polygon[0].should == linear_ring1 polygon[1].should == linear_ring2 - polygon = Polygon.from_points([[point1,point2,point3,point4],[point5,point6,point7,point8]],256) + polygon = GeoRuby::SimpleFeatures::Polygon.from_points([[point1,point2,point3,point4],[point5,point6,point7,point8]],256) polygon.length.should eql(2) polygon[0].should == linear_ring1 polygon[1].should == linear_ring2 - polygon = Polygon.from_coordinates([[[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],[[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]]],256,true) - polygon.class.should eql(Polygon) + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],[[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]]],256,true) + polygon.class.should eql(GeoRuby::SimpleFeatures::Polygon) polygon.length.should eql(2) - linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],256,true) - linear_ring2 = LinearRing.from_coordinates([[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]],256,true) + linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],256,true) + linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]],256,true) polygon[0].should == linear_ring1 polygon[1].should == linear_ring2 end it "bbox" do - bbox = Polygon.from_coordinates([[[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],[[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]]],256,true).bounding_box + bbox = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],[[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]]],256,true).bounding_box bbox.length.should eql(2) - bbox[0].should == Point.from_x_y_z(4.456,-45.3,2.4) - bbox[1].should == Point.from_x_y_z(45.4,41.6,123.1) + bbox[0].should == GeoRuby::SimpleFeatures::Point.from_x_y_z(4.456,-45.3,2.4) + bbox[1].should == GeoRuby::SimpleFeatures::Point.from_x_y_z(45.4,41.6,123.1) end it "test_polygon_equal" do - polygon1 = Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) - polygon2 = Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06]]]) - point = Point.from_x_y(12.4,-45.3,123) + polygon1 = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) + polygon2 = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06]]]) + point = GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3,123) - polygon1.should == Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) + polygon1.should == GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256) polygon1.should_not == polygon2 polygon1.should_not == point end it "test_polygon_binary" do - polygon = Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) #taken from PostGIS answer polygon.as_hex_ewkb.should eql("0103000020000100000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F") - polygon = Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true) + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true) #taken from PostGIS answer polygon.as_hex_ewkb.should eql("01030000A000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040") - polygon = Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true) + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true) polygon.as_hex_ewkb.should eql("010300006000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040") - polygon = Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true) + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true) polygon.as_hex_ewkb.should eql("01030000E0000100000200000005000000000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C00000000000001040000000000000000000000000000000400000000000001440000000000000104000000000000010400000000000000040AE47E17A14AE1240000000000000000000000000000010400000000000000040713D0AD7A370F53F000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C005000000000000000000F03F000000000000F03F00000000000000409A999999999928400000000000000840000000000000F03F00000000000000400000000000C05E400000000000000840000000000000084000000000000000406666666666662840000000000000F03F000000000000084000000000000000400000000000002840000000000000F03F000000000000F03F00000000000000409A99999999992840") end it "should test_polygon_text" do - polygon = Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) polygon.as_ewkt.should eql("SRID=256;POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1))") - polygon = Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true) + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true) polygon.as_ewkt.should eql("SRID=256;POLYGON((0 0 2,4 0 2,4 4 2,0 4 2,0 0 2),(1 1 2,3 1 2,3 3 2,1 3 2,1 1 2))") - polygon = Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true) + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true) polygon.as_ewkt.should eql("SRID=256;POLYGONM((0 0 2,4 0 2,4 4 2,0 4 2,0 0 2),(1 1 2,3 1 2,3 3 2,1 3 2,1 1 2))") - polygon = Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true) + polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true) polygon.as_ewkt.should eql("SRID=256;POLYGON((0 0 2 -45.1,4 0 2 5,4 4 2 4.67,0 4 2 1.34,0 0 2 -45.1),(1 1 2 12.3,3 1 2 123,3 3 2 12.2,1 3 2 12,1 1 2 12.3))") end diff --git a/spec/geo_ruby_spec.rb b/spec/geo_ruby_spec.rb index 09b71ab..5a24164 100644 --- a/spec/geo_ruby_spec.rb +++ b/spec/geo_ruby_spec.rb @@ -2,26 +2,21 @@ # Time to add your specs! # http://rspec.info/ -describe "GeoRuby Stuff" do - +describe GeoRuby do + it "should instantiate Geometry" do @geo = GeoRuby::SimpleFeatures::Geometry.new - @geo.class.should eql(Geometry) - end - - it "should instantiate from SimpleFeatures for compatibility" do - @geo = GeoRuby::SimpleFeatures::Geometry.new - @geo.class.should eql(Geometry) + @geo.class.should eql(::GeoRuby::SimpleFeatures::Geometry) end it "should instantiate Point" do - @point = Point.new - @point.should be_instance_of(Point) + @point = GeoRuby::SimpleFeatures::Point.new + @point.should be_instance_of(::GeoRuby::SimpleFeatures::Point) end it "should instantiate Line" do - @line = LineString.new - @line.should be_instance_of(LineString) + @line = GeoRuby::SimpleFeatures::LineString.new + @line.should be_instance_of(::GeoRuby::SimpleFeatures::LineString) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 56b04e2..acb63d8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,13 +6,8 @@ #require 'active_support/core_ext/object' #require 'json/pure' -# begin -# require 'spec' -# rescue LoadError require 'rspec' -#end -$:.unshift(File.dirname(__FILE__) + '/../lib') require 'geo_ruby' require 'geo_ruby/shp' require 'geo_ruby/gpx' @@ -20,9 +15,6 @@ require 'geo_ruby/georss' require 'geo_ruby/kml' -include GeoRuby -include SimpleFeatures - module GeorubyMatchers class BeGeometric @@ -52,7 +44,7 @@ def matches?(actual) end end end - actual.should be_instance_of(Point) + actual.should be_instance_of(GeoRuby::SimpleFeatures::Point) end def failure_message; "expected #{@expect} but received #{@actual.inspect}"; end