charta 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a519ab8c11228ddf45e3aa026fd28ed199d21d1
4
- data.tar.gz: 93830bdbc7cc63b2e049a7071e235fcab76a496d
3
+ metadata.gz: 3f4d4b8c77ea6aa5ca3e9193b3c0eadfc5379e94
4
+ data.tar.gz: 8452aca0e8b426053fded96f161cb556dab02713
5
5
  SHA512:
6
- metadata.gz: 4b30a72a075cc7b48a4894d3bfa1f9ab62472d40abb509aeeb2a0f778e4e328e8da8249c745fb1ca880f664158f619b5fb951353e5c5396f9328ef9bb38ea68e
7
- data.tar.gz: 1cbfc29635b9a5874e20a83ed78902a2b762ebbd6431df4997b0b0afa57dda335231cecedec51fa71fdcb9bd50bc19b23ae948aae1194442f4edeaab078ce2d9
6
+ metadata.gz: e06c74e261508bdce78f9e04e0203ef9c2afe079cf691d283020ed7dc42aace2fdf38f3c943122a19c320ae8a5f25fe9055adf6416766d6d5502a95ad52844dd
7
+ data.tar.gz: e930f668c1e6967d09289f3cd698f3ff4dbceeccaab9ab1dbad5858cb0fb6d304a67668dac15e4c3fddf3a9aa4a46abf40c128ad60e73568c1954d8afd1ac0cc
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Charta
2
2
 
3
- Charta is an overlay to RGeo. Basically, it was developped to permit to manipulate more easily spatial data without using factory system. It's always the case. The code was extracted from [Ekylibre](https://github.com/ekylibre/ekylibre).
3
+ Charta is an overlay to [RGeo](https://github.com/rgeo/rgeo). Basically, it was developped to permit to manipulate more easily spatial data without using factory system. It's always the case. The code was extracted from [Ekylibre](https://github.com/ekylibre/ekylibre).
4
4
 
5
5
  ## Installation
6
6
 
@@ -5,8 +5,9 @@ require 'rgeo/svg' # integrated lib for now
5
5
  module Charta
6
6
  # Represents a Geometry with SRID
7
7
  class Geometry
8
- def initialize(ewkt)
8
+ def initialize(ewkt, properties = {})
9
9
  @ewkt = ewkt
10
+ @properties = properties
10
11
  raise ArgumentError, 'Need EWKT to instantiate Geometry' if @ewkt.to_s =~ /\A[[:space:]]*\z/
11
12
  end
12
13
 
@@ -127,23 +128,24 @@ module Charta
127
128
  # Computes the geometric center of a geometry, or equivalently, the center
128
129
  # of mass of the geometry as a POINT.
129
130
  def centroid
130
- surface? ? feature.centroid : nil
131
+ return nil unless surface?
132
+ point = feature.centroid
133
+ [point.y, point.x]
131
134
  end
132
135
 
133
136
  # Returns a POINT guaranteed to lie on the surface.
134
137
  def point_on_surface
135
- surface? ? feature.point_on_surface : nil
138
+ return nil unless surface?
139
+ point = feature.point_on_surface
140
+ [point.y, point.x]
136
141
  end
137
142
 
138
143
  def convert_to(new_type)
139
- if new_type == type
140
- self
141
- elsif new_type == :multi_point
142
- flatten_multi(:point)
143
- elsif new_type == :multi_line_string
144
- flatten_multi(:line_string)
145
- elsif new_type == :multi_polygon
146
- flatten_multi(:polygon)
144
+ case new_type
145
+ when type then self
146
+ when :multi_point then flatten_multi(:point)
147
+ when :multi_line_string then flatten_multi(:line_string)
148
+ when :multi_polygon then flatten_multi(:polygon)
147
149
  end
148
150
  end
149
151
 
@@ -152,7 +154,7 @@ module Charta
152
154
  as_multi_type = "multi_#{as_type}".to_sym
153
155
  if type == as_type
154
156
  items << feature
155
- elsif is_a? :geometry_collection
157
+ elsif as_type == :geometry_collection
156
158
  feature.each do |geom|
157
159
  type_name = Charta.underscore(geom.geometry_type.type_name).to_sym
158
160
  if type_name == as_type
@@ -233,6 +235,10 @@ module Charta
233
235
  self.class.feature(@ewkt)
234
236
  end
235
237
 
238
+ def to_json_feature
239
+ { type: 'Feature', geometry: to_json_object }
240
+ end
241
+
236
242
  class << self
237
243
  def srs_database
238
244
  @srs_database ||= RGeo::CoordSys::SRSDatabase::Proj4Data.new('epsg', authority: 'EPSG', cache: true)
@@ -5,5 +5,13 @@ module Charta
5
5
  srid = Charta.find_srid(srid.nil? ? :WGS84 : srid)
6
6
  new("SRID=#{srid};GEOMETRYCOLLECTION EMPTY")
7
7
  end
8
+
9
+ def to_json_feature_collection
10
+ features = []
11
+ feature.each do |f|
12
+ features << Charta.new_geometry(f).to_json_feature
13
+ end
14
+ { type: 'FeatureCollection', features: features }
15
+ end
8
16
  end
9
17
  end
@@ -1,3 +1,3 @@
1
1
  module Charta
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brice TEXIER
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-09 00:00:00.000000000 Z
11
+ date: 2017-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri