Open mathieu17g opened 3 years ago
(MAYBE) define a function dataset(::AbstractFeatureLayer) instead of calling ownedby property.
I do think it's a good idea to move away from the ownedby
property -- I have ideas/plans of moving away from it in a systematic approach for addressing #171 and #215.
I'll write up about it in a RFC and get thoughts and feedback first.
Unfortunately, it'll be difficult to review this PR with https://github.com/yeesian/ArchGDAL.jl/pull/243/commits/38a23ef8fea0600da272e65fe1583511dc046620. If I still remember it right, I'd suggest
master
using git at the command line, resolve any conflicts, andOK as PR #245, I will close this PR and open a new one.
Currently, I have rebase to abort locally that blocks me. I'm digging into it
- keeping a copy of this branch (in case something goes wrong),
- deleting the merge commit 38a23ef (e.g. possibly in a git rebase interactive session)
- rebasing to master using git at the command line, resolve any conflicts, and
- force pushing to this branch
Thanks, I did as advised below
I have added a 1st draft for GeoInterface geometries handling
julia> using ArchGDAL; const AG = ArchGDAL
using LibGEOS
using DataFrames
julia> df = DataFrame(AG.getlayer(AG.read("tmp/road/road.shp"), 0))
df = transform(
df,
Symbol("") =>
(x -> passmissing(LibGEOS.readgeom ∘ ArchGDAL.toWKT).(x)) =>
Symbol("")
)
df[1:5, :]
5×8 DataFrame
Row │ gid roadcode plod absd plof absf analyse ⋯
│ Abstract…? Int32 String String Float64 String Float64 String ⋯
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ LineString(Ptr{Nothing} @0x00007… 1 01A903905CD DB1 0.0 FB1 0.0 2 - Bretelles autor ⋯
2 │ LineString(Ptr{Nothing} @0x00007… 2 01A903905CD DB2 0.0 FB2 0.0 2 - Bretelles autor
3 │ LineString(Ptr{Nothing} @0x00007… 3 01A903905CD DB3 0.0 FB3 0.0 2 - Bretelles autor
4 │ LineString(Ptr{Nothing} @0x00007… 4 01A903905CD DB4 0.0 FB4 0.0 2 - Bretelles autor
5 │ LineString(Ptr{Nothing} @0x00007… 5 01A903910CD DB1 0.0 FB1 0.0 2 - Bretelles autor ⋯
1 column omitted
julia> AG.IFeatureLayer(df; name="roads")
Layer: roads
Geometry 0 (): [wkbUnknown], LINESTRING (874644.4...), ...
Field 0 (gid): [OFTInteger], 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ...
Field 1 (roadcode): [OFTString], 01A903905CD, 01A903905CD, 01A903905CD, ...
Field 2 (plod): [OFTString], DB1, DB2, DB3, DB4, DB1, DB2, DB1, DB2, ...
Field 3 (absd): [OFTReal], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ...
Field 4 (plof): [OFTString], FB1, FB2, FB3, FB4, FB1, FB2, FB1, FB2, ...
...
Number of Fields: 7
Voilà, it seems to work
julia> using ArchGDAL; const AG = ArchGDAL
using LibGEOS
using DataFrames
julia> nt = NamedTuple([
:point => [LibGEOS.readgeom("POINT (30 10)"), missing, LibGEOS.readgeom("POINT (3 7)")],
:id => [nothing, "5.1", "5.2"]
])
(point = Union{Missing, Point}[Point(Ptr{Nothing} @0x00007f87e1571600), missing, Point(Ptr{Nothing} @0x00007f87e15a7bf0)], id = Union{Nothing, String}[nothing, "5.1", "5.2"])
julia> AG.IFeatureLayer(nt)
Layer: layer
Geometry 0 (point): [wkbPoint], POINT (30 10), NULL Geometry, POINT (3 7)
Field 0 (id): [OFTString], nothing, 5.1, 5.2
julia> DataFrame(ans)
3×2 DataFrame
Row │ point id
│ IGeometr…? Union…
─────┼────────────────────────────
1 │ Geometry: wkbPoint
2 │ missing 5.1
3 │ Geometry: wkbPoint 5.2
julia> nt = NamedTuple([
:point => ["POINT (30 10)", missing, "POINT (3 7)"],
:id => [nothing, "5.1", "5.2"]
])
(point = Union{Missing, String}["POINT (30 10)", missing, "POINT (3 7)"], id = Union{Nothing, String}[nothing, "5.1", "5.2"])
julia> AG.IFeatureLayer(nt; parseWKT=true)
Layer: layer
Geometry 0 (point): [wkbPoint], POINT (30 10), NULL Geometry, POINT (3 7)
Field 0 (id): [OFTString], nothing, 5.1, 5.2
julia> DataFrame(ans)
3×2 DataFrame
Row │ point id
│ IGeometr…? Union…
─────┼────────────────────────────
1 │ Geometry: wkbPoint
2 │ missing 5.1
3 │ Geometry: wkbPoint 5.2
julia> nt = NamedTuple([
:point => [AG.toWKB(AG.createpoint(30, 10)), missing, AG.toWKB(AG.createpoint(3, 7))],
:id => [nothing, "5.1", "5.2"]
])
(point = Union{Missing, Vector{UInt8}}[UInt8[0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 … 0x3e, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40], missing, UInt8[0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 … 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x40]], id = Union{Nothing, String}[nothing, "5.1", "5.2"])
julia> AG.IFeatureLayer(nt; parseWKB=true)
Layer: layer
Geometry 0 (point): [wkbPoint], POINT (30 10), NULL Geometry, POINT (3 7)
Field 0 (id): [OFTString], nothing, 5.1, 5.2
julia> DataFrame(ans)
3×2 DataFrame
Row │ point id
│ IGeometr…? Union…
─────┼────────────────────────────
1 │ Geometry: wkbPoint
2 │ missing 5.1
3 │ Geometry: wkbPoint 5.2
IGeometry
, GeoInterface.AbstractGeometry
, WKT or WKB) is handled (see relevant test in test_tables.jl) but not the case where geometries are of different types within a same column@yeesian I dropped fieldtypes
kwarg in src/ and test/ to check if it still works properly before stashing all the WKT/WKB parsing and geomcols
kwarg
@yeesian, in commit e8560e4, I dropped geomcols kwarg in src/ and test/
Note: Coverage is still impaired by codecov coverage not handling generated code properly. When I test coverage locally with Pkg.jl and Coverage.jl everything new is covered
Wanted to say I like the new API a lot, thank you so much for working through all the review comments!
It would very nice to have this feature. It would make integration with other geometry packages easier. Is there any reason why this effort stopped? Is there still interest on this feature?
Here is a 1st draft to fix issue #152
I have implemented the conversion from table to an
IFeatureLayer
in a memory dataset. It is done via anIFeatureLayer
constructor but it can be moved to acreatelayer
method.Here are some modifications that has / may need to be implemented:
Tables.schema
returnsnothing
orTable.Schema{names, nothing}
=== nothing
to nulldataset(::AbstractFeatureLayer)
instead of callingownedby
property. Could be generalized to all ArchGDAL objects once Issue #215 has been addressed<: Union{Missing, Nothing, GeoInterface.AbstractGeometry}
or WKT/WKBwrite(::AbstractFeatureLayer, args...)
to simplify table to geofile workflow syntaxOther additions:
convert
methods betweenOGRwkbGeometryType
andIGeometry{OGRwkbGeometryType}
. Necessary in column types conversion since it is based on try-catch onconvert
methodsGDAL.ogr_gfld_setname
to set first geomfield name, sincesetname!
is not implemented forFeatureDefn
. set name!(::FeatureDefn, ::String) may require to fix issue #215 first@ogrerr
: message has to be escaped. This fix may also be necessary in other similar macros (not tested)convert
methods betweenOGRFieldType
andDataType
for vectors,Int8
andFloat16
Here is a test on multi_geom.csv test file: