From 4c9411f23cd2a118833ba97d6f4a4e0e37b37c72 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Wed, 30 Aug 2023 11:12:37 -0300 Subject: [PATCH 1/2] Add support for the GeoParquet file format --- Project.toml | 2 ++ src/GeoIO.jl | 5 +++++ src/conversion.jl | 2 +- src/precompile.jl | 3 +++ test/data/lines.parquet | Bin 0 -> 703 bytes test/data/points.parquet | Bin 0 -> 683 bytes test/data/polygons.parquet | Bin 0 -> 711 bytes test/runtests.jl | 30 ++++++++++++++++++++++++++++++ 8 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/data/lines.parquet create mode 100644 test/data/points.parquet create mode 100644 test/data/polygons.parquet diff --git a/Project.toml b/Project.toml index c510a06..6025884 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" GADM = "a8dd9ffe-31dc-4cf5-a379-ea69100a8233" GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f" GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9" +GeoParquet = "e99870d8-ce00-4fdd-aeee-e09192881159" Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa" PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4" @@ -18,6 +19,7 @@ ArchGDAL = "0.10" GADM = "1.0" GeoInterface = "1.0" GeoJSON = "0.7" +GeoParquet = "0.1" Meshes = "0.33, 0.34" PrecompileTools = "1.2" Shapefile = "0.10" diff --git a/src/GeoIO.jl b/src/GeoIO.jl index 5f58977..090073a 100644 --- a/src/GeoIO.jl +++ b/src/GeoIO.jl @@ -13,6 +13,7 @@ import GADM import Shapefile as SHP import GeoJSON as GJS import ArchGDAL as AG +import GeoParquet as GPQ import GeoInterface as GI include("conversion.jl") @@ -45,6 +46,8 @@ function load(fname; layer=0, lazy=false, kwargs...) elseif endswith(fname, ".geojson") data = Base.read(fname) table = GJS.read(data; kwargs...) + elseif endswith(fname, ".parquet") + table = GPQ.read(fname) else # fallback to GDAL data = AG.read(fname; kwargs...) table = AG.getlayer(data, layer) @@ -73,6 +76,8 @@ function save(fname, geotable; kwargs...) SHP.write(fname, geotable; kwargs...) elseif endswith(fname, ".geojson") GJS.write(fname, geotable; kwargs...) + elseif endswith(fname, ".parquet") + GPQ.write(fname, geotable, (:geometry,); kwargs...) else # fallback to GDAL agwrite(fname, geotable; kwargs...) end diff --git a/src/conversion.jl b/src/conversion.jl index 7009e6f..282b309 100644 --- a/src/conversion.jl +++ b/src/conversion.jl @@ -56,7 +56,7 @@ end function tochain(geom, is3d::Bool) points = topoints(geom, is3d) - if GI.isclosed(geom) + if first(points) == last(points) # fix backend issues: https://github.com/JuliaEarth/GeoTables.jl/issues/32 while first(points) == last(points) && length(points) ≥ 2 pop!(points) diff --git a/src/precompile.jl b/src/precompile.jl index 251fa40..07a00a2 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -9,6 +9,9 @@ using PrecompileTools load(joinpath(datadir, "points.geojson")) load(joinpath(datadir, "lines.geojson")) load(joinpath(datadir, "polygons.geojson")) + load(joinpath(datadir, "points.parquet")) + load(joinpath(datadir, "lines.parquet")) + load(joinpath(datadir, "polygons.parquet")) load(joinpath(datadir, "field.kml")) load(joinpath(datadir, "points.gpkg")) load(joinpath(datadir, "lines.gpkg")) diff --git a/test/data/lines.parquet b/test/data/lines.parquet new file mode 100644 index 0000000000000000000000000000000000000000..8c5b3b0e1f1b8d2d030717aeeba8309ace981651 GIT binary patch literal 703 zcmZvaKZw&%9LImJO?xp{@b2V=Ml#3~i$iUD=Ly;+ITsJ?P*m{L(<5ykZAzNN*Yvd1 zLInj!C*j1w(ZNa7O|O%Gz`@B)5D_O8y-9=-eAOX=Moxz%*?)?7^jZk>S6Set;!;42GDPa!D3pO>H zP}wnIiNN=pbBFf7dSq<%;=g{LduOos@bdNQX9MJY51#M+Wblo91?|LF0~0<<^fuX% zu}$E^F&s)__=>~bjUNUvH_6a2H;tib3}@i}oq_JBj*@SQQnI*9hTYev{rt=_O>KyQ z9`xwliik%Kf*^PjrFifI1bgx(^dR08^&|zsx4R}iv~!yGe*gdfy&cwCI5$gyTGXsi z1uq3!066+$<}X}&1+YpW2YHZS0l=qY?OR!wsiZBQE_B@%4{Ry} zmFOydQb}^72KS#%nUk1Di$|~%+5z|Vq*OAEyle~4c6^=*$3V_yNh=o z;;VRJ6U7(LoJ8HovK03_oYk)~EAqmaUBd){?y%?k6~-G)js@%Zc4!N9IZm`PhMmZ5 ljfzNkJdEu)T{JNdheIgswQO;-$K$zb+lOcP02cnH{{W7CukHW< literal 0 HcmV?d00001 diff --git a/test/data/polygons.parquet b/test/data/polygons.parquet new file mode 100644 index 0000000000000000000000000000000000000000..13bdac9115ec9035250af90a53518b960a97d698 GIT binary patch literal 711 zcmZuv&5P4O6n|-EyV=-FS0^-*!!ly=P-}OsmtK>>qfQX@lU z+{9@d;Lyt>zhPw)U`>D+h(KTlqK}-%T0q{F{|jm%@uufj7MG6Zj}bCs1j1W3J5I27 zB`gc@{qFqX1MgqxJALuj&&wZm_6gp7D1OmFT6pq$|7V@AKg_8ozUk<&5vPxZT^<)= zurGE7Qw1^n;Ue&0{f90X!(kBU#!wFoJ(vebnx!{ZFxQ$bUR;>_`fNM5O5sP|lR_Ooh;-0&BD|NSu Date: Wed, 30 Aug 2023 11:34:59 -0300 Subject: [PATCH 2/2] Apply suggestions from code review --- src/GeoIO.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GeoIO.jl b/src/GeoIO.jl index 4e06639..ff867cb 100644 --- a/src/GeoIO.jl +++ b/src/GeoIO.jl @@ -59,7 +59,7 @@ function load(fname; layer=0, lazy=false, kwargs...) data = Base.read(fname) GJS.read(data; kwargs...) elseif endswith(fname, ".parquet") - GPQ.read(fname) + GPQ.read(fname; kwargs...) else # fallback to GDAL data = AG.read(fname; kwargs...) AG.getlayer(data, layer)