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

Supporting GeometryBasics geometries #660

Open
Sov-trotter opened this issue Jul 22, 2020 · 5 comments
Open

Supporting GeometryBasics geometries #660

Sov-trotter opened this issue Jul 22, 2020 · 5 comments

Comments

@Sov-trotter
Copy link
Contributor

Sov-trotter commented Jul 22, 2020

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
Copy link
Collaborator

ffreyer commented Aug 21, 2024

These are supported now

@ffreyer ffreyer closed this as completed Aug 21, 2024
@asinghvi17
Copy link
Member

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

@ffreyer
Copy link
Collaborator

ffreyer commented Aug 22, 2024

They are supported:

Makie.jl/src/conversions.jl

Lines 211 to 221 in 2b5931e

function convert_arguments(PB::PointBased, linestring::Union{<:AbstractVector{<:LineString{N, T}}, 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

@kongdd
Copy link

kongdd commented Nov 3, 2024

There also need a function for AbstractVector{<:MultiLineString{N,T}}
Related with the issue of JuliaGeo/Shapefile.jl#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
Copy link
Collaborator

ffreyer commented Nov 4, 2024

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

@ffreyer ffreyer reopened this Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants