Something went wrong. Try again.
Zig parser for the OSM PBF file format. jeff.jcollie.pages/osm.zig
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie// SPDX-License-Identifier: MIT
const std = @import("std");
pub const LatLonDir = enum { neg, pos,
pub fn init(latlon: i64) LatLonDir { return if (latlon < 0) .neg else .pos; }};
pub const LatLonType = enum { latitude, longitude,
pub inline fn toChar(self: @This(), dir: LatLonDir) u8 { return switch (comptime self) { .latitude => switch (dir) { .neg => 'S', .pos => 'N', }, .longitude => switch (dir) { .neg => 'W', .pos => 'E', }, }; }};
pub fn LatLon(comptime T: LatLonType) type { return struct { latlon: i64, offset: i64, granularity: i64,
pub fn init(latlon: i64, offset: i64, granularity: i64) @This() { return .{ .latlon = latlon, .offset = offset, .granularity = granularity, }; }
pub fn format(self: *const @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void { const latlon_ = (self.granularity * self.latlon) + self.offset; const dir: LatLonDir = .init(latlon_); const latlon = @abs(latlon_);
const d = @divFloor(latlon, 1000000000); const f = @mod(latlon, 1000000000); try writer.print("{d}.{d:0>9}°{c}", .{ d, f, T.toChar(dir), }); }
pub fn float(self: *const @This(), comptime F: type) F { return @as(T, 0.000000001) * @as(F, @floatFromInt(self.offset + (self.granularity * self.latlon))); } };}