Skip to content

Commit f004943

Browse files
committed
Redirect macros to extensions.
1 parent 299f4eb commit f004943

File tree

3 files changed

+119
-8
lines changed

3 files changed

+119
-8
lines changed

GeoInterfaceRecipes/Project.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
name = "GeoInterfaceRecipes"
22
uuid = "0329782f-3d07-4b52-b9f6-d3137cf03c7a"
3-
authors = ["JuliaGeo and contributors"]
43
version = "1.0.3"
4+
authors = ["JuliaGeo and contributors"]
55

66
[deps]
77
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
8+
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
89

910
[compat]
1011
GeoInterface = "1.5"
11-
julia = "1.6"
12+
RecipesBase = "1"
13+
julia = "1.9"
14+
15+
[extras]
16+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
17+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
18+
19+
[targets]
20+
test = ["Plots", "Test"]
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
module GeoInterfaceRecipes
2+
using RecipesBase
3+
using GeoInterface
4+
5+
export @enable_geo_plots
26

37
# This package is deprecated. Plotting recipes are now built into GeoInterface.jl
48
# as package extensions. See:
59
# - GeoInterfaceRecipesBaseExt for Plots.jl support
610
# - GeoInterfaceMakieExt for Makie.jl support
7-
#
8-
# This empty package exists only to allow smooth upgrades for users who had
11+
12+
# This stub package exists only to allow smooth upgrades for users who had
913
# GeoInterfaceRecipes.jl installed. No action is needed - simply load
1014
# GeoInterface with Plots or Makie and the recipes will work automatically.
1115

16+
macro enable(typ)
17+
:(GeoInterface.@enable_plots RecipesBase $(esc(typ)))
18+
end
19+
20+
# Compat
21+
macro enable_geo_plots(typ)
22+
:(GeoInterface.@enable_plots RecipesBase $(esc(typ)))
23+
end
24+
1225
end
Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,97 @@
11
using GeoInterfaceRecipes
2+
using GeoInterface
3+
using Plots
24
using Test
35

4-
@testset "GeoInterfaceRecipes.jl" begin
5-
# This is now an empty stub package.
6-
# The actual recipes are in GeoInterface.jl extensions.
7-
@test true
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())
897
end

0 commit comments

Comments
 (0)