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

Add support for OFSTJSON when fetching fields #342

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/ogr/feature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ const _FETCHFIELD = Dict{Union{OGRFieldType,OGRFieldSubType},Function}(
OFSTBoolean => asbool,
OFSTInt16 => asint16,
OFSTFloat32 => assingle,
OFSTJSON => asstring,
)

"""
Expand Down
19 changes: 13 additions & 6 deletions test/test_feature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ end
AG.setsubtype!(fielddefn, AG.OFSTFloat32)
return AG.addfielddefn!(layer, fielddefn)
end
AG.createfielddefn("jsonsubfield", AG.OFTString) do fielddefn
AG.setsubtype!(fielddefn, AG.OFSTJSON)
return AG.addfielddefn!(layer, fielddefn)
end
AG.createfielddefn("uint1616subfield", AG.OFTInteger) do fielddefn
return AG.addfielddefn!(layer, fielddefn)
end
Expand All @@ -255,6 +259,7 @@ end
return AG.addfielddefn!(layer, fielddefn)
end
AG.createfeature(layer) do feature
geojsonstring = "{ \"type\": \"Polygon\", \"coordinates\": [ [ [ 4, 44 ], [ 5, 44 ], [ 5, 45 ], [ 4, 45 ], [ 4, 44 ] ] ] }"
AG.setfield!(feature, 0, Int64(1))
AG.setfield!(feature, 1, Float64(1.0))
AG.setfield!(feature, 2, Int32[1, 2])
Expand All @@ -270,9 +275,10 @@ end
AG.setfield!(feature, 12, Int8(1))
AG.setfield!(feature, 13, Float32(1.0))
AG.setfield!(feature, 14, Float16(1.0))
AG.setfield!(feature, 15, UInt16(1.0))
AG.setfield!(feature, 16, UInt32(1.0))
AG.setfield!(feature, 17, EnumValue)
AG.setfield!(feature, 15, geojsonstring)
AG.setfield!(feature, 16, UInt16(1.0))
AG.setfield!(feature, 17, UInt32(1.0))
AG.setfield!(feature, 18, EnumValue)
for i in 1:AG.nfield(feature)
@test !AG.isfieldnull(feature, i - 1)
@test AG.isfieldsetandnotnull(feature, i - 1)
Expand All @@ -289,9 +295,10 @@ end
@test AG.getfield(feature, 12) === Int16(1) # Widened from Int8
@test AG.getfield(feature, 13) === Float32(1.0)
@test AG.getfield(feature, 14) === Float32(1.0) # Widened from Float16
@test AG.getfield(feature, 15) === Int32(1) # Widened from UInt16
@test AG.getfield(feature, 16) === Int64(1) # Widened from UInt32
@test AG.getfield(feature, 17) === false # Enum is lost
@test AG.getfield(feature, 15) === geojsonstring
@test AG.getfield(feature, 16) === Int32(1) # Widened from UInt16
@test AG.getfield(feature, 17) === Int64(1) # Widened from UInt32
@test AG.getfield(feature, 18) === false # Enum is lost

AG.addfeature(layer) do newfeature
AG.setfrom!(newfeature, feature)
Expand Down