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 +4 -4
- data/.gitignore +1 -0
- data/README.md +16 -3
- data/lib/geojson2image/version.rb +1 -1
- data/lib/geojson2image.rb +35 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33173d33967cf8a5a9bb42290c4c3b6f65dc44fa
|
4
|
+
data.tar.gz: bd0ed61c9c47f5240d61ac389ec08abed9313a9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f0bfc47273445945432cb3a903ad5c6e91d9e6987f4c5823c051870215efe781a15e7ec2f93fed7ef2d8d6b7874ddd8ec489f57354486cd7d0e60043de6e5a0
|
7
|
+
data.tar.gz: 4c005b627609e0c84feaed9314b5047d14fbabadccdc92661ed12b3ee894120c135614624626e1b3f5c7da18f46992d8dc8b7cf6ea30fe890b9d47d5dac01963
|
data/.gitignore
CHANGED
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
|
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
|
-
|
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
|
|
data/lib/geojson2image.rb
CHANGED
@@ -84,7 +84,7 @@ module Geojson2image
|
|
84
84
|
end
|
85
85
|
|
86
86
|
else
|
87
|
-
puts "
|
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]
|
96
|
-
lat = @coordinates[i][1]
|
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
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|