module RGeo::SVG

Public Class Methods

encode(feature) click to toggle source
# File lib/rgeo/svg.rb, line 4
def encode(feature)
  send('encode_' + Charta.underscore(feature.geometry_type.type_name), feature)
end

Protected Class Methods

coordinates(feature) click to toggle source
# File lib/rgeo/svg.rb, line 64
def coordinates(feature)
  feature.x.to_s + ',' + feature.y.to_s
end
encode_geometry_collection(feature) click to toggle source
# File lib/rgeo/svg.rb, line 56
def encode_geometry_collection(feature)
  geometries = []
  feature.each do |geometry|
    geometries << encode(geometry)
  end
  geometries.join(' ')
end
encode_line_string(feature) click to toggle source
# File lib/rgeo/svg.rb, line 22
def encode_line_string(feature)
  points = []
  feature.points.each do |point|
    points << coordinates(point)
  end
  'M' + points.join('L')
end
encode_multi_line_string(feature) click to toggle source
# File lib/rgeo/svg.rb, line 30
def encode_multi_line_string(feature)
  line_strings = []
  feature.each do |line_string|
    line_strings << encode_line_string(line_string)
  end
  line_strings.join(' ')
end
encode_multi_point(feature) click to toggle source
# File lib/rgeo/svg.rb, line 14
def encode_multi_point(feature)
  points = []
  feature.each do |point|
    points << encode_point(point)
  end
  points.join(' ')
end
encode_multi_polygon(feature) click to toggle source
# File lib/rgeo/svg.rb, line 48
def encode_multi_polygon(feature)
  polygons = []
  feature.each do |polygon|
    polygons << encode_polygon(polygon)
  end
  polygons.join(' ')
end
encode_point(feature) click to toggle source
# File lib/rgeo/svg.rb, line 10
def encode_point(feature)
  'M' + coordinates(feature)
end
encode_polygon(feature) click to toggle source
# File lib/rgeo/svg.rb, line 38
def encode_polygon(feature)
  rings = []
  # TODO: Optimize useless last point repetition
  rings << encode_line_string(feature.exterior_ring) + 'Z'
  feature.interior_rings.each do |ring|
    rings << encode_line_string(ring) + 'Z'
  end
  rings.join(' ')
end