libgd-gis 0.4.2 → 0.4.3
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 +29 -0
- data/lib/gd/gis/bbox_resolver.rb +21 -6
- data/lib/gd/gis/extents.rb +19 -1
- data/lib/gd/gis/map.rb +11 -4
- data/lib/gd/gis/style.rb +74 -0
- data/lib/gd/gis.rb +1 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8fdfcd8c25a4c2d5be9f69153957d4d3c5fbd2b82e26167554be17c7e0ff058c
|
|
4
|
+
data.tar.gz: 9b5b504f06e11d6a0ac465747237e8832986234bee3ded81f0360a5c6749d29f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7ded6603953b5144db8794841f6c898aea15819960b8d1a3b89c46e7122e74bf7c0e344814a983d5fbede7f4472080dc39ea360743d6d73d24c82d31371e5dcc
|
|
7
|
+
data.tar.gz: 2a2b7f255b78b338e128d9a2a0bd293db0936da7a30cfdb94e710c541251937c798504b9f5c20fd5ccabb8845c10fc29a47878d886a723e0a66f3ce25effd4aa
|
data/README.md
CHANGED
|
@@ -202,6 +202,35 @@ This design ensures predictable rendering and makes all visual decisions explici
|
|
|
202
202
|
and reproducible.
|
|
203
203
|
|
|
204
204
|
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
## Named geographic extents
|
|
209
|
+
|
|
210
|
+
LibGD-GIS includes a global dataset of predefined geographic areas.
|
|
211
|
+
You can use them directly as the `bbox` parameter.
|
|
212
|
+
|
|
213
|
+
### Example
|
|
214
|
+
|
|
215
|
+
```ruby
|
|
216
|
+
map = GD::GIS::Map.new(
|
|
217
|
+
bbox: :argentina,
|
|
218
|
+
zoom: 5,
|
|
219
|
+
width: 800,
|
|
220
|
+
height: 600,
|
|
221
|
+
basemap: :osm
|
|
222
|
+
)
|
|
223
|
+
```
|
|
224
|
+
You can also use continents or regions:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
bbox: :world
|
|
228
|
+
bbox: :europe
|
|
229
|
+
bbox: :south_america
|
|
230
|
+
bbox: :north_america
|
|
231
|
+
bbox: :asia
|
|
232
|
+
```
|
|
233
|
+
|
|
205
234
|
---
|
|
206
235
|
|
|
207
236
|
## CRS Support
|
data/lib/gd/gis/bbox_resolver.rb
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GD
|
|
2
4
|
module GIS
|
|
5
|
+
# Resolves bounding box inputs into a normalized WGS84 bbox array.
|
|
6
|
+
#
|
|
7
|
+
# Accepts:
|
|
8
|
+
# - Symbol or String referencing a named extent (e.g. :world, :argentina)
|
|
9
|
+
# - Array in the form [min_lng, min_lat, max_lng, max_lat]
|
|
10
|
+
#
|
|
11
|
+
# Returns a 4-element array of Float values.
|
|
12
|
+
#
|
|
13
|
+
# @example Using a named extent
|
|
14
|
+
# BBoxResolver.resolve(:europe)
|
|
15
|
+
#
|
|
16
|
+
# @example Using a raw bbox
|
|
17
|
+
# BBoxResolver.resolve([-10, 35, 5, 45])
|
|
3
18
|
module BBoxResolver
|
|
4
19
|
def self.resolve(bbox)
|
|
5
20
|
case bbox
|
|
@@ -12,16 +27,16 @@ module GD
|
|
|
12
27
|
|
|
13
28
|
else
|
|
14
29
|
raise ArgumentError,
|
|
15
|
-
|
|
30
|
+
"bbox must be Symbol, String or [min_lng, min_lat, max_lng, max_lat]"
|
|
16
31
|
end
|
|
17
32
|
end
|
|
18
33
|
|
|
19
34
|
def self.validate!(bbox)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
return if bbox.is_a?(Array) && bbox.size == 4
|
|
36
|
+
|
|
37
|
+
raise ArgumentError,
|
|
38
|
+
"bbox must be [min_lng, min_lat, max_lng, max_lat]"
|
|
24
39
|
end
|
|
25
40
|
end
|
|
26
41
|
end
|
|
27
|
-
end
|
|
42
|
+
end
|
data/lib/gd/gis/extents.rb
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "json"
|
|
2
4
|
|
|
3
5
|
module GD
|
|
4
6
|
module GIS
|
|
7
|
+
# Provides access to predefined geographic extents loaded from
|
|
8
|
+
# a JSON dataset.
|
|
9
|
+
#
|
|
10
|
+
# Extents are WGS84 bounding boxes defined as:
|
|
11
|
+
# [min_lng, min_lat, max_lng, max_lat]
|
|
12
|
+
#
|
|
13
|
+
# Supports lookup by symbolic name.
|
|
14
|
+
#
|
|
15
|
+
# @example Fetch extent
|
|
16
|
+
# Extents.fetch(:world)
|
|
17
|
+
#
|
|
18
|
+
# @example Using bracket syntax
|
|
19
|
+
# Extents[:argentina]
|
|
20
|
+
#
|
|
21
|
+
# @note Bounding boxes are approximate and intended for visualization.
|
|
5
22
|
module Extents
|
|
6
23
|
DATA_PATH = File.expand_path(
|
|
7
24
|
"data/extents_global.json",
|
|
@@ -31,9 +48,10 @@ module GD
|
|
|
31
48
|
|
|
32
49
|
def load_data!
|
|
33
50
|
return if @extents
|
|
51
|
+
|
|
34
52
|
@extents = JSON.parse(File.read(DATA_PATH))
|
|
35
53
|
end
|
|
36
54
|
end
|
|
37
55
|
end
|
|
38
56
|
end
|
|
39
|
-
end
|
|
57
|
+
end
|
data/lib/gd/gis/map.rb
CHANGED
|
@@ -132,9 +132,6 @@ module GD
|
|
|
132
132
|
@lines_layers = []
|
|
133
133
|
@polygons_layers = []
|
|
134
134
|
|
|
135
|
-
# 7. Style
|
|
136
|
-
@style = nil
|
|
137
|
-
|
|
138
135
|
@debug = false
|
|
139
136
|
@used_labels = {}
|
|
140
137
|
@count = 1
|
|
@@ -190,6 +187,7 @@ module GD
|
|
|
190
187
|
# before rendering. It intentionally does not depend on map style
|
|
191
188
|
# configuration, which is applied later during rendering.
|
|
192
189
|
def maybe_create_line_label(feature)
|
|
190
|
+
@style ||= GD::GIS::Style.default
|
|
193
191
|
return true if @style.global[:label] == false || @style.global[:label].nil?
|
|
194
192
|
|
|
195
193
|
geom = feature.geometry
|
|
@@ -215,7 +213,8 @@ module GD
|
|
|
215
213
|
label: ->(_) { name },
|
|
216
214
|
font: @style.global[:label][:font] || GD::GIS::FontHelper.random,
|
|
217
215
|
size: @style.global[:label][:size] || (6..20).to_a.sample,
|
|
218
|
-
color: @style.global[:label][:color] || GD::GIS::ColorHelpers.random_rgba
|
|
216
|
+
color: @style.global[:label][:color] || GD::GIS::ColorHelpers.random_rgba,
|
|
217
|
+
font_color: @style.global[:label][:color] || GD::GIS::ColorHelpers.random_rgba
|
|
219
218
|
)
|
|
220
219
|
|
|
221
220
|
@used_labels[key] = true
|
|
@@ -237,6 +236,7 @@ module GD
|
|
|
237
236
|
end
|
|
238
237
|
|
|
239
238
|
def draw_legend
|
|
239
|
+
@style ||= GD::GIS::Style.default
|
|
240
240
|
return unless @legend
|
|
241
241
|
return unless @image
|
|
242
242
|
return unless @style
|
|
@@ -335,6 +335,7 @@ module GD
|
|
|
335
335
|
# @param path [String] path to GeoJSON file
|
|
336
336
|
# @return [void]
|
|
337
337
|
def add_geojson(path)
|
|
338
|
+
@style ||= GD::GIS::Style.default
|
|
338
339
|
features = LayerGeoJSON.load(path)
|
|
339
340
|
|
|
340
341
|
features.each do |feature|
|
|
@@ -482,6 +483,8 @@ module GD
|
|
|
482
483
|
label: label
|
|
483
484
|
}
|
|
484
485
|
|
|
486
|
+
@style ||= GD::GIS::Style.default
|
|
487
|
+
|
|
485
488
|
@points_layers << GD::GIS::PointsLayer.new(
|
|
486
489
|
[row],
|
|
487
490
|
lon: ->(r) { r[:lon] },
|
|
@@ -502,6 +505,7 @@ module GD
|
|
|
502
505
|
# @param opts [Hash]
|
|
503
506
|
# @return [void]
|
|
504
507
|
def add_points(data, **)
|
|
508
|
+
@style ||= GD::GIS::Style.default
|
|
505
509
|
@points_layers << GD::GIS::PointsLayer.new(data, **)
|
|
506
510
|
end
|
|
507
511
|
|
|
@@ -511,6 +515,7 @@ module GD
|
|
|
511
515
|
# @param opts [Hash]
|
|
512
516
|
# @return [void]
|
|
513
517
|
def add_lines(features, **)
|
|
518
|
+
@style ||= GD::GIS::Style.default
|
|
514
519
|
@lines_layers << GD::GIS::LinesLayer.new(features, **)
|
|
515
520
|
end
|
|
516
521
|
|
|
@@ -520,6 +525,7 @@ module GD
|
|
|
520
525
|
# @param opts [Hash]
|
|
521
526
|
# @return [void]
|
|
522
527
|
def add_polygons(polygons, **)
|
|
528
|
+
@style ||= GD::GIS::Style.default
|
|
523
529
|
@polygons_layers << GD::GIS::PolygonsLayer.new(polygons, **)
|
|
524
530
|
end
|
|
525
531
|
|
|
@@ -531,6 +537,7 @@ module GD
|
|
|
531
537
|
# @return [void]
|
|
532
538
|
# @raise [RuntimeError] if style is not set
|
|
533
539
|
def render
|
|
540
|
+
# Style assign DEFAULT Styles
|
|
534
541
|
raise "map.style must be set" unless @style
|
|
535
542
|
|
|
536
543
|
if @width && @height
|
data/lib/gd/gis/style.rb
CHANGED
|
@@ -110,6 +110,80 @@ module GD
|
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
112
|
|
|
113
|
+
# Returns a built-in default style so Map can render even if no external style is set.
|
|
114
|
+
#
|
|
115
|
+
# @return [Style]
|
|
116
|
+
def self.default
|
|
117
|
+
new({
|
|
118
|
+
global: {
|
|
119
|
+
background: [15, 23, 42],
|
|
120
|
+
font: GD::GIS::FontHelper.find("DejaVuSans"),
|
|
121
|
+
font_color: [243, 244, 246],
|
|
122
|
+
label: {
|
|
123
|
+
color: [229, 231, 235],
|
|
124
|
+
font: GD::GIS::FontHelper.find("DejaVuSans"),
|
|
125
|
+
size: 12
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
label: {
|
|
130
|
+
label: { # ← envolver
|
|
131
|
+
color: [229, 231, 235],
|
|
132
|
+
font: GD::GIS::FontHelper.find("DejaVuSans"),
|
|
133
|
+
size: 12
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
roads: {
|
|
138
|
+
roads: { # ← envolver
|
|
139
|
+
color: [229, 231, 235],
|
|
140
|
+
font: GD::GIS::FontHelper.find("DejaVuSans"),
|
|
141
|
+
width: 6
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
rails: {
|
|
146
|
+
rails: {
|
|
147
|
+
color: [156, 163, 175],
|
|
148
|
+
font: GD::GIS::FontHelper.find("DejaVuSans"),
|
|
149
|
+
width: 5
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
water: {
|
|
154
|
+
water: {
|
|
155
|
+
color: [59, 130, 246]
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
parks: {
|
|
160
|
+
parks: {
|
|
161
|
+
color: [34, 197, 94]
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
points: {
|
|
166
|
+
points: {
|
|
167
|
+
color: [239, 68, 68],
|
|
168
|
+
radius: 4,
|
|
169
|
+
font: GD::GIS::FontHelper.find("DejaVuSans"),
|
|
170
|
+
font_color: [243, 244, 246]
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
track: {
|
|
175
|
+
track: { # ← CLAVE
|
|
176
|
+
stroke: [0, 85, 127, 250],
|
|
177
|
+
color: [250, 204, 21],
|
|
178
|
+
width: 2,
|
|
179
|
+
font_color: [243, 244, 246]
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
order: %i[water parks rails roads points track]
|
|
184
|
+
})
|
|
185
|
+
end
|
|
186
|
+
|
|
113
187
|
# Normalizes a color definition into a GD::Color.
|
|
114
188
|
#
|
|
115
189
|
# Accepted formats:
|
data/lib/gd/gis.rb
CHANGED
|
@@ -29,12 +29,11 @@ require "gd"
|
|
|
29
29
|
#
|
|
30
30
|
require_relative "gis/color_helpers"
|
|
31
31
|
require_relative "gis/font_helper"
|
|
32
|
-
require_relative "gis/style"
|
|
33
32
|
require_relative "gis/classifier"
|
|
33
|
+
require_relative "gis/style"
|
|
34
34
|
|
|
35
35
|
require_relative "gis/extents"
|
|
36
36
|
require_relative "gis/bbox_resolver"
|
|
37
|
-
|
|
38
37
|
require_relative "gis/feature"
|
|
39
38
|
require_relative "gis/map"
|
|
40
39
|
require_relative "gis/basemap"
|