Module: NSWTopo::Overlay

Includes:
VectorRender
Defined in:
lib/nswtopo/layer/overlay.rb

Constant Summary collapse

CREATE =
%w[simplify tolerance]
TOLERANCE =
0.4
GPX_STYLES =
YAML.load <<~YAML
  stroke: black
  stroke-width: 0.4
  barrier: true
YAML

Constants included from VectorRender

VectorRender::FONT_SCALED_ATTRIBUTES, VectorRender::MARGIN, VectorRender::SVG_ATTRIBUTES

Instance Method Summary collapse

Methods included from VectorRender

#categorise, #create, #drawing_features, #features, #filename, #labeling_features, #params_for, #render

Instance Method Details

#get_featuresObject



13
14
15
16
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
# File 'lib/nswtopo/layer/overlay.rb', line 13

def get_features
  GPS.new(@path).tap do |gps|
    @simplify = true if GPS::GPX === gps
    @tolerance ||= [@map.to_mm(5), TOLERANCE].max if @simplify
  end.collection.reproject_to(@map.neatline.projection).explode.map! do |feature|
    if @tolerance && GeoJSON::LineString === feature
      feature.simplify(@tolerance).segmentise(2*@tolerance).smooth_window(3)
    else
      feature
    end
  end.map! do |feature|
    styles, folder, name = feature.values_at "styles", "folder", "name"
    styles ||= GPX_STYLES
    case feature
    when GeoJSON::LineString
      styles["stroke-linejoin"] = "round"
    when GeoJSON::Polygon
      styles["stroke-linejoin"] = "miter"
    end

    categories = [folder, name].compact.reject(&:empty?).map(&method(:categorise))
    keys = styles.keys - params_for(categories.to_set).keys
    styles = styles.slice *keys
    categories << feature.object_id

    @params[categories.join(?\s)] = styles if styles.any?
    feature.with_properties("category" => categories)
  end
end

#to_sObject



43
44
45
46
47
48
49
50
# File 'lib/nswtopo/layer/overlay.rb', line 43

def to_s
  counts = %i[linestrings polygons].map do |type|
    features.send type
  end.reject(&:empty?).map(&:length).zip(%w[line polygon]).map do |count, word|
    "%s %s%s" % [count, word, (?s if count > 1)]
  end.join(", ")
  "%s: %s" % [@name, counts]
end