Last active
August 29, 2015 14:15
-
-
Save jamiecook/bd1337f2ebf299440cc7 to your computer and use it in GitHub Desktop.
How to kml export some band widths
This file contains hidden or 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 'utils/gis/link_to_polygon_converter' | |
require 'utils/gis/tab_file_writer' | |
def kml_output | |
links_to_export = get_links_to_export('LinkType', [15,16,17,19]) # [linknr1, linknr2, ...] | |
links = OtSpatialReader.new.readLinks.reject { |linknr, _| !links_to_export.include?(linknr) } | |
polygons_by_linknr = links.map_values { |line| LinkToPolygonConverter.translate(line, $Ot.project.city) } | |
polygons_by_linknr_dirn = polygons_by_linknr.each_with_object({}) { |(linknr, (poly1,poly2)), memo| | |
memo[[linknr, 1]] = poly1 | |
memo[[linknr, 2]] = poly2 | |
} | |
# This constructs a hash from [linknr,direction] -> [p,m,t,u,r,i] -> load | |
loads_by_linknr_dirn_and_pmturi = LinkLoadExtractor.get_loads_by_linknr_pmturi(nil, 1, links_to_export) | |
vc_ratio_pmturi = [1,1,1,1,100,1] | |
vc_ratio_by_linknr_dirn = | |
loads_by_linknr_dirn_and_pmturi.map_values { |_linknr_dirn, loads_by_pmturi| loads_by_pmturi[vc_ratio_pmturi] } | |
polygons_by_linknr_dirn.each { |linknr_dirn, polygon| | |
vc_ratio = vc_ratio_by_linknr_dirn.fetch(linknr_dirn, 1.0) | |
polygon.mi_style = get_style(vc_ratio) | |
polygon.data['vc_ratio'] = vc_ratio | |
} | |
fields = [{ :name => "vc_ratio", :type => 'Float', :index => false }] | |
TabFileWriter.writeFromArray(filename, polygons_by_linknr_dirn.values, fields) | |
end | |
def get_style(vc_ratio) | |
brush = Mapinfo::Brush.new(2,'red','red') | |
pen = case | |
when vc_ratio > 1.0 then Mapinfo::Pen.new(3,2,'red') | |
when vc_ratio > 0.8 then Mapinfo::Pen.new(3,2,'light red') | |
else Mapinfo::Pen.new(3,2,'green') | |
end | |
{ :pen => pen, :brush => brush } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment