libgd-gis 0.4.8 → 0.5.0
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 +45 -17
- data/lib/gd/gis/map.rb +8 -0
- data/lib/gd/gis/ontology.rb +24 -3
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d3a1a097a70594f97c1bc94eaf18e02c1494b530b430c137051eb1bc9d3c293
|
|
4
|
+
data.tar.gz: 1c3d4d8b4c9476dd06eab30fa0708063a9f6605dda34a2d23690460d98713edb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '069642af657e39514e8b16f2076e25abb097f8174abd5612c2427c0a8e64041ac0d82dd5769a4712a946bde371db8b697c65043b290a889b7840f3580f885b65'
|
|
7
|
+
data.tar.gz: d20ceb5e7e8c129100f6e536a633d9ea2cb9f423852878a829563c0132d01014ce9221637cfdd1f8ed3ff32c50c95c734022eacb175b502e7683b81505cef0fa
|
data/lib/gd/gis/layer_geojson.rb
CHANGED
|
@@ -26,19 +26,9 @@ module GD
|
|
|
26
26
|
# @raise [JSON::ParserError] if the file is invalid JSON
|
|
27
27
|
# @raise [Errno::ENOENT] if the file does not exist
|
|
28
28
|
def self.load(source)
|
|
29
|
+
data = normalize_source(source)
|
|
29
30
|
|
|
30
|
-
data
|
|
31
|
-
when String
|
|
32
|
-
if source.strip.start_with?("{", "[")
|
|
33
|
-
JSON.parse(source)
|
|
34
|
-
else
|
|
35
|
-
JSON.parse(File.read(source))
|
|
36
|
-
end
|
|
37
|
-
when Hash
|
|
38
|
-
source
|
|
39
|
-
else
|
|
40
|
-
raise ArgumentError, "Unsupported GeoJSON source"
|
|
41
|
-
end
|
|
31
|
+
validate_geojson!(data)
|
|
42
32
|
|
|
43
33
|
# 1) Detect CRS
|
|
44
34
|
crs_name = data["crs"]&.dig("properties", "name")
|
|
@@ -48,16 +38,54 @@ module GD
|
|
|
48
38
|
ontology = Ontology.new
|
|
49
39
|
|
|
50
40
|
# 3) Normalize geometries + classify
|
|
51
|
-
data["features"].map do |
|
|
52
|
-
|
|
41
|
+
data["features"].map do |feature|
|
|
42
|
+
geometry = feature["geometry"]
|
|
43
|
+
properties = feature["properties"] || {}
|
|
44
|
+
|
|
45
|
+
raise ArgumentError, "Missing geometry" unless geometry
|
|
46
|
+
raise ArgumentError, "Missing geometry type" unless geometry["type"]
|
|
47
|
+
raise ArgumentError, "Missing coordinates" unless geometry["coordinates"]
|
|
48
|
+
|
|
49
|
+
normalize_geometry!(geometry, normalizer)
|
|
50
|
+
|
|
53
51
|
layer = ontology.classify(
|
|
54
|
-
|
|
55
|
-
geometry_type:
|
|
52
|
+
properties,
|
|
53
|
+
geometry_type: geometry["type"]
|
|
56
54
|
)
|
|
57
|
-
|
|
55
|
+
|
|
56
|
+
Feature.new(geometry, properties, layer)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def self.normalize_source(source)
|
|
61
|
+
case source
|
|
62
|
+
when Hash
|
|
63
|
+
source
|
|
64
|
+
|
|
65
|
+
when String
|
|
66
|
+
begin
|
|
67
|
+
JSON.parse(source)
|
|
68
|
+
rescue JSON::ParserError
|
|
69
|
+
raise ArgumentError, "File not found: #{source}" unless File.exist?(source)
|
|
70
|
+
|
|
71
|
+
JSON.parse(File.read(source))
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
else
|
|
75
|
+
raise ArgumentError, "Unsupported GeoJSON source: #{source.class}"
|
|
58
76
|
end
|
|
59
77
|
end
|
|
60
78
|
|
|
79
|
+
def self.validate_geojson!(data)
|
|
80
|
+
raise ArgumentError, "GeoJSON must be an object" unless data.is_a?(Hash)
|
|
81
|
+
|
|
82
|
+
raise ArgumentError, "Only FeatureCollection is supported" unless data["type"] == "FeatureCollection"
|
|
83
|
+
|
|
84
|
+
return if data["features"].is_a?(Array)
|
|
85
|
+
|
|
86
|
+
raise ArgumentError, "GeoJSON must contain features array"
|
|
87
|
+
end
|
|
88
|
+
|
|
61
89
|
# Normalizes a GeoJSON geometry in-place.
|
|
62
90
|
#
|
|
63
91
|
# Supports 2D and 3D coordinate arrays.
|
data/lib/gd/gis/map.rb
CHANGED
|
@@ -404,6 +404,10 @@ module GD
|
|
|
404
404
|
@layers[:minor] << feature
|
|
405
405
|
end
|
|
406
406
|
end
|
|
407
|
+
puts "\n=== ONTOLOGY DEBUG ==="
|
|
408
|
+
puts "Properties: #{feature.properties}"
|
|
409
|
+
puts "Geometry: #{feature.geometry['type']}"
|
|
410
|
+
puts "→ Classified as: #{feature.layer.inspect}"
|
|
407
411
|
end
|
|
408
412
|
end
|
|
409
413
|
|
|
@@ -674,6 +678,10 @@ module GD
|
|
|
674
678
|
items = @layers[kind]
|
|
675
679
|
return if items.nil? || items.empty?
|
|
676
680
|
|
|
681
|
+
puts ">>>>>>debug<<<<<<"
|
|
682
|
+
puts kind
|
|
683
|
+
|
|
684
|
+
|
|
677
685
|
style =
|
|
678
686
|
case kind
|
|
679
687
|
when :street, :primary, :motorway, :secondary, :minor
|
data/lib/gd/gis/ontology.rb
CHANGED
|
@@ -31,6 +31,20 @@ module GD
|
|
|
31
31
|
@rules = YAML.load_file(path)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
def print_rules
|
|
35
|
+
@rules.each do |layer, sources|
|
|
36
|
+
puts "\n=== #{layer.to_s.upcase} ==="
|
|
37
|
+
|
|
38
|
+
sources.each do |source, rules|
|
|
39
|
+
puts " [#{source}]"
|
|
40
|
+
|
|
41
|
+
rules.each do |key, values|
|
|
42
|
+
puts " #{key} → #{values.join(', ')}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
34
48
|
# Classifies a feature into a semantic layer.
|
|
35
49
|
#
|
|
36
50
|
# Properties are matched against ontology rules using
|
|
@@ -64,9 +78,16 @@ module GD
|
|
|
64
78
|
end
|
|
65
79
|
|
|
66
80
|
# Fallback classification
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
case geometry_type
|
|
82
|
+
when "Point"
|
|
83
|
+
:points
|
|
84
|
+
when "LineString", "MultiLineString"
|
|
85
|
+
:minor
|
|
86
|
+
when "Polygon", "MultiPolygon"
|
|
87
|
+
:area
|
|
88
|
+
else
|
|
89
|
+
nil
|
|
90
|
+
end
|
|
70
91
|
end
|
|
71
92
|
end
|
|
72
93
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: libgd-gis
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Germán Alberto Giménez Silva
|
|
@@ -15,7 +15,7 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.
|
|
18
|
+
version: 0.3.0
|
|
19
19
|
- - "<"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
21
|
version: 0.4.0
|
|
@@ -25,7 +25,7 @@ dependencies:
|
|
|
25
25
|
requirements:
|
|
26
26
|
- - ">="
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
|
-
version: 0.
|
|
28
|
+
version: 0.3.0
|
|
29
29
|
- - "<"
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
31
|
version: 0.4.0
|