Module: NSWTopo::Declination
- Includes:
- Vector
- Defined in:
- lib/nswtopo/layer/declination.rb
Constant Summary collapse
- CREATE =
%w[angle spacing arrows offset]- DEFAULTS =
YAML.load "spacing: 40.0\noffset: 0.0\narrows: 160.0\nstroke: darkred\nstroke-width: 0.1\nsymbol:\n path:\n d: M 0 0 L 0.4 2 L 0 1.3 L -0.4 2 Z\n stroke: none\n"
Constants included from Vector
Vector::FONT_SCALED_ATTRIBUTES, Vector::MARGIN, Vector::SVG_ATTRIBUTES
Instance Method Summary collapse
Methods included from Vector
#categorise, #create, #drawing_features, #features, #filename, #labeling_features, #params_for, #render, #svg_path_data, #to_mm
Instance Method Details
#get_features ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nswtopo/layer/declination.rb', line 17 def get_features @params["fill"] ||= @params["stroke"] declination = @angle || @map.declination col_spacing = 0.001 * @map.scale * @spacing row_spacing = 0.001 * @map.scale * @arrows * 0.5 col_offset = 0.001 * @map.scale * (@offset % @spacing) radius = 0.5 * @map.bounds.transpose.distance j_max = (radius / col_spacing).ceil i_max = (radius / row_spacing).ceil collection = GeoJSON::Collection.new(@map.projection) (-j_max..j_max).each do |j| x = j * col_spacing + col_offset coordinates = [[x, -radius], [x, radius]].map do |point| point.rotate_by_degrees(-declination).plus(@map.centre) end collection.add_linestring coordinates (-i_max..i_max).reject(&j.even? ? :even? : :odd?).map do |i| [x, i * row_spacing].rotate_by_degrees(-declination).plus(@map.centre) end.each do |coordinates| collection.add_point coordinates, "rotation" => declination end end collection end |
#to_s ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/nswtopo/layer/declination.rb', line 44 def to_s lines = features.grep(GeoJSON::LineString) return @name if lines.none? line = lines.map(&:coordinates).max_by(&:distance) angle = 90 - 180 * Math::atan2(*line.difference.reverse) / Math::PI "%s: %i line%s at %.1f°%s" % [@name, lines.length, (?s unless lines.one?), angle.abs, angle > 0 ? ?E : angle < 0 ? ?W : nil] end |