Module: Charta

Defined in:
lib/charta.rb,
lib/charta/gml.rb,
lib/charta/kml.rb,
lib/charta/point.rb,
lib/charta/polygon.rb,
lib/charta/version.rb,
lib/charta/geo_json.rb,
lib/charta/geometry.rb,
lib/charta/coordinates.rb,
lib/charta/line_string.rb,
lib/charta/bounding_box.rb,
lib/charta/multi_polygon.rb,
lib/charta/ewkt_serializer.rb,
lib/charta/geometry_collection.rb,
lib/charta/factory/srid_provider.rb,
lib/charta/factory/ewkt_feature_builder.rb,
lib/charta/factory/feature_factory_base.rb,
lib/charta/factory/simple_feature_factory.rb,
lib/charta/factory/simple_geometry_factory.rb,
lib/charta/factory/transformers/ewkt_passthrough.rb,
lib/charta/factory/transformers/ewkt_transformer.rb,
lib/charta/factory/transformers/from_gml_transformer.rb,
lib/charta/factory/transformers/from_kml_transformer.rb,
lib/charta/factory/transformers/from_wkb_transformer.rb,
lib/charta/factory/transformers/transformation_error.rb,
lib/charta/factory/transformers/ewkt_transformer_chain.rb,
lib/charta/factory/transformers/from_geo_json_transformer.rb

Overview

Charta aims to supply easy geom/geog tools

Defined Under Namespace

Modules: Coordinates, EwktSerializer, Factory Classes: BoundingBox, GML, GeoJSON, Geometry, GeometryCollection, KML, LineString, MultiPolygon, Point, Polygon

Constant Summary collapse

SRS =
{
  WGS84: 4326,
  CRS84: 4326,
  RGF93: 2143
}.freeze
VERSION =
'0.3.1'.freeze

Class Method Summary collapse

Class Method Details

.camelcase(text, first_letter = :upper) ⇒ Object



135
136
137
138
139
# 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_factoryObject

Deprecated.

This is deprecated and will be removed in 0.4



36
37
38
# 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) ⇒ Object



30
31
32
33
# File 'lib/charta.rb', line 30

def default_feature_factory=(factory)
  @default_feature_factory = factory
  @geometry_factory = nil
end

.empty_geometry(srid = :WGS84) ⇒ Object



72
73
74
# File 'lib/charta.rb', line 72

def empty_geometry(srid = :WGS84)
  geometry_factory.empty_geometry(srid)
end

.find_srid(srname_or_srid) ⇒ Object

Deprecated.

Check and returns the SRID matching with srname or SRID.



101
102
103
# File 'lib/charta.rb', line 101

def find_srid(srname_or_srid)
  Factory::SridProvider.build.find(srname_or_srid)
end

.find_system(_srname) ⇒ Object



95
96
97
# File 'lib/charta.rb', line 95

def find_system(_srname)
  nil
end

.find_system_by_srid(_srid) ⇒ Object



87
88
89
# File 'lib/charta.rb', line 87

def find_system_by_srid(_srid)
  nil
end

.find_system_by_urn(_urn) ⇒ Object



91
92
93
# File 'lib/charta.rb', line 91

def find_system_by_urn(_urn)
  nil
end

.from(format, data) ⇒ Object



105
106
107
108
109
110
111
# 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) ⇒ Object



121
122
123
# 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) ⇒ Object



113
114
115
# 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) ⇒ Object



117
118
119
# 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) ⇒ Object



76
77
78
79
# 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_factoryObject



40
41
42
# File 'lib/charta.rb', line 40

def geometry_factory
  @geometry_factory ||= Factory::SimpleGeometryFactory.new(feature_factory: default_feature_factory)
end

.make_line(points, options = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# 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 = {}) ⇒ Object

Deprecated.

This is deprecated and will be removed in 0.4



45
46
47
# 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 = {}) ⇒ Object



49
50
51
# 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) ⇒ Object



53
54
55
56
# 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) ⇒ Object



81
82
83
84
85
# 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) ⇒ Object

Utility methods



127
128
129
130
131
132
133
# 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