Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Apr 25, 2024
1 parent 1b7f03d commit e76f9b3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/Manifest.toml
.CondaPkg
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ uuid = "f157c2ba-572d-4438-a710-d9db9a9b13c0"
authors = ["Josh Day <[email protected]> and contributors"]
version = "1.0.0-DEV"

[deps]
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"

[compat]
julia = "1.6.7"

Expand Down
39 changes: 38 additions & 1 deletion src/QGIS.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
module QGIS

# Write your package code here.
using JSON3

#-----------------------------------------------------------------------------# __init__
qgis_process::String = "" # Path to qgis_process
algorithms::Vector{String} = [] # Provider => Algorithm

function __init__()
for path in [
"/Applications/QGIS.app/Contents/MacOS/bin/qgis_process"
]
if isfile(path)
set_qgis_process_path(path)
break
end
end
isnothing(qgis_process) && @warn("qgis_process not found. You must explicitly set `QGIS.set_qgis_process_path(\"path/to/qgis_process\")`.")
end

function set_qgis_process_path(path::String)
isfile(path) || error("Not found: $path")
global qgis_process = path
foreach(values(process("list").providers)) do provider
append!(algorithms, string.(keys(provider.algorithms)))
end
end

function process(x...)
io = IOBuffer()
cmd = pipeline(`$qgis_process --json $x`; stdout=io, stderr=devnull)
Base.run(cmd)
JSON3.read(String(take!(io)))
end

#-----------------------------------------------------------------------------# run
run(algorithm_id::String, args...) = process("run", algorithm_id, args...)
Base.propertynames(::typeof(run)) = Symbol.(algorithms)
Base.getproperty(::typeof(run), alg_id::Symbol) = (x...) -> run(alg_id, x...)


end # module QGIS

0 comments on commit e76f9b3

Please sign in to comment.