This commit is contained in:
qwjyh 2025-07-13 20:15:20 +09:00
commit ff8244896a
5 changed files with 1720 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
data/

1593
Manifest.toml Normal file

File diff suppressed because it is too large Load diff

5
Project.toml Normal file
View file

@ -0,0 +1,5 @@
[deps]
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"

12
README.md Normal file
View file

@ -0,0 +1,12 @@
# 河川情報プロット
国土数値情報の河川データをプロットする
https://nlftp.mlit.go.jp/ksj/jpgis/datalist/KsjTmplt-W05.html
```julia
includet("main.jl") # with Revise
xml = readxml("path/to/xml")
gb02s = get_datasets_objs(xml.root) |> get_gb
plot(gb02s)
```

109
main.jl Normal file
View file

@ -0,0 +1,109 @@
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