using EzXML using GLMakie using ProgressMeter function get_datasets_objs(root_node::EzXML.Node) findfirst("/ksj:GI/dataset/ksj:object/ksj:AA01/ksj:OBJ", root_node) end struct GmPoint "PT_00000 or p000000" id::String "Latitude N=+" lat::Float64 "Longitude E=+" lon::Float64 end function get_coord(node_gm_point) node_coords = findall("./jps:GM_Point.position/jps:DirectPosition/DirectPosition.coordinate", node_gm_point) @assert length(node_coords) == 1 node_coords = first(node_coords) x_s, y_s = split(node_coords.content) parse(Float64, x_s), parse(Float64, y_s) end function get_points(node_objs) T_POINT = Tuple{Float64,Float64} points = Dict{String,T_POINT}() for node in elements(node_objs) if node.name != "GM_Point" continue end push!(points, node["id"] => get_coord(node)) end points end struct GmCurve id::String pos_array::Vector{Tuple{Float64,Float64}} end function get_curves(node_objs) gm_points = get_points(node_objs) curves = Dict{String,Vector{Tuple{Float64,Float64}}}() for node in elements(node_objs) if node.name != "GM_Curve" continue end points = let node_segment = findfirst("./jps:GM_Curve.segment", node) @assert length(elements(node_segment)) == 1 node_points = elements(findfirst("./jps:GM_LineString.controlPoint/jps:GM_PointArray", node_segment |> elements |> first)) map(node_points) do node_point @assert length(elements(node_point)) == 1 node_pos = elements(node_point) |> first if node_pos.name == "GM_Position.direct" x_s, y_s = findfirst("./DirectPosition.coordinate", node_pos).content |> split parse(Float64, x_s), parse(Float64, y_s) elseif node_pos.name == "GM_Position.indirect" idref = findfirst("./GM_PointRef.point", node_pos)["idref"] gm_points[idref] else error("Unexpected GM_Position type $(node_pos)") end end end push!(curves, node["id"] => points) end curves end @kwdef struct Gb02 id::String loc::GmCurve "RIN" name::String end function get_gb02(node_objs) gm_curves = get_curves(node_objs) gb02s = Vector{Gb02}() for node in elements(node_objs) if node.name != "GB02" continue end curve_ref = findfirst("./ksj:LOC", node)["idref"] push!(gb02s, Gb02(id=node["id"], loc=GmCurve(curve_ref, gm_curves[curve_ref]), name=findfirst("./ksj:RIN", node).content)) end gb02s end function plot(gb02s) fig = Figure(; fonts=(; bold="Noto Sans CJK JP Bold", regular="Noto Sans CJK JP")) # boundary = ((130.3, 130.7), (33.2, 33.5)) ax = Axis(fig[1, 1], aspect=nothing#= , limits=boundary =#) @showprogress for (_i, gb02) in enumerate(gb02s) pos = gb02.loc.pos_array .|> (((x, y),) -> (y, x)) # if !all(pos) do (x, y) # boundary[1][1] < x < boundary[1][2] && boundary[2][1] < y < boundary[2][2] # end # continue # end lines!(ax, pos) text!(ax, last(pos)[1], last(pos)[2]; text=gb02.name) # display(fig) end fig end