|
45 | 45 | mesh = triangle_mesh(Sphere(Point3f(0), 1))
|
46 | 46 | @test testgeometry(mesh)
|
47 | 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