charta 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/charta.gemspec +21 -21
- data/lib/charta.rb +39 -87
- data/lib/charta/bounding_box.rb +4 -0
- data/lib/charta/coordinates.rb +65 -0
- data/lib/charta/ewkt_serializer.rb +101 -0
- data/lib/charta/factory/ewkt_feature_builder.rb +17 -0
- data/lib/charta/factory/feature_factory_base.rb +15 -0
- data/lib/charta/factory/simple_feature_factory.rb +50 -0
- data/lib/charta/factory/simple_geometry_factory.rb +46 -0
- data/lib/charta/factory/srid_provider.rb +36 -0
- data/lib/charta/factory/transformers/ewkt_passthrough.rb +20 -0
- data/lib/charta/factory/transformers/ewkt_transformer.rb +20 -0
- data/lib/charta/factory/transformers/ewkt_transformer_chain.rb +42 -0
- data/lib/charta/factory/transformers/from_geo_json_transformer.rb +20 -0
- data/lib/charta/factory/transformers/from_gml_transformer.rb +20 -0
- data/lib/charta/factory/transformers/from_kml_transformer.rb +20 -0
- data/lib/charta/factory/transformers/from_wkb_transformer.rb +24 -0
- data/lib/charta/factory/transformers/transformation_error.rb +10 -0
- data/lib/charta/geo_json.rb +12 -124
- data/lib/charta/geometry.rb +111 -68
- data/lib/charta/geometry_collection.rb +6 -4
- data/lib/charta/gml.rb +18 -2
- data/lib/charta/gml_import.rb +24 -24
- data/lib/charta/kml.rb +21 -3
- data/lib/charta/multi_polygon.rb +1 -1
- data/lib/charta/point.rb +6 -0
- data/lib/charta/polygon.rb +5 -0
- data/lib/charta/version.rb +1 -1
- data/lib/rgeo/svg.rb +44 -44
- metadata +76 -55
- data/.gitignore +0 -11
- data/.travis.yml +0 -7
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -21
- data/README.md +0 -44
- data/Rakefile +0 -10
data/lib/charta/kml.rb
CHANGED
@@ -22,7 +22,9 @@ module Charta
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_ewkt
|
25
|
-
"SRID=#{@srid};"
|
25
|
+
srid_part = @srid.nil? ? '' : "SRID=#{@srid};"
|
26
|
+
|
27
|
+
srid_part + self.class.document_to_ewkt(@kml)
|
26
28
|
end
|
27
29
|
|
28
30
|
def valid?
|
@@ -46,15 +48,18 @@ module Charta
|
|
46
48
|
|
47
49
|
def document_to_ewkt(kml)
|
48
50
|
return 'GEOMETRYCOLLECTION EMPTY' if kml.css('Document').nil?
|
51
|
+
|
49
52
|
'GEOMETRYCOLLECTION(' + kml.css('Placemark').collect do |placemark|
|
50
53
|
TAGS.collect do |tag|
|
51
54
|
next if placemark.css(tag).empty?
|
55
|
+
|
52
56
|
placemark.css(tag).collect do |fragment|
|
53
57
|
object_to_ewkt(fragment)
|
54
58
|
end.compact.join(', ')
|
55
59
|
end.compact.join(', ')
|
56
60
|
end.compact.join(', ') + ')'
|
57
61
|
end
|
62
|
+
|
58
63
|
alias geometry_collection_to_ewkt document_to_ewkt
|
59
64
|
|
60
65
|
def feature_to_ewkt(kml)
|
@@ -63,13 +68,14 @@ module Charta
|
|
63
68
|
|
64
69
|
def point_to_ewkt(kml)
|
65
70
|
return 'POINT EMPTY' if kml.css('coordinates').nil?
|
71
|
+
|
66
72
|
'POINT(' + kml.css('coordinates').collect { |coords| coords.content.split ',' }.flatten.join(' ') + ')'
|
67
73
|
end
|
68
74
|
|
69
75
|
def line_string_to_ewkt(kml)
|
70
76
|
return 'LINESTRING EMPTY' if kml.css('coordinates').nil?
|
71
77
|
|
72
|
-
|
78
|
+
"LINESTRING(#{transform_coordinates(kml)})"
|
73
79
|
end
|
74
80
|
|
75
81
|
def polygon_to_ewkt(kml)
|
@@ -79,7 +85,7 @@ module Charta
|
|
79
85
|
next if kml.css(boundary).empty?
|
80
86
|
|
81
87
|
kml.css(boundary).collect do |hole|
|
82
|
-
|
88
|
+
"(#{transform_coordinates(hole)})"
|
83
89
|
end.join(', ')
|
84
90
|
end.compact.join(', ') + ')'
|
85
91
|
end
|
@@ -87,6 +93,18 @@ module Charta
|
|
87
93
|
def multigeometry_to_ewkt(_kml)
|
88
94
|
raise :not_implemented
|
89
95
|
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def transform_coordinates(coordinates)
|
100
|
+
coordinates.css('coordinates')
|
101
|
+
.collect { |coords| coords.content.split(/\r\n|\n| /) }
|
102
|
+
.flatten
|
103
|
+
.reject(&:empty?)
|
104
|
+
.collect { |c| c.split ',' }
|
105
|
+
.collect { |dimension| %(#{dimension.first} #{dimension[1]}) }
|
106
|
+
.join(', ')
|
107
|
+
end
|
90
108
|
end
|
91
109
|
end
|
92
110
|
end
|
data/lib/charta/multi_polygon.rb
CHANGED
data/lib/charta/point.rb
CHANGED
data/lib/charta/polygon.rb
CHANGED
data/lib/charta/version.rb
CHANGED
data/lib/rgeo/svg.rb
CHANGED
@@ -7,63 +7,63 @@ module RGeo
|
|
7
7
|
|
8
8
|
protected
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def encode_point(feature)
|
11
|
+
'M' + coordinates(feature)
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def encode_multi_point(feature)
|
15
|
+
points = []
|
16
|
+
feature.each do |point|
|
17
|
+
points << encode_point(point)
|
18
|
+
end
|
19
|
+
points.join(' ')
|
18
20
|
end
|
19
|
-
points.join(' ')
|
20
|
-
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def encode_line_string(feature)
|
23
|
+
points = []
|
24
|
+
feature.points.each do |point|
|
25
|
+
points << coordinates(point)
|
26
|
+
end
|
27
|
+
'M' + points.join('L')
|
26
28
|
end
|
27
|
-
'M' + points.join('L')
|
28
|
-
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def encode_multi_line_string(feature)
|
31
|
+
line_strings = []
|
32
|
+
feature.each do |line_string|
|
33
|
+
line_strings << encode_line_string(line_string)
|
34
|
+
end
|
35
|
+
line_strings.join(' ')
|
34
36
|
end
|
35
|
-
line_strings.join(' ')
|
36
|
-
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
def encode_polygon(feature)
|
39
|
+
rings = []
|
40
|
+
# TODO: Optimize useless last point repetition
|
41
|
+
rings << encode_line_string(feature.exterior_ring) + 'Z'
|
42
|
+
feature.interior_rings.each do |ring|
|
43
|
+
rings << encode_line_string(ring) + 'Z'
|
44
|
+
end
|
45
|
+
rings.join(' ')
|
44
46
|
end
|
45
|
-
rings.join(' ')
|
46
|
-
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
def encode_multi_polygon(feature)
|
49
|
+
polygons = []
|
50
|
+
feature.each do |polygon|
|
51
|
+
polygons << encode_polygon(polygon)
|
52
|
+
end
|
53
|
+
polygons.join(' ')
|
52
54
|
end
|
53
|
-
polygons.join(' ')
|
54
|
-
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
def encode_geometry_collection(feature)
|
57
|
+
geometries = []
|
58
|
+
feature.each do |geometry|
|
59
|
+
geometries << encode(geometry)
|
60
|
+
end
|
61
|
+
geometries.join(' ')
|
60
62
|
end
|
61
|
-
geometries.join(' ')
|
62
|
-
end
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
def coordinates(feature)
|
65
|
+
feature.x.to_s + ',' + feature.y.to_s
|
66
|
+
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
metadata
CHANGED
@@ -1,172 +1,194 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: charta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Ekylibre developers
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.8.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.8.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: nokogiri
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.7.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rgeo
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rgeo-geojson
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: '2.0'
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: '2.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rgeo-proj4
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: '2.0'
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: '2.0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: zeitwerk
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- - "
|
101
|
+
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
103
|
+
version: 2.4.0
|
90
104
|
type: :runtime
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - "
|
108
|
+
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
110
|
+
version: 2.4.0
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: bundler
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
117
|
+
version: '2.0'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
124
|
+
version: '2.0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
126
|
+
name: minitest
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
131
|
+
version: '5.0'
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
138
|
+
version: '5.0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
140
|
+
name: rake
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - "~>"
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
145
|
+
version: '12.0'
|
132
146
|
type: :development
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
150
|
- - "~>"
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
152
|
+
version: '12.0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
154
|
+
name: rubocop
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
|
-
- -
|
157
|
+
- - '='
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
159
|
+
version: 1.3.1
|
146
160
|
type: :development
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
|
-
- -
|
164
|
+
- - '='
|
151
165
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
153
|
-
description:
|
166
|
+
version: 1.3.1
|
167
|
+
description:
|
154
168
|
email:
|
155
|
-
-
|
169
|
+
- dev@ekylibre.com
|
156
170
|
executables: []
|
157
171
|
extensions: []
|
158
172
|
extra_rdoc_files: []
|
159
173
|
files:
|
160
|
-
- ".gitignore"
|
161
|
-
- ".travis.yml"
|
162
|
-
- CODE_OF_CONDUCT.md
|
163
|
-
- Gemfile
|
164
|
-
- LICENSE.txt
|
165
|
-
- README.md
|
166
|
-
- Rakefile
|
167
174
|
- charta.gemspec
|
168
175
|
- lib/charta.rb
|
169
176
|
- lib/charta/bounding_box.rb
|
177
|
+
- lib/charta/coordinates.rb
|
178
|
+
- lib/charta/ewkt_serializer.rb
|
179
|
+
- lib/charta/factory/ewkt_feature_builder.rb
|
180
|
+
- lib/charta/factory/feature_factory_base.rb
|
181
|
+
- lib/charta/factory/simple_feature_factory.rb
|
182
|
+
- lib/charta/factory/simple_geometry_factory.rb
|
183
|
+
- lib/charta/factory/srid_provider.rb
|
184
|
+
- lib/charta/factory/transformers/ewkt_passthrough.rb
|
185
|
+
- lib/charta/factory/transformers/ewkt_transformer.rb
|
186
|
+
- lib/charta/factory/transformers/ewkt_transformer_chain.rb
|
187
|
+
- lib/charta/factory/transformers/from_geo_json_transformer.rb
|
188
|
+
- lib/charta/factory/transformers/from_gml_transformer.rb
|
189
|
+
- lib/charta/factory/transformers/from_kml_transformer.rb
|
190
|
+
- lib/charta/factory/transformers/from_wkb_transformer.rb
|
191
|
+
- lib/charta/factory/transformers/transformation_error.rb
|
170
192
|
- lib/charta/geo_json.rb
|
171
193
|
- lib/charta/geojson_import.rb
|
172
194
|
- lib/charta/geometry.rb
|
@@ -180,11 +202,11 @@ files:
|
|
180
202
|
- lib/charta/polygon.rb
|
181
203
|
- lib/charta/version.rb
|
182
204
|
- lib/rgeo/svg.rb
|
183
|
-
homepage: https://
|
205
|
+
homepage: https://gitlab.com/ekylibre
|
184
206
|
licenses:
|
185
|
-
-
|
207
|
+
- AGPL-3.0-only
|
186
208
|
metadata: {}
|
187
|
-
post_install_message:
|
209
|
+
post_install_message:
|
188
210
|
rdoc_options: []
|
189
211
|
require_paths:
|
190
212
|
- lib
|
@@ -192,16 +214,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
214
|
requirements:
|
193
215
|
- - ">="
|
194
216
|
- !ruby/object:Gem::Version
|
195
|
-
version:
|
217
|
+
version: 2.6.0
|
196
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
219
|
requirements:
|
198
220
|
- - ">="
|
199
221
|
- !ruby/object:Gem::Version
|
200
222
|
version: '0'
|
201
223
|
requirements: []
|
202
|
-
|
203
|
-
|
204
|
-
signing_key:
|
224
|
+
rubygems_version: 3.0.3
|
225
|
+
signing_key:
|
205
226
|
specification_version: 4
|
206
227
|
summary: Simple tool over geos and co
|
207
228
|
test_files: []
|