diff --git a/Project.toml b/Project.toml index 9c04d2d1..4b3caa98 100644 --- a/Project.toml +++ b/Project.toml @@ -3,7 +3,7 @@ uuid = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" keywords = ["GDAL", "IO"] license = "MIT" desc = "A high level API for GDAL - Geospatial Data Abstraction Library" -version = "0.8.3" +version = "0.8.4" [deps] CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" diff --git a/src/base/display.jl b/src/base/display.jl index 3f7cbe11..e66017ce 100644 --- a/src/base/display.jl +++ b/src/base/display.jl @@ -213,7 +213,7 @@ function Base.show(io::IO, gfd::AbstractGeomFieldDefn)::Nothing return nothing end -function Base.show(io::IO, feature::Feature)::Nothing +function Base.show(io::IO, feature::AbstractFeature)::Nothing if feature.ptr == C_NULL print(io, "NULL Feature") return nothing diff --git a/src/base/iterators.jl b/src/base/iterators.jl index 5beb30c0..a619e9be 100644 --- a/src/base/iterators.jl +++ b/src/base/iterators.jl @@ -1,7 +1,7 @@ function Base.iterate( layer::AbstractFeatureLayer, state::Integer = 0, -)::Union{Nothing,Tuple{Feature,Int64}} +)::Union{Nothing,Tuple{IFeature,Int64}} layer.ptr == C_NULL && return nothing state == 0 && resetreading!(layer) ptr = GDAL.ogr_l_getnextfeature(layer.ptr) @@ -9,11 +9,11 @@ function Base.iterate( resetreading!(layer) nothing else - (Feature(ptr), state + 1) + (IFeature(ptr), state + 1) end end -Base.eltype(layer::AbstractFeatureLayer)::DataType = Feature +Base.eltype(layer::AbstractFeatureLayer)::DataType = IFeature Base.IteratorSize(::Type{<:AbstractFeatureLayer}) = Base.SizeUnknown() diff --git a/src/ogr/feature.jl b/src/ogr/feature.jl index b304489b..4c478763 100644 --- a/src/ogr/feature.jl +++ b/src/ogr/feature.jl @@ -1,15 +1,16 @@ """ - unsafe_clone(feature::Feature) + unsafe_clone(feature::AbstractFeature) Duplicate feature. The newly created feature is owned by the caller, and will have its own reference to the OGRFeatureDefn. """ -unsafe_clone(feature::Feature)::Feature = Feature(GDAL.ogr_f_clone(feature.ptr)) +unsafe_clone(feature::AbstractFeature)::AbstractFeature = + Feature(GDAL.ogr_f_clone(feature.ptr)) """ - destroy(feature::Feature) + destroy(feature::AbstractFeature) Destroy the feature passed in. @@ -19,14 +20,14 @@ to delete a feature created within the DLL. If the delete is done in the calling application the memory will be freed onto the application heap which is inappropriate. """ -function destroy(feature::Feature)::Nothing +function destroy(feature::AbstractFeature)::Nothing GDAL.ogr_f_destroy(feature.ptr) feature.ptr = C_NULL return nothing end """ - setgeom!(feature::Feature, geom::AbstractGeometry) + setgeom!(feature::AbstractFeature, geom::AbstractGeometry) Set feature geometry. @@ -42,18 +43,21 @@ passed geometry, but instead makes a copy of it. `OGRERR_NONE` if successful, or `OGR_UNSUPPORTED_GEOMETRY_TYPE` if the geometry type is illegal for the `OGRFeatureDefn` (checking not yet implemented). """ -function setgeom!(feature::Feature, geom::AbstractGeometry)::Feature +function setgeom!( + feature::AbstractFeature, + geom::AbstractGeometry, +)::AbstractFeature result = GDAL.ogr_f_setgeometry(feature.ptr, geom.ptr) @ogrerr result "OGRErr $result: Failed to set feature geometry." return feature end """ - getgeom(feature::Feature) + getgeom(feature::AbstractFeature) Returns a clone of the geometry corresponding to the feature. """ -function getgeom(feature::Feature)::IGeometry +function getgeom(feature::AbstractFeature)::IGeometry result = GDAL.ogr_f_getgeometryref(feature.ptr) return if result == C_NULL IGeometry() @@ -62,7 +66,7 @@ function getgeom(feature::Feature)::IGeometry end end -function unsafe_getgeom(feature::Feature)::Geometry +function unsafe_getgeom(feature::AbstractFeature)::Geometry result = GDAL.ogr_f_getgeometryref(feature.ptr) return if result == C_NULL Geometry() @@ -72,16 +76,17 @@ function unsafe_getgeom(feature::Feature)::Geometry end """ - nfield(feature::Feature) + nfield(feature::AbstractFeature) Fetch number of fields on this feature. This will always be the same as the field count for the OGRFeatureDefn. """ -nfield(feature::Feature)::Integer = GDAL.ogr_f_getfieldcount(feature.ptr) +nfield(feature::AbstractFeature)::Integer = + GDAL.ogr_f_getfieldcount(feature.ptr) """ - getfielddefn(feature::Feature, i::Integer) + getfielddefn(feature::AbstractFeature, i::Integer) Fetch definition for this field. @@ -93,11 +98,11 @@ Fetch definition for this field. an handle to the field definition (from the `FeatureDefn`). This is an internal reference, and should not be deleted or modified. """ -getfielddefn(feature::Feature, i::Integer)::IFieldDefnView = +getfielddefn(feature::AbstractFeature, i::Integer)::IFieldDefnView = IFieldDefnView(GDAL.ogr_f_getfielddefnref(feature.ptr, i)) """ - findfieldindex(feature::Feature, name::Union{AbstractString, Symbol}) + findfieldindex(feature::AbstractFeature, name::Union{AbstractString, Symbol}) Fetch the field index given field name. @@ -112,7 +117,7 @@ the field index, or `nothing` if no matching field is found. This is a cover for the `OGRFeatureDefn::GetFieldIndex()` method. """ function findfieldindex( - feature::Feature, + feature::AbstractFeature, name::Union{AbstractString,Symbol}, )::Union{Integer,Nothing} i = GDAL.ogr_f_getfieldindex(feature.ptr, name) @@ -124,7 +129,7 @@ function findfieldindex( end """ - isfieldset(feature::Feature, i::Integer) + isfieldset(feature::AbstractFeature, i::Integer) Test if a field has ever been assigned a value or not. @@ -132,11 +137,11 @@ Test if a field has ever been assigned a value or not. * `feature`: the feature that owned the field. * `i`: the field to fetch, from 0 to GetFieldCount()-1. """ -isfieldset(feature::Feature, i::Integer)::Bool = +isfieldset(feature::AbstractFeature, i::Integer)::Bool = Bool(GDAL.ogr_f_isfieldset(feature.ptr, i)) """ - unsetfield!(feature::Feature, i::Integer) + unsetfield!(feature::AbstractFeature, i::Integer) Clear a field, marking it as unset. @@ -144,13 +149,13 @@ Clear a field, marking it as unset. * `feature`: the feature that owned the field. * `i`: the field to fetch, from 0 to GetFieldCount()-1. """ -function unsetfield!(feature::Feature, i::Integer)::Feature +function unsetfield!(feature::AbstractFeature, i::Integer)::AbstractFeature GDAL.ogr_f_unsetfield(feature.ptr, i) return feature end """ - isfieldnull(feature::Feature, i::Integer) + isfieldnull(feature::AbstractFeature, i::Integer) Test if a field is null. @@ -164,11 +169,11 @@ Test if a field is null. ### References * https://gdal.org/development/rfc/rfc67_nullfieldvalues.html """ -isfieldnull(feature::Feature, i::Integer)::Bool = +isfieldnull(feature::AbstractFeature, i::Integer)::Bool = Bool(GDAL.ogr_f_isfieldnull(feature.ptr, i)) """ - isfieldsetandnotnull(feature::Feature, i::Integer) + isfieldsetandnotnull(feature::AbstractFeature, i::Integer) Test if a field is set and not null. @@ -182,11 +187,11 @@ Test if a field is set and not null. ### References * https://gdal.org/development/rfc/rfc67_nullfieldvalues.html """ -isfieldsetandnotnull(feature::Feature, i::Integer)::Bool = +isfieldsetandnotnull(feature::AbstractFeature, i::Integer)::Bool = Bool(GDAL.ogr_f_isfieldsetandnotnull(feature.ptr, i)) """ - setfieldnull!(feature::Feature, i::Integer) + setfieldnull!(feature::AbstractFeature, i::Integer) Clear a field, marking it as null. @@ -197,7 +202,7 @@ Clear a field, marking it as null. ### References * https://gdal.org/development/rfc/rfc67_nullfieldvalues.html """ -function setfieldnull!(feature::Feature, i::Integer)::Feature +function setfieldnull!(feature::AbstractFeature, i::Integer)::AbstractFeature GDAL.ogr_f_setfieldnull(feature.ptr, i) return feature end @@ -219,7 +224,7 @@ end # end """ - asbool(feature::Feature, i::Integer) + asbool(feature::AbstractFeature, i::Integer) Fetch field value as a boolean @@ -227,11 +232,11 @@ Fetch field value as a boolean * `feature`: the feature that owned the field. * `i`: the field to fetch, from 0 to GetFieldCount()-1. """ -asbool(feature::Feature, i::Integer)::Bool = +asbool(feature::AbstractFeature, i::Integer)::Bool = convert(Bool, GDAL.ogr_f_getfieldasinteger(feature.ptr, i)) """ - asint16(feature::Feature, i::Integer) + asint16(feature::AbstractFeature, i::Integer) Fetch field value as integer 16 bit. @@ -239,11 +244,11 @@ Fetch field value as integer 16 bit. * `feature`: the feature that owned the field. * `i`: the field to fetch, from 0 to GetFieldCount()-1. """ -asint16(feature::Feature, i::Integer)::Int16 = +asint16(feature::AbstractFeature, i::Integer)::Int16 = convert(Int16, GDAL.ogr_f_getfieldasinteger(feature.ptr, i)) """ - asint(feature::Feature, i::Integer) + asint(feature::AbstractFeature, i::Integer) Fetch field value as integer. @@ -251,11 +256,11 @@ Fetch field value as integer. * `feature`: the feature that owned the field. * `i`: the field to fetch, from 0 to GetFieldCount()-1. """ -asint(feature::Feature, i::Integer)::Int32 = +asint(feature::AbstractFeature, i::Integer)::Int32 = GDAL.ogr_f_getfieldasinteger(feature.ptr, i) """ - asint64(feature::Feature, i::Integer) + asint64(feature::AbstractFeature, i::Integer) Fetch field value as integer 64 bit. @@ -263,11 +268,11 @@ Fetch field value as integer 64 bit. * `feature`: the feature that owned the field. * `i`: the field to fetch, from 0 to GetFieldCount()-1. """ -asint64(feature::Feature, i::Integer)::Int64 = +asint64(feature::AbstractFeature, i::Integer)::Int64 = GDAL.ogr_f_getfieldasinteger64(feature.ptr, i) """ -assingle(feature::Feature, i::Integer) +assingle(feature::AbstractFeature, i::Integer) Fetch field value as a single. @@ -275,11 +280,11 @@ Fetch field value as a single. * `feature`: the feature that owned the field. * `i`: the field to fetch, from 0 to GetFieldCount()-1. """ -assingle(feature::Feature, i::Integer)::Float32 = +assingle(feature::AbstractFeature, i::Integer)::Float32 = convert(Float32, GDAL.ogr_f_getfieldasdouble(feature.ptr, i)) """ - asdouble(feature::Feature, i::Integer) + asdouble(feature::AbstractFeature, i::Integer) Fetch field value as a double. @@ -287,11 +292,11 @@ Fetch field value as a double. * `feature`: the feature that owned the field. * `i`: the field to fetch, from 0 to GetFieldCount()-1. """ -asdouble(feature::Feature, i::Integer)::Float64 = +asdouble(feature::AbstractFeature, i::Integer)::Float64 = GDAL.ogr_f_getfieldasdouble(feature.ptr, i) """ - asstring(feature::Feature, i::Integer) + asstring(feature::AbstractFeature, i::Integer) Fetch field value as a string. @@ -299,11 +304,11 @@ Fetch field value as a string. * `feature`: the feature that owned the field. * `i`: the field to fetch, from 0 to GetFieldCount()-1. """ -asstring(feature::Feature, i::Integer)::String = +asstring(feature::AbstractFeature, i::Integer)::String = GDAL.ogr_f_getfieldasstring(feature.ptr, i) """ - asintlist(feature::Feature, i::Integer) + asintlist(feature::AbstractFeature, i::Integer) Fetch field value as a list of integers. @@ -317,14 +322,14 @@ the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief. If *pnCount is zero on return the returned pointer may be NULL or non-NULL. """ -function asintlist(feature::Feature, i::Integer)::Vector{Int32} +function asintlist(feature::AbstractFeature, i::Integer)::Vector{Int32} n = Ref{Cint}() ptr = GDAL.ogr_f_getfieldasintegerlist(feature.ptr, i, n) return (n.x == 0) ? Int32[] : unsafe_wrap(Vector{Int32}, ptr, n.x) end """ - asint64list(feature::Feature, i::Integer) + asint64list(feature::AbstractFeature, i::Integer) Fetch field value as a list of 64 bit integers. @@ -338,14 +343,14 @@ the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief. If *pnCount is zero on return the returned pointer may be NULL or non-NULL. """ -function asint64list(feature::Feature, i::Integer)::Vector{Int64} +function asint64list(feature::AbstractFeature, i::Integer)::Vector{Int64} n = Ref{Cint}() ptr = GDAL.ogr_f_getfieldasinteger64list(feature.ptr, i, n) return (n.x == 0) ? Int64[] : unsafe_wrap(Vector{Int64}, ptr, n.x) end """ - asdoublelist(feature::Feature, i::Integer) + asdoublelist(feature::AbstractFeature, i::Integer) Fetch field value as a list of doubles. @@ -359,14 +364,14 @@ the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief. If *pnCount is zero on return the returned pointer may be NULL or non-NULL. """ -function asdoublelist(feature::Feature, i::Integer)::Vector{Float64} +function asdoublelist(feature::AbstractFeature, i::Integer)::Vector{Float64} n = Ref{Cint}() ptr = GDAL.ogr_f_getfieldasdoublelist(feature.ptr, i, n) return (n.x == 0) ? Float64[] : unsafe_wrap(Vector{Float64}, ptr, n.x) end """ - asstringlist(feature::Feature, i::Integer) + asstringlist(feature::AbstractFeature, i::Integer) Fetch field value as a list of strings. @@ -378,11 +383,11 @@ Fetch field value as a list of strings. 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)::Vector{String} = +asstringlist(feature::AbstractFeature, i::Integer)::Vector{String} = GDAL.ogr_f_getfieldasstringlist(feature.ptr, i) """ - asbinary(feature::Feature, i::Integer) + asbinary(feature::AbstractFeature, i::Integer) Fetch field value as binary. @@ -394,14 +399,14 @@ Fetch field value as binary. the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief. """ -function asbinary(feature::Feature, i::Integer)::Vector{UInt8} +function asbinary(feature::AbstractFeature, i::Integer)::Vector{UInt8} n = Ref{Cint}() ptr = GDAL.ogr_f_getfieldasbinary(feature.ptr, i, n) return (n.x == 0) ? UInt8[] : unsafe_wrap(Vector{UInt8}, ptr, n.x) end """ - asdatetime(feature::Feature, i::Integer) + asdatetime(feature::AbstractFeature, i::Integer) Fetch field value as date and time. Currently this method only works for OFTDate, OFTTime and OFTDateTime fields. @@ -413,7 +418,7 @@ OFTDate, OFTTime and OFTDateTime fields. ### Returns `true` on success or `false` on failure. """ -function asdatetime(feature::Feature, i::Integer)::DateTime +function asdatetime(feature::AbstractFeature, i::Integer)::DateTime pyr = Ref{Cint}() pmth = Ref{Cint}() pday = Ref{Cint}() @@ -470,11 +475,11 @@ end # pfSecond,pnTZFlag) # end -function getdefault(feature::Feature, i::Integer)::Union{String,Nothing} +function getdefault(feature::AbstractFeature, i::Integer)::Union{String,Nothing} return getdefault(getfielddefn(feature, i)) end -getfield(feature::Feature, i::Nothing)::Missing = missing +getfield(feature::AbstractFeature, i::Nothing)::Missing = missing const _FETCHFIELD = Dict{Union{OGRFieldType,OGRFieldSubType},Function}( OFTInteger => asint, @@ -504,7 +509,7 @@ null, it will return `missing`. * https://gdal.org/development/rfc/rfc53_ogr_notnull_default.html * https://gdal.org/development/rfc/rfc67_nullfieldvalues.html """ -function getfield(feature::Feature, i::Integer) +function getfield(feature::AbstractFeature, i::Integer) return if !isfieldset(feature, i) nothing elseif isfieldnull(feature, i) @@ -526,13 +531,13 @@ function getfield(feature::Feature, i::Integer) end end -function getfield(feature::Feature, name::Union{AbstractString,Symbol}) +function getfield(feature::AbstractFeature, name::Union{AbstractString,Symbol}) return getfield(feature, findfieldindex(feature, name)) end """ - setfield!(feature::Feature, i::Integer, value) - setfield!(feature::Feature, i::Integer, value::DateTime, tzflag::Int = 0) + setfield!(feature::AbstractFeature, i::Integer, value) + setfield!(feature::AbstractFeature, i::Integer, value::DateTime, tzflag::Int = 0) Set a feature's `i`-th field to `value`. @@ -553,12 +558,20 @@ field types may be unaffected. """ function setfield! end -function setfield!(feature::Feature, i::Integer, value::Nothing)::Feature +function setfield!( + feature::AbstractFeature, + i::Integer, + value::Nothing, +)::AbstractFeature unsetfield!(feature, i) return feature end -function setfield!(feature::Feature, i::Integer, value::Missing)::Feature +function setfield!( + feature::AbstractFeature, + i::Integer, + value::Missing, +)::AbstractFeature if isnullable(getfielddefn(feature, i)) setfieldnull!(feature, 1) else @@ -568,61 +581,73 @@ function setfield!(feature::Feature, i::Integer, value::Missing)::Feature end function setfield!( - feature::Feature, + feature::AbstractFeature, i::Integer, value::Union{Bool,UInt8,Int8,UInt16,Int16,Int32}, -)::Feature +)::AbstractFeature GDAL.ogr_f_setfieldinteger(feature.ptr, i, value) return feature end function setfield!( - feature::Feature, + feature::AbstractFeature, i::Integer, value::Union{UInt32,Int64}, -)::Feature +)::AbstractFeature GDAL.ogr_f_setfieldinteger64(feature.ptr, i, value) return feature end function setfield!( - feature::Feature, + feature::AbstractFeature, i::Integer, value::Union{Float16,Float32,Float64}, -)::Feature +)::AbstractFeature GDAL.ogr_f_setfielddouble(feature.ptr, i, value) return feature end -function setfield!(feature::Feature, i::Integer, value::AbstractString)::Feature +function setfield!( + feature::AbstractFeature, + i::Integer, + value::AbstractString, +)::AbstractFeature GDAL.ogr_f_setfieldstring(feature.ptr, i, value) return feature end -function setfield!(feature::Feature, i::Integer, value::Vector{Int32})::Feature +function setfield!( + feature::AbstractFeature, + i::Integer, + value::Vector{Int32}, +)::AbstractFeature GDAL.ogr_f_setfieldintegerlist(feature.ptr, i, length(value), value) return feature end -function setfield!(feature::Feature, i::Integer, value::Vector{Int64})::Feature +function setfield!( + feature::AbstractFeature, + i::Integer, + value::Vector{Int64}, +)::AbstractFeature GDAL.ogr_f_setfieldinteger64list(feature.ptr, i, length(value), value) return feature end function setfield!( - feature::Feature, + feature::AbstractFeature, i::Integer, value::Vector{Float64}, -)::Feature +)::AbstractFeature GDAL.ogr_f_setfielddoublelist(feature.ptr, i, length(value), value) return feature end function setfield!( - feature::Feature, + feature::AbstractFeature, i::Integer, value::Vector{T}, -)::Feature where {T<:AbstractString} +)::AbstractFeature where {T<:AbstractString} GDAL.ogr_f_setfieldstringlist(feature.ptr, i, value) return feature end @@ -642,17 +667,21 @@ end # Ptr{OGRField}),arg1,arg2,arg3) # end -function setfield!(feature::Feature, i::Integer, value::Vector{UInt8})::Feature +function setfield!( + feature::AbstractFeature, + i::Integer, + value::Vector{UInt8}, +)::AbstractFeature GDAL.ogr_f_setfieldbinary(feature.ptr, i, sizeof(value), value) return feature end function setfield!( - feature::Feature, + feature::AbstractFeature, i::Integer, dt::DateTime, tzflag::Int = 0, -)::Feature +)::AbstractFeature GDAL.ogr_f_setfielddatetime( feature.ptr, i, @@ -668,16 +697,17 @@ function setfield!( end """ - ngeom(feature::Feature) + ngeom(feature::AbstractFeature) Fetch number of geometry fields on this feature. This will always be the same as the geometry field count for OGRFeatureDefn. """ -ngeom(feature::Feature)::Integer = GDAL.ogr_f_getgeomfieldcount(feature.ptr) +ngeom(feature::AbstractFeature)::Integer = + GDAL.ogr_f_getgeomfieldcount(feature.ptr) """ - getgeomdefn(feature::Feature, i::Integer) + getgeomdefn(feature::AbstractFeature, i::Integer) Fetch definition for this geometry field. @@ -689,12 +719,12 @@ Fetch definition for this geometry field. The field definition (from the OGRFeatureDefn). This is an internal reference, and should not be deleted or modified. """ -function getgeomdefn(feature::Feature, i::Integer)::IGeomFieldDefnView +function getgeomdefn(feature::AbstractFeature, i::Integer)::IGeomFieldDefnView return IGeomFieldDefnView(GDAL.ogr_f_getgeomfielddefnref(feature.ptr, i)) end """ - findgeomindex(feature::Feature, name::Union{AbstractString, Symbol} = "") + findgeomindex(feature::AbstractFeature, name::Union{AbstractString, Symbol} = "") Fetch the geometry field index given geometry field name. @@ -709,14 +739,14 @@ the geometry field index, or -1 if no matching geometry field is found. This is a cover for the `OGRFeatureDefn::GetGeomFieldIndex()` method. """ function findgeomindex( - feature::Feature, + feature::AbstractFeature, name::Union{AbstractString,Symbol} = "", )::Integer return GDAL.ogr_f_getgeomfieldindex(feature.ptr, name) end """ - getgeom(feature::Feature, i::Integer) + getgeom(feature::AbstractFeature, i::Integer) Returns a clone of the feature geometry at index `i`. @@ -724,7 +754,7 @@ Returns a clone of the feature geometry at index `i`. * `feature`: the feature to get geometry from. * `i`: geometry field to get. """ -function getgeom(feature::Feature, i::Integer)::IGeometry +function getgeom(feature::AbstractFeature, i::Integer)::IGeometry result = GDAL.ogr_f_getgeomfieldref(feature.ptr, i) return if result == C_NULL IGeometry() @@ -733,7 +763,7 @@ function getgeom(feature::Feature, i::Integer)::IGeometry end end -function unsafe_getgeom(feature::Feature, i::Integer)::Geometry +function unsafe_getgeom(feature::AbstractFeature, i::Integer)::Geometry result = GDAL.ogr_f_getgeomfieldref(feature.ptr, i) return if result == C_NULL Geometry() @@ -743,7 +773,7 @@ function unsafe_getgeom(feature::Feature, i::Integer)::Geometry end function getgeom( - feature::Feature, + feature::AbstractFeature, name::Union{AbstractString,Symbol}, )::IGeometry i = findgeomindex(feature, name) @@ -755,7 +785,7 @@ function getgeom( end function unsafe_getgeom( - feature::Feature, + feature::AbstractFeature, name::Union{AbstractString,Symbol}, )::Geometry i = findgeomindex(feature, name) @@ -767,7 +797,7 @@ function unsafe_getgeom( end """ - setgeom!(feature::Feature, i::Integer, geom::AbstractGeometry) + setgeom!(feature::AbstractFeature, i::Integer, geom::AbstractGeometry) Set feature geometry of a specified geometry field. @@ -784,24 +814,28 @@ the passed geometry, but instead makes a copy of it. `OGRERR_NONE` if successful, or `OGR_UNSUPPORTED_GEOMETRY_TYPE` if the geometry type is illegal for the `OGRFeatureDefn` (checking not yet implemented). """ -function setgeom!(feature::Feature, i::Integer, geom::AbstractGeometry)::Feature +function setgeom!( + feature::AbstractFeature, + i::Integer, + geom::AbstractGeometry, +)::AbstractFeature result = GDAL.ogr_f_setgeomfield(feature.ptr, i, geom.ptr) @ogrerr result "OGRErr $result: Failed to set feature geometry" return feature end """ - getfid(feature::Feature) + getfid(feature::AbstractFeature) Get feature identifier. ### Returns feature id or `OGRNullFID` (`-1`) if none has been assigned. """ -getfid(feature::Feature) = GDAL.ogr_f_getfid(feature.ptr)::Integer +getfid(feature::AbstractFeature) = GDAL.ogr_f_getfid(feature.ptr)::Integer """ - setfid!(feature::Feature, i::Integer) + setfid!(feature::AbstractFeature, i::Integer) Set the feature identifier. @@ -812,15 +846,15 @@ Set the feature identifier. ### Returns On success OGRERR_NONE, or on failure some other value. """ -function setfid!(feature::Feature, i::Integer)::Feature +function setfid!(feature::AbstractFeature, i::Integer)::AbstractFeature result = GDAL.ogr_f_setfid(feature.ptr, i) @ogrerr result "OGRErr $result: Failed to set FID $i" return feature end """ - setfrom!(feature1::Feature, feature2::Feature, forgiving::Bool = false) - setfrom!(feature1::Feature, feature2::Feature, indices::Vector{Cint}, + setfrom!(feature1::AbstractFeature, feature2::AbstractFeature, forgiving::Bool = false) + setfrom!(feature1::AbstractFeature, feature2::AbstractFeature, indices::Vector{Cint}, forgiving::Bool = false) Set one feature from another. @@ -843,21 +877,21 @@ otherwise an error code. function setfrom! end function setfrom!( - feature1::Feature, - feature2::Feature, + feature1::AbstractFeature, + feature2::AbstractFeature, forgiving::Bool = false, -)::Feature +)::AbstractFeature result = GDAL.ogr_f_setfrom(feature1.ptr, feature2.ptr, forgiving) @ogrerr result "OGRErr $result: Failed to set feature" return feature1 end function setfrom!( - feature1::Feature, - feature2::Feature, + feature1::AbstractFeature, + feature2::AbstractFeature, indices::Vector{Cint}, forgiving::Bool = false, -)::Feature +)::AbstractFeature result = GDAL.ogr_f_setfromwithmap( feature1.ptr, feature2.ptr, @@ -869,46 +903,52 @@ function setfrom!( end """ - getstylestring(feature::Feature) + getstylestring(feature::AbstractFeature) Fetch style string for this feature. """ -getstylestring(feature::Feature)::String = +getstylestring(feature::AbstractFeature)::String = GDAL.ogr_f_getstylestring(feature.ptr) """ - setstylestring!(feature::Feature, style::AbstractString) + setstylestring!(feature::AbstractFeature, style::AbstractString) Set feature style string. This method operate exactly as `setstylestringdirectly!()` except that it doesn't assume ownership of the passed string, but makes a copy of it. """ -function setstylestring!(feature::Feature, style::AbstractString)::Feature +function setstylestring!( + feature::AbstractFeature, + style::AbstractString, +)::AbstractFeature GDAL.ogr_f_setstylestring(feature.ptr, style) return feature end """ - getstyletable(feature::Feature) + getstyletable(feature::AbstractFeature) Fetch style table for this feature. """ -getstyletable(feature::Feature)::StyleTable = +getstyletable(feature::AbstractFeature)::StyleTable = StyleTable(GDAL.ogr_f_getstyletable(feature.ptr)) """ - setstyletable!(feature::Feature, styletable::StyleTable) + setstyletable!(feature::AbstractFeature, styletable::StyleTable) Set the style table for this feature. """ -function setstyletable!(feature::Feature, styletable::StyleTable)::Feature +function setstyletable!( + feature::AbstractFeature, + styletable::StyleTable, +)::AbstractFeature GDAL.ogr_f_setstyletable(feature.ptr, styletable.ptr) return feature end """ - getnativedata(feature::Feature) + getnativedata(feature::AbstractFeature) Returns the native data for the feature. @@ -926,10 +966,11 @@ than what can be obtained with the rest of the API, but it may be useful in round-tripping scenarios where some characteristics of the underlying format are not captured otherwise by the OGR abstraction. """ -getnativedata(feature::Feature)::String = GDAL.ogr_f_getnativedata(feature.ptr) +getnativedata(feature::AbstractFeature)::String = + GDAL.ogr_f_getnativedata(feature.ptr) """ - setnativedata!(feature::Feature, data::AbstractString) + setnativedata!(feature::AbstractFeature, data::AbstractString) Sets the native data for the feature. @@ -938,13 +979,16 @@ driver that created this feature, or that is aimed at an output driver. The native data may be in different format, which is indicated by GetNativeMediaType(). """ -function setnativedata!(feature::Feature, data::AbstractString)::Feature +function setnativedata!( + feature::AbstractFeature, + data::AbstractString, +)::AbstractFeature GDAL.ogr_f_setnativedata(feature.ptr, data) return feature end """ - getmediatype(feature::Feature) + getmediatype(feature::AbstractFeature) Returns the native media type for the feature. @@ -952,11 +996,11 @@ The native media type is the identifier for the format of the native data. It follows the IANA RFC 2045 (see https://en.wikipedia.org/wiki/Media_type), e.g. \"application/vnd.geo+json\" for JSON. """ -getmediatype(feature::Feature)::String = +getmediatype(feature::AbstractFeature)::String = GDAL.ogr_f_getnativemediatype(feature.ptr) """ - setmediatype!(feature::Feature, mediatype::AbstractString) + setmediatype!(feature::AbstractFeature, mediatype::AbstractString) Sets the native media type for the feature. @@ -964,13 +1008,16 @@ The native media type is the identifier for the format of the native data. It follows the IANA RFC 2045 (see https://en.wikipedia.org/wiki/Media_type), e.g. \"application/vnd.geo+json\" for JSON. """ -function setmediatype!(feature::Feature, mediatype::AbstractString)::Feature +function setmediatype!( + feature::AbstractFeature, + mediatype::AbstractString, +)::AbstractFeature GDAL.ogr_f_setnativemediatype(feature.ptr, mediatype) return feature end """ - fillunsetwithdefault!(feature::Feature; notnull = true, + fillunsetwithdefault!(feature::AbstractFeature; notnull = true, options = StringList(C_NULL)) Fill unset fields with default values that might be defined. @@ -984,16 +1031,16 @@ Fill unset fields with default values that might be defined. * https://gdal.org/development/rfc/rfc53_ogr_notnull_default.html """ function fillunsetwithdefault!( - feature::Feature; + feature::AbstractFeature; notnull::Bool = true, options = StringList(C_NULL), -)::Feature +)::AbstractFeature GDAL.ogr_f_fillunsetwithdefault(feature.ptr, notnull, options) return feature end """ - validate(feature::Feature, flags::Integer, emiterror::Bool) + validate(feature::AbstractFeature, flags::Integer, emiterror::Bool) Validate that a feature meets constraints of its schema. @@ -1017,5 +1064,8 @@ fails, then it will fail for all interpretations). ### References * https://gdal.org/development/rfc/rfc53_ogr_notnull_default.html """ -validate(feature::Feature, flags::FieldValidation, emiterror::Bool)::Bool = - Bool(GDAL.ogr_f_validate(feature.ptr, flags, emiterror)) +validate( + feature::AbstractFeature, + flags::FieldValidation, + emiterror::Bool, +)::Bool = Bool(GDAL.ogr_f_validate(feature.ptr, flags, emiterror)) diff --git a/src/ogr/featuredefn.jl b/src/ogr/featuredefn.jl index bc7e40ec..8728f2e0 100644 --- a/src/ogr/featuredefn.jl +++ b/src/ogr/featuredefn.jl @@ -364,9 +364,9 @@ function unsafe_createfeature(featuredefn::AbstractFeatureDefn)::Feature end """ - getfeaturedefn(feature::Feature) + getfeaturedefn(feature::AbstractFeature) Fetch feature definition. """ -getfeaturedefn(feature::Feature)::IFeatureDefnView = +getfeaturedefn(feature::AbstractFeature)::IFeatureDefnView = IFeatureDefnView(GDAL.ogr_f_getdefnref(feature.ptr)) diff --git a/src/ogr/featurelayer.jl b/src/ogr/featurelayer.jl index d1c1e19b..48a5f02d 100644 --- a/src/ogr/featurelayer.jl +++ b/src/ogr/featurelayer.jl @@ -456,7 +456,7 @@ unsafe_getfeature(layer::AbstractFeatureLayer, i::Integer)::Feature = Feature(GDAL.ogr_l_getfeature(layer.ptr, i)) """ - setfeature!(layer::AbstractFeatureLayer, feature::Feature) + setfeature!(layer::AbstractFeatureLayer, feature::AbstractFeature) Rewrite an existing feature. @@ -467,7 +467,7 @@ the OGRFeature. Use OGR_L_TestCapability(OLCRandomWrite) to establish if this layer supports random access writing via OGR_L_SetFeature(). """ -function setfeature!(layer::AbstractFeatureLayer, feature::Feature) +function setfeature!(layer::AbstractFeatureLayer, feature::AbstractFeature) result = GDAL.ogr_l_setfeature(layer.ptr, feature.ptr) # OGRERR_NONE if the operation works, otherwise an appropriate error code # (e.g OGRERR_NON_EXISTING_FEATURE if the feature does not exist). @@ -476,7 +476,7 @@ function setfeature!(layer::AbstractFeatureLayer, feature::Feature) end """ - addfeature!(layer::AbstractFeatureLayer, feature::Feature) + addfeature!(layer::AbstractFeatureLayer, feature::AbstractFeature) Write a new feature within a layer. @@ -489,7 +489,7 @@ will have been updated with the new feature id. """ function addfeature!( layer::L, - feature::Feature, + feature::AbstractFeature, )::L where {L<:AbstractFeatureLayer} result = GDAL.ogr_l_createfeature(layer.ptr, feature.ptr) @ogrerr result "Failed to create and write feature in layer." diff --git a/src/ogr/fielddefn.jl b/src/ogr/fielddefn.jl index 1ec4feab..79a46dd7 100644 --- a/src/ogr/fielddefn.jl +++ b/src/ogr/fielddefn.jl @@ -336,7 +336,7 @@ function destroy(geomdefn::GeomFieldDefn)::Nothing return nothing end -"Destroy a geometry field definition." +"Destroy a geometry field definition view." function destroy(geomdefn::IGeomFieldDefnView)::Nothing geomdefn.ptr = C_NULL return nothing diff --git a/src/tables.jl b/src/tables.jl index 7d42f0fa..be5070b6 100644 --- a/src/tables.jl +++ b/src/tables.jl @@ -9,7 +9,7 @@ function Tables.rows(layer::T)::T where {T<:AbstractFeatureLayer} return layer end -function Tables.getcolumn(row::Feature, i::Int) +function Tables.getcolumn(row::AbstractFeature, i::Int) if i > nfield(row) return getgeom(row, i - nfield(row) - 1) elseif i > 0 @@ -19,7 +19,7 @@ function Tables.getcolumn(row::Feature, i::Int) end end -function Tables.getcolumn(row::Feature, name::Symbol) +function Tables.getcolumn(row::AbstractFeature, name::Symbol) field = getfield(row, name) if !ismissing(field) return field @@ -32,7 +32,7 @@ function Tables.getcolumn(row::Feature, name::Symbol) end function Tables.columnnames( - row::Feature, + row::AbstractFeature, )::NTuple{Int64(nfield(row) + ngeom(row)),Symbol} geom_names, field_names = schema_names(getfeaturedefn(row)) return (geom_names..., field_names...) diff --git a/src/types.jl b/src/types.jl index 23934e2e..cd19ab31 100644 --- a/src/types.jl +++ b/src/types.jl @@ -13,6 +13,9 @@ abstract type AbstractSpatialRef end abstract type AbstractDataset end # needs to have a `ptr::GDAL.GDALDatasetH` attribute +abstract type AbstractFeature end +# needs to have a `ptr::GDAL.OGRFeatureH` attribute + abstract type AbstractFeatureDefn end # needs to have a `ptr::GDAL.OGRFeatureDefnH` attribute @@ -142,8 +145,18 @@ mutable struct IFeatureLayer <: AbstractFeatureLayer end end -mutable struct Feature +mutable struct Feature <: AbstractFeature + ptr::GDAL.OGRFeatureH +end + +mutable struct IFeature <: AbstractFeature ptr::GDAL.OGRFeatureH + + function IFeature(ptr::GDAL.OGRFeatureH = C_NULL) + feature = new(ptr) + finalizer(destroy, feature) + return feature + end end mutable struct FeatureDefn <: AbstractFeatureDefn