GeoInterface.jl icon indicating copy to clipboard operation
GeoInterface.jl copied to clipboard

Can't plot geometry wrapper types

Open evetion opened this issue 2 years ago • 7 comments

julia> using GeoInterface, Plots, GeoFormatTypes

julia> points = GeoInterface.Point.(rand(10),rand(10), crs=GeoFormatTypes.EPSG(4326))
10-element Vector{GeoInterface.Wrappers.Point{false, false, Tuple{Float64, Float64}, EPSG}}:
 GeoInterface.Wrappers.Point{false, false, Tuple{Float64, Float64}, EPSG}((0.6569792502348218, 0.5196554284209661), EPSG(4326))
...

julia> plot(points)
ERROR: Cannot convert GeoInterface.Wrappers.Point{false, false, Tuple{Float64, Float64}, EPSG} to series data for plotting
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] _prepare_series_data(x::GeoInterface.Wrappers.Point{false, false, Tuple{Float64, Float64}, EPSG})
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:8
  [3] _series_data_vector(x::GeoInterface.Wrappers.Point{false, false, Tuple{Float64, Float64}, EPSG}, plotattributes::Dict{Symbol, Any})
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:36
  [4] (::RecipesPipeline.var"#21#24"{Dict{Symbol, Any}})(vi::GeoInterface.Wrappers.Point{false, false, Tuple{Float64, Float64}, EPSG})
    @ RecipesPipeline ./none:0
  [5] iterate
    @ ./generator.jl:47 [inlined]
  [6] _series_data_vector(v::Vector{GeoInterface.Wrappers.Point{false, false, Tuple{Float64, Float64}, EPSG}}, plotattributes::Dict{Symbol, Any})
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:51
  [7] macro expansion
    @ ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:129 [inlined]
  [8] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{RecipesPipeline.SliceIt}, x::Any, y::Any, z::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:300
  [9] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl:38
 [10] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/RecipesPipeline.jl:72
 [11] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/3BCH5/src/plot.jl:223
 [12] #plot#188
    @ ~/.julia/packages/Plots/3BCH5/src/plot.jl:102 [inlined]
 [13] plot(args::Any)
    @ Plots ~/.julia/packages/Plots/3BCH5/src/plot.jl:93
 [14] top-level scope
    @ REPL[10]:1

evetion avatar Sep 04 '23 12:09 evetion

Yeah you need to do using GeoInterfaceRecipes and it will work.

I recently did this: https://github.com/JuliaGeo/GeoInterface.jl/blob/main/GeoInterfaceRecipes/src/GeoInterfaceRecipes.jl#L184

It would be so much better if it just worked, but the dependency structure makes that impossible. I wish we could load packages in extensions then we could just load GeoInterfaceRecipes.jl if Plots.jl was around.

I've also wondered if we can hack in an include("../GeoInterfaceRecipes/src/GeoInterfaceRecipes.jl") from a Plots.jl extension of GeoInterface. It does mean compiling that code twice but maybe that's fine.

rafaqz avatar Sep 04 '23 13:09 rafaqz

Ah, of course, I forgot I explicitly needed to load it.

evetion avatar Sep 04 '23 13:09 evetion

Probably everyone will do that tho... what do you think about doing the the include hack?

rafaqz avatar Sep 04 '23 14:09 rafaqz

Why can't we make GeoInterfaceRecipes a proper extension depending on Plots?

felixcremer avatar Sep 05 '23 06:09 felixcremer

Extensions can only extend existing methods AFAIK. Not even sure whether recipes would count as such, probably not.

evetion avatar Sep 05 '23 06:09 evetion

The problem is other packages need to use the macro even when Plots is not avalable, or everyone has to do it in extensions.

But we can do both with the include hack

rafaqz avatar Sep 05 '23 08:09 rafaqz

If we're able to drop the GeometryBasics dependency in GeoInterfaceMakie, then it could be included as an extension on MakieCore! That solves the circular dependency issue, and we can probably pass polygons as vectors of vectors of tuples to Makie (if that doesn't work now, it can be made to work before Makie v0.21).

asinghvi17 avatar Apr 19 '24 22:04 asinghvi17

Fixed

rafaqz avatar Nov 08 '25 07:11 rafaqz