$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'geo_ruby'
require 'test/unit'
include GeoRuby::SimpleFeatures
class TestGeorssKml < Test::Unit::TestCase
def test_geometry_creation
point = Point.from_x_y(3,4)
assert_equal("4 3", point.as_georss(:dialect => :simple, :elev => 45.7, :featuretypetag => "hoyoyo").gsub("\n",""))
assert_equal("43",point.as_georss(:dialect => :w3cgeo).gsub("\n",""))
assert_equal("4 3",point.as_georss(:dialect => :gml).gsub("\n",""))
assert_equal("3,4",point.as_kml(:id => "HOYOYO-42").gsub("\n",""))
end
def test_line_string
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)
assert_equal("-45.3 12.4 41.6 45.4",ls.as_georss.gsub("\n",""))
assert_equal("-45.312.4",ls.as_georss(:dialect => :w3cgeo).gsub("\n",""))
assert_equal("-45.3 12.4 41.6 45.4",ls.as_georss(:dialect => :gml).gsub("\n",""))
assert_equal("1absolute12.4,-45.3,56 45.4,41.6,45",ls.as_kml(:extrude => 1, :altitude_mode => "absolute").gsub("\n",""))
end
def test_polygon
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)
assert_equal("-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4",polygon.as_georss(:georss_ns => "hoyoyo").gsub("\n",""))
assert_equal("-45.312.4",polygon.as_georss(:dialect => :w3cgeo, :w3cgeo_ns => "bouyoul").gsub("\n",""))
assert_equal("-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4",polygon.as_georss(:dialect => :gml).gsub("\n",""))
assert_equal("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",polygon.as_kml.gsub("\n",""))
end
def test_geometry_collection
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
assert_equal("45.4 4.67",gc.as_georss(:dialect => :simple,:floor => 4).gsub("\n",""))
assert_equal("45.44.67",gc.as_georss(:dialect => :w3cgeo).gsub("\n",""))
assert_equal("45.4 4.67",gc.as_georss(:dialect => :gml).gsub("\n",""))
assert_equal("4.67,45.45.7,12.45 67.55,54",gc.as_kml(:id => "HOYOYO-42").gsub("\n",""))
end
def test_envelope
linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3,5],[45.4,41.6,6],[4.456,1.0698,8],[12.4,-45.3,3.5]],256,true)
linear_ring2 = LinearRing.from_coordinates([[2.4,5.3,9.0],[5.4,1.4263,-5.4],[14.46,1.06,34],[2.4,5.3,3.14]],256,true)
polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256,true)
e = polygon.envelope
assert_equal("-45.3 4.456 41.6 45.4",e.as_georss(:dialect => :simple).gsub("\n",""))
#center
assert_equal("-1.8524.928",e.as_georss(:dialect => :w3cgeo).gsub("\n",""))
assert_equal("-45.3 4.45641.6 45.4",e.as_georss(:dialect => :gml).gsub("\n",""))
assert_equal("41.6-45.345.44.456-5.434",e.as_kml.gsub("\n",""))
end
end