|
1 | 1 | using GeoInterface |
2 | 2 | using Test |
3 | 3 |
|
4 | | -@testset "Developer" begin |
5 | | - # Implement interface |
6 | | - struct MyPoint end |
7 | | - struct MyEmptyPoint end |
8 | | - struct MyCurve end |
9 | | - struct MyPolygon end |
10 | | - struct MyTriangle end |
11 | | - struct MyMultiPoint end |
12 | | - struct MyMultiCurve end |
13 | | - struct MyMultiPolygon end |
14 | | - struct MyTIN end |
15 | | - struct MyCollection end |
16 | | - struct MyFeature{G,P} |
17 | | - geometry::G |
18 | | - properties::P |
19 | | - end |
20 | | - struct MyFeatureCollection{G} |
21 | | - geoms::G |
22 | | - end |
| 4 | +# Implement interface |
| 5 | +struct MyPoint end |
| 6 | +struct MyEmptyPoint end |
| 7 | +struct MyCurve end |
| 8 | +struct MyPolygon end |
| 9 | +struct MyTriangle end |
| 10 | +struct MyMultiPoint end |
| 11 | +struct MyMultiCurve end |
| 12 | +struct MyMultiPolygon end |
| 13 | +struct MyTIN end |
| 14 | +struct MyCollection end |
| 15 | +struct MyFeature{G,P} |
| 16 | + geometry::G |
| 17 | + properties::P |
| 18 | +end |
| 19 | +struct MyFeatureCollection{G} |
| 20 | + geoms::G |
| 21 | +end |
| 22 | + |
| 23 | +GeoInterface.isgeometry(::MyPoint) = true |
| 24 | +GeoInterface.geomtrait(::MyPoint) = PointTrait() |
| 25 | +GeoInterface.ncoord(::PointTrait, geom::MyPoint) = 2 |
| 26 | +GeoInterface.getcoord(::PointTrait, geom::MyPoint, i) = [1, 2][i] |
| 27 | + |
| 28 | +GeoInterface.isgeometry(::MyEmptyPoint) = true |
| 29 | +GeoInterface.geomtrait(::MyEmptyPoint) = PointTrait() |
| 30 | +GeoInterface.ncoord(::PointTrait, geom::MyEmptyPoint) = 0 |
| 31 | +GeoInterface.isempty(::PointTrait, geom::MyEmptyPoint) = true |
| 32 | + |
| 33 | +GeoInterface.isgeometry(::MyCurve) = true |
| 34 | +GeoInterface.geomtrait(::MyCurve) = LineStringTrait() |
| 35 | +GeoInterface.ngeom(::LineStringTrait, geom::MyCurve) = 2 |
| 36 | +GeoInterface.getgeom(::LineStringTrait, geom::MyCurve, i) = MyPoint() |
| 37 | + |
| 38 | +GeoInterface.isgeometry(::MyPolygon) = true |
| 39 | +GeoInterface.geomtrait(::MyPolygon) = PolygonTrait() |
| 40 | +GeoInterface.ngeom(::PolygonTrait, geom::MyPolygon) = 2 |
| 41 | +GeoInterface.getgeom(::PolygonTrait, geom::MyPolygon, i) = MyCurve() |
| 42 | + |
| 43 | +GeoInterface.isgeometry(::MyTriangle) = true |
| 44 | +GeoInterface.geomtrait(::MyTriangle) = TriangleTrait() |
| 45 | +GeoInterface.ngeom(::TriangleTrait, geom::MyTriangle) = 3 |
| 46 | +GeoInterface.getgeom(::TriangleTrait, geom::MyTriangle, i) = MyCurve() |
| 47 | + |
| 48 | +GeoInterface.isgeometry(::MyMultiPoint) = true |
| 49 | +GeoInterface.geomtrait(::MyMultiPoint) = MultiPointTrait() |
| 50 | +GeoInterface.ngeom(::MultiPointTrait, geom::MyMultiPoint) = 2 |
| 51 | +GeoInterface.getgeom(::MultiPointTrait, geom::MyMultiPoint, i) = MyPoint() |
| 52 | + |
| 53 | +GeoInterface.isgeometry(::MyMultiCurve) = true |
| 54 | +GeoInterface.geomtrait(::MyMultiCurve) = MultiCurveTrait() |
| 55 | +GeoInterface.ngeom(::MultiCurveTrait, geom::MyMultiCurve) = 2 |
| 56 | +GeoInterface.getgeom(::MultiCurveTrait, geom::MyMultiCurve, i) = MyCurve() |
| 57 | + |
| 58 | +GeoInterface.isgeometry(::MyMultiPolygon) = true |
| 59 | +GeoInterface.geomtrait(::MyMultiPolygon) = MultiPolygonTrait() |
| 60 | +GeoInterface.ngeom(::MultiPolygonTrait, geom::MyMultiPolygon) = 2 |
| 61 | +GeoInterface.getgeom(::MultiPolygonTrait, geom::MyMultiPolygon, i) = MyPolygon() |
| 62 | + |
| 63 | +GeoInterface.isgeometry(::MyTIN) = true |
| 64 | +GeoInterface.geomtrait(::MyTIN) = PolyhedralSurfaceTrait() |
| 65 | +GeoInterface.ngeom(::PolyhedralSurfaceTrait, geom::MyTIN) = 2 |
| 66 | +GeoInterface.getgeom(::PolyhedralSurfaceTrait, geom::MyTIN, i) = MyTriangle() |
| 67 | + |
| 68 | +GeoInterface.isgeometry(::MyCollection) = true |
| 69 | +GeoInterface.geomtrait(::MyCollection) = GeometryCollectionTrait() |
| 70 | +GeoInterface.ngeom(::GeometryCollectionTrait, geom::MyCollection) = 2 |
| 71 | +GeoInterface.getgeom(::GeometryCollectionTrait, geom::MyCollection, i) = MyCurve() |
| 72 | + |
| 73 | +GeoInterface.isfeature(::Type{<:MyFeature}) = true |
| 74 | +GeoInterface.trait(feature::MyFeature) = FeatureTrait() |
| 75 | +GeoInterface.geometry(f::MyFeature) = f.geometry |
| 76 | +GeoInterface.properties(f::MyFeature) = f.properties |
| 77 | +GeoInterface.extent(f::MyFeature) = nothing |
| 78 | + |
| 79 | +GeoInterface.isfeaturecollection(fc::Type{<:MyFeatureCollection}) = true |
| 80 | +GeoInterface.trait(fc::MyFeatureCollection) = FeatureCollectionTrait() |
| 81 | +GeoInterface.nfeature(::FeatureCollectionTrait, fc::MyFeatureCollection) = length(fc.geoms) |
| 82 | +GeoInterface.getfeature(::FeatureCollectionTrait, fc::MyFeatureCollection) = fc.geoms |
| 83 | +GeoInterface.getfeature(::FeatureCollectionTrait, fc::MyFeatureCollection, i::Integer) = fc.geoms[i] |
23 | 84 |
|
24 | | - GeoInterface.isgeometry(::MyPoint) = true |
25 | | - GeoInterface.geomtrait(::MyPoint) = PointTrait() |
26 | | - GeoInterface.ncoord(::PointTrait, geom::MyPoint) = 2 |
27 | | - GeoInterface.getcoord(::PointTrait, geom::MyPoint, i) = [1, 2][i] |
28 | | - |
29 | | - GeoInterface.isgeometry(::MyEmptyPoint) = true |
30 | | - GeoInterface.geomtrait(::MyEmptyPoint) = PointTrait() |
31 | | - GeoInterface.ncoord(::PointTrait, geom::MyEmptyPoint) = 0 |
32 | | - GeoInterface.isempty(::PointTrait, geom::MyEmptyPoint) = true |
33 | | - |
34 | | - GeoInterface.isgeometry(::MyCurve) = true |
35 | | - GeoInterface.geomtrait(::MyCurve) = LineStringTrait() |
36 | | - GeoInterface.ngeom(::LineStringTrait, geom::MyCurve) = 2 |
37 | | - GeoInterface.getgeom(::LineStringTrait, geom::MyCurve, i) = MyPoint() |
38 | | - |
39 | | - GeoInterface.isgeometry(::MyPolygon) = true |
40 | | - GeoInterface.geomtrait(::MyPolygon) = PolygonTrait() |
41 | | - GeoInterface.ngeom(::PolygonTrait, geom::MyPolygon) = 2 |
42 | | - GeoInterface.getgeom(::PolygonTrait, geom::MyPolygon, i) = MyCurve() |
43 | | - |
44 | | - GeoInterface.isgeometry(::MyTriangle) = true |
45 | | - GeoInterface.geomtrait(::MyTriangle) = TriangleTrait() |
46 | | - GeoInterface.ngeom(::TriangleTrait, geom::MyTriangle) = 3 |
47 | | - GeoInterface.getgeom(::TriangleTrait, geom::MyTriangle, i) = MyCurve() |
48 | | - |
49 | | - GeoInterface.isgeometry(::MyMultiPoint) = true |
50 | | - GeoInterface.geomtrait(::MyMultiPoint) = MultiPointTrait() |
51 | | - GeoInterface.ngeom(::MultiPointTrait, geom::MyMultiPoint) = 2 |
52 | | - GeoInterface.getgeom(::MultiPointTrait, geom::MyMultiPoint, i) = MyPoint() |
53 | | - |
54 | | - GeoInterface.isgeometry(::MyMultiCurve) = true |
55 | | - GeoInterface.geomtrait(::MyMultiCurve) = MultiCurveTrait() |
56 | | - GeoInterface.ngeom(::MultiCurveTrait, geom::MyMultiCurve) = 2 |
57 | | - GeoInterface.getgeom(::MultiCurveTrait, geom::MyMultiCurve, i) = MyCurve() |
58 | | - |
59 | | - GeoInterface.isgeometry(::MyMultiPolygon) = true |
60 | | - GeoInterface.geomtrait(::MyMultiPolygon) = MultiPolygonTrait() |
61 | | - GeoInterface.ngeom(::MultiPolygonTrait, geom::MyMultiPolygon) = 2 |
62 | | - GeoInterface.getgeom(::MultiPolygonTrait, geom::MyMultiPolygon, i) = MyPolygon() |
63 | | - |
64 | | - GeoInterface.isgeometry(::MyTIN) = true |
65 | | - GeoInterface.geomtrait(::MyTIN) = PolyhedralSurfaceTrait() |
66 | | - GeoInterface.ngeom(::PolyhedralSurfaceTrait, geom::MyTIN) = 2 |
67 | | - GeoInterface.getgeom(::PolyhedralSurfaceTrait, geom::MyTIN, i) = MyTriangle() |
68 | | - |
69 | | - GeoInterface.isgeometry(::MyCollection) = true |
70 | | - GeoInterface.geomtrait(::MyCollection) = GeometryCollectionTrait() |
71 | | - GeoInterface.ngeom(::GeometryCollectionTrait, geom::MyCollection) = 2 |
72 | | - GeoInterface.getgeom(::GeometryCollectionTrait, geom::MyCollection, i) = MyCurve() |
73 | | - |
74 | | - GeoInterface.isfeature(::Type{<:MyFeature}) = true |
75 | | - GeoInterface.trait(feature::MyFeature) = FeatureTrait() |
76 | | - GeoInterface.geometry(f::MyFeature) = f.geometry |
77 | | - GeoInterface.properties(f::MyFeature) = f.properties |
78 | | - GeoInterface.extent(f::MyFeature) = nothing |
79 | | - |
80 | | - GeoInterface.isfeaturecollection(fc::Type{<:MyFeatureCollection}) = true |
81 | | - GeoInterface.trait(fc::MyFeatureCollection) = FeatureCollectionTrait() |
82 | | - GeoInterface.nfeature(::FeatureCollectionTrait, fc::MyFeatureCollection) = length(fc.geoms) |
83 | | - GeoInterface.getfeature(::FeatureCollectionTrait, fc::MyFeatureCollection) = fc.geoms |
84 | | - GeoInterface.getfeature(::FeatureCollectionTrait, fc::MyFeatureCollection, i::Integer) = fc.geoms[i] |
| 85 | +@testset "Developer" begin |
85 | 86 |
|
86 | 87 | @testset "Point" begin |
87 | 88 | geom = MyPoint() |
|
366 | 367 | @test GeoInterface.testfeature(feature) |
367 | 368 | @test GeoInterface.testfeaturecollection([feature, feature]) |
368 | 369 | end |
| 370 | + |
| 371 | + |
| 372 | +end |
| 373 | + |
| 374 | +module ConvertTestModule |
| 375 | + using GeoInterface |
| 376 | + struct TestPolygon end |
| 377 | + geointerface_geomtype(::GeoInterface.PolygonTrait) = TestPolygon |
| 378 | + |
| 379 | + GeoInterface.isgeometry(::TestPolygon) = true |
| 380 | + GeoInterface.geomtrait(::TestPolygon) = PolygonTrait() |
| 381 | + GeoInterface.ngeom(::PolygonTrait, geom::TestPolygon) = 2 |
| 382 | + GeoInterface.getgeom(::PolygonTrait, geom::TestPolygon, i) = TestCurve() |
| 383 | + GeoInterface.convert(::Type{<:TestPolygon}, ::PolygonTrait, geom) = TestPolygon() |
369 | 384 | end |
| 385 | + |
| 386 | +@test GeoInterface.convert(ConvertTestModule, MyPolygon()) == ConvertTestModule.TestPolygon() |
0 commit comments