|
| 1 | +@testset "Basic types" begin |
| 2 | + point = Point(2, 3) |
| 3 | + @test testgeometry(point) |
| 4 | + @test ncoord(point) == 2 |
| 5 | + @test getcoord(point, 2) == 3 |
| 6 | + @test GeoInterface.coordinates(point) == [2, 3] |
| 7 | + |
| 8 | + mp = MultiPoint([point, point]) |
| 9 | + @test testgeometry(mp) |
| 10 | + @test ngeom(mp) == 2 |
| 11 | + @test getgeom(mp, 2) == point |
| 12 | + @test GeoInterface.coordinates(mp) == [[2, 3], [2, 3]] |
| 13 | + |
| 14 | + linestring = LineString(Point{2,Int}[(10, 10), (20, 20), (10, 40)]) |
| 15 | + @test testgeometry(linestring) |
| 16 | + @test ngeom(linestring) == 3 |
| 17 | + @test getgeom(linestring, 1) == Point(10, 10) |
| 18 | + @test getgeom(linestring, 2) == Point(20, 20) |
| 19 | + @test getgeom(linestring, 3) == Point(10, 40) |
| 20 | + @test GeoInterface.coordinates(linestring) == [[10, 10], [20, 20], [10, 40]] |
| 21 | + |
| 22 | + multilinestring = MultiLineString([linestring, linestring]) |
| 23 | + @test testgeometry(multilinestring) |
| 24 | + @test GeoInterface.coordinates(multilinestring) == |
| 25 | + [[[10, 10], [20, 20], [10, 40]], [[10, 10], [20, 20], [10, 40]]] |
| 26 | + |
| 27 | + poly = Polygon(rand(Point{2,Float32}, 5), [rand(Point{2,Float32}, 5)]) |
| 28 | + @test testgeometry(poly) |
| 29 | + @test length(GeoInterface.coordinates(poly)) == 2 |
| 30 | + @test length(GeoInterface.coordinates(poly)[1]) == 5 |
| 31 | + |
| 32 | + triangle = Triangle(point, point, point) |
| 33 | + @test testgeometry(triangle) |
| 34 | + @test length(GeoInterface.coordinates(triangle)) == 1 |
| 35 | + @test length(GeoInterface.coordinates(triangle)[1]) == 3 |
| 36 | + |
| 37 | + polys = MultiPolygon([poly, poly]) |
| 38 | + @test testgeometry(polys) |
| 39 | + @test length(GeoInterface.coordinates(polys)) == 2 |
| 40 | + @test length(GeoInterface.coordinates(polys)[1]) == 2 |
| 41 | + @test length(GeoInterface.coordinates(polys)[1][1]) == 5 |
| 42 | +end |
| 43 | + |
| 44 | +@testset "Mesh" begin |
| 45 | + mesh = triangle_mesh(Sphere(Point3f(0), 1)) |
| 46 | + @test testgeometry(mesh) |
| 47 | +end |
| 48 | + |
| 49 | +@testset "Convert" begin |
| 50 | + # convert GeoJSON geometry types to GeometryBasics via the GeoInterface |
| 51 | + point_str = """{"type":"Point","coordinates":[30.1,10.1]}""" |
| 52 | + point_3d_str = """{"type":"Point","coordinates":[30.1,10.1,5.1]}""" |
| 53 | + linestring_str = """{"type":"LineString","coordinates":[[30.1,10.1],[10.1,30.1],[40.1,40.1]]}""" |
| 54 | + polygon_str = """{"type":"Polygon","coordinates":[[[30.1,10.1],[40.1,40.1],[20.1,40.1],[10.1,20.1],[30.1,10.1]]]}""" |
| 55 | + polygon_hole_str = """{"type":"Polygon","coordinates":[[[35.1,10.1],[45.1,45.1],[15.1,40.1],[10.1,20.1],[35.1,10.1]],[[20.1,30.1],[35.1,35.1],[30.1,20.1],[20.1,30.1]]]}""" |
| 56 | + multipoint_str = """{"type":"MultiPoint","coordinates":[[10.1,40.1],[40.1,30.1],[20.1,20.1],[30.1,10.1]]}""" |
| 57 | + multilinestring_str = """{"type":"MultiLineString","coordinates":[[[10.1,10.1],[20.1,20.1],[10.1,40.1]],[[40.1,40.1],[30.1,30.1],[40.1,20.1],[30.1,10.1]]]}""" |
| 58 | + multipolygon_str = """{"type":"MultiPolygon","coordinates":[[[[30.1,20.1],[45.1,40.1],[10.1,40.1],[30.1,20.1]]],[[[15.1,5.1],[40.1,10.1],[10.1,20.1],[5.1,10.1],[15.1,5.1]]]]}""" |
| 59 | + multipolygon_hole_str = """{"type":"MultiPolygon","coordinates":[[[[40.1,40.1],[20.1,45.1],[45.1,30.1],[40.1,40.1]]],[[[20.1,35.1],[10.1,30.1],[10.1,10.1],[30.1,5.1],[45.1,20.1],[20.1,35.1]],[[30.1,20.1],[20.1,15.1],[20.1,25.1],[30.1,20.1]]]]}""" |
| 60 | + |
| 61 | + point_json = GeoJSON.read(point_str) |
| 62 | + point_3d_json = GeoJSON.read(point_3d_str) |
| 63 | + linestring_json = GeoJSON.read(linestring_str) |
| 64 | + polygon_json = GeoJSON.read(polygon_str) |
| 65 | + polygon_hole_json = GeoJSON.read(polygon_hole_str) |
| 66 | + multipoint_json = GeoJSON.read(multipoint_str) |
| 67 | + multilinestring_json = GeoJSON.read(multilinestring_str) |
| 68 | + multipolygon_json = GeoJSON.read(multipolygon_str) |
| 69 | + multipolygon_hole_json = GeoJSON.read(multipolygon_hole_str) |
| 70 | + |
| 71 | + point_gb = GeoInterface.convert(Point, point_json) |
| 72 | + point_3d_gb = GeoInterface.convert(Point, point_3d_json) |
| 73 | + linestring_gb = GeoInterface.convert(LineString, linestring_json) |
| 74 | + polygon_gb = GeoInterface.convert(Polygon, polygon_json) |
| 75 | + polygon_hole_gb = GeoInterface.convert(Polygon, polygon_hole_json) |
| 76 | + multipoint_gb = GeoInterface.convert(MultiPoint, multipoint_json) |
| 77 | + multilinestring_gb = GeoInterface.convert(MultiLineString, multilinestring_json) |
| 78 | + multipolygon_gb = GeoInterface.convert(MultiPolygon, multipolygon_json) |
| 79 | + multipolygon_hole_gb = GeoInterface.convert(MultiPolygon, multipolygon_hole_json) |
| 80 | + |
| 81 | + @test point_gb === Point{2, Float64}(30.1, 10.1) |
| 82 | + @test point_3d_gb === Point{3, Float64}(30.1, 10.1, 5.1) |
| 83 | + @test linestring_gb isa LineString |
| 84 | + @test length(linestring_gb) == 2 |
| 85 | + @test eltype(linestring_gb) == Line{2, Float64} |
| 86 | + @test polygon_gb isa Polygon |
| 87 | + @test isempty(polygon_gb.interiors) |
| 88 | + @test polygon_hole_gb isa Polygon |
| 89 | + @test length(polygon_hole_gb.interiors) == 1 |
| 90 | + @test multipoint_gb isa MultiPoint |
| 91 | + @test length(multipoint_gb) == 4 |
| 92 | + @test multipoint_gb[4] === Point{2, Float64}(30.1, 10.1) |
| 93 | + @test multilinestring_gb isa MultiLineString |
| 94 | + @test length(multilinestring_gb) == 2 |
| 95 | + @test multipolygon_gb isa MultiPolygon |
| 96 | + @test length(multipolygon_gb) == 2 |
| 97 | + @test multipolygon_hole_gb isa MultiPolygon |
| 98 | + @test length(multipolygon_hole_gb) == 2 |
| 99 | + @test length(multipolygon_hole_gb[1].interiors) == 0 |
| 100 | + @test length(multipolygon_hole_gb[2].interiors) == 1 |
| 101 | +end |
0 commit comments