|
| 1 | +using GeoInterfaceRecipes |
| 2 | +using GeoInterface |
| 3 | +using Plots |
| 4 | +using Test |
| 5 | + |
| 6 | + |
| 7 | +abstract type MyAbstractGeom{N} end |
| 8 | +# Implement interface |
| 9 | +struct MyPoint{N} <: MyAbstractGeom{N} end |
| 10 | +struct MyCurve{N} <: MyAbstractGeom{N} end |
| 11 | +struct MyLinearRing{N} <: MyAbstractGeom{N} end |
| 12 | +struct MyLineString{N} <: MyAbstractGeom{N} end |
| 13 | +struct MyPolygon{N} <: MyAbstractGeom{N} end |
| 14 | +struct MyMultiPoint{N} <: MyAbstractGeom{N} end |
| 15 | +struct MyMultiCurve{N} <: MyAbstractGeom{N} end |
| 16 | +struct MyMultiPolygon{N} <: MyAbstractGeom{N} end |
| 17 | +struct MyCollection{N} <: MyAbstractGeom{N} end |
| 18 | +struct MyFeature end |
| 19 | +struct MyFeatureCollection end |
| 20 | + |
| 21 | +GeoInterfaceRecipes.@enable MyAbstractGeom |
| 22 | +GeoInterfaceRecipes.@enable MyFeature |
| 23 | +# Test legacy interface |
| 24 | +GeoInterfaceRecipes.@enable_geo_plots MyFeatureCollection |
| 25 | + |
| 26 | +GeoInterface.isgeometry(::MyAbstractGeom) = true |
| 27 | +GeoInterface.is3d(::GeoInterface.AbstractGeometryTrait, ::MyAbstractGeom{N}) where {N} = N == 3 |
| 28 | +GeoInterface.ncoord(::GeoInterface.AbstractGeometryTrait, geom::MyAbstractGeom{N}) where {N} = N |
| 29 | +GeoInterface.coordnames(::GeoInterface.AbstractGeometryTrait, ::MyAbstractGeom{2}) = (:X, :Y) |
| 30 | +GeoInterface.coordnames(::GeoInterface.AbstractGeometryTrait, ::MyAbstractGeom{3}) = (:X, :Y, :Z) |
| 31 | + |
| 32 | +GeoInterface.geomtrait(::MyPoint) = GeoInterface.PointTrait() |
| 33 | +GeoInterface.getcoord(::GeoInterface.PointTrait, geom::MyPoint{2}, i::Integer) = (rand(1:10), rand(11:20))[i] |
| 34 | +GeoInterface.getcoord(::GeoInterface.PointTrait, geom::MyPoint{3}, i::Integer) = (rand(1:10), rand(11:20), rand(21:30))[i] |
| 35 | + |
| 36 | +GeoInterface.geomtrait(::MyCurve) = GeoInterface.LineStringTrait() |
| 37 | +GeoInterface.ngeom(::GeoInterface.LineStringTrait, geom::MyCurve) = 3 |
| 38 | +GeoInterface.getgeom(::GeoInterface.LineStringTrait, geom::MyCurve{N}, i) where {N} = MyPoint{N}() |
| 39 | +GeoInterface.convert(::Type{MyCurve}, ::GeoInterface.LineStringTrait, geom) = geom |
| 40 | + |
| 41 | +GeoInterface.geomtrait(::MyLinearRing) = GeoInterface.LinearRingTrait() |
| 42 | +GeoInterface.ngeom(::GeoInterface.LinearRingTrait, geom::MyLinearRing) = 3 |
| 43 | +GeoInterface.getgeom(::GeoInterface.LinearRingTrait, geom::MyLinearRing{N}, i) where {N} = MyPoint{N}() |
| 44 | +GeoInterface.convert(::Type{MyLinearRing}, ::GeoInterface.LinearRingTrait, geom) = geom |
| 45 | + |
| 46 | +GeoInterface.geomtrait(::MyLineString) = GeoInterface.LineStringTrait() |
| 47 | +GeoInterface.ngeom(::GeoInterface.LineStringTrait, geom::MyLineString) = 3 |
| 48 | +GeoInterface.getgeom(::GeoInterface.LineStringTrait, geom::MyLineString{N}, i) where {N} = MyPoint{N}() |
| 49 | +GeoInterface.convert(::Type{MyLineString}, ::GeoInterface.LineStringTrait, geom) = geom |
| 50 | + |
| 51 | +GeoInterface.geomtrait(::MyPolygon) = GeoInterface.PolygonTrait() |
| 52 | +GeoInterface.ngeom(::GeoInterface.PolygonTrait, geom::MyPolygon) = 2 |
| 53 | +GeoInterface.getgeom(::GeoInterface.PolygonTrait, geom::MyPolygon{N}, i) where {N} = MyCurve{N}() |
| 54 | + |
| 55 | +GeoInterface.geomtrait(::MyMultiPolygon) = GeoInterface.MultiPolygonTrait() |
| 56 | +GeoInterface.ngeom(::GeoInterface.MultiPolygonTrait, geom::MyMultiPolygon) = 2 |
| 57 | +GeoInterface.getgeom(::GeoInterface.MultiPolygonTrait, geom::MyMultiPolygon{N}, i) where {N} = MyPolygon{N}() |
| 58 | + |
| 59 | +GeoInterface.geomtrait(::MyMultiPoint) = GeoInterface.MultiPointTrait() |
| 60 | +GeoInterface.ngeom(::GeoInterface.MultiPointTrait, geom::MyMultiPoint) = 10 |
| 61 | +GeoInterface.getgeom(::GeoInterface.MultiPointTrait, geom::MyMultiPoint{N}, i) where {N} = MyPoint{N}() |
| 62 | + |
| 63 | +GeoInterface.geomtrait(geom::MyCollection) = GeoInterface.GeometryCollectionTrait() |
| 64 | +GeoInterface.ncoord(::GeoInterface.GeometryCollectionTrait, geom::MyCollection{N}) where {N} = N |
| 65 | +GeoInterface.ngeom(::GeoInterface.GeometryCollectionTrait, geom::MyCollection) = 4 |
| 66 | +GeoInterface.getgeom(::GeoInterface.GeometryCollectionTrait, geom::MyCollection{N}, i) where {N} = MyMultiPolygon{N}() |
| 67 | + |
| 68 | +GeoInterface.trait(::MyFeature) = FeatureTrait() |
| 69 | +GeoInterface.trait(::MyFeatureCollection) = FeatureCollectionTrait() |
| 70 | +GeoInterface.getfeature(::GeoInterface.FeatureCollectionTrait, geom::MyFeatureCollection, i) = MyFeature() |
| 71 | +GeoInterface.getfeature(::GeoInterface.FeatureCollectionTrait, geom::MyFeatureCollection) = [MyFeature(), MyFeature()] |
| 72 | +GeoInterface.geometry(geom::MyFeature) = rand((MyPolygon{2}(), MyMultiPolygon{2}())) |
| 73 | +GeoInterface.nfeature(::GeoInterface.FeatureTrait, geom::MyFeature) = 1 |
| 74 | + |
| 75 | +@testset "plot" begin |
| 76 | + # We just check if they actually run |
| 77 | + # 2d |
| 78 | + plot(MyPoint{2}()) |
| 79 | + plot(MyCurve{2}()) |
| 80 | + plot(MyLinearRing{2}()) |
| 81 | + plot(MyLineString{2}()) |
| 82 | + plot(MyMultiPoint{2}()) |
| 83 | + plot(MyPolygon{2}()) |
| 84 | + plot(MyMultiPolygon{2}()) |
| 85 | + plot(MyCollection{2}()) |
| 86 | + # 3d |
| 87 | + plot(MyPoint{3}()) |
| 88 | + plot(MyCurve{3}()) |
| 89 | + plot(MyLinearRing{3}()) |
| 90 | + plot(MyLineString{3}()) |
| 91 | + plot(MyMultiPoint{3}()) |
| 92 | + plot(MyPolygon{3}()) |
| 93 | + plot(MyMultiPolygon{3}()) |
| 94 | + plot(MyCollection{3}()) |
| 95 | + plot(MyFeature()) |
| 96 | + plot(MyFeatureCollection()) |
| 97 | +end |
0 commit comments