Content-Length: 405005 | pFad | http://github.com/yeesian/ArchGDAL.jl/pull/243/commits/a6277afb008f5cfdd6cd8edd902df6d2fb1e2455

7D Table to IFeatureLayer by mathieu17g · Pull Request #243 · yeesian/ArchGDAL.jl · GitHub
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

Table to IFeatureLayer #243

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fd7eeec
1st draft of an IFeatureLayer constructor from table
mathieu17g Oct 12, 2021
163e9b8
Fixed IFeatureLayer(table) for tables not supporting view on row (e.g…
mathieu17g Oct 12, 2021
9e0e900
Test table to `IFeatureLayer` conversion with a`missing`, mixed geome…
mathieu17g Oct 12, 2021
91e3a10
Fixed handling of type Any in a column and modified error messages
mathieu17g Oct 12, 2021
a79ec71
Fixed conversion to OGRFieldType error handing
mathieu17g Oct 12, 2021
843155d
JuliaFormatter formating
mathieu17g Oct 12, 2021
d8849e4
Handling of `Tables.schema` returning `nothing` or `Schema{names, no…
mathieu17g Oct 12, 2021
a5090a0
Added basic conversion to layer documentation in "Tables interface" s…
mathieu17g Oct 12, 2021
848fe0e
Completed doc on conversion to layer with an example of writing to a …
mathieu17g Oct 12, 2021
0bd76de
Added in doc an example of writing to the GML more capable driver
mathieu17g Oct 12, 2021
2045d55
Fixed a typo in table docs
mathieu17g Oct 12, 2021
a6277af
Added docstring with example to IFeatureLayer(table)
mathieu17g Oct 12, 2021
5035a0e
Formatted with JuliaFormatter
mathieu17g Oct 12, 2021
541ff9b
Fixed a typo on name option for IFeatureLayer(table)
mathieu17g Oct 12, 2021
1b6ab33
Added `nothing` values handling (cf. PR #238):
mathieu17g Oct 12, 2021
7fa434c
`_fromtable` function code readability enhancements:
mathieu17g Oct 12, 2021
8f8b1bd
Fixed a typo in `_fromtable` column types conversion error message
mathieu17g Oct 12, 2021
0e12703
Corrections following @yeesian review
mathieu17g Oct 13, 2021
6454e09
Fixed arg type in `ctv_toWKT` signature ("Table to layer conversion" …
mathieu17g Oct 13, 2021
8f07154
Added GeoInterface geometries handling to table to layer conversion
mathieu17g Oct 16, 2021
a4bd378
Fixed typo in GeoInterface to IGeometry conversion and added tests on it
mathieu17g Oct 16, 2021
7166097
Added tests on GeoInterface geometries types to `OGRwkbGeometryType`
mathieu17g Oct 16, 2021
33c3a76
Formatting and cleaning
mathieu17g Oct 16, 2021
0b1b9d9
Added WKT and WKB parsing options in table to layer conversion
mathieu17g Oct 21, 2021
f8da022
Enhance test coverage by pruning handling of `Vector{String}` convers…
mathieu17g Oct 22, 2021
c0e4da6
Corrected a typo in `_fromtable`
mathieu17g Oct 22, 2021
77d561d
Extended test coverage by testing individually GeoInterface, WKT, WKB…
mathieu17g Oct 22, 2021
a33bc88
Merge branch 'master' into IFeatureLayer_from_table
mathieu17g Oct 28, 2021
b08919b
Folliowing @visr and @yeesian remarks:
mathieu17g Oct 28, 2021
d41cbc2
Fixed test_tables.jl to use `layer_name` kwarg instead of `name` to c…
mathieu17g Oct 28, 2021
1ff0196
Added geometry column specification kwarg `geom_cols`, without any te…
mathieu17g Oct 29, 2021
125a076
Added `fieldtypes` kwarg option to table to layer conversion, without…
mathieu17g Oct 30, 2021
9e90dc1
Added tests on `geomcols` kwarg and corrected issues revealed while a…
mathieu17g Oct 31, 2021
f57a867
A few issue fixes while adding test to `fieldtypes` kwarg option.
mathieu17g Nov 1, 2021
8911988
Added test on `fieldtypes` kwarg and fixed issues raised by those tests
mathieu17g Nov 1, 2021
fbb4618
Added error message test in `@test_throws` tests for `fieldtypes` and…
mathieu17g Nov 2, 2021
1d39170
Merge branch 'master' into IFeatureLayer_from_table
mathieu17g Nov 3, 2021
5cd1f16
Modified conversion from `GeoInterface.AbstracGeometry` to `IGeometry`
mathieu17g Nov 3, 2021
d08a47c
Exclude columns in `fieldtypes` from WKT/WKB parsing in `_infergeomet…
mathieu17g Nov 3, 2021
ad14efd
Typo in the previous commit `spfieldtypes` intead of `fieldtypes`
mathieu17g Nov 3, 2021
0c61b85
Deleted 2 comments in `_fromtable(sch::Tables.Schema{names,types}, ..…
mathieu17g Nov 3, 2021
60df39e
Dropped `fieldtypes` kwarg in src and tests
mathieu17g Nov 27, 2021
a197973
Merge branch 'master' into IFeatureLayer_from_table
mathieu17g Nov 27, 2021
6ae870c
Refixed `ogrerr` macro
mathieu17g Nov 27, 2021
e8560e4
Dropped `geomcols` kwarg and WKT/WKB parsing in src/ and test/
mathieu17g Nov 28, 2021
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
Prev Previous commit
Next Next commit
Added docstring with example to IFeatureLayer(table)
Adjusted prerequisite
Added layer name option to IFeatureLayer
  • Loading branch information
mathieu17g committed Oct 12, 2021
commit a6277afb008f5cfdd6cd8edd902df6d2fb1e2455
6 changes: 3 additions & 3 deletions docs/src/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ DataFrame(AG.getlayer(ds, 0))
```
## Conversion to layer
A table-like source implementing Tables.jl interface can be converted to a layer, provided that:
- Geometry columns are of type `<: Union{IGeometry, Nothing, Missing}`
- Object contains at least one column of geometries
- Non geometry columns contain types handled by GDAL (e.g. not `Int128` nor composite type)
- Source must contains at least one geometry column
mathieu17g marked this conversation as resolved.
Show resolved Hide resolved
- Geometry columns are recognized by their element type being a subtype of `Union{IGeometry, Nothing, Missing}`
- Non geometry columns must contain types handled by GDAL/OGR (e.g. not `Int128` nor composite type)

**Note**: As geometries and fields are stored separately in GDAL features, the backward conversion of the layer won't have the same column ordering. Geometry columns will be the first columns.

Expand Down
54 changes: 46 additions & 8 deletions src/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ end

function _fromtable(
mathieu17g marked this conversation as resolved.
Show resolved Hide resolved
sch::Tables.Schema{names,types},
rows,
rows;
name::String="",
)::IFeatureLayer where {names,types}
# TODO maybe constrain `names` and `types` types
strnames = string.(sch.names)
Expand All @@ -122,7 +123,7 @@ function _fromtable(
fieldnames = strnames[fieldindices]

# Create layer
layer = createlayer(geom = first(geomtypes))
layer = createlayer(name = name, geom = first(geomtypes))
# TODO: create setname! for IGeomFieldDefnView. Probably needs first to fix issue #215
# TODO: "Model and handle relationships between GDAL objects systematically"
GDAL.ogr_gfld_setname(
Expand Down Expand Up @@ -172,27 +173,64 @@ end

function _fromtable(
::Tables.Schema{names,nothing},
rows,
rows;
name::String="",
)::IFeatureLayer where {names}
cols = Tables.columns(rows)
types = (eltype(collect(col)) for col in cols)
return _fromtable(Tables.Schema(names, types), rows)
return _fromtable(Tables.Schema(names, types), rows; name)
end

function _fromtable(::Nothing, rows)::IFeatureLayer
function _fromtable(::Nothing, rows, name::String="")::IFeatureLayer
state = iterate(rows)
state === nothing && return IFeatureLayer()
row, _ = state
names = Tables.columnnames(row)
return _fromtable(Tables.Schema(names, nothing), rows)
return _fromtable(Tables.Schema(names, nothing), rows; name)
end

function IFeatureLayer(table)::IFeatureLayer
"""
IFeatureLayer(table; name="")

Construct an IFeatureLayer from a source implementing Tables.jl interface

## Restrictions
- Source must contains at least one geometry column
- Geometry columns are recognized by their element type being a subtype of `Union{IGeometry, Nothing, Missing}`
- Non geometry columns must contain types handled by GDAL/OGR (e.g. not `Int128` nor composite type)

## Returns
An IFeatureLayer within a **MEMORY** driver dataset

## Examples
```jldoctest
julia> using ArchGDAL; AG = ArchGDAL
ArchGDAL

julia> nt = NamedTuple([
:point => [AG.createpoint(30, 10), missing],
:mixedgeom => [AG.createpoint(5, 10), AG.createlinestring([(30.0, 10.0), (10.0, 30.0)])],
:id => ["5.1", "5.2"],
:zoom => [1.0, 2],
:location => [missing, "New Delhi"],
])
(point = Union{Missing, ArchGDAL.IGeometry{ArchGDAL.wkbPoint}}[Geometry: POINT (30 10), missing], mixedgeom = ArchGDAL.IGeometry[Geometry: POINT (5 10), Geometry: LINESTRING (30 10,10 30)], id = ["5.1", "5.2"], zoom = [1.0, 2.0], location = Union{Missing, String}[missing, "New Delhi"])

julia> layer = AG.IFeatureLayer(nt; name="towns")
Layer: towns
Geometry 0 (point): [wkbPoint]
Geometry 1 (mixedgeom): [wkbUnknown]
Field 0 (id): [OFTString], 5.1, 5.2
Field 1 (zoom): [OFTReal], 1.0, 2.0
Field 2 (location): [OFTString], missing, New Delhi
```
"""
function IFeatureLayer(table; name::String="")::IFeatureLayer
# Check tables interface's conformance
!Tables.istable(table) &&
throw(DomainError(table, "$table has not a Table interface"))
# Extract table data
rows = Tables.rows(table)
schema = Tables.schema(table)
return _fromtable(schema, rows)
return _fromtable(schema, rows; name)
end








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/yeesian/ArchGDAL.jl/pull/243/commits/a6277afb008f5cfdd6cd8edd902df6d2fb1e2455

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy