geojson2image 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +9 -14
- data/geojson2image.gemspec +4 -4
- data/lib/geojson2image.rb +29 -42
- data/lib/geojson2image/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4d57d980e7f20c09aff8e48a7d87719d8479c46e408434be90572d0906a88a6e
|
4
|
+
data.tar.gz: e2161ec9208b0bdbbcf5894b22c58cfe304060c67ac5108816e4bf21ac0b0e80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bc18885348912a802dc18ecf1e01a846069da43256662ec1b8280e120b189caff4fa9b565c32c57270d1646275653a856197874ab900ba5e3f46cfd68831e41
|
7
|
+
data.tar.gz: 1bc17400680e42e23bd805cfff2b935ca36c9be6fd98188ede76a16851f35b50dd4b728803af08ee36657797a6c6d93fd7f6bd1cb7caa39b6f7f94a41391b188
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -4,13 +4,11 @@
|
|
4
4
|
|
5
5
|
[gem]: https://rubygems.org/gems/geojson2image
|
6
6
|
|
7
|
-
Ruby library for generating images from GeoJSON.
|
8
|
-
|
9
|
-
Currently, MultiPolygon and Polygon GeoJSON types should output images properly. Other GeoJSON types have not been thoroughly tested.
|
7
|
+
Ruby library for generating images from GeoJSON using the [ChunkyPNG library](https://github.com/wvanbergen/chunky_png).
|
10
8
|
|
11
9
|
## Installation
|
12
10
|
|
13
|
-
|
11
|
+
Add this line to your application's Gemfile:
|
14
12
|
|
15
13
|
```ruby
|
16
14
|
gem 'geojson2image'
|
@@ -34,10 +32,9 @@ g2i = Geojson2image::Convert.new(
|
|
34
32
|
width: 500,
|
35
33
|
height: 500,
|
36
34
|
padding: 50,
|
37
|
-
background_color:
|
38
|
-
fill_color:
|
39
|
-
stroke_color:
|
40
|
-
stroke_width: 3,
|
35
|
+
background_color: "#ffffff",
|
36
|
+
fill_color: "#008000",
|
37
|
+
stroke_color: "#006400",
|
41
38
|
output: "output.jpg"
|
42
39
|
)
|
43
40
|
g2i.to_image
|
@@ -49,8 +46,7 @@ g2i.to_image
|
|
49
46
|
|
50
47
|
### Stroke and Fill Color Options
|
51
48
|
|
52
|
-
|
53
|
-
https://www.imagemagick.org/script/color.php
|
49
|
+
Accepts hex color format
|
54
50
|
|
55
51
|
Stroke and fill color options can be globally set when initializing a
|
56
52
|
new Geojson2image::Convert object, or you can override them by adding
|
@@ -59,9 +55,8 @@ feature. Example:
|
|
59
55
|
|
60
56
|
```json
|
61
57
|
"properties": {
|
62
|
-
"fill_color": "
|
63
|
-
"stroke_color": "
|
64
|
-
"stoke_width": "3",
|
58
|
+
"fill_color": "#008000",
|
59
|
+
"stroke_color": "#006400"
|
65
60
|
},
|
66
61
|
```
|
67
62
|
**Example Output**
|
@@ -76,7 +71,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
76
71
|
|
77
72
|
## Contributing
|
78
73
|
|
79
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
74
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/beaorn/geojson2image.
|
80
75
|
|
81
76
|
|
82
77
|
## License
|
data/geojson2image.gemspec
CHANGED
@@ -7,11 +7,11 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "geojson2image"
|
8
8
|
spec.version = Geojson2image::VERSION
|
9
9
|
spec.authors = ["Bryce Johnston"]
|
10
|
-
spec.email = ["bryce@
|
10
|
+
spec.email = ["bryce@beaorn.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{Ruby library for generating images from GeoJSON}
|
13
13
|
spec.description = %q{Ruby library for generating images from GeoJSON}
|
14
|
-
spec.homepage = "https://github.com/
|
14
|
+
spec.homepage = "https://github.com/beaorn/geojson2image"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_dependency "oj", "~> 3.
|
25
|
-
spec.add_dependency "
|
24
|
+
spec.add_dependency "oj", "~> 3.6"
|
25
|
+
spec.add_dependency "chunky_png", "~> 1.3"
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.13"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
data/lib/geojson2image.rb
CHANGED
@@ -1,25 +1,21 @@
|
|
1
1
|
require "geojson2image/version"
|
2
2
|
require "oj"
|
3
|
-
require "
|
3
|
+
require "chunky_png"
|
4
4
|
|
5
5
|
module Geojson2image
|
6
6
|
class Convert
|
7
|
-
attr_accessor :parsed_json, :width, :height, :background_color,
|
8
|
-
:border_color, :border_width, :padding, :output, :min_xy, :max_xy,
|
9
|
-
:coordinates, :width_padding, :height_padding, :global_ratio
|
10
7
|
|
11
8
|
def initialize(json: nil, width: nil, height: nil, padding: nil,
|
12
9
|
background_color: nil, fill_color: nil, stroke_color: nil,
|
13
|
-
|
10
|
+
output: nil)
|
14
11
|
begin
|
15
12
|
@parsed_json = Oj.load(json)
|
16
13
|
@width = width || 500
|
17
14
|
@height = height || 500
|
18
15
|
@padding = padding || 50
|
19
|
-
@background_color = background_color
|
20
|
-
@fill_color = fill_color
|
21
|
-
@stroke_color = stroke_color
|
22
|
-
@stroke_width = stroke_width || 3
|
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))
|
23
19
|
@output = output || "output.jpg"
|
24
20
|
@min_xy = [-1, -1]
|
25
21
|
@max_xy = [-1, -1]
|
@@ -27,6 +23,7 @@ module Geojson2image
|
|
27
23
|
@width_padding = 0
|
28
24
|
@height_padding = 0
|
29
25
|
@global_ratio = 0
|
26
|
+
@png = ChunkyPNG::Image.new(@width, @height, @background_color)
|
30
27
|
rescue Oj::ParseError
|
31
28
|
puts "GeoJSON parse error"
|
32
29
|
end
|
@@ -98,16 +95,16 @@ module Geojson2image
|
|
98
95
|
@coordinates[i][0] = lon
|
99
96
|
@coordinates[i][1] = Math.log(Math.tan(quarter_pi + 0.5 * lat))
|
100
97
|
|
101
|
-
@min_xy[0] = (min_xy[0] == -1 ? @coordinates[i][0] : [min_xy[0], @coordinates[i][0]].min)
|
102
|
-
@min_xy[1] = (min_xy[1] == -1 ? @coordinates[i][1] : [min_xy[1], @coordinates[i][1]].min)
|
98
|
+
@min_xy[0] = (@min_xy[0] == -1 ? @coordinates[i][0] : [@min_xy[0], @coordinates[i][0]].min)
|
99
|
+
@min_xy[1] = (@min_xy[1] == -1 ? @coordinates[i][1] : [@min_xy[1], @coordinates[i][1]].min)
|
103
100
|
end
|
104
101
|
|
105
102
|
@coordinates.each_with_index do |point,i|
|
106
103
|
@coordinates[i][0] = @coordinates[i][0] - @min_xy[0]
|
107
104
|
@coordinates[i][1] = @coordinates[i][1] - @min_xy[1]
|
108
105
|
|
109
|
-
@max_xy[0] = (max_xy[0] == -1 ? @coordinates[i][0] : [max_xy[0], @coordinates[i][0]].max)
|
110
|
-
@max_xy[1] = (max_xy[1] == -1 ? @coordinates[i][1] : [max_xy[1], @coordinates[i][1]].max)
|
106
|
+
@max_xy[0] = (@max_xy[0] == -1 ? @coordinates[i][0] : [@max_xy[0], @coordinates[i][0]].max)
|
107
|
+
@max_xy[1] = (@max_xy[1] == -1 ? @coordinates[i][1] : [@max_xy[1], @coordinates[i][1]].max)
|
111
108
|
end
|
112
109
|
end
|
113
110
|
|
@@ -149,10 +146,16 @@ module Geojson2image
|
|
149
146
|
end
|
150
147
|
|
151
148
|
when 'Point'
|
149
|
+
tmp_stroke_color = @stroke_color
|
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'])
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
152
156
|
point = json['coordinates']
|
153
157
|
new_point = transform_point(point)
|
154
|
-
|
155
|
-
@convert.draw(draw_point)
|
158
|
+
@png.compose_pixel(new_point[0], new_point[1], tmp_stroke_color)
|
156
159
|
|
157
160
|
when 'MultiPoint'
|
158
161
|
json['coordinates'].each do |coordinate|
|
@@ -164,15 +167,10 @@ module Geojson2image
|
|
164
167
|
end
|
165
168
|
|
166
169
|
when 'LineString'
|
170
|
+
tmp_stroke_color = @stroke_color
|
167
171
|
if !properties.nil?
|
168
|
-
if properties.key?('
|
169
|
-
|
170
|
-
end
|
171
|
-
if properties.key?('stroke_color')
|
172
|
-
@convert.stroke(properties['stroke_color'])
|
173
|
-
end
|
174
|
-
if properties.key?('stroke_width')
|
175
|
-
@convert.strokewidth(properties['stroke_width'])
|
172
|
+
if properties.key?('stroke_color') && !properties['stroke_color'].nil?
|
173
|
+
tmp_stroke_color = ChunkyPNG::Color.from_hex(properties['stroke_color'])
|
176
174
|
end
|
177
175
|
end
|
178
176
|
|
@@ -181,8 +179,7 @@ module Geojson2image
|
|
181
179
|
json['coordinates'].each do |point|
|
182
180
|
new_point = transform_point(point)
|
183
181
|
if !last_point.nil?
|
184
|
-
|
185
|
-
@convert.draw(polyline)
|
182
|
+
@png.line(last_point[0], last_point[1], new_point[0], new_point[1], tmp_stroke_color)
|
186
183
|
end
|
187
184
|
last_point = new_point
|
188
185
|
end
|
@@ -197,15 +194,14 @@ module Geojson2image
|
|
197
194
|
end
|
198
195
|
|
199
196
|
when 'Polygon'
|
197
|
+
tmp_fill_color = @fill_color
|
198
|
+
tmp_stroke_color = @stroke_color
|
200
199
|
if !properties.nil?
|
201
200
|
if properties.key?('fill_color') && !properties['fill_color'].nil?
|
202
|
-
|
201
|
+
tmp_fill_color = ChunkyPNG::Color.from_hex(properties['fill_color'])
|
203
202
|
end
|
204
203
|
if properties.key?('stroke_color') && !properties['stroke_color'].nil?
|
205
|
-
|
206
|
-
end
|
207
|
-
if properties.key?('stroke_width') && !properties['stroke_width'].nil?
|
208
|
-
@convert.strokewidth(properties['stroke_width'])
|
204
|
+
tmp_stroke_color = ChunkyPNG::Color.from_hex(properties['stroke_color'])
|
209
205
|
end
|
210
206
|
end
|
211
207
|
|
@@ -220,8 +216,8 @@ module Geojson2image
|
|
220
216
|
border_points << "#{new_point[0]},#{new_point[1]}"
|
221
217
|
end
|
222
218
|
|
223
|
-
|
224
|
-
@
|
219
|
+
points = ChunkyPNG::Vector.multiple_from_string(border_points.join(", "))
|
220
|
+
@png.polygon(points, tmp_stroke_color, tmp_fill_color)
|
225
221
|
end
|
226
222
|
|
227
223
|
when 'MultiPolygon'
|
@@ -239,13 +235,6 @@ module Geojson2image
|
|
239
235
|
end
|
240
236
|
|
241
237
|
def to_image
|
242
|
-
@convert = MiniMagick::Tool::Convert.new
|
243
|
-
@convert.size("#{@width}x#{@height}")
|
244
|
-
@convert.xc(@background_color)
|
245
|
-
@convert.fill(@fill_color)
|
246
|
-
@convert.stroke(@stroke_color)
|
247
|
-
@convert.strokewidth(@stroke_width)
|
248
|
-
|
249
238
|
get_points(@parsed_json)
|
250
239
|
get_boundary
|
251
240
|
|
@@ -262,9 +251,7 @@ module Geojson2image
|
|
262
251
|
@height_padding = (@height - (@global_ratio * @max_xy[1])) / 2
|
263
252
|
|
264
253
|
draw(@parsed_json)
|
265
|
-
|
266
|
-
@convert << @output
|
267
|
-
@convert.call
|
254
|
+
@png.save(@output)
|
268
255
|
end
|
269
256
|
|
270
257
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce Johnston
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.6'
|
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: '3.
|
26
|
+
version: '3.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: chunky_png
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.3'
|
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: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
version: '3.0'
|
83
83
|
description: Ruby library for generating images from GeoJSON
|
84
84
|
email:
|
85
|
-
- bryce@
|
85
|
+
- bryce@beaorn.com
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
@@ -101,7 +101,7 @@ files:
|
|
101
101
|
- geojson2image.gemspec
|
102
102
|
- lib/geojson2image.rb
|
103
103
|
- lib/geojson2image/version.rb
|
104
|
-
homepage: https://github.com/
|
104
|
+
homepage: https://github.com/beaorn/geojson2image
|
105
105
|
licenses:
|
106
106
|
- MIT
|
107
107
|
metadata: {}
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.6
|
124
|
+
rubygems_version: 2.7.6
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Ruby library for generating images from GeoJSON
|