Class: GD::GIS::Classifier

Inherits:
Object
  • Object
show all
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

Class Method Details

.park?(feature) ⇒ Boolean

Determines whether a feature represents a park or green area.

Parameters:

Returns:

  • (Boolean)

    true if the feature is a park or green space



72
73
74
75
76
# File 'lib/gd/gis/classifier.rb', line 72

def self.park?(feature)
  tags = feature.properties || {}
  %w[park recreation_ground garden].include?(tags["leisure"]) ||
    %w[park grass forest].include?(tags["landuse"])
end

.rail?(feature) ⇒ Boolean

Determines whether a feature represents a railway.

Parameters:

Returns:

  • (Boolean)

    true if the feature is a rail feature



63
64
65
66
# File 'lib/gd/gis/classifier.rb', line 63

def self.rail?(feature)
  tags = feature.properties || {}
  tags["railway"]
end

.road(feature) ⇒ Symbol?

Classifies a road feature into a road category.

The classification is based on the ‘highway` tag.

Parameters:

Returns:

  • (Symbol, nil)

    one of:

    • :motorway

    • :primary

    • :secondary

    • :street

    • :minor

    • nil if the feature is not a road



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)
  tags = feature.properties || {}

  case tags["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.

Parameters:

Returns:

  • (Boolean)

    true if the feature is water-related



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.

Parameters:

Returns:

  • (Symbol)
    • :river

    • :stream

    • :minor (default / fallback)



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