11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/shape2work.rb', line 11
def convert_to(shapefile = nil, file_out = 'output', chosen_format = 'geojson')
unless shapefile.nil?
RGeo::Shapefile::Reader.open(shapefile) do |file|
open("#{file_out}.#{chosen_format}", 'w+') do |f|
f.puts '{' + '"type":' + '"FeatureCollection"' + ','
f.puts '"features":' + '['
file.each do |record|
f.puts '{ "type": "Feature",'
f.puts '"id": ' + "#{record.index},"
f.puts '"geometry":' + "#{walk_geometry(record.geometry)},"
if file.next
f.puts '"properties": ' + " #{record.attributes.to_json}},"
else
f.puts '"properties": ' + " #{record.attributes.to_json}}"
end
end
f.puts ']}'
end
end
end
end
|