-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support Base.filter
on FeatureCollection
#87
Comments
Is there a reason not to convert to a DataFrames.jl |
Well my use case was GeoMakie, which works directly on FeatureCollections. |
You can pass the geometry column of a dataframe to GeoMakie and it should just work. |
It doesn't, though. Here's a reproducer: using CairoMakie, GeoMakie, GeoMakie.GeoJSON
using DataFrames, HTTP
url = "https://raw.githubusercontent.com/" *
"nvkelso/natural-earth-vector/master/geojson/" *
"ne_10m_admin_0_countries.geojson"
df = GeoJSON.read(HTTP.get(url).body) |> DataFrame
let fig = Figure()
ax = GeoAxis(fig[1, 1])
poly!(ax, df.geometry)
fig
end this throws a conversion error: ERROR: `Makie.convert_arguments` for the plot type Scatter and its conversion trait PointBased() was unsuccessful.
The signature that could not be converted was:
::Vector{Any}
[...] I suspect it has to do with the geometry column having both polygon and multipolygon entries: julia> df.geometry
258-element Vector{Union{GeoJSON.MultiPolygon{2, Float32}, GeoJSON.Polygon{2, Float32}}}:
2D MultiPolygonwith 264 sub-geometries
2D MultiPolygonwith 17 sub-geometries
2D MultiPolygonwith 163 sub-geometries
2D Polygonwith 1 sub-geometries
[...] (there seems to be a space missing in the show method for polygons, btw.) So I guess it might just be an XY problem, but maybe having |
ah yeah, somehow the type doesn't union to In this case you can do something like this: basically forcibly convert all of your geometries to multipolygons, so that the array has the correct type. |
As an aside GeoMakie.jl could accept any Tables.jl compatible table and get the But yeah that dispatch on mixed geometry vectors is annoying in a lot of places. @asinghvi17 would wrapping a mixed column as a |
I'm not sure that GeoMakie would accept a geometrycollection, given that it has to go to multiple plot types. Perhaps after Makie v0.21 once we figure out this specapi thing... We could special case it for the |
Anyway, I will close this. Operations like |
If you want to use filter on a GeoJSON feature collection, you can use TableOperations.jl, which is implementation-agnostic - though it will probably be slower than DataFrames! |
It would be convenient if you could do something like
filter(f -> f.NAME == "France", collection)
, but currently filtering is not supported.Right now, I'm naivley pirating this like so:
But I'm sure there is potential for improvement.
The text was updated successfully, but these errors were encountered: