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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d57d980e7f20c09aff8e48a7d87719d8479c46e408434be90572d0906a88a6e
4
- data.tar.gz: e2161ec9208b0bdbbcf5894b22c58cfe304060c67ac5108816e4bf21ac0b0e80
3
+ metadata.gz: c5f4d8a2517650fec48a157253308edc3012cddef9cfd53013dc111d6aec65c7
4
+ data.tar.gz: a092b7c91a0fb1323049b72e8c1068b5d6b456a190402beb33d95732db0737df
5
5
  SHA512:
6
- metadata.gz: 7bc18885348912a802dc18ecf1e01a846069da43256662ec1b8280e120b189caff4fa9b565c32c57270d1646275653a856197874ab900ba5e3f46cfd68831e41
7
- data.tar.gz: 1bc17400680e42e23bd805cfff2b935ca36c9be6fd98188ede76a16851f35b50dd4b728803af08ee36657797a6c6d93fd7f6bd1cb7caa39b6f7f94a41391b188
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
- background_color: "#ffffff",
36
- fill_color: "#008000",
37
- stroke_color: "#006400",
38
- output: "output.jpg"
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
- "fill_color": "#008000",
59
- "stroke_color": "#006400"
58
+ "fill": "#008000",
59
+ "stroke": "#006400"
60
60
  },
61
61
  ```
62
62
  **Example Output**
@@ -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, padding: nil,
9
- background_color: nil, fill_color: nil, stroke_color: nil,
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
- @background_color = (background_color.nil? ? ChunkyPNG::Color::WHITE : ChunkyPNG::Color.from_hex(background_color))
17
- @fill_color = (fill_color.nil? ? ChunkyPNG::Color::TRANSPARENT : ChunkyPNG::Color.from_hex(fill_color))
18
- @stroke_color = (stroke_color.nil? ? ChunkyPNG::Color::BLACK : ChunkyPNG::Color.from_hex(stroke_color))
19
- @output = output || "output.jpg"
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, @background_color)
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
- tmp_stroke_color = @stroke_color
149
+ tmp_stroke = @stroke
150
150
  if !properties.nil?
151
- if properties.key?('stroke_color') && !properties['stroke_color'].nil?
152
- tmp_stroke_color = ChunkyPNG::Color.from_hex(properties['stroke_color'])
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], tmp_stroke_color)
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
- tmp_stroke_color = @stroke_color
170
+ tmp_stroke = @stroke
171
171
  if !properties.nil?
172
- if properties.key?('stroke_color') && !properties['stroke_color'].nil?
173
- tmp_stroke_color = ChunkyPNG::Color.from_hex(properties['stroke_color'])
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], tmp_stroke_color)
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
- tmp_fill_color = @fill_color
198
- tmp_stroke_color = @stroke_color
197
+ tmp_fill = @fill
198
+ tmp_stroke = @stroke
199
199
  if !properties.nil?
200
- if properties.key?('fill_color') && !properties['fill_color'].nil?
201
- tmp_fill_color = ChunkyPNG::Color.from_hex(properties['fill_color'])
200
+ if properties.key?('fill') && !properties['fill'].nil?
201
+ tmp_fill = ChunkyPNG::Color.from_hex(properties['fill'])
202
202
  end
203
- if properties.key?('stroke_color') && !properties['stroke_color'].nil?
204
- tmp_stroke_color = ChunkyPNG::Color.from_hex(properties['stroke_color'])
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, tmp_stroke_color, tmp_fill_color)
220
+ @png.polygon(points, tmp_stroke, tmp_fill)
221
221
  end
222
222
 
223
223
  when 'MultiPolygon'
@@ -1,3 +1,3 @@
1
1
  module Geojson2image
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.0
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-13 00:00:00.000000000 Z
11
+ date: 2018-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj