Following on from hereβ¦
geo = GeoIO.load("os_bng_grids.gpkg"), layer=4) # Read the grid gpkg file
abdf = CSV.read("addresses.csv", DataFrame) # Read the address file
subset!(abdf, [:X_COORDINATE, :Y_COORDINATE] => ByRow((x, y) -> !ismissing(x) && !ismissing(y)))
points = Point.(zip(abdf.X_COORDINATE, abdf.Y_COORDINATE)) # Convert (x,y) to geometry
geoabdf = georef(abdf, points) # join x,y geometry back to main dataset
println(typeof(geoabdf[1, "geometry"]))
newdf = geojoin(geoabdf, geo, kind=:left, pred=((g1, g2) -> intersects(g1, g2))) # Match grids to addresses based on geometry intersection
newabdf = values(newdf)
println(describe(newabdf))
The geojoin
fails and the error seems to materialise in Unitful
.
ERROR: LoadError: UndefVarError: `U` not defined
Stacktrace:
[1] unit
@ C:\Users\TGebbels\.julia\packages\Unitful\GYzMo\src\utils.jl:119 [inlined]
[2] _absunit(::Core.TypeofBottom, x::SentinelArrays.MissingVector)
@ GeoTables C:\Users\TGebbels\.julia\packages\GeoTables\8up7e\src\geoops\utils.jl:56
[3] _absunit(x::SentinelArrays.MissingVector)
@ GeoTables C:\Users\TGebbels\.julia\packages\GeoTables\8up7e\src\geoops\utils.jl:53
[4] (::GeoTables.var"#39#40"{DataFrames.DataFrameColumns{DataFrame}})(var::Symbol)
@ GeoTables .\none:0
[5] iterate
@ .\generator.jl:47 [inlined]
[6] merge(a::@NamedTuple{}, itr::Base.Generator{Vector{Symbol}, GeoTables.var"#39#40"{DataFrames.DataFrameColumns{DataFrame}}})
@ Base .\namedtuple.jl:371
[7] _adjustunits(tab::DataFrame)
@ GeoTables C:\Users\TGebbels\.julia\packages\GeoTables\8up7e\src\geoops\utils.jl:50
[8] _adjustunits(geotable::GeoTables.GeoTable{DataFrame})
@ GeoTables C:\Users\TGebbels\.julia\packages\GeoTables\8up7e\src\geoops\utils.jl:42
[9] _geojoin(gtb1::GeoTables.GeoTable{DataFrame}, gtb2::GeoTables.GeoTable{@NamedTuple{tile_name::Vector{String}, 1km_grid_ref::Vector{String}}}, selector::ColumnSelectors.NoneSelector, aggfuns::Vector{Function}; kind::Symbol, pred::Function, on::Nothing)
@ GeoTables C:\Users\TGebbels\.julia\packages\GeoTables\8up7e\src\geoops\geojoin.jl:86
[10] _geojoin
@ C:\Users\TGebbels\.julia\packages\GeoTables\8up7e\src\geoops\geojoin.jl:45 [inlined]
[11] #geojoin#45
@ C:\Users\TGebbels\.julia\packages\GeoTables\8up7e\src\geoops\geojoin.jl:39 [inlined]
[12] addgridtoaddressbase(OSdatapath::String, Status::OSDatasets.AllDatasets)
@ OSDatasets C:\Users\TGebbels\...\Documents\Julia\Packages\OSDatasets\src\OSaddressbase.jl:91
[13] top-level scope
@ c:\Users\TGebbels\...\Documents\Julia\Packages\Test-OSDatasets.jl:20
[14] include(fname::String)
@ Base.MainInclude .\client.jl:489
[15] run(debug_session::VSCodeDebugger.DebugAdapter.DebugSession, error_handler::VSCodeDebugger.var"#3#4"{String})
@ VSCodeDebugger.DebugAdapter c:\Users\TGebbels\.vscode\extensions\julialang.language-julia-1.105.2\scripts\packages\DebugAdapter\src\packagedef.jl:126
[16] startdebugger()
@ VSCodeDebugger c:\Users\TGebbels\.vscode\extensions\julialang.language-julia-1.105.2\scripts\packages\VSCodeDebugger\src\VSCodeDebugger.jl:45
[17] top-level scope
@ c:\Users\TGebbels\.vscode\extensions\julialang.language-julia-1.105.2\scripts\debugger\run_debugger.jl:12
[18] include(mod::Module, _path::String)
@ Base .\Base.jl:495
[19] exec_options(opts::Base.JLOptions)
@ Base .\client.jl:318
[20] _start()
@ Base .\client.jl:552
in expression starting at c:\Users\TGebbels\...\Documents\Julia\Packages\Test-OSDatasets.jl:20
* Terminal will be reused by tasks, press any key to close it.
In this case, the points data are of type
Meshes.Point{Meshes.πΌ {2}, CoordRefSystems.Cartesian2D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, π , Unitful.FreeUnits{(m,), π , nothing}}}}
In another example of the same approach, the points data are of type
@NamedTuple{geometry::Point{πΌ {2}, Cartesian2D{NoDatum, Quantity{Float64, π , Unitful.FreeUnits{(m,), π , nothing}}}}}
and in this case the geojoin
works. I donβt know why the types are different in these cases but Iβm assuming the difference is where the error arises.
What have I done wrong?