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 +4 -4
- data/README.md +1 -1
- data/lib/charta/geometry.rb +18 -12
- data/lib/charta/geometry_collection.rb +8 -0
- data/lib/charta/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f4d4b8c77ea6aa5ca3e9193b3c0eadfc5379e94
|
4
|
+
data.tar.gz: 8452aca0e8b426053fded96f161cb556dab02713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/charta/geometry.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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
|
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
|
data/lib/charta/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|