geojson2image 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28f40062001e387eb73050e7ab8e58374b2b6906
4
- data.tar.gz: 663faeebb08988d1d2af68b75031e9d4d6b7632f
3
+ metadata.gz: 33173d33967cf8a5a9bb42290c4c3b6f65dc44fa
4
+ data.tar.gz: bd0ed61c9c47f5240d61ac389ec08abed9313a9f
5
5
  SHA512:
6
- metadata.gz: 49dece8d38b249e3e53cf6f4011c60444549b6318a80d5cfbe8151afeaab82df134cddf81dee41a2a26e35459c88b72e96ddbeff7668376c5985c3932ece37df
7
- data.tar.gz: ed141b41854390a0b73bdfa41b3a34b62d345e3743886812cee8c8d8ad8c0bdce2444e4570384f0bd3ab0a7eb8637289481bbfe91fad51bb09fcc9a41346cf2d
6
+ metadata.gz: 2f0bfc47273445945432cb3a903ad5c6e91d9e6987f4c5823c051870215efe781a15e7ec2f93fed7ef2d8d6b7874ddd8ec489f57354486cd7d0e60043de6e5a0
7
+ data.tar.gz: 4c005b627609e0c84feaed9314b5047d14fbabadccdc92661ed12b3ee894120c135614624626e1b3f5c7da18f46992d8dc8b7cf6ea30fe890b9d47d5dac01963
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  /*.png
11
11
  /*.jpg
12
12
  /*.gif
13
+ /example/*.json
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Ruby library for generating images from GeoJSON.
8
8
 
9
- Currently, MultiPolygon and Polygon GeoJSON types should output images properly. Other GeoJSON types have not been thoroughly tested, and properties from the GeoJSON are not being parsed.
9
+ Currently, MultiPolygon and Polygon GeoJSON types should output images properly. Other GeoJSON types have not been thoroughly tested.
10
10
 
11
11
  ## Installation
12
12
 
@@ -46,9 +46,22 @@ g2i.to_image
46
46
  ### Example Output
47
47
  ![Example Output](example/example_output.jpg?raw=true "Example Output")
48
48
 
49
- ### Color Options
49
+ ### Stroke and Fill Color Options
50
50
 
51
- ImageMagick Color Names Reference: https://www.imagemagick.org/script/color.php
51
+ These options can be globally set when initializing a
52
+ new Geojson2image::Convert object, or you can override them by adding properties to
53
+ your GeoJSON that include the desired stroke and fill options per feature. Example:
54
+
55
+ ```json
56
+ "properties": {
57
+ "fill_color": "rgba(0, 158, 40, 0.3)",
58
+ "stroke_color": "rgb(0, 107, 27)",
59
+ "stoke_width": "3",
60
+ },
61
+ ```
62
+
63
+ Valid color values are defined in the ImageMagick Color Names Reference:
64
+ https://www.imagemagick.org/script/color.php
52
65
 
53
66
  ## Development
54
67
 
@@ -1,3 +1,3 @@
1
1
  module Geojson2image
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/geojson2image.rb CHANGED
@@ -84,7 +84,7 @@ module Geojson2image
84
84
  end
85
85
 
86
86
  else
87
- puts "get_boundary invalid GeoJSON parse error"
87
+ puts "get_points - invalid GeoJSON parse error"
88
88
  end
89
89
  end
90
90
 
@@ -92,8 +92,8 @@ module Geojson2image
92
92
  quarter_pi = Math::PI / 4.0
93
93
 
94
94
  @coordinates.each_with_index do |point,i|
95
- lon = @coordinates[i][0].to_f * Math::PI / 180
96
- lat = @coordinates[i][1].to_f * Math::PI / 180
95
+ lon = @coordinates[i][0] * Math::PI / 180
96
+ lat = @coordinates[i][1] * Math::PI / 180
97
97
 
98
98
  @coordinates[i][0] = lon
99
99
  @coordinates[i][1] = Math.log(Math.tan(quarter_pi + 0.5 * lat))
@@ -128,7 +128,7 @@ module Geojson2image
128
128
  return xy
129
129
  end
130
130
 
131
- def draw(json)
131
+ def draw(json, properties = nil)
132
132
  case json['type']
133
133
  when 'GeometryCollection'
134
134
  json['geometries'].each do |geometry|
@@ -142,7 +142,11 @@ module Geojson2image
142
142
  end
143
143
 
144
144
  when 'Feature'
145
- draw(json['geometry'])
145
+ if json.key?('properties')
146
+ draw(json['geometry'], json['properties'])
147
+ else
148
+ draw(json['geometry'])
149
+ end
146
150
 
147
151
  when 'Point'
148
152
  point = json['coordinates']
@@ -160,6 +164,18 @@ module Geojson2image
160
164
  end
161
165
 
162
166
  when 'LineString'
167
+ if !properties.nil?
168
+ if properties.key?('fill_color')
169
+ @convert.fill(properties['fill_color'])
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'])
176
+ end
177
+ end
178
+
163
179
  last_point = null
164
180
 
165
181
  json['coordinates'].each do |point|
@@ -181,6 +197,18 @@ module Geojson2image
181
197
  end
182
198
 
183
199
  when 'Polygon'
200
+ if !properties.nil?
201
+ if properties.key?('fill_color')
202
+ @convert.fill(properties['fill_color'])
203
+ end
204
+ if properties.key?('stroke_color')
205
+ @convert.stroke(properties['stroke_color'])
206
+ end
207
+ if properties.key?('stroke_width')
208
+ @convert.strokewidth(properties['stroke_width'])
209
+ end
210
+ end
211
+
184
212
  json['coordinates'].each do |linestrings|
185
213
  border_points = []
186
214
  if linestrings[0] != linestrings[linestrings.count - 1]
@@ -206,7 +234,7 @@ module Geojson2image
206
234
  end
207
235
 
208
236
  else
209
- puts "draw invalid GeoJSON parse error - #{json['type']}"
237
+ puts "draw - invalid GeoJSON parse error - #{json['type']}"
210
238
  end
211
239
  end
212
240
 
@@ -236,7 +264,7 @@ module Geojson2image
236
264
  draw(@parsed_json)
237
265
 
238
266
  @convert << @output
239
- cmd_string = @convert.call
267
+ @convert.call
240
268
  end
241
269
 
242
270
  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.1.0
4
+ version: 0.1.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: 2017-01-28 00:00:00.000000000 Z
11
+ date: 2017-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj