Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Makie extension #103

Merged
merged 6 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: true
matrix:
version:
- '1.7'
- '1.9'
- '1'
os:
- ubuntu-latest
Expand Down
14 changes: 12 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DBFTables = "75c7ada1-017a-5fb6-b8c7-2125ff2d6c93"
Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
GeoFormatTypes = "68eda718-8dee-11e9-39e7-89f7f65f511f"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
GeoInterfaceMakie = "0edc0954-3250-4c18-859d-ec71c1660c08"
GeoInterfaceRecipes = "0329782f-3d07-4b52-b9f6-d3137cf03c7a"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Expand All @@ -18,18 +19,27 @@ DBFTables = "1.2"
Extents = "0.1"
GeoFormatTypes = "0.4"
GeoInterface = "1.0"
GeoInterfaceMakie = "0.1"
GeoInterfaceRecipes = "1.0"
Makie = "0.20"
OrderedCollections = "1"
RecipesBase = "1"
Tables = "0.2, 1"
julia = "1.6"
julia = "1.9"

[weakdeps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
ShapefileMakieExt = "Makie"

[extras]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
RemoteFiles = "cbe49d4c-5af1-5b60-bb70-0a60aa018e1b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["ArchGDAL", "DataFrames", "Plots", "RemoteFiles", "Test"]
test = ["ArchGDAL", "DataFrames", "Makie", "Plots", "RemoteFiles", "Test"]
22 changes: 22 additions & 0 deletions ext/ShapefileMakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module ShapefileMakieExt
using GeoInterfaceMakie: GeoInterfaceMakie
using Shapefile: Shapefile
using Makie: Makie

GeoInterfaceMakie.@enable Shapefile.AbstractShape
GeoInterfaceMakie.@enable Shapefile.SubPolygon
GeoInterfaceMakie.@enable Shapefile.LinearRing

Makie.plottype(tbl::Shapefile.Table) = Makie.plottype(Shapefile.shapes(tbl))
Makie.plottype(shp::Shapefile.Handle) = Makie.plottype(Shapefile.shapes(shp))

for T in (Any, Union{Type{Any}, Type{<:Makie.AbstractPlot}}, Type{<:Makie.Poly}, Type{<:Makie.Lines}, Makie.PointBased)
@eval begin
Makie.convert_arguments(t::$T, tbl::Shapefile.Table) =
Makie.convert_arguments(t, Shapefile.shapes(tbl))
Makie.convert_arguments(t::$T, shp::Shapefile.Handle) =
Makie.convert_arguments(t, Shapefile.shapes(shp))
end
end

end
36 changes: 32 additions & 4 deletions test/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Shapefile
using Test
using RemoteFiles
using Plots
using Makie
import DBFTables
import Tables
import DataFrames
Expand Down Expand Up @@ -198,10 +199,37 @@ for shx_path in ne_shx
end
end

@testset "plot tables" begin
plot(ne_land)
plot(ne_coastline)
plot(ne_cities)

@testset "plot tables with Plots.jl" begin
# Tables
Plots.plot(ne_land)
Plots.plot(ne_coastline)
Plots.plot(ne_cities)
# Handles
Plots.plot(getfield(ne_land, :shp))
Plots.plot(getfield(ne_coastline, :shp))
Plots.plot(getfield(ne_cities, :shp))
end

@testset "plot tables with Makie.jl" begin
# Tables
p = Makie.plot(ne_land)
# Makie doesn't actually plot vectors of multiline string:
# Makie.plot(ne_coastline)
# So we do it manually
for geom in Shapefile.shapes(ne_coastline)
Makie.plot!(p.axis, geom)
end
Makie.plot!(p.axis, ne_cities)
# Handles
p = Makie.plot(getfield(ne_land, :shp))
# Makie doesn't actually plot vectors of multiline string:
# Makie.plot(ne_coastline)
# So we do it manually
for geom in Shapefile.shapes(getfield(ne_coastline, :shp))
Makie.plot!(p.axis, geom)
end
Makie.plot!(p.axis, getfield(ne_cities, :shp))
end

end # testset "Tables interface"
Loading