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 more informative error when trying to write vector of geometry #80

Open
alex-s-gardner opened this issue Oct 5, 2024 · 1 comment

Comments

@alex-s-gardner
Copy link

alex-s-gardner commented Oct 5, 2024

load data

using GeoDataFrames
using Shapefile

path2shp = splitpath(pathof(Shapefile))
path2shp = joinpath(vcat(path2shp[1:end-2], ["test", "shapelib_testcases", "test.shp"]))

gdf = GeoDataFrames.read(path2shp)

write geopackage with attributes [works as expected]

GeoDataFrames.write("test.gpkg", gdf)

write geopackage with geometry only [I would have thought this would work but it doesn't]

GeoDataFrames.write("test.gpkg", gdf[:,:geometry])
ERROR: type IGeometry has no field geometry
Stacktrace:
 [1] getproperty
   @ ./Base.jl:37 [inlined]
 [2] getcolumn
   @ ~/.julia/packages/Tables/8p03y/src/Tables.jl:102 [inlined]
 [3] getcolumn
   @ ~/.julia/packages/Tables/8p03y/src/tofromdatavalues.jl:73 [inlined]
 [4] getproperty
   @ ~/.julia/packages/Tables/8p03y/src/Tables.jl:186 [inlined]
 [5] write(fn::String, table::Vector{…}; layer_name::String, crs::Nothing, driver::Nothing, options::Dict{…}, geom_columns::Tuple{…}, chunksize::Int64, kwargs::@Kwargs{})
   @ GeoDataFrames ~/.julia/packages/GeoDataFrames/eP9Sg/src/io.jl:136
 [6] write(fn::String, table::Vector{ArchGDAL.IGeometry{ArchGDAL.wkbPolygon}})
   @ GeoDataFrames ~/.julia/packages/GeoDataFrames/eP9Sg/src/io.jl:112
 [7] top-level scope
   @ ~/Documents/GitHub/Altim.jl/src/junk9.jl:12
Some type information was truncated. Use `show(err)` to see complete types.
@evetion
Copy link
Owner

evetion commented Oct 23, 2024

Yeah this is expected (for me that is), as this writes tables, dataframes and the like. It expects something that supports the Tables.jl interface. I had a check (istable), but apparently the Tables.jl devs discourage doing that, as it doesn't always hold. So this is the other side of the coin, that you get a vague error message. We should improve that.

Writing a vector just needs wrapping in a named tuple:

GeoDataFrames.write("test.gpkg", (;geometry=[(1,0)]))

@alex-s-gardner alex-s-gardner changed the title can not write vector of geometry, is that expected? Add more informative error when trying to write vector of geometry Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants