From 452a9ddb77ccd9bcc8c012fe6e50416d777aba7f Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Thu, 3 Oct 2024 17:16:03 -0300 Subject: [PATCH 1/4] Add support for GeoInterface CRS metadata --- src/io.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/io.jl b/src/io.jl index 2f51b80..ce957a4 100644 --- a/src/io.jl +++ b/src/io.jl @@ -51,5 +51,9 @@ function read(fn::Union{AbstractString,Parquet2.FilePathsBase.AbstractPath,Parqu for column in keys(meta.columns) df[!, column] = GFT.WellKnownBinary.(Ref(GFT.Geom()), df[!, column]) end + mc = meta.columns[meta.primary_column] + if !isnothing(mc.crs) + metadata!(df, "GEOINTERFACE:crs", mc.crs) + end df end From 3fefcee34076063e805bc4729a8bca1db5d34fe7 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Thu, 3 Oct 2024 18:06:55 -0300 Subject: [PATCH 2/4] Apply suggestions --- src/io.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/io.jl b/src/io.jl index ce957a4..efa4523 100644 --- a/src/io.jl +++ b/src/io.jl @@ -48,12 +48,15 @@ function read(fn::Union{AbstractString,Parquet2.FilePathsBase.AbstractPath,Parqu is_valid(ds) || error("Not a valid GeoParquet file") meta = geometadata(ds) df = DataFrame(ds; copycols=false) - for column in keys(meta.columns) + geocolumns = Symbol.(keys(meta.columns)) + for column in geocolumns df[!, column] = GFT.WellKnownBinary.(Ref(GFT.Geom()), df[!, column]) end - mc = meta.columns[meta.primary_column] - if !isnothing(mc.crs) - metadata!(df, "GEOINTERFACE:crs", mc.crs) + # set GeoInterface metadata + metadata!(df, "GEOINTERFACE:geometrycolumns", geocolumns) + crs = meta.columns[meta.primary_column].crs + if !isnothing(crs) + metadata!(df, "GEOINTERFACE:crs", crs) end df end From 1ce6114d0ec9c9961ab9df206d3afc591e9d97c7 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Thu, 3 Oct 2024 18:13:33 -0300 Subject: [PATCH 3/4] Apply suggestions --- src/io.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/io.jl b/src/io.jl index efa4523..e0977bd 100644 --- a/src/io.jl +++ b/src/io.jl @@ -48,12 +48,11 @@ function read(fn::Union{AbstractString,Parquet2.FilePathsBase.AbstractPath,Parqu is_valid(ds) || error("Not a valid GeoParquet file") meta = geometadata(ds) df = DataFrame(ds; copycols=false) - geocolumns = Symbol.(keys(meta.columns)) - for column in geocolumns + for column in keys(meta.columns) df[!, column] = GFT.WellKnownBinary.(Ref(GFT.Geom()), df[!, column]) end # set GeoInterface metadata - metadata!(df, "GEOINTERFACE:geometrycolumns", geocolumns) + metadata!(df, "GEOINTERFACE:geometrycolumns", Tuple(Symbol.(keys(meta.columns)))) crs = meta.columns[meta.primary_column].crs if !isnothing(crs) metadata!(df, "GEOINTERFACE:crs", crs) From a710a8b8b20e16928035289ea0d314f31157e798 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Tue, 8 Oct 2024 17:22:12 -0300 Subject: [PATCH 4/4] Add tests --- test/runtests.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index a837776..42201ac 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -37,6 +37,9 @@ end df = GeoParquet.read(fn) @test nrow(df) === 5 @test df.geometry[1] isa GFT.WellKnownBinary + # GeoInterface metadata + @test metadata(df, "GEOINTERFACE:geometrycolumns") == (:geometry,) + @test metadata(df, "GEOINTERFACE:crs") isa GFT.ProjJSON @test_throws Exception GeoParquet.read(fn, columns=(:geom,)) end