MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.41k stars 312 forks source link

Supporting GeometryBasics geometries #660

Open Sov-trotter opened 4 years ago

Sov-trotter commented 4 years ago

Hello folks! Currently Makie only supports plotting Point or MultiPoint geometry.

using Makie, GeometryBasics

scatter([Point(1,2), Point(2, 3)])

mp = MultiPoint([Point(1,2), Point(2, 3)])

scatter(mp)

Other geometries like Linestring, polygon etc and their multi-geometry counterparts are not supported directly per se.

ls=LineString([Point(1, 2), Point(4,5), Point(10, 8), Point(1, 2)])

lines(ls)
ERROR: There was no `AbstractPlotting.convert_arguments` overload found for
the plot type Lines{...}, or its conversion trait AbstractPlotting.PointBased().
The arguments were:
(LineString{2,Int64,Point{2,Int64},Base.ReinterpretArray{GeometryBasics.Ngon{2,Int64,2,Point{2,Int64}},1,Tuple{Point{2,Int64},Point{2,Int64}},TupleView{Tuple{Point{2,Int64},Point{2,Int64}},2,1,Array{Point{2,Int64},1}}}},)

To fix this, define `AbstractPlotting.convert_arguments(::Lines{...}, ::LineString{2,Int64,Point{2,Int64},Base.ReinterpretArray{GeometryBasics.Ngon{2,Int64,2,Point{2,Int64}},1,Tuple{Point{2,Int64},Point{2,Int64}},TupleView{Tuple{Point{2,Int64},Point{2,Int64}},2,1,Array{Point{2,Int64},1}}}})`.

So it is clear that the convert_arguments method isn't defined for linestring yet.

But this way we can get it to plot our linestring

ls = LineString([Point(1, 2), Point(4,5), Point(10, 8), Point(1, 2)])

lines(ls.points.parent.data)

So can the GeometryBasics geometries added to Makie? I'd be more than happy to make a PR. :) If yes, then is there any better way to do it?

ffreyer commented 2 months ago

These are supported now

asinghvi17 commented 2 months ago

MultiLineStrings are still not supported but I have an implementation floating around somewhere in GeoMakie I think.

ffreyer commented 2 months ago

They are supported: https://github.com/MakieOrg/Makie.jl/blob/2b5931ee92c00603a669d02b8103bff49315024b/src/conversions.jl#L211-L221

kongdd commented 2 days ago

There also need a function for AbstractVector{<:MultiLineString{N,T}} Related with the issue of https://github.com/JuliaGeo/Shapefile.jl/issues/123.

function convert_arguments(PB::PointBased, linestring::AbstractVector{<:MultiLineString{N,T}}) where {N,T}
  T_out = float_type(T)
  arr = Point{N,T_out}[]
  n = length(linestring)
  for idx in 1:n
    append!(arr, convert_arguments(PB, linestring[idx])[1])
    if idx != n # don't add NaN at the end 
      push!(arr, Point{N,T_out}(NaN))
    end
  end
  return (arr,)
end
ffreyer commented 1 day ago

Seems like we could just extend the existing function to include AbstractVector{<: MultiLineString{N, T}}? Do you want to make a pr for this?