Created
May 9, 2019 10:19
-
-
Save wheresalice/f97fee062cc133cd26ec9ad72884be49 to your computer and use it in GitHub Desktop.
Hacky ruby script to generate RFC 1876 DNS LOC records from RFC 7946 Geojson file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
def degrees(point) | |
point.abs.to_i | |
end | |
def minutes(point) | |
(point.abs * 60).to_i % 60 | |
end | |
def seconds(point) | |
(point.abs * 3600) % 60 | |
end | |
def lath(point) | |
point > 0 ? 'N' : 'S' | |
end | |
def lonh(point) | |
point > 0 ? 'E' : 'W' | |
end | |
def loc(lat, lon, altitude=0) | |
fail(ArgumentError) if lat.abs > 90 | |
fail(ArgumentError) if lon.abs > 180 | |
sprintf("%d %d %g %s %d %d %g %s %gm", | |
degrees(lat), | |
minutes(lat), | |
seconds(lat).round(2), | |
lath(lat), | |
degrees(lon), | |
minutes(lon), | |
seconds(lon).round(2), | |
lonh(lon), | |
altitude.round(2)) | |
end | |
places = JSON.parse(File.read('places.json'))['features'] | |
places.each do |place| | |
lon, lat = place['geometry']['coordinates'] | |
#puts [lat, lon].join(',') | |
puts loc(lat, lon) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment