Sign inSign up

lukasmartinelli/classify

By lukasmartinelli

•Updated almost 9 years ago

YAML format for classification of values.

Image
0

332

lukasmartinelli/classify repository overview

⁠classify Build Status Scrutinizer Code Quality MIT license

Classification of many values

:warning: This repository is no longer maintained by Lukas Martinelli.

A YAML format for classification⁠ of single values. The classify.py Python program will produce a classification function for various language targets for the given YAML format.

This approach is used in osm2vectortiles⁠ where we categorize OpenStreetMap values into different feature classes and icons.

⁠Get started

You need to have Python 2 or Python 3 installed on your system.

git clone https://github.com/lukasmartinelli/classify.git
cd classify
pip install -r requirements.txt

# generate sql code
./classify.py sql <yaml-definition>

# generate python code
./classify.py python <yaml-definition>

⁠Example

Map the value of a OpenStreetMap tag into a feature_class. This enables map designers to style several map features at once (e.g. the main roads instead of alot of individual road types).

Create a new file feature_class.yml and name your classification system. Then you need to list all classes you want to reduce (street, main, driveway). For each class you define a list of values that you want to map to your class.

system:
  name: feature_class
  classes:
    street:
    - residential
    - unclassified
    - living_street
    - road
    - raceway
    main:
    - primary
    - primary_link
    - trunk
    - trunk_link
    - secondary
    - secondary_link
    - tertiary
    - tertiary_link
    driveway:
    - driveway

Generated SQL.

CREATE OR REPLACE FUNCTION classify_osm_feature_class(type VARCHAR)
  RETURNS VARCHAR AS $$
  BEGIN
  RETURN CASE
    WHEN type IN ('motorway','motorway_link','driveway') THEN 'highway'
    WHEN type IN ('primary','primary_link', 'trunk', 'trunk_link',
                  'secondary','secondary_link',
                  'tertiary','tertiary_link') THEN 'main'
  END;
END;
$$ LANGUAGE plpgsql IMMUTABLE;

⁠Structure

The system defines a classification system for values. You can give a system a name. The name of your system will appear in the generated code.

A classification system has many classes. Each class is a key (the class name) and values (the values that are matched to the class). Only text values are supported.

system:
  name: <name-classification-system>
  classes:
    <class-name>:
    - <value-to-match>

Tag summary

Content type

Image

Digest

Size

263.1 MB

Last updated

almost 9 years ago

docker pull lukasmartinelli/classify