Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for latest JuliaGeo/GDAL #48

Merged
merged 13 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@

docs/build/
docs/site/

test/data/
test/gdalworkshop/
test/ospy/
test/pyrasterio/
test/spatialite/
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ notifications:
# uncomment the following lines to override the default test script
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --color=yes -e 'Pkg.clone("https://github.com/visr/GDAL.jl.git"); Pkg.build("GDAL")'
- LD_LIBRARY_PATH="/home/travis/.julia/v0.6/Conda/deps/usr/lib/" julia -e 'Pkg.build("GDAL"); Pkg.clone(pwd()); Pkg.build("ArchGDAL"); Pkg.test("ArchGDAL"; coverage=true)'
- julia -e 'Pkg.clone(pwd()); Pkg.test("ArchGDAL"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("ArchGDAL")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'
- LD_LIBRARY_PATH="/home/travis/.julia/v0.6/Conda/deps/usr/lib/" julia -e 'Pkg.add("Documenter"); cd(Pkg.dir("ArchGDAL")); include(joinpath("docs", "make.jl"))'
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[GDAL](http://gdal.org/) is a translator library for raster and vector geospatial data formats that is released under an [X/MIT](https://trac.osgeo.org/gdal/wiki/FAQGeneral#WhatlicensedoesGDALOGRuse) license by the [Open Source Geospatial Foundation](http://www.osgeo.org/). As a library, it presents an abstract data model to drivers for various [raster](http://www.gdal.org/formats_list.html) and [vector](http://www.gdal.org/ogr_formats.html) formats.

This package aims to be a complete solution for working with GDAL in Julia, similar in scope to [the SWIG bindings for Python](https://pypi.python.org/pypi/GDAL/). It builds on top of [GDAL.jl](https://github.com/visr/GDAL.jl), and provides a high level API for GDAL, espousing the following principles.
This package aims to be a complete solution for working with GDAL in Julia, similar in scope to [the SWIG bindings for Python](https://pypi.python.org/pypi/GDAL/). It builds on top of [GDAL.jl](https://github.com/JuliaGeo/GDAL.jl), and provides a high level API for GDAL, espousing the following principles.

## Principles (The Arch Way)
(adapted from: https://wiki.archlinux.org/index.php/Arch_Linux#Principles)
Expand All @@ -24,14 +24,12 @@ This package aims to be a complete solution for working with GDAL in Julia, simi
This package is currently unregistered, so add it using `Pkg.clone`, then find or get the GDAL dependencies using `Pkg.build`:

```julia
Pkg.clone("https://github.com/visr/GDAL.jl.git")
Pkg.build("GDAL")
Pkg.add("GDAL")
Pkg.clone("https://github.com/yeesian/ArchGDAL.jl.git")
```

`Pkg.build("GDAL")` searches for a GDAL 2.1+ shared library on the path. If not found, it will download and install it. To test if it is installed correctly, use:
To test if it is installed correctly,

```julia
Pkg.test("GDAL")
Pkg.test("ArchGDAL")
```
2 changes: 2 additions & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
julia 0.6
DataStreams
GeoInterface
GDAL
Compat
3 changes: 3 additions & 0 deletions src/ArchGDAL.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
__precompile__()

module ArchGDAL

using Compat
import Compat.String
import GDAL, GeoInterface
import DataStreams: Data
using Base.Dates

include("utils.jl")
include("types.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Base.length(layer::FeatureLayer) = nfeature(layer, true)

function Base.done(layer::FeatureLayer, state::Vector{Feature})
destroy(state[1])
ptr = @gdal(OGR_L_GetNextFeature::GDALFeature, layer.ptr::GDALFeatureLayer)
ptr = GDAL.getnextfeature(layer.ptr)
state[1] = Feature(ptr)

if ptr == C_NULL
Expand Down
89 changes: 18 additions & 71 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ function copywholeraster(
progressfunc::Function = GDAL.C.GDALDummyProgress,
progressdata::Any = C_NULL
)
result = @gdal(GDALDatasetCopyWholeRaster::GDAL.CPLErr,
source.ptr::GDALDataset,
dest.ptr::GDALDataset,
options::StringList,
@cplprogress(progressfunc)::GDALProgressFunc,
progressdata::Ptr{Void}
)
result = GDAL.datasetcopywholeraster(source.ptr, dest.ptr, options,
@cplprogress(progressfunc), progressdata)
@cplerr result "Failed to copy whole raster"
end

Expand Down Expand Up @@ -86,17 +81,9 @@ function unsafe_createcopy(
progressfunc::Function = GDAL.C.GDALDummyProgress,
progressdata = C_NULL
)
GDAL.checknull(dataset.ptr)
result = GDAL.checknull(@gdal(GDALCreateCopy::GDALDataset,
driver.ptr::GDALDriver,
filename::Cstring,
dataset.ptr::GDALDataset,
strict::Cint,
options::StringList,
@cplprogress(progressfunc)::GDALProgressFunc,
progressdata::Ptr{Void}
))
Dataset(result)

Dataset(GDAL.createcopy(driver.ptr, filename, GDAL.checknull(dataset.ptr),
strict, options, @cplprogress(progressfunc), progressdata))
end

function unsafe_createcopy(
Expand Down Expand Up @@ -160,15 +147,8 @@ function unsafe_create(
dtype::DataType = Any,
options = StringList(C_NULL)
)
result = GDAL.checknull(@gdal(GDALCreate::GDALDataset,
driver.ptr::GDALDriver,
filename::Cstring,
width::Cint,
height::Cint,
nbands::Cint,
_GDALTYPE[dtype]::GDAL.GDALDataType,
options::StringList
))
result = GDAL.create(driver.ptr, filename, width, height, nbands,
_GDALTYPE[dtype], options)
Dataset(result)
end

Expand Down Expand Up @@ -245,13 +225,8 @@ function unsafe_read(
options = StringList(C_NULL),
siblingfiles = StringList(C_NULL)
)
result = GDAL.checknull(@gdal(GDALOpenEx::GDALDataset,
filename::Cstring,
flags::UInt32,
alloweddrivers::StringList,
options::StringList,
siblingfiles::StringList
))
result = GDAL.openex(filename, Int(flags), alloweddrivers, options,
siblingfiles)
Dataset(result)
end

Expand Down Expand Up @@ -284,11 +259,7 @@ list is owned by the caller and should be deallocated with `CSLDestroy()`.
The returned filenames will normally be relative or absolute paths depending on
the path used to originally open the dataset. The strings will be UTF-8 encoded
"""
function filelist(dataset::Dataset)
unsafe_loadstringlist(@gdal(GDALGetFileList::Ptr{Cstring},
dataset.ptr::GDALDataset
))
end
filelist(dataset::Dataset) = GDAL.getfilelist(dataset.ptr)

"""
Fetch the layer at index `i` (between `0` and `nlayer(dataset)-1`)
Expand Down Expand Up @@ -349,14 +320,8 @@ function createlayer(
geom::OGRwkbGeometryType = wkbUnknown,
options = StringList(C_NULL)
)
result = GDAL.checknull(@gdal(GDALDatasetCreateLayer::GDALFeatureLayer,
dataset.ptr::GDALDataset,
name::Cstring,
spatialref.ptr::GDALSpatialRef,
geom::GDAL.OGRwkbGeometryType,
options::StringList
))
FeatureLayer(result)
FeatureLayer(GDAL.datasetcreatelayer(dataset.ptr, name, spatialref.ptr,
geom, options))
end

"""
Expand All @@ -374,13 +339,7 @@ function copylayer(
name::AbstractString;
options = StringList(C_NULL)
)
result = GDAL.checknull(@gdal(GDALDatasetCopyLayer::GDALFeatureLayer,
dataset.ptr::GDALDataset,
layer.ptr::GDALFeatureLayer,
name::Cstring,
options::StringList
))
FeatureLayer(result)
FeatureLayer(GDAL.datasetcopylayer(dataset.ptr, layer.ptr, name, options))
end

"""
Expand Down Expand Up @@ -467,13 +426,8 @@ function unsafe_executesql(
dialect::AbstractString = "",
spatialfilter::Geometry = Geometry(C_NULL)
)
result = @gdal(GDALDatasetExecuteSQL::GDALFeatureLayer,
dataset.ptr::GDALDataset,
query::Cstring,
spatialfilter.ptr::GDALGeometry,
dialect::Cstring
)
FeatureLayer(result)
FeatureLayer(GDAL.datasetexecutesql(dataset.ptr, query, spatialfilter.ptr,
dialect))
end


Expand Down Expand Up @@ -579,16 +533,9 @@ function buildoverviews!(dataset::Dataset,
resampling::AbstractString = "NEAREST",
progressfunc::Function = GDAL.C.GDALDummyProgress,
progressdata = C_NULL)
result = @gdal(GDALBuildOverviews::GDAL.CPLErr,
dataset.ptr::GDALDataset,
resampling::Cstring,
length(overviewlist)::Cint,
overviewlist::Ptr{Cint},
length(bandlist)::Cint,
bandlist::Ptr{Cint},
@cplprogress(progressfunc)::GDALProgressFunc,
progressdata::Ptr{Void}
)
result = GDAL.buildoverviews(dataset.ptr, resampling, length(overviewlist),
overviewlist, length(bandlist), bandlist, @cplprogress(progressfunc),
progressdata)
@cplerr result "Failed to build overviews"
dataset
end
Expand Down
5 changes: 1 addition & 4 deletions src/datastreams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ function Data.streamfrom{T}(
end
if col == source.schema.cols
destroy(source.feature)
source.feature.ptr = @gdal(
OGR_L_GetNextFeature::GDALFeature,
source.featurelayer.ptr::GDALFeatureLayer
)
source.feature.ptr = GDAL.getnextfeature(source.featurelayer.ptr)
if row == source.schema.rows
@assert source.feature.ptr == C_NULL
resetreading!(source.featurelayer)
Expand Down
5 changes: 1 addition & 4 deletions src/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ by the `GDAL_DMD_CREATIONOPTIONLIST` metadata item. In case of incompatibility
a (non fatal) warning will be emited and `FALSE` will be returned.
"""
validate(drv::Driver, options::Vector{T}) where {T <: AbstractString} =
Bool(@gdal(GDALValidateCreationOptions::Cint,
drv.ptr::GDALDriver,
options::StringList
))
Bool(GDAL.validatecreationoptions(drv.ptr, options))

"Copy all the files associated with a dataset."
function copyfiles(drv::Driver, new::AbstractString, old::AbstractString)
Expand Down
30 changes: 10 additions & 20 deletions src/ogr/feature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ pointer may be NULL or non-NULL.
"""
function asintlist(feature::Feature, i::Integer)
n = Ref{Cint}()
a = Array{Int32}
ptr = GDAL.checknull(GDAL.getfieldasintegerlist(feature.ptr, i, n))
unsafe_wrap(a, ptr, n.x)
ptr = GDAL.getfieldasintegerlist(feature.ptr, i, n)
return (n.x == 0) ? Int32[] : unsafe_wrap(Array{Int32}, ptr, n.x)
end

"""
Expand All @@ -199,9 +198,8 @@ pointer may be NULL or non-NULL.
"""
function asint64list(feature::Feature, i::Integer)
n = Ref{Cint}()
a = Array{Int64}
ptr = GDAL.checknull(GDAL.getfieldasinteger64list(feature.ptr, i, n))
unsafe_wrap(a, ptr, n.x)
ptr = GDAL.getfieldasinteger64list(feature.ptr, i, n)
return (n.x == 0) ? Int64[] : unsafe_wrap(Array{Int64}, ptr, n.x)
end

"""
Expand All @@ -220,9 +218,8 @@ pointer may be NULL or non-NULL.
"""
function asdoublelist(feature::Feature, i::Integer)
n = Ref{Cint}()
ptr = GDAL.checknull(GDAL.getfieldasdoublelist(feature.ptr, i, n))
a = Array{Float64}
unsafe_wrap(a, ptr, n.x)
ptr = GDAL.getfieldasdoublelist(feature.ptr, i, n)
return (n.x == 0) ? Float64[] : unsafe_wrap(Array{Float64}, ptr, n.x)
end

"""
Expand All @@ -237,9 +234,7 @@ the field value. This list is internal, and should not be modified, or freed.
Its lifetime may be very brief.
"""
asstringlist(feature::Feature, i::Integer) =
unsafe_loadstringlist(
GDAL.C.OGR_F_GetFieldAsStringList(Ptr{Void}(feature.ptr), Cint(i))
)
GDAL.getfieldasstringlist(feature.ptr, i)

"""
OGR_F_GetFieldAsBinary(OGRFeatureH hFeat,
Expand All @@ -256,9 +251,8 @@ Its lifetime may be very brief.
"""
function asbinary(feature::Feature, i::Integer)
n = Ref{Cint}()
a = Array{UInt8}
ptr = GDAL.checknull(GDAL.getfieldasbinary(feature.ptr, i, n))
unsafe_wrap(a, ptr, n.x)
ptr = GDAL.getfieldasbinary(feature.ptr, i, n)
return (n.x == 0) ? UInt8[] : unsafe_wrap(Array{UInt8}, ptr, n.x)
end

"""
Expand Down Expand Up @@ -491,11 +485,7 @@ function setfield!(
i::Integer,
value::Vector{T}
) where T <: AbstractString
@gdal(OGR_F_SetFieldStringList::Void,
feature.ptr::GDALFeature,
i::Cint,
value::StringList
)
GDAL.setfieldstringlist(feature.ptr, i, value)
feature
end

Expand Down
7 changes: 2 additions & 5 deletions src/ogr/featuredefn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ type. The geometry type should generally not be changed after any OGRFeatures
have been created against this definition.
"""
function setgeomtype!(fd::FeatureDefn, etype::OGRwkbGeometryType)
@gdal(OGR_FD_SetGeomType::Void,
fd.ptr::GDALFeatureDefn,
etype::GDAL.OGRwkbGeometryType
)
GDAL.setgeomtype(fd.ptr, etype)
fd
end

Expand Down Expand Up @@ -228,7 +225,7 @@ OGRFeatures that depend on it is likely to result in a crash.
Starting with GDAL 2.1, returns NULL in case out of memory situation.
"""
unsafe_createfeature(fd::FeatureDefn) =
Feature(GDAL.checknull(GDAL.f_create(fd.ptr)))
Feature(GDAL.f_create(fd.ptr))

"Fetch feature definition."
getfeaturedefn(feature::Feature) = FeatureDefn(GDAL.getdefnref(feature.ptr))
15 changes: 3 additions & 12 deletions src/ogr/featurelayer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,7 @@ available on the current layer use the `TestCapability()` method with a value of
* `i`: the index indicating how many steps into the result set to seek.
"""
function setnextbyindex!(layer::FeatureLayer, i::Integer)
result = @gdal(OGR_L_SetNextByIndex::GDAL.OGRErr,
layer.ptr::GDALFeatureLayer,
i::GDAL.GIntBig
)
result = GDAL.setnextbyindex(layer.ptr, i)
@ogrerr result "Failed to move the cursor to index $i"
layer
end
Expand All @@ -255,10 +252,7 @@ interrupted by a OGR_L_GetFeature() call.
The returned feature should be free with OGR_F_Destroy().
"""
unsafe_getfeature(layer::FeatureLayer, i::Integer) =
Feature(GDAL.checknull(@gdal(OGR_L_GetFeature::GDALFeature,
layer.ptr::GDALFeatureLayer,
i::GDAL.GIntBig
)))
Feature(GDAL.getfeature(layer.ptr, i))

"""
Rewrite an existing feature.
Expand Down Expand Up @@ -837,10 +831,7 @@ OGRERR_NONE if all field names have been resolved (even if the driver does not
support this method)
"""
function setignoredfields!(layer::FeatureLayer, fieldnames)
result = @gdal(OGR_L_SetIgnoredFields::GDAL.OGRErr,
layer.ptr::GDALFeatureLayer,
fieldnames::StringList
)
result = GDAL.setignoredfields(layer.ptr, fieldnames)
@ogrerr result "Failed to set ignored fields $fieldnames."
layer
end
Expand Down
Loading