module Charta

Charta aims to supply easy geom/geog tools

Constants

SRS
VERSION

Public Class Methods

camelcase(text, first_letter = :upper) click to toggle source
# File lib/charta.rb, line 135
def camelcase(text, first_letter = :upper)
  ret = text.split(/[_\-]+/).map { |word| word[0..0].upcase + word[1..-1].downcase }.join
  ret = text[0..0].downcase + text[1..-1] if first_letter == :lower
  ret
end
default_feature_factory() click to toggle source

@deprecated This is deprecated and will be removed in 0.4

# File lib/charta.rb, line 36
def default_feature_factory
  @default_feature_factory || (self.default_feature_factory = Factory::SimpleFeatureFactory.build)
end
default_feature_factory=(factory) click to toggle source
# File lib/charta.rb, line 30
def default_feature_factory=(factory)
  @default_feature_factory = factory
  @geometry_factory = nil
end
empty_geometry(srid = :WGS84) click to toggle source
# File lib/charta.rb, line 72
def empty_geometry(srid = :WGS84)
  geometry_factory.empty_geometry(srid)
end
find_srid(srname_or_srid) click to toggle source

Check and returns the SRID matching with srname or SRID. @deprecated

# File lib/charta.rb, line 101
def find_srid(srname_or_srid)
  Factory::SridProvider.build.find(srname_or_srid)
end
find_system(_srname) click to toggle source
# File lib/charta.rb, line 95
def find_system(_srname)
  nil
end
find_system_by_srid(_srid) click to toggle source
# File lib/charta.rb, line 87
def find_system_by_srid(_srid)
  nil
end
find_system_by_urn(_urn) click to toggle source
# File lib/charta.rb, line 91
def find_system_by_urn(_urn)
  nil
end
from(format, data) click to toggle source
# File lib/charta.rb, line 105
def from(format, data)
  unless respond_to?("from_#{format}")
    raise "Unknown format: #{format.inspect}"
  end

  send("from_#{format}", data)
end
from_geojson(data, srid = nil) click to toggle source
# File lib/charta.rb, line 121
def from_geojson(data, srid = nil)
  new_geometry(::Charta::GeoJSON.new(data, srid).to_ewkt)
end
from_gml(data, srid = nil, flatten_collection = false) click to toggle source
# File lib/charta.rb, line 113
def from_gml(data, srid = nil, flatten_collection = false)
  new_geometry(::Charta::GML.new(data, srid).to_ewkt, nil, nil, flatten_collection)
end
from_kml(data, flatten_collection = false) click to toggle source
# File lib/charta.rb, line 117
def from_kml(data, flatten_collection = false)
  new_geometry(::Charta::KML.new(data).to_ewkt, nil, nil, flatten_collection)
end
generate_ewkt(feature) click to toggle source
# File lib/charta.rb, line 76
def generate_ewkt(feature)
  generator = RGeo::WKRep::WKTGenerator.new(tag_format: :ewkt, emit_ewkt_srid: true)
  generator.generate(feature)
end
geometry_factory() click to toggle source
# File lib/charta.rb, line 40
def geometry_factory
  @geometry_factory ||= Factory::SimpleGeometryFactory.new(feature_factory: default_feature_factory)
end
make_line(points, options = {}) click to toggle source
# File lib/charta.rb, line 58
def make_line(points, options = {})
  options[:srid] ||= new_geometry(points.first).srid if points.any?
  options[:srid] ||= 4326

  points_coordinates = points.map do |wkt|
    p = new_geometry(wkt)

    "#{p.x} #{p.y}"
  end

  ewkt = "SRID=#{options[:srid]};LINESTRING(#{points_coordinates.join(', ')})"
  new_geometry(ewkt)
end
new_feature(coordinates, srs = nil, format = nil, _flatten_collection = true, _options = {}) click to toggle source

@deprecated This is deprecated and will be removed in 0.4

# File lib/charta.rb, line 45
def new_feature(coordinates, srs = nil, format = nil, _flatten_collection = true, _options = {})
  default_feature_factory.new_feature(coordinates, srs: srs, format: format)
end
new_geometry(coordinates, srs = nil, format = nil, _flatten_collection = true, _options = {}) click to toggle source
# File lib/charta.rb, line 49
def new_geometry(coordinates, srs = nil, format = nil, _flatten_collection = true, _options = {})
  geometry_factory.new_geometry(coordinates, srs: srs, format: format)
end
new_point(lat, lon, srid = 4326) click to toggle source
# File lib/charta.rb, line 53
def new_point(lat, lon, srid = 4326)
  feature = Charta.new_feature("SRID=#{srid};POINT(#{lon} #{lat})")
  Point.new(feature)
end
parse_ewkt(coordinates) click to toggle source
# File lib/charta.rb, line 81
def parse_ewkt(coordinates)
  # parser = RGeo::WKRep::WKTParser.new(factory, support_ewkt: true)
  # factory.parse_wkt(coordinates)
  coordinates
end
underscore(text) click to toggle source

Utility methods

# File lib/charta.rb, line 127
def underscore(text)
  text.gsub(/::/, '/')
      .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      .gsub(/([a-z\d])([A-Z])/, '\1_\2')
      .tr('-', '_')
      .downcase
end