Skip to content

Instantly share code, notes, and snippets.

@KMR-zoar
Created February 10, 2015 07:24
Show Gist options
  • Save KMR-zoar/52d9d09e736be317a3ed to your computer and use it in GitHub Desktop.
Save KMR-zoar/52d9d09e736be317a3ed to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# encofing: utf-8
# This software is released under the MIT License
# see http://opensource.org/licenses/mit-license.php
# Copyright (c) 2015 Zoar
require 'json'
require 'kconv'
filename = ARGV[0]
number = ARGV[1].to_s
featuresstock = []
epsgcodes = {"1"=>"2443", "2"=>"2444", "3"=>"2445", "4"=>"2446", "5"=>"2447", "6"=>"2448", "7"=>"2449", "8"=>"2450", "9"=>"2451", "10"=>"2452", "11"=>"2453", "12"=>"2454", "13"=>"2455", "14"=>"2456", "15"=>"2457", "16"=>"2458", "17"=>"2459", "18"=>"2460", "19"=>"2461"}
epsgcode = epsgcodes[number]
# Create CRS Properties
crsproperties = {"name" => "urn:ogc:def:crs:EPSG::#{epsgcode}"}
crs = {"type" => "name", "properties" => crsproperties}
open(filename) do |sima|
sima.each do |simaline|
simaline = simaline.kconv(Kconv::UTF8)
if simaline =~ /^A01/
simaline = simaline.split(",")
simaline.each do |column|
column.strip!
end
coordinates = [simaline[4].to_f, simaline[3].to_f]
geometry = {"type" => "Point", "coordinates" => coordinates}
properties = {"Number" => simaline[1], "Name" => simaline[2]}
features = {"type" => "Feature", "properties" => properties, "geometry" => geometry}
featuresstock << features
end
end
end
geojson = JSON.generate("type"=> "FeatureCollection", "crs" => crs ,"features" => featuresstock)
open(filename.gsub(".sim",".geojson"),"w") do |json|
json.write(geojson)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment