geojson2image 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +6 -6
- data/lib/geojson2image.rb +22 -22
- data/lib/geojson2image/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5f4d8a2517650fec48a157253308edc3012cddef9cfd53013dc111d6aec65c7
|
4
|
+
data.tar.gz: a092b7c91a0fb1323049b72e8c1068b5d6b456a190402beb33d95732db0737df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79400af28d504d48cd56ad9fd1c3b3e3f2b43fe6324b6cf876b776379cc99d15cfcf80fcc8b95dd573371c4bede7c2a6728d99de48a90118c167ae1cbb9c76f0
|
7
|
+
data.tar.gz: 568e84a410e00ee3f8fc04d0488e17071f5259ce71f3d197cb7982f7efdcc5d892c58460e946c60e5dadfa0f080d9a0dfc50d049b31e07838fa5dbb673311abd
|
data/README.md
CHANGED
@@ -32,10 +32,10 @@ g2i = Geojson2image::Convert.new(
|
|
32
32
|
width: 500,
|
33
33
|
height: 500,
|
34
34
|
padding: 50,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
output: "output.
|
35
|
+
background: "#ffffff",
|
36
|
+
fill: "#008000",
|
37
|
+
stroke: "#006400",
|
38
|
+
output: "output.png"
|
39
39
|
)
|
40
40
|
g2i.to_image
|
41
41
|
```
|
@@ -55,8 +55,8 @@ feature. Example:
|
|
55
55
|
|
56
56
|
```json
|
57
57
|
"properties": {
|
58
|
-
"
|
59
|
-
"
|
58
|
+
"fill": "#008000",
|
59
|
+
"stroke": "#006400"
|
60
60
|
},
|
61
61
|
```
|
62
62
|
**Example Output**
|
data/lib/geojson2image.rb
CHANGED
@@ -5,25 +5,25 @@ require "chunky_png"
|
|
5
5
|
module Geojson2image
|
6
6
|
class Convert
|
7
7
|
|
8
|
-
def initialize(json: nil, width: nil, height: nil,
|
9
|
-
|
8
|
+
def initialize(json: nil, width: nil, height: nil, padding: nil,
|
9
|
+
background: nil, fill: nil, stroke: nil,
|
10
10
|
output: nil)
|
11
11
|
begin
|
12
12
|
@parsed_json = Oj.load(json)
|
13
13
|
@width = width || 500
|
14
14
|
@height = height || 500
|
15
15
|
@padding = padding || 50
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@output = output || "output.
|
16
|
+
@background = (background.nil? ? ChunkyPNG::Color::WHITE : ChunkyPNG::Color.from_hex(background))
|
17
|
+
@fill = (fill.nil? ? ChunkyPNG::Color::TRANSPARENT : ChunkyPNG::Color.from_hex(fill))
|
18
|
+
@stroke = (stroke.nil? ? ChunkyPNG::Color::BLACK : ChunkyPNG::Color.from_hex(stroke))
|
19
|
+
@output = output || "output.png"
|
20
20
|
@min_xy = [-1, -1]
|
21
21
|
@max_xy = [-1, -1]
|
22
22
|
@coordinates = []
|
23
23
|
@width_padding = 0
|
24
24
|
@height_padding = 0
|
25
25
|
@global_ratio = 0
|
26
|
-
@png = ChunkyPNG::Image.new(@width, @height, @
|
26
|
+
@png = ChunkyPNG::Image.new(@width, @height, @background)
|
27
27
|
rescue Oj::ParseError
|
28
28
|
puts "GeoJSON parse error"
|
29
29
|
end
|
@@ -146,16 +146,16 @@ module Geojson2image
|
|
146
146
|
end
|
147
147
|
|
148
148
|
when 'Point'
|
149
|
-
|
149
|
+
tmp_stroke = @stroke
|
150
150
|
if !properties.nil?
|
151
|
-
if properties.key?('
|
152
|
-
|
151
|
+
if properties.key?('stroke') && !properties['stroke'].nil?
|
152
|
+
tmp_stroke = ChunkyPNG::Color.from_hex(properties['stroke'])
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
156
|
point = json['coordinates']
|
157
157
|
new_point = transform_point(point)
|
158
|
-
@png.compose_pixel(new_point[0], new_point[1],
|
158
|
+
@png.compose_pixel(new_point[0], new_point[1], tmp_stroke)
|
159
159
|
|
160
160
|
when 'MultiPoint'
|
161
161
|
json['coordinates'].each do |coordinate|
|
@@ -167,10 +167,10 @@ module Geojson2image
|
|
167
167
|
end
|
168
168
|
|
169
169
|
when 'LineString'
|
170
|
-
|
170
|
+
tmp_stroke = @stroke
|
171
171
|
if !properties.nil?
|
172
|
-
if properties.key?('
|
173
|
-
|
172
|
+
if properties.key?('stroke') && !properties['stroke'].nil?
|
173
|
+
tmp_stroke = ChunkyPNG::Color.from_hex(properties['stroke'])
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
@@ -179,7 +179,7 @@ module Geojson2image
|
|
179
179
|
json['coordinates'].each do |point|
|
180
180
|
new_point = transform_point(point)
|
181
181
|
if !last_point.nil?
|
182
|
-
@png.line(last_point[0], last_point[1], new_point[0], new_point[1],
|
182
|
+
@png.line(last_point[0], last_point[1], new_point[0], new_point[1], tmp_stroke)
|
183
183
|
end
|
184
184
|
last_point = new_point
|
185
185
|
end
|
@@ -194,14 +194,14 @@ module Geojson2image
|
|
194
194
|
end
|
195
195
|
|
196
196
|
when 'Polygon'
|
197
|
-
|
198
|
-
|
197
|
+
tmp_fill = @fill
|
198
|
+
tmp_stroke = @stroke
|
199
199
|
if !properties.nil?
|
200
|
-
if properties.key?('
|
201
|
-
|
200
|
+
if properties.key?('fill') && !properties['fill'].nil?
|
201
|
+
tmp_fill = ChunkyPNG::Color.from_hex(properties['fill'])
|
202
202
|
end
|
203
|
-
if properties.key?('
|
204
|
-
|
203
|
+
if properties.key?('stroke') && !properties['stroke'].nil?
|
204
|
+
tmp_stroke = ChunkyPNG::Color.from_hex(properties['stroke'])
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
@@ -217,7 +217,7 @@ module Geojson2image
|
|
217
217
|
end
|
218
218
|
|
219
219
|
points = ChunkyPNG::Vector.multiple_from_string(border_points.join(", "))
|
220
|
-
@png.polygon(points,
|
220
|
+
@png.polygon(points, tmp_stroke, tmp_fill)
|
221
221
|
end
|
222
222
|
|
223
223
|
when 'MultiPolygon'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geojson2image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce Johnston
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|