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

Support constructing FeatureCollection from Tables #55

Open
visr opened this issue Nov 16, 2022 · 4 comments
Open

Support constructing FeatureCollection from Tables #55

visr opened this issue Nov 16, 2022 · 4 comments

Comments

@visr
Copy link
Member

visr commented Nov 16, 2022

Right now we can convert FeatureCollection to DataFrames, but not back:

julia> using GeoJSON, DataFrames

julia> p = GeoJSON.Point(coordinates = [1.1, 2.2])
Point([1.1, 2.2])

julia> f = GeoJSON.Feature(p; properties = (a = 1, geometry = "g", b = 2))
Feature with a Point and 3 properties: (:geometry, :a, :b)

julia> features = [f]
1-element Vector{GeoJSON.Feature{NamedTuple{(:type, :geometry, :properties), Tuple{String, GeoJSON.Point{NamedTuple{(:type, :coordinates), Tuple{String, Vector{Float64}}}}, NamedTuple{(:a, :geometry, :b), Tuple{Int64, String, Int64}}}}}}:
 Feature with a Point and 3 properties: (:geometry, :a, :b)

julia> fc = GeoJSON.FeatureCollection(features)
FeatureCollection with 1 Features

julia> df = DataFrame(fc)
1×3 DataFrame
 Row │ geometry           a      b
     │ Geometry           Int64  Int64
─────┼─────────────────────────────────
   1Point([1.1, 2.2])      1      2

julia> GeoJSON.FeatureCollection(df)
ERROR: ArgumentError: column name :features not found in the data frame

It would be nice if this worked. We could also test with GeoDataFrames, and also look at that package for how to identify geometry columns (GeoInterface.geometrycolumns).

@rafaqz
Copy link
Member

rafaqz commented Dec 13, 2022

The issue will be that we don't have GeoInterface.geometrycolumns on a DataFrame. So we could just look for :geometry and have a geometrycolumn keyword to specify if it's different.

To reduce the need for the keyword we could also use DataAPI.jl metadata
JuliaGeo/GeoInterface.jl#77

@tlnagy
Copy link

tlnagy commented Jan 22, 2024

Just ran into this. I would love to be able to filter a FeatureCollection using all the power of the DataFrames-suite and then plot with GeoMakie. Do you have any suggestions on how to do this?

@rafaqz
Copy link
Member

rafaqz commented Jan 22, 2024

You can already conveet to a dataframe with DataFrame(feature). The problem here is getting it back to a GeoJSON.FeatureCollection... but it doesnt sound like you need that?

And geomakie should accept a vector of geometries?

You can also just plot a vector of GeoJSON geometries (e.g. a DataFrame column) with raw Makie.plot.

@rafaqz
Copy link
Member

rafaqz commented Jan 22, 2024

@visr you can just use GeoInterface.FeatureCollection now. We should add a Tables.jl extension to GeoInterface to let that injest tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants