charta 0.1.11 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +13 -0
- data/charta.gemspec +2 -4
- data/lib/charta.rb +4 -1
- data/lib/charta/coordinates.rb +65 -0
- data/lib/charta/ewkt_serializer.rb +92 -0
- data/lib/charta/geo_json.rb +9 -124
- data/lib/charta/geometry.rb +85 -63
- data/lib/charta/version.rb +1 -1
- metadata +14 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 27a2e5f7689bcfa650af268dd6a6f0d8a62bdea6cc20fdc3b7e4b372d62205c8
|
4
|
+
data.tar.gz: 39cb1fb8023d04d19e211323987dd2a80231e616e34c81134729e7b7a231fbf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff3edbf296fe4736cd84da7a689ce5e2df6605aa1a181827b80bebc1e9d2131744b25bd491ebc180f946af615de60acba5f2463d2e97f1ab409f3d8fdb0c35fb
|
7
|
+
data.tar.gz: 1c418aba1d2113235ad8886a425a1a8ab49120d1bea3bdfb4dd7d2476b45f4022da4ac7503e67f8a2dd1272182e9d11174f5119b94f02d3eedbc708f92896824
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
ADDED
data/charta.gemspec
CHANGED
@@ -18,11 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
20
|
spec.add_dependency 'nokogiri', '>= 1.7.0'
|
21
|
-
spec.add_dependency 'rgeo', '~>
|
21
|
+
spec.add_dependency 'rgeo', '~> 0.6.0'
|
22
22
|
spec.add_dependency 'json', '>= 1.8.0'
|
23
|
-
spec.add_dependency 'rgeo-geojson', '~>
|
24
|
-
spec.add_dependency 'rgeo-proj4', '~> 1.0.0'
|
25
|
-
spec.add_dependency 'activesupport', '>= 5.1'
|
23
|
+
spec.add_dependency 'rgeo-geojson', '~> 0.4.3'
|
26
24
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
27
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
26
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
data/lib/charta.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# Gathers geomatic calculations
|
2
2
|
# Completes RGeo
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'bigdecimal/util'
|
3
5
|
require 'rgeo'
|
4
|
-
require '
|
6
|
+
require 'charta/coordinates'
|
7
|
+
require 'charta/ewkt_serializer'
|
5
8
|
require 'charta/geometry'
|
6
9
|
require 'charta/geometry_collection'
|
7
10
|
require 'charta/point'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Charta
|
2
|
+
module Coordinates
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# Force coordinates to 2D
|
6
|
+
def flatten(hash)
|
7
|
+
map_coordinates(hash) { |position| position[0..1] }
|
8
|
+
end
|
9
|
+
|
10
|
+
def map_coordinates(hash, &block)
|
11
|
+
case hash['type']
|
12
|
+
when 'FeatureCollection'
|
13
|
+
map_feature_collection_coordinates hash, &block
|
14
|
+
when 'Feature'
|
15
|
+
map_feature_coordinates hash, &block
|
16
|
+
else
|
17
|
+
map_geometry_coordinates hash, &block
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def normalize_4326_geometry(json)
|
22
|
+
map_coordinates json do |(x, y)|
|
23
|
+
[((x + 180.to_d) % 360.to_d) - 180.to_d, ((y + 90.to_d) % 180.to_d) - 90.to_d]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def map_feature_collection_coordinates(hash, &block)
|
30
|
+
hash.merge 'features' => hash['features'].map { |feature| map_feature_coordinates feature, &block }
|
31
|
+
end
|
32
|
+
|
33
|
+
def map_feature_coordinates(hash, &block)
|
34
|
+
hash.merge 'geometry' => map_geometry_coordinates(hash['geometry'], &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def map_geometry_coordinates(hash, &block)
|
38
|
+
if hash['type'] == 'GeometryCollection'
|
39
|
+
map_geometry_collection_coordinates hash, &block
|
40
|
+
else
|
41
|
+
coordinates = hash['coordinates']
|
42
|
+
mapped =
|
43
|
+
case hash['type']
|
44
|
+
when 'Point' then
|
45
|
+
block.call coordinates
|
46
|
+
when 'MultiPoint', 'LineString'
|
47
|
+
coordinates.map(&block)
|
48
|
+
when 'MultiLineString', 'Polygon'
|
49
|
+
coordinates.map { |line| line.map(&block) }
|
50
|
+
when 'MultiPolygon'
|
51
|
+
coordinates.map { |poly| poly.map { |line| line.map(&block) } }
|
52
|
+
else
|
53
|
+
raise StandardError, "Cannot handle: #{hash['type'].inspect}. In #{hash.inspect}"
|
54
|
+
end
|
55
|
+
|
56
|
+
hash.merge 'coordinates' => mapped
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def map_geometry_collection_coordinates(hash, &block)
|
61
|
+
hash.merge 'geometries' => hash['geometries'].map { |geometry| map_geometry_coordinates(geometry, &block) }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Charta
|
2
|
+
module EwktSerializer
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def object_to_ewkt(hash)
|
6
|
+
type = hash[:type] || hash['type']
|
7
|
+
send("#{type.gsub(/(.)([A-Z])/, '\1_\2').downcase}_to_ewkt", hash)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def feature_collection_to_ewkt(hash)
|
13
|
+
return 'GEOMETRYCOLLECTION EMPTY' if hash['features'].nil?
|
14
|
+
'GEOMETRYCOLLECTION(' + hash['features'].collect do |feature|
|
15
|
+
object_to_ewkt(feature)
|
16
|
+
end.join(', ') + ')'
|
17
|
+
end
|
18
|
+
|
19
|
+
def geometry_collection_to_ewkt(hash)
|
20
|
+
return 'GEOMETRYCOLLECTION EMPTY' if hash['geometries'].nil?
|
21
|
+
'GEOMETRYCOLLECTION(' + hash['geometries'].collect do |feature|
|
22
|
+
object_to_ewkt(feature)
|
23
|
+
end.join(', ') + ')'
|
24
|
+
end
|
25
|
+
|
26
|
+
def feature_to_ewkt(hash)
|
27
|
+
object_to_ewkt(hash['geometry'])
|
28
|
+
end
|
29
|
+
|
30
|
+
def point_to_ewkt(hash)
|
31
|
+
return 'POINT EMPTY' if hash['coordinates'].nil?
|
32
|
+
'POINT(' + hash['coordinates'].join(' ') + ')'
|
33
|
+
end
|
34
|
+
|
35
|
+
def line_string_to_ewkt(hash)
|
36
|
+
return 'LINESTRING EMPTY' if hash['coordinates'].nil?
|
37
|
+
'LINESTRING(' + hash['coordinates'].collect do |point|
|
38
|
+
point.join(' ')
|
39
|
+
end.join(', ') + ')'
|
40
|
+
end
|
41
|
+
|
42
|
+
def polygon_to_ewkt(hash)
|
43
|
+
return 'POLYGON EMPTY' if hash['coordinates'].nil?
|
44
|
+
'POLYGON(' + hash['coordinates'].collect do |hole|
|
45
|
+
'(' + hole.collect do |point|
|
46
|
+
point.join(' ')
|
47
|
+
end.join(', ') + ')'
|
48
|
+
end.join(', ') + ')'
|
49
|
+
end
|
50
|
+
|
51
|
+
def multi_point_to_ewkt(hash)
|
52
|
+
return 'MULTIPOINT EMPTY' if hash['coordinates'].nil?
|
53
|
+
'MULTIPOINT(' + hash['coordinates'].collect do |point|
|
54
|
+
'(' + point.join(' ') + ')'
|
55
|
+
end.join(', ') + ')'
|
56
|
+
end
|
57
|
+
|
58
|
+
def multi_line_string_to_ewkt(hash)
|
59
|
+
return 'MULTILINESTRING EMPTY' if hash['coordinates'].nil?
|
60
|
+
'MULTILINESTRING(' + hash['coordinates'].collect do |line|
|
61
|
+
'(' + line.collect do |point|
|
62
|
+
point.join(' ')
|
63
|
+
end.join(', ') + ')'
|
64
|
+
end.join(', ') + ')'
|
65
|
+
end
|
66
|
+
|
67
|
+
def multipolygon_to_ewkt(hash)
|
68
|
+
return 'MULTIPOLYGON EMPTY' if hash['coordinates'].nil?
|
69
|
+
'MULTIPOLYGON(' + hash['coordinates'].collect do |polygon|
|
70
|
+
'(' + polygon.collect do |hole|
|
71
|
+
'(' + hole.collect do |point|
|
72
|
+
point.join(' ')
|
73
|
+
end.join(', ') + ')'
|
74
|
+
end.join(', ') + ')'
|
75
|
+
end.join(', ') + ')'
|
76
|
+
end
|
77
|
+
|
78
|
+
# for PostGIS ST_ASGeoJSON compatibility
|
79
|
+
def multi_polygon_to_ewkt(hash)
|
80
|
+
return 'MULTIPOLYGON EMPTY' if hash['coordinates'].nil?
|
81
|
+
'MULTIPOLYGON(' + hash['coordinates'].collect do |polygon|
|
82
|
+
'(' + polygon.collect do |hole|
|
83
|
+
'(' + hole.collect do |point|
|
84
|
+
point.join(' ')
|
85
|
+
end.join(', ') + ')'
|
86
|
+
end.join(', ') + ')'
|
87
|
+
end.join(', ') + ')'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
data/lib/charta/geo_json.rb
CHANGED
@@ -7,12 +7,14 @@ module Charta
|
|
7
7
|
|
8
8
|
def initialize(data, srid = :WGS84)
|
9
9
|
srid ||= :WGS84
|
10
|
-
@json =
|
10
|
+
@json = Coordinates.flatten(data.is_a?(Hash) ? data : JSON.parse(data))
|
11
11
|
lsrid = @json['crs']['properties']['name'] if @json.is_a?(Hash) &&
|
12
12
|
@json['crs'].is_a?(Hash) &&
|
13
13
|
@json['crs']['properties'].is_a?(Hash)
|
14
14
|
lsrid ||= srid
|
15
15
|
@srid = ::Charta.find_srid(lsrid)
|
16
|
+
|
17
|
+
@json = Coordinates.normalize_4326_geometry(@json) if @srid.to_i == 4326
|
16
18
|
end
|
17
19
|
|
18
20
|
def geom
|
@@ -24,7 +26,7 @@ module Charta
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def to_ewkt
|
27
|
-
"SRID=#{
|
29
|
+
"SRID=#{srid};" + EwktSerializer.object_to_ewkt(@json)
|
28
30
|
end
|
29
31
|
|
30
32
|
def valid?
|
@@ -42,131 +44,14 @@ module Charta
|
|
42
44
|
false
|
43
45
|
end
|
44
46
|
|
45
|
-
# Force coordinates to 2D
|
46
47
|
def flatten(hash)
|
47
|
-
|
48
|
-
flatten_feature_collection(hash)
|
49
|
-
elsif hash['type'] == 'Feature'
|
50
|
-
flatten_feature(hash)
|
51
|
-
else
|
52
|
-
flatten_geometry(hash)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def flatten_feature_collection(hash)
|
57
|
-
hash.merge('features' => hash['features'].map { |f| flatten_feature(f) })
|
58
|
-
end
|
59
|
-
|
60
|
-
def flatten_feature(hash)
|
61
|
-
hash.merge('geometry' => flatten_geometry(hash['geometry']))
|
62
|
-
end
|
63
|
-
|
64
|
-
def flatten_geometry(hash)
|
65
|
-
coordinates = hash['coordinates']
|
66
|
-
flattened =
|
67
|
-
case hash['type']
|
68
|
-
when 'Point' then
|
69
|
-
flatten_position(coordinates)
|
70
|
-
when 'MultiPoint', 'LineString'
|
71
|
-
coordinates.map { |p| flatten_position(p) }
|
72
|
-
when 'MultiLineString', 'Polygon'
|
73
|
-
coordinates.map { |l| l.map { |p| flatten_position(p) } }
|
74
|
-
when 'MultiPolygon'
|
75
|
-
coordinates.map { |m| m.map { |l| l.map { |p| flatten_position(p) } } }
|
76
|
-
when 'GeometryCollection' then
|
77
|
-
return hash.merge('geometries' => hash['geometries'].map { |g| flatten_geometry(g) })
|
78
|
-
else
|
79
|
-
raise StandardError, "Cannot handle: #{hash['type'].inspect}. In #{hash.inspect}"
|
80
|
-
end
|
81
|
-
|
82
|
-
hash.merge('coordinates' => flattened)
|
83
|
-
end
|
84
|
-
|
85
|
-
def flatten_position(position)
|
86
|
-
position[0..1]
|
87
|
-
end
|
88
|
-
|
89
|
-
def object_to_ewkt(hash)
|
90
|
-
type = hash[:type] || hash['type']
|
91
|
-
send("#{type.gsub(/(.)([A-Z])/, '\1_\2').downcase}_to_ewkt", hash)
|
92
|
-
end
|
93
|
-
|
94
|
-
def feature_collection_to_ewkt(hash)
|
95
|
-
return 'GEOMETRYCOLLECTION EMPTY' if hash['features'].nil?
|
96
|
-
'GEOMETRYCOLLECTION(' + hash['features'].collect do |feature|
|
97
|
-
object_to_ewkt(feature)
|
98
|
-
end.join(', ') + ')'
|
99
|
-
end
|
100
|
-
|
101
|
-
def geometry_collection_to_ewkt(hash)
|
102
|
-
return 'GEOMETRYCOLLECTION EMPTY' if hash['geometries'].nil?
|
103
|
-
'GEOMETRYCOLLECTION(' + hash['geometries'].collect do |feature|
|
104
|
-
object_to_ewkt(feature)
|
105
|
-
end.join(', ') + ')'
|
106
|
-
end
|
107
|
-
|
108
|
-
def feature_to_ewkt(hash)
|
109
|
-
object_to_ewkt(hash['geometry'])
|
110
|
-
end
|
111
|
-
|
112
|
-
def point_to_ewkt(hash)
|
113
|
-
return 'POINT EMPTY' if hash['coordinates'].nil?
|
114
|
-
'POINT(' + hash['coordinates'].join(' ') + ')'
|
115
|
-
end
|
116
|
-
|
117
|
-
def line_string_to_ewkt(hash)
|
118
|
-
return 'LINESTRING EMPTY' if hash['coordinates'].nil?
|
119
|
-
'LINESTRING(' + hash['coordinates'].collect do |point|
|
120
|
-
point.join(' ')
|
121
|
-
end.join(', ') + ')'
|
122
|
-
end
|
123
|
-
|
124
|
-
def polygon_to_ewkt(hash)
|
125
|
-
return 'POLYGON EMPTY' if hash['coordinates'].nil?
|
126
|
-
'POLYGON(' + hash['coordinates'].collect do |hole|
|
127
|
-
'(' + hole.collect do |point|
|
128
|
-
point.join(' ')
|
129
|
-
end.join(', ') + ')'
|
130
|
-
end.join(', ') + ')'
|
131
|
-
end
|
132
|
-
|
133
|
-
def multi_point_to_ewkt(hash)
|
134
|
-
return 'MULTIPOINT EMPTY' if hash['coordinates'].nil?
|
135
|
-
'MULTIPOINT(' + hash['coordinates'].collect do |point|
|
136
|
-
'(' + point.join(' ') + ')'
|
137
|
-
end.join(', ') + ')'
|
138
|
-
end
|
139
|
-
|
140
|
-
def multi_line_string_to_ewkt(hash)
|
141
|
-
return 'MULTILINESTRING EMPTY' if hash['coordinates'].nil?
|
142
|
-
'MULTILINESTRING(' + hash['coordinates'].collect do |line|
|
143
|
-
'(' + line.collect do |point|
|
144
|
-
point.join(' ')
|
145
|
-
end.join(', ') + ')'
|
146
|
-
end.join(', ') + ')'
|
147
|
-
end
|
148
|
-
|
149
|
-
def multipolygon_to_ewkt(hash)
|
150
|
-
return 'MULTIPOLYGON EMPTY' if hash['coordinates'].nil?
|
151
|
-
'MULTIPOLYGON(' + hash['coordinates'].collect do |polygon|
|
152
|
-
'(' + polygon.collect do |hole|
|
153
|
-
'(' + hole.collect do |point|
|
154
|
-
point.join(' ')
|
155
|
-
end.join(', ') + ')'
|
156
|
-
end.join(', ') + ')'
|
157
|
-
end.join(', ') + ')'
|
48
|
+
Coordinates.flatten hash
|
158
49
|
end
|
159
50
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
'(' + polygon.collect do |hole|
|
165
|
-
'(' + hole.collect do |point|
|
166
|
-
point.join(' ')
|
167
|
-
end.join(', ') + ')'
|
168
|
-
end.join(', ') + ')'
|
169
|
-
end.join(', ') + ')'
|
51
|
+
%i[object_to_ewkt feature_collection_to_ewkt geometry_collection_to_ewkt feature_to_ewkt point_to_ewkt line_string_to_ewkt polygon_to_ewkt multi_point_to_ewkt multi_line_string_to_ewkt multipolygon_to_ewkt multi_polygon_to_ewkt].each do |m|
|
52
|
+
define_method m do |*args|
|
53
|
+
EwktSerializer.send m, *args
|
54
|
+
end
|
170
55
|
end
|
171
56
|
end
|
172
57
|
end
|
data/lib/charta/geometry.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rgeo/geo_json'
|
3
3
|
require 'rgeo/svg' # integrated lib for now
|
4
|
-
require 'active_support/core_ext/module/delegation'
|
5
4
|
|
6
5
|
module Charta
|
7
6
|
# Represents a Geometry with SRID
|
8
7
|
class Geometry
|
9
|
-
delegate_missing_to :to_rgeo
|
10
|
-
|
11
8
|
def initialize(feature, properties = {})
|
12
9
|
self.feature = feature
|
13
10
|
@properties = properties
|
@@ -46,6 +43,7 @@ module Charta
|
|
46
43
|
def to_text
|
47
44
|
feature.as_text.match(/\ASRID=.*;(.*)/)[1]
|
48
45
|
end
|
46
|
+
|
49
47
|
alias as_text to_text
|
50
48
|
alias to_wkt to_text
|
51
49
|
|
@@ -53,6 +51,7 @@ module Charta
|
|
53
51
|
def to_ewkt
|
54
52
|
Charta.generate_ewkt(feature).to_s
|
55
53
|
end
|
54
|
+
|
56
55
|
alias to_s to_ewkt
|
57
56
|
|
58
57
|
def ewkt
|
@@ -65,6 +64,7 @@ module Charta
|
|
65
64
|
generator = RGeo::WKRep::WKBGenerator.new(tag_format: :ewkbt, emit_ewkbt_srid: true)
|
66
65
|
generator.generate(feature)
|
67
66
|
end
|
67
|
+
|
68
68
|
alias to_ewkb to_binary
|
69
69
|
|
70
70
|
# Pas bien compris le fonctionnement
|
@@ -88,6 +88,7 @@ module Charta
|
|
88
88
|
def to_geojson
|
89
89
|
to_json_object.to_json
|
90
90
|
end
|
91
|
+
|
91
92
|
alias to_json to_geojson
|
92
93
|
|
93
94
|
# Returns object in JSON (Hash)
|
@@ -113,12 +114,24 @@ module Charta
|
|
113
114
|
|
114
115
|
# Returns true if Geometry is a Surface
|
115
116
|
def surface?
|
116
|
-
|
117
|
+
if collection?
|
118
|
+
feature.any? { |geometry| Charta.new_geometry(geometry).surface? }
|
119
|
+
else
|
120
|
+
[RGeo::Feature::Polygon, RGeo::Feature::MultiPolygon].include? feature.geometry_type
|
121
|
+
end
|
117
122
|
end
|
118
123
|
|
119
124
|
# Returns area in unit corresponding to the SRS
|
120
125
|
def area
|
121
|
-
surface?
|
126
|
+
if surface?
|
127
|
+
if collection?
|
128
|
+
feature.sum { |geometry| Charta.new_geometry(geometry).area }
|
129
|
+
else
|
130
|
+
feature.area
|
131
|
+
end
|
132
|
+
else
|
133
|
+
0
|
134
|
+
end
|
122
135
|
end
|
123
136
|
|
124
137
|
# Returns true if this Geometry is an empty geometrycollection, polygon,
|
@@ -126,6 +139,7 @@ module Charta
|
|
126
139
|
def empty?
|
127
140
|
feature.is_empty?
|
128
141
|
end
|
142
|
+
|
129
143
|
alias blank? empty?
|
130
144
|
|
131
145
|
# Computes the geometric center of a geometry, or equivalently, the center
|
@@ -145,10 +159,16 @@ module Charta
|
|
145
159
|
|
146
160
|
def convert_to(new_type)
|
147
161
|
case new_type
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
162
|
+
when type then
|
163
|
+
self
|
164
|
+
when :multi_point then
|
165
|
+
flatten_multi(:point)
|
166
|
+
when :multi_line_string then
|
167
|
+
flatten_multi(:line_string)
|
168
|
+
when :multi_polygon then
|
169
|
+
flatten_multi(:polygon)
|
170
|
+
else
|
171
|
+
self
|
152
172
|
end
|
153
173
|
end
|
154
174
|
|
@@ -199,6 +219,7 @@ module Charta
|
|
199
219
|
other_geometry = Charta.new_geometry(other).transform(srid)
|
200
220
|
feature.union(other_geometry.feature)
|
201
221
|
end
|
222
|
+
|
202
223
|
alias + merge
|
203
224
|
|
204
225
|
def intersection(other)
|
@@ -206,10 +227,16 @@ module Charta
|
|
206
227
|
feature.intersection(other_geometry.feature)
|
207
228
|
end
|
208
229
|
|
230
|
+
def intersects?(other)
|
231
|
+
other_geometry = Charta.new_geometry(other).transform(srid)
|
232
|
+
feature.intersects?(other_geometry.feature)
|
233
|
+
end
|
234
|
+
|
209
235
|
def difference(other)
|
210
236
|
other_geometry = Charta.new_geometry(other).transform(srid)
|
211
237
|
feature.difference(other_geometry.feature)
|
212
238
|
end
|
239
|
+
|
213
240
|
alias - difference
|
214
241
|
|
215
242
|
def bounding_box
|
@@ -237,12 +264,12 @@ module Charta
|
|
237
264
|
# TODO: Manage YAML domain type to ensure maintainability of YAML
|
238
265
|
# serialization in time.
|
239
266
|
def feature
|
240
|
-
|
241
|
-
if
|
267
|
+
if @feature.nil?
|
268
|
+
if @ewkt.nil?
|
269
|
+
raise StandardError, 'Invalid geometry (no feature, no EWKT)'
|
270
|
+
else
|
242
271
|
@feature = ::Charta::Geometry.from_ewkt(@ewkt)
|
243
272
|
@properties = @options.dup if @options
|
244
|
-
else
|
245
|
-
raise StandardError, 'Invalid geometry (no feature, no EWKT)'
|
246
273
|
end
|
247
274
|
end
|
248
275
|
@feature.dup
|
@@ -291,57 +318,52 @@ module Charta
|
|
291
318
|
|
292
319
|
private
|
293
320
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
def projected_factory(srid)
|
317
|
-
proj4 = '+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs'
|
318
|
-
RGeo::Geographic.projected_factory(
|
319
|
-
srid: srid,
|
320
|
-
wkt_generator: {
|
321
|
-
type_format: :ewkt,
|
322
|
-
emit_ewkt_srid: true,
|
323
|
-
convert_case: :upper
|
324
|
-
},
|
325
|
-
wkt_parser: {
|
326
|
-
support_ewkt: true
|
327
|
-
},
|
328
|
-
wkb_generator: {
|
329
|
-
type_format: :ewkb,
|
330
|
-
emit_ewkb_srid: true,
|
331
|
-
hex_format: true
|
332
|
-
},
|
333
|
-
wkb_parser: {
|
334
|
-
support_ewkb: true
|
335
|
-
},
|
336
|
-
projection_srid: 6933,
|
337
|
-
projection_proj4: proj4
|
338
|
-
)
|
339
|
-
end
|
340
|
-
end
|
321
|
+
def geos_factory(srid)
|
322
|
+
RGeo::Geos.factory(
|
323
|
+
srid: srid,
|
324
|
+
wkt_generator: {
|
325
|
+
type_format: :ewkt,
|
326
|
+
emit_ewkt_srid: true,
|
327
|
+
convert_case: :upper
|
328
|
+
},
|
329
|
+
wkt_parser: {
|
330
|
+
support_ewkt: true
|
331
|
+
},
|
332
|
+
wkb_generator: {
|
333
|
+
type_format: :ewkb,
|
334
|
+
emit_ewkb_srid: true,
|
335
|
+
hex_format: true
|
336
|
+
},
|
337
|
+
wkb_parser: {
|
338
|
+
support_ewkb: true
|
339
|
+
}
|
340
|
+
)
|
341
|
+
end
|
341
342
|
|
342
|
-
|
343
|
-
|
344
|
-
|
343
|
+
def projected_factory(srid)
|
344
|
+
proj4 = '+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs'
|
345
|
+
RGeo::Geographic.projected_factory(
|
346
|
+
srid: srid,
|
347
|
+
wkt_generator: {
|
348
|
+
type_format: :ewkt,
|
349
|
+
emit_ewkt_srid: true,
|
350
|
+
convert_case: :upper
|
351
|
+
},
|
352
|
+
wkt_parser: {
|
353
|
+
support_ewkt: true
|
354
|
+
},
|
355
|
+
wkb_generator: {
|
356
|
+
type_format: :ewkb,
|
357
|
+
emit_ewkb_srid: true,
|
358
|
+
hex_format: true
|
359
|
+
},
|
360
|
+
wkb_parser: {
|
361
|
+
support_ewkb: true
|
362
|
+
},
|
363
|
+
projection_srid: 6933,
|
364
|
+
projection_proj4: proj4
|
365
|
+
)
|
366
|
+
end
|
345
367
|
end
|
346
368
|
end
|
347
369
|
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.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brice TEXIER
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.6.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:
|
40
|
+
version: 0.6.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,42 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.4.3
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rgeo-proj4
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 1.0.0
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.0.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: activesupport
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '5.1'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '5.1'
|
68
|
+
version: 0.4.3
|
97
69
|
- !ruby/object:Gem::Dependency
|
98
70
|
name: bundler
|
99
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,7 +122,7 @@ dependencies:
|
|
150
122
|
- - ">="
|
151
123
|
- !ruby/object:Gem::Version
|
152
124
|
version: '0'
|
153
|
-
description:
|
125
|
+
description:
|
154
126
|
email:
|
155
127
|
- brice@ekylibre.com
|
156
128
|
executables: []
|
@@ -158,6 +130,7 @@ extensions: []
|
|
158
130
|
extra_rdoc_files: []
|
159
131
|
files:
|
160
132
|
- ".gitignore"
|
133
|
+
- ".gitlab-ci.yml"
|
161
134
|
- ".travis.yml"
|
162
135
|
- CODE_OF_CONDUCT.md
|
163
136
|
- Gemfile
|
@@ -167,6 +140,8 @@ files:
|
|
167
140
|
- charta.gemspec
|
168
141
|
- lib/charta.rb
|
169
142
|
- lib/charta/bounding_box.rb
|
143
|
+
- lib/charta/coordinates.rb
|
144
|
+
- lib/charta/ewkt_serializer.rb
|
170
145
|
- lib/charta/geo_json.rb
|
171
146
|
- lib/charta/geojson_import.rb
|
172
147
|
- lib/charta/geometry.rb
|
@@ -184,7 +159,7 @@ homepage: https://github.com/ekylibre/charta
|
|
184
159
|
licenses:
|
185
160
|
- MIT
|
186
161
|
metadata: {}
|
187
|
-
post_install_message:
|
162
|
+
post_install_message:
|
188
163
|
rdoc_options: []
|
189
164
|
require_paths:
|
190
165
|
- lib
|
@@ -199,9 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
174
|
- !ruby/object:Gem::Version
|
200
175
|
version: '0'
|
201
176
|
requirements: []
|
202
|
-
|
203
|
-
|
204
|
-
signing_key:
|
177
|
+
rubygems_version: 3.0.3
|
178
|
+
signing_key:
|
205
179
|
specification_version: 4
|
206
180
|
summary: Simple tool over geos and co
|
207
181
|
test_files: []
|