Bounded LAS point-record IO, metadata-preserving filtering and elevation grids in pure MoonBit
moon add wrMamba/moonlas@0.1.0import { "wrMamba/moonlas" @las }fn main {
try {
let p = @las.Point::new(10, 20, 30)
let points = [p, { ..p, x: 40, classification: 2 }]
let doc = @las.create(points, 0, @las.Transform::new(0.01), minor=2)
let raw = @las.encode(doc)
let parsed = @las.decode(raw)
let ground = parsed.select({ ..@las.Selection::all(), classifications: [2] })
println(ground.points.length()) // 1
println(@las.encode(ground).length()) // 247
} catch { _ => abort("LAS processing failed") }
}| 能力 | 具体契约 |
|---|---|
| 读写 | LAS 1.2 格式 0/1/2/3;LAS 1.4 格式 0/1/2/3/6/7/8 |
| 点属性 | raw Int32 XYZ、强度、回波、分类、标志、扫描角、来源 ID、用户数据,以及对应格式的 GPS/RGB/NIR |
| 元数据 | 16 字节项目 UUID、文件头标识、VLR 不透明 payload、VLR 到点区的 gap、每点额外字节 |
| 质量审计 | 分类/回波/标志直方图,强度范围与均值、实际边界,发现头部边界/回波统计陈旧 |
| 筛选 | 分类、来源 ID、强度、首/末/单回波、withheld、GPS 闭区间;所有条件取交集,输出顺序不变 |
| 空间操作 | 缩放坐标下的闭 AABB / 球形裁剪,正比例尺和偏移校验 |
| 栅格 | 有界稠密 XY 网格;非空 cell 的点数、class 2 数量、高程最小/最大/均值及平均强度 |
| 量化/拼接 | 半远离零舍入,Int32 溢出检查、调用者显式误差容限;元数据冲突拒绝而非猜测合并 |
| 按需访问 | open_records、seek、next、batch;输入仍为完整有界 Bytes,不是磁盘流式 reader |
let report = doc.audit()
let repaired = doc.with_points(doc.points)
let output = @las.encode(repaired)let ground = doc.select({ ..@las.Selection::all(), classifications: [2], include_withheld: false })
let area = ground.crop({ min: { x: 0.0, y: 0.0, z: -100.0 }, max: { x: 100.0, y: 100.0, z: 500.0 } })
let grid = area.elevation_grid(2.0)
let cell = grid.at(0, 0) // Cell?;空 cell/越界为 Nonelet cursor = @las.open_records(input_bytes)
let batch = cursor.batch(256)
cursor.seek(0)
let result = doc.requantize(@las.Transform::new(0.02), 0.011)
let output_bytes = @las.encode(result.document)
let joined = doc.merge(other_doc, 0.011)moon run examples/quality --deny-warn # 120 点质量统计,剔除 withheld/低强度,101 点输出
moon run examples/terrain --deny-warn # 地面筛选与裁剪,3×3 网格,CSV 统计输出
moon run examples/ingest --deny-warn # 格式 8,64 点分批读取,量化、球裁剪,27 点输出moon info
moon fmt --check
moon check --deny-warn --target wasm-gc
moon test --deny-warn --target wasm-gc
moon build --deny-warn --target wasm-gc
python tools/audit_source.pypython -m venv .oracle-env
# 激活该环境后:
python -m pip install laspy==2.6.1 numpy==2.2.6
python tools/generate_oracles.py
moon fmt
# 生成物应与提交版本一致:
git diff --exit-code -- reference_wbtest.mbt tools/oracle-manifest.jsonpub suberror LasError {
Truncated(Int)
Limit(String)
Invalid(String)
Unsupported(String)
} derive(Debug)pub(all) struct Header {
minor : Int
file_source_id : Int
global_encoding : Int
project_id : Bytes
system : String
software : String
day : Int
year : Int
point_offset : Int
vlr_count : Int
format : Int
record_length : Int
point_count : Int
by_return : Array[Int]
transform : Transform
bounds : (Double, Double, Double, Double, Double, Double)
} derive(Debug)pub(all) struct Point {
x : Int
y : Int
z : Int
intensity : Int
return_number : Int
returns : Int
classification : Int
flags : Int
scanner_channel : Int
scan_direction : Bool
edge : Bool
scan_angle : Int
user_data : Int
source_id : Int
gps_time : Double?
rgb : (Int, Int, Int)?
nir : Int?
extra : Bytes
} derive(Eq, Debug)pub(all) struct Selection {
classifications : Array[Int]
source_ids : Array[Int]
min_intensity : Int
max_intensity : Int
return_mode : ReturnMode
include_withheld : Bool
gps_min : Double?
gps_max : Double?
} derive(Debug)Install
Download zipBounded LAS point-record IO, metadata-preserving filtering and elevation grids in pure MoonBit