Skip to content

Commit

Permalink
Upgrade to AG 0.7 (#21)
Browse files Browse the repository at this point in the history
* Upgrade to AG 0.7

* Remove Manifest.
  • Loading branch information
evetion authored Jul 6, 2021
1 parent 48eeeff commit 3d2fb76
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GeoDataFrames"
uuid = "62cb38b5-d8d2-4862-a48e-6a340996859f"
authors = ["Maarten Pronk <[email protected]> and contributors"]
version = "0.1.4"
version = "0.1.5"

[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Expand All @@ -11,7 +11,7 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
ArchGDAL = "0.5.3, 0.6"
ArchGDAL = "0.7.1"
DataFrames = "0.22, 1.0"
GeoFormatTypes = "0.3"
Tables = "1.2, 1.3, 1.4"
Expand Down
54 changes: 27 additions & 27 deletions src/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ macro reexport(ex)
isa(ex, Expr) && (ex.head == :module ||
ex.head == :using ||
(ex.head == :toplevel &&
all(e->isa(e, Expr) && e.head == :using, ex.args))) ||
all(e -> isa(e, Expr) && e.head == :using, ex.args))) ||
error("@reexport: syntax error")

if ex.head == :module
modules = Any[ex.args[2]]
ex = Expr(:toplevel, ex, :(using .$(ex.args[2])))
elseif ex.head == :using && all(e->isa(e, Symbol), ex.args)
elseif ex.head == :using && all(e -> isa(e, Symbol), ex.args)
modules = Any[ex.args[end]]
elseif ex.head == :using && ex.args[1].head == :(:)
symbols = [e.args[end] for e in ex.args[1].args[2:end]]
Expand All @@ -30,30 +30,30 @@ end
@reexport using ArchGDAL: geomlength, geomarea, centroid
@reexport using ArchGDAL: isempty, isvalid, issimple, isring, geomarea, centroid
@reexport using ArchGDAL: createpoint, createlinestring, createlinearring, createpolygon, createmultilinestring, createmultipolygon
@reexport using ArchGDAL: reproject
@reexport using ArchGDAL:reproject

AG.intersects(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.intersects.(a, b)
AG.equals(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.equals.(a, b)
AG.disjoint(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.disjoint.(a, b)
AG.touches(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.touches.(a, b)
AG.crosses(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.crosses.(a, b)
AG.within(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.within.(a, b)
AG.contains(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.contains.(a, b)
AG.overlaps(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.overlaps.(a, b)
AG.intersection(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.intersection.(a, b)
AG.union(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.union.(a, b)
AG.difference(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.difference.(a, b)
AG.symdifference(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.symdifference.(a, b)
AG.distance(a::Vector{AG.IGeometry}, b::Vector{AG.IGeometry}) = AG.distance.(a, b)
AG.intersects(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.intersects.(a, b)
AG.equals(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.equals.(a, b)
AG.disjoint(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.disjoint.(a, b)
AG.touches(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.touches.(a, b)
AG.crosses(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.crosses.(a, b)
AG.within(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.within.(a, b)
AG.contains(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.contains.(a, b)
AG.overlaps(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.overlaps.(a, b)
AG.intersection(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.intersection.(a, b)
AG.union(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.union.(a, b)
AG.difference(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.difference.(a, b)
AG.symdifference(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.symdifference.(a, b)
AG.distance(a::Vector{AG.IGeometry{T}}, b::Vector{AG.IGeometry{X}}) where {X,T} = AG.distance.(a, b)

AG.boundary(v::Vector{AG.IGeometry}) = AG.boundary.(v)
AG.convexhull(v::Vector{AG.IGeometry}) = AG.convexhull.(v)
AG.buffer(v::Vector{AG.IGeometry}, d) = AG.buffer.(v, d)
AG.transform!(v::Vector{AG.IGeometry}, d) = AG.buffer.(v, d)
AG.geomlength(v::Vector{AG.IGeometry}) = AG.geomlength.(v)
AG.geomarea(v::Vector{AG.IGeometry}) = AG.geomarea.(v)
AG.centroid(v::Vector{AG.IGeometry}) = AG.centroid.(v)
AG.isempty(v::Vector{AG.IGeometry}) = AG.isempty.(v)
AG.isvalid(v::Vector{AG.IGeometry}) = AG.isvalid.(v)
AG.issimple(v::Vector{AG.IGeometry}) = AG.issimple.(v)
AG.isring(v::Vector{AG.IGeometry}) = AG.isring.(v)
AG.boundary(v::Vector{AG.IGeometry{T}}) where {T} = AG.boundary.(v)
AG.convexhull(v::Vector{AG.IGeometry{T}}) where {T} = AG.convexhull.(v)
AG.buffer(v::Vector{AG.IGeometry{T}}, d) where {T} = AG.buffer.(v, d)
AG.transform!(v::Vector{AG.IGeometry{T}}, d) where {T} = AG.buffer.(v, d)
AG.geomlength(v::Vector{AG.IGeometry{T}}) where {T} = AG.geomlength.(v)
AG.geomarea(v::Vector{AG.IGeometry{T}}) where {T} = AG.geomarea.(v)
AG.centroid(v::Vector{AG.IGeometry{T}}) where {T} = AG.centroid.(v)
AG.isempty(v::Vector{AG.IGeometry{T}}) where {T} = AG.isempty.(v)
AG.isvalid(v::Vector{AG.IGeometry{T}}) where {T} = AG.isvalid.(v)
AG.issimple(v::Vector{AG.IGeometry{T}}) where {T} = AG.issimple.(v)
AG.isring(v::Vector{AG.IGeometry{T}}) where {T} = AG.isring.(v)
23 changes: 10 additions & 13 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ const drivermapping = Dict(
".gml" => "GML",
".nc" => "netCDF",
)
const fieldmapping = Dict(v => k for (k, v) in AG._FIELDTYPE)

# Support "exotic" types, but this needs some piracy
fieldmapping[Float32] = fieldmapping[Float64]
fieldmapping[Int16] = fieldmapping[Int32]
fieldmapping[Bool] = fieldmapping[Int32]
Base.convert(::Type{AG.OGRFieldType}, ft::Type{Bool}) = AG.OFTInteger
Base.convert(::Type{AG.OGRFieldType}, ft::Type{Int16}) = AG.OFTInteger
Base.convert(::Type{AG.OGRFieldType}, ft::Type{Float32}) = AG.OFTReal

subtypes = Dict(
Bool => AG.GDAL.OFSTBoolean,
Int16 => AG.GDAL.OFSTInt16,
Float32 => AG.GDAL.OFSTFloat32,
Bool => AG.OFSTBoolean,
Int16 => AG.OFSTInt16,
Float32 => AG.OFSTFloat32,
)

function AG.setfield!(feature::AG.Feature, i::Integer, value::Int16)
Expand Down Expand Up @@ -51,11 +50,10 @@ function read(fn::AbstractString, layer::Union{Integer,AbstractString}; kwargs..
end

function read(ds, layer)
layer = AG.getlayer(ds, layer)
if layer.ptr == C_NULL
table = AG.getlayer(ds, layer)
if table.ptr == C_NULL
throw(ArgumentError("Given layer id/name doesn't exist. For reference this is the dataset:\n$ds"))
end
table = AG.Table(layer)
df = DataFrame(table)
"" in names(df) && rename!(df, Dict(Symbol("") => :geom, )) # needed for now
df
Expand Down Expand Up @@ -92,7 +90,6 @@ function write(fn::AbstractString, table; layer_name::AbstractString="data", geo
end
end
end

AG.create(
fn,
driver=driver
Expand All @@ -103,8 +100,8 @@ function write(fn::AbstractString, table; layer_name::AbstractString="data", geo
spatialref=AG.importCRS(crs)
) do layer
for (name, type) in fields
AG.createfielddefn(String(name), fieldmapping[type]) do fd
AG.setsubtype!(fd, get(subtypes, type, AG.GDAL.OFSTNone))
AG.createfielddefn(String(name), convert(AG.OGRFieldType, type)) do fd
AG.setsubtype!(fd, get(subtypes, type, AG.OFSTNone))
AG.addfielddefn!(layer, fd)
end
end
Expand Down

2 comments on commit 3d2fb76

@evetion
Copy link
Owner Author

@evetion evetion commented on 3d2fb76 Jul 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/40357

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.5 -m "<description of version>" 3d2fb76cf066a0b2c0027b4e291a644401db0f35
git push origin v0.1.5

Please sign in to comment.