-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/Manifest.toml | ||
.CondaPkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |