From a6ec96bb0a2f4dc0f86304e1b67582525e7ac48b Mon Sep 17 00:00:00 2001 From: Maarten Pronk Date: Mon, 17 May 2021 18:20:27 +0000 Subject: [PATCH] Pass on keywords arguments in `read` to ArchGDAL (#16) * Pass on keywords arguments in `read` to ArchGDAL * Address minor comments. --- Project.toml | 2 +- README.md | 29 +++++++++++++++++++++++------ src/io.jl | 4 ++-- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 2a28daf..b8b3377 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GeoDataFrames" uuid = "62cb38b5-d8d2-4862-a48e-6a340996859f" authors = ["Maarten Pronk and contributors"] -version = "0.1.2" +version = "0.1.3" [deps] ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" diff --git a/README.md b/README.md index 98e7a41..bb2d64f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Simple geographical vector interaction built on top of [ArchGDAL](https://github.com/yeesian/ArchGDAL.jl/). Inspiration from geopandas. -** this is a draft, it needs polishing ** +** this is a beta, it needs polishing ** # Installation ```julia @@ -14,7 +14,7 @@ Simple geographical vector interaction built on top of [ArchGDAL](https://github ``` # Usage -Writing +## Writing ```julia using GeoDataFrames; const GDF=GeoDataFrames using DataFrames @@ -24,7 +24,13 @@ df = DataFrame(geom=createpoint.(coords), name="test"); GDF.write("test_points.shp", df) ``` -Reading +You can also set options such as the layername or crs. +```julia +using GeoFormatTypes; const GFT = GeoFormatTypes +GDF.write("test_points.shp", df; layer_name="data", geom_column=:geom, crs=GFT.EPSG(4326)) +``` + +## Reading ```julia df = GDF.read("test_points.shp") 10×2 DataFrame @@ -43,7 +49,18 @@ df = GDF.read("test_points.shp") 10 │ test Geometry: POINT (0.1207370929831… ``` -Geometric operations +You can also specify the layer index or layer name in opening, useful if there are multiple layers: +```julia +GDF.read("test_points.shp", 0) +GDF.read("test_points.shp", "test_points") +``` + +Any keywords arguments are passed on to the underlying ArchGDAL [`read`](https://yeesian.com/ArchGDAL.jl/dev/reference/#ArchGDAL.read-Tuple%7BAbstractString%7D) function: +```julia +GDF.read("test.csv", options=["GEOM_POSSIBLE_NAMES=point,linestring", "KEEP_GEOM_COLUMNS=NO"]) +``` + +## Geometric operations ```julia df.geom = buffer(df.geom, 10); df @@ -63,7 +80,7 @@ df 10 │ test Geometry: POLYGON ((20.937183925… ``` -Reprojection +## Reprojection ```julia using GeoFormatTypes; const GFT=GeoFormatTypes df.geom = reproject(df.geom, GFT.EPSG(4326), GFT.EPSG(28992)) @@ -84,7 +101,7 @@ df 10 │ Geometry: POLYGON ((-435978.6036… test ``` -Plotting +## Plotting ```julia using Plots plot(df.geom) diff --git a/src/io.jl b/src/io.jl index 8228cef..5710de9 100644 --- a/src/io.jl +++ b/src/io.jl @@ -9,8 +9,8 @@ const fieldmapping = Dict(v => k for (k, v) in AG._FIELDTYPE) -function read(fn::AbstractString, layer::Union{Integer,AbstractString}=0) - ds = AG.read(fn) +function read(fn::AbstractString, layer::Union{Integer,AbstractString}=0; kwargs...) + ds = AG.read(fn; kwargs...) layer = AG.getlayer(ds, layer) table = AG.Table(layer) df = DataFrame(table)