libgd-gis 0.2.8 → 0.2.9
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/lib/gd/gis/layer_geojson.rb +4 -2
- data/lib/gd/gis/layer_points.rb +11 -12
- data/lib/gd/gis/map.rb +29 -2
- data/lib/gd/gis/ontology.rb +5 -1
- data/lib/gd/gis/style.rb +28 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5f3f45fc1508b900f78e5b11cd5fff6854ff81e1482ca26b8478be88957ba086
|
|
4
|
+
data.tar.gz: 30df288e61f15f66d0c0f210f9842cc1897ae35b1e6c0a442d6238dbb0c1ce4c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ca3069e841e805116089bc949fa4f14a708775100eed78dbc488fa1c1bba0d0fa66a7acb2fce50711d134e9d98695c2b3c0ecc7f28cdf723b4936da37e22825b
|
|
7
|
+
data.tar.gz: d12da69bd604584ba37b2b250de904e622a93a325437afec6c6f79f81c53c4863043c2b837e2f73d965423e62229f4838458d485f7f2d44bdf746e7df8c44075
|
data/lib/gd/gis/layer_geojson.rb
CHANGED
|
@@ -6,7 +6,6 @@ require_relative "ontology"
|
|
|
6
6
|
module GD
|
|
7
7
|
module GIS
|
|
8
8
|
class LayerGeoJSON
|
|
9
|
-
|
|
10
9
|
def self.load(path)
|
|
11
10
|
data = JSON.parse(File.read(path))
|
|
12
11
|
|
|
@@ -20,7 +19,10 @@ module GD
|
|
|
20
19
|
# 3) Normalize geometries + classify
|
|
21
20
|
data["features"].map do |f|
|
|
22
21
|
normalize_geometry!(f["geometry"], normalizer)
|
|
23
|
-
layer = ontology.classify(
|
|
22
|
+
layer = ontology.classify(
|
|
23
|
+
f["properties"] || {},
|
|
24
|
+
geometry_type: f["geometry"]["type"]
|
|
25
|
+
)
|
|
24
26
|
Feature.new(f["geometry"], f["properties"], layer)
|
|
25
27
|
end
|
|
26
28
|
end
|
data/lib/gd/gis/layer_points.rb
CHANGED
|
@@ -7,10 +7,11 @@ module GD
|
|
|
7
7
|
@lon = lon
|
|
8
8
|
@lat = lat
|
|
9
9
|
|
|
10
|
-
if icon
|
|
11
|
-
|
|
10
|
+
if icon.kind_of?(Array) || icon.nil?
|
|
11
|
+
fill, stroke = icon || [GD::GIS::ColorHelpers.random_rgb, GD::GIS::ColorHelpers.random_rgb]
|
|
12
|
+
@icon = build_default_marker(fill, stroke)
|
|
12
13
|
else
|
|
13
|
-
@icon =
|
|
14
|
+
@icon = GD::Image.open(icon)
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
@label = label
|
|
@@ -22,23 +23,21 @@ module GD
|
|
|
22
23
|
@icon.save_alpha = true
|
|
23
24
|
end
|
|
24
25
|
|
|
25
|
-
def build_default_marker
|
|
26
|
+
def build_default_marker(fill, stroke)
|
|
26
27
|
size = 32
|
|
28
|
+
|
|
27
29
|
img = GD::Image.new(size, size)
|
|
28
30
|
img.antialias = true
|
|
29
|
-
|
|
30
|
-
white = GD::Color.rgb(255,255,255)
|
|
31
|
-
black = GD::Color.rgb(0,0,0)
|
|
32
31
|
|
|
33
32
|
cx = size / 2
|
|
34
33
|
cy = size / 2
|
|
35
|
-
r =
|
|
34
|
+
r = 5
|
|
36
35
|
|
|
37
|
-
#
|
|
38
|
-
img.arc(cx, cy, r*2+4, r*2+4, 0, 360,
|
|
36
|
+
# stroke
|
|
37
|
+
img.arc(cx, cy, r*2+4, r*2+4, 0, 360, stroke)
|
|
39
38
|
|
|
40
|
-
#
|
|
41
|
-
img.filled_arc(cx, cy, r*2, r*2, 0, 360,
|
|
39
|
+
# fill
|
|
40
|
+
img.filled_arc(cx, cy, r*2, r*2, 0, 360, fill)
|
|
42
41
|
|
|
43
42
|
img
|
|
44
43
|
end
|
data/lib/gd/gis/map.rb
CHANGED
|
@@ -24,7 +24,7 @@ module GD
|
|
|
24
24
|
width: nil,
|
|
25
25
|
height: nil,
|
|
26
26
|
crs: nil,
|
|
27
|
-
|
|
27
|
+
fitted_bbox: false
|
|
28
28
|
)
|
|
29
29
|
# --------------------------------------------------
|
|
30
30
|
# 1. Basic input validation
|
|
@@ -150,7 +150,34 @@ module GD
|
|
|
150
150
|
# o @layers[:street] << feature
|
|
151
151
|
else
|
|
152
152
|
geom_type = feature.geometry["type"]
|
|
153
|
-
|
|
153
|
+
|
|
154
|
+
if geom_type == "Point"
|
|
155
|
+
points_style = @style.points or
|
|
156
|
+
raise ArgumentError, "Style error: missing 'points' section"
|
|
157
|
+
|
|
158
|
+
font = points_style[:font] or
|
|
159
|
+
raise ArgumentError, "Style error: points.font is required"
|
|
160
|
+
|
|
161
|
+
size = points_style[:size] or
|
|
162
|
+
raise ArgumentError, "Style error: points.size is required"
|
|
163
|
+
|
|
164
|
+
raw_color = points_style[:color]
|
|
165
|
+
color = @style.normalize_color(raw_color)
|
|
166
|
+
|
|
167
|
+
icon = points_style.key?(:icon_fill) && points_style.key?(:icon_stroke) ? [points_style[:icon_stroke], points_style[:icon_stroke]] : nil
|
|
168
|
+
icon = points_style.key?(:icon) ? points_style[:icon] : nil if icon.nil?
|
|
169
|
+
|
|
170
|
+
@points_layers << GD::GIS::PointsLayer.new(
|
|
171
|
+
[feature],
|
|
172
|
+
lon: ->(f) { f.geometry["coordinates"][0] },
|
|
173
|
+
lat: ->(f) { f.geometry["coordinates"][1] },
|
|
174
|
+
icon: icon,
|
|
175
|
+
label: ->(f) { f.properties["name"] }, # 👈 TEXTO
|
|
176
|
+
font: font,
|
|
177
|
+
size: size,
|
|
178
|
+
color: color
|
|
179
|
+
)
|
|
180
|
+
elsif geom_type == "LineString" || geom_type == "MultiLineString"
|
|
154
181
|
@layers[:minor] << feature
|
|
155
182
|
end
|
|
156
183
|
end
|
data/lib/gd/gis/ontology.rb
CHANGED
|
@@ -8,7 +8,7 @@ module GD
|
|
|
8
8
|
@rules = YAML.load_file(path)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def classify(properties)
|
|
11
|
+
def classify(properties, geometry_type: nil)
|
|
12
12
|
@rules.each do |layer, sources|
|
|
13
13
|
sources.each do |source, rules|
|
|
14
14
|
rules.each do |key, values|
|
|
@@ -19,8 +19,12 @@ module GD
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
return :points if geometry_type == "Point"
|
|
24
|
+
|
|
22
25
|
nil
|
|
23
26
|
end
|
|
27
|
+
|
|
24
28
|
end
|
|
25
29
|
end
|
|
26
30
|
end
|
data/lib/gd/gis/style.rb
CHANGED
|
@@ -3,13 +3,14 @@ require "yaml"
|
|
|
3
3
|
module GD
|
|
4
4
|
module GIS
|
|
5
5
|
class Style
|
|
6
|
-
attr_reader :roads, :rails, :water, :parks, :order
|
|
6
|
+
attr_reader :roads, :rails, :water, :parks, :points, :order
|
|
7
7
|
|
|
8
8
|
def initialize(definition)
|
|
9
9
|
@roads = definition[:roads] || {}
|
|
10
10
|
@rails = definition[:rails] || {}
|
|
11
11
|
@water = definition[:water] || {}
|
|
12
12
|
@parks = definition[:parks] || {}
|
|
13
|
+
@points = definition[:points] || {}
|
|
13
14
|
@order = definition[:order] || []
|
|
14
15
|
end
|
|
15
16
|
|
|
@@ -25,6 +26,7 @@ module GD
|
|
|
25
26
|
rails: data[:rail] || data[:rails],
|
|
26
27
|
water: data[:water],
|
|
27
28
|
parks: data[:park] || data[:parks],
|
|
29
|
+
points: data[:points],
|
|
28
30
|
order: (data[:order] || []).map(&:to_sym)
|
|
29
31
|
)
|
|
30
32
|
end
|
|
@@ -40,6 +42,31 @@ module GD
|
|
|
40
42
|
obj
|
|
41
43
|
end
|
|
42
44
|
end
|
|
45
|
+
|
|
46
|
+
def normalize_color(color)
|
|
47
|
+
case color
|
|
48
|
+
when GD::Color
|
|
49
|
+
color
|
|
50
|
+
|
|
51
|
+
when Array
|
|
52
|
+
case color.length
|
|
53
|
+
when 3
|
|
54
|
+
GD::Color.rgb(*color)
|
|
55
|
+
when 4
|
|
56
|
+
GD::Color.rgba(*color)
|
|
57
|
+
else
|
|
58
|
+
raise ArgumentError,
|
|
59
|
+
"Style error: color array must be [r,g,b] or [r,g,b,a]"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
when nil
|
|
63
|
+
GD::GIS::ColorHelpers.random_vivid
|
|
64
|
+
|
|
65
|
+
else
|
|
66
|
+
raise ArgumentError,
|
|
67
|
+
"Style error: invalid color format (#{color.inspect})"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
43
70
|
end
|
|
44
71
|
end
|
|
45
72
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: libgd-gis
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Germán Alberto Giménez Silva
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-01-
|
|
11
|
+
date: 2026-01-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ruby-libgd
|