Class: GD::GIS::Classifier
- Inherits:
-
Object
- Object
- GD::GIS::Classifier
- Defined in:
- lib/gd/gis/classifier.rb
Overview
Classifies geographic features based on their properties.
This class provides a set of stateless helpers used to infer semantic categories (roads, water, parks, rails) from feature attribute tags, typically originating from OpenStreetMap or similar datasets.
All methods are pure functions and return symbols or booleans suitable for styling or rendering decisions.
Class Method Summary collapse
-
.park?(feature) ⇒ Boolean
Determines whether a feature represents a park or green area.
-
.rail?(feature) ⇒ Boolean
Determines whether a feature represents a railway.
-
.road(feature) ⇒ Symbol?
Classifies a road feature into a road category.
-
.water?(feature) ⇒ Boolean
Determines whether a feature represents water.
-
.water_kind(feature) ⇒ Symbol
Classifies the type of water feature.
Class Method Details
.park?(feature) ⇒ Boolean
Determines whether a feature represents a park or green area.
72 73 74 75 76 |
# File 'lib/gd/gis/classifier.rb', line 72 def self.park?(feature) = feature.properties || {} %w[park recreation_ground garden].include?(["leisure"]) || %w[park grass forest].include?(["landuse"]) end |
.rail?(feature) ⇒ Boolean
Determines whether a feature represents a railway.
63 64 65 66 |
# File 'lib/gd/gis/classifier.rb', line 63 def self.rail?(feature) = feature.properties || {} ["railway"] end |
.road(feature) ⇒ Symbol?
Classifies a road feature into a road category.
The classification is based on the ‘highway` tag.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gd/gis/classifier.rb', line 29 def self.road(feature) = feature.properties || {} case ["highway"] when "motorway", "trunk" :motorway when "primary", "primary_link" :primary when "secondary", "secondary_link" :secondary when "tertiary", "residential", "living_street" :street when "service", "track" :minor end end |
.water?(feature) ⇒ Boolean
Determines whether a feature represents water.
50 51 52 53 54 55 56 57 |
# File 'lib/gd/gis/classifier.rb', line 50 def self.water?(feature) p = feature.properties p["waterway"] || p["natural"] == "water" || p["fclass"] == "river" || p["fclass"] == "stream" end |
.water_kind(feature) ⇒ Symbol
Classifies the type of water feature.
85 86 87 88 89 90 91 92 93 |
# File 'lib/gd/gis/classifier.rb', line 85 def self.water_kind(feature) p = feature.properties case p["waterway"] || p["fclass"] when "river" then :river when "stream" then :stream else :minor end end |