Newer
Older
JAXAtools / GPS / umap2json.rb
@HIROSE Yuuji HIROSE Yuuji on 28 Oct 2022 647 bytes Add converter from uMap file to geojson files
#!/usr/bin/env ruby
# Usage: $0 LocationHolding.umap
# 	 $0 -o OutputDir LocationHolding.umap
# uMap Layer should contain filename in description property
#
require 'json'

if ARGV[0] == "-o"
  ARGV.shift; outdir = ARGV.shift
else
  outdir = "."
end
file = ARGV[0]

exit unless file

begin
  umap = JSON.parse(IO.readlines(file).join)
rescue
  abort "Format error on #{file}"
end

for layer in umap["layers"]
  p layer["_umap_options"]["name"]
  geojson = layer["_umap_options"]["description"]
  if /^(.*\.geojson)/ =~ geojson
    ofile = File.expand_path(geojson, outdir)
    open(ofile, "w"){|gj| gj.write JSON.pretty_generate(layer)}
  end
end