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

Makie ext #74

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[weakdeps]
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
MakieExt = ["GeoMakie", "Makie"]

[compat]
ArchGDAL = "0.10"
DataAPI = "1.13"
DataFrames = "1.4"
GeoFormatTypes = "0.3, 0.4"
GeoInterface = "1.0.1"
GeoMakie = "0.6, 0.7"
Makie = "0.20.8, 0.21"
Tables = "1"
julia = "1.6"

Expand Down
80 changes: 80 additions & 0 deletions ext/MakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module MakieExt

using GeoDataFrames
using Makie, GeoMakie

import GeoDataFrames.DataFrame
import GeoMakie.GeoInterface as GI
using GeoMakie.GeometryBasics


"""
plot(gdf::DataFrame)

Plot geometries from first column found to hold geometry data.

# Arguments
- `gdf` : GeoDataFrame
"""
function GeoDataFrames.plot(gdf::DataFrame)
col = try
first(GI.geometrycolumns(gdf))
catch err
rethrow(err)
end

return GeoDataFrames.plot(gdf, col)
end

"""
plot(gdf::DataFrame, geom_col::Symbol)

# Arguments
- `gdf` : GeoDataFrame
- `geom_col` : Column holding geometries to display
"""
function GeoDataFrames.plot(gdf::DataFrame, geom_col::Symbol)
f = Figure(; size=(600, 900))
ga = GeoAxis(
f[1,1];
dest="+proj=latlong +datum=WGS84",
xlabel="Longitude",
ylabel="Latitude",
xticklabelpad=15,
yticklabelpad=40,
xticklabelsize=10,
yticklabelsize=10,
aspect=AxisAspect(0.75)
)

trait = GI.trait(gdf[1, geom_col])
if trait == GI.PointTrait()
_plot!(ga, GeoMakie.geo2basic(gdf[!, geom_col]))
else
# Try plotting as multipolygon
_plot!(ga, GeoMakie.to_multipoly(gdf[!, geom_col]))
end

xlims!(ga)
ylims!(ga)

return f
end

function _plot!(ga::GeoAxis, data::Vector{<:GeometryBasics.Point})::Nothing
scatter!(ga, data)

return nothing
end
function _plot!(ga::GeoAxis, data::Vector{<:Vector{<:T}})::Nothing where {T<:GeometryBasics.MultiPolygon}
poly!(ga, data)

return nothing
end
function _plot!(ga::GeoAxis, data::Vector{<:T})::Nothing where {T<:GeometryBasics.MultiPolygon}
poly!(ga, data)

return nothing
end

end
1 change: 1 addition & 0 deletions src/GeoDataFrames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ using DataAPI
include("exports.jl")
include("io.jl")
include("utils.jl")
include("viz.jl")

end # module
4 changes: 4 additions & 0 deletions src/viz.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Dummy interface functions for extensions to hook into"""

function plot()
end