-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_vrt.rb
30 lines (23 loc) · 866 Bytes
/
build_vrt.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'nokogiri'
layer_name = ARGV[0]
vrt_name = ARGV[1]
base_dir = '/mnt/NAS/Maptrail/Mapping Data/OS Open Map Local'
shapefiles = Dir.glob("#{base_dir}/*/*_#{layer_name}.shp")
command = <<-SH
python ogr2vrt.py -relative '#{shapefiles.first}' #{vrt_name}
SH
system(command)
doc = File.open(vrt_name) { |f| Nokogiri::XML(f) }
layer_template = doc.xpath('//OGRVRTLayer').first
layer_template.remove
doc.xpath("//OGRVRTDataSource").first.inner_html = '<OGRVRTUnionLayer name="Buildings"/>'
layers = shapefiles.map do |path_to_shapefile|
layer = layer_template
name = File.basename(path_to_shapefile,'.shp')
layer['name'] = name
layer.css('SrcDataSource')[0].inner_html = path_to_shapefile
layer.css('SrcLayer')[0].inner_html = name
layer.to_xml
end.join
doc.css("OGRVRTUnionLayer").first.inner_html = layers
File.write(vrt_name, doc.to_xml)