filter

package
v1.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompileError

type CompileError struct {
	Cause error // reported by the Compile{Expression|Condition} funcs

	// The parsed yaml that was used as input
	Input interface{}
}

CompileError represents an errors during the compiling of conditions orr expressions.

func (*CompileError) Error

func (e *CompileError) Error() string

Error returns a summary of the error.

func (*CompileError) YAML

func (e *CompileError) YAML() string

YAML returns the input yaml that caused the error.

type Condition

type Condition interface {
	Eval(*Context) bool
}

A Condition is something that evaluates to a boolean.

func CompileCondition

func CompileCondition(cond interface{}) (Condition, error)

CompileCondition will take the parsed YAML condition and return a compiled condition interface.

type Context

type Context struct {
	Debug   bool
	Verbose bool

	FeatureID osm.FeatureID
	Geometry  orb.Geometry

	// To compute ways and/or relations if needed
	OSM *osm.OSM

	Tags map[string]string

	// OSMTags are used during post processing we need access
	// the original osm tags as well as the new filter outputs.
	OSMTags map[string]string

	WayMembership      map[osm.NodeID]osm.Ways
	RelationMembership map[osm.FeatureID]osm.Relations
	// contains filtered or unexported fields
}

Context is the evaluation context which is a bag of data. Also used as a data cache.

func NewContext

func NewContext(ctx *Context, feature *geojson.Feature) *Context

NewContext creates a new filter.Context from an osmgeojson feature.

func NewContextFromProperties

func NewContextFromProperties(ctx *Context, props geojson.Properties) *Context

NewContextFromProperties will create a context using a set of properties. This limits the queries one can do since not all the geometry is present.

func (*Context) Area

func (ctx *Context) Area() float64

Area computes the area of the element. This is used many places so it's computed/cached on the context.

func (*Context) Height

func (ctx *Context) Height() float64

Height returns the height of the thing, usually a building.

func (*Context) Length

func (ctx *Context) Length() float64

Length computes the length of the element. This is used many places so it's computed/cached on the context.

func (*Context) MinZoom

func (ctx *Context) MinZoom() float64

MinZoom computes the min zoom that the attributes should be displayed at. https://github.com/tilezen/vector-datasource/blob/e01d363c7279ba23c2e61c26b3562dccb7f33e60/data/functions.sql#L166-L187

type Expression

type Expression interface {
	Eval(*Context) interface{}
}

An Expression is something that evaluates to a boolean, number or string, depending on context.

func CompileExpression

func CompileExpression(expr interface{}) (Expression, error)

CompileExpression will compile the parsed YAML into an Expression that can be evaluated into a bool, float64 or string.

type Filter

type Filter struct {
	Skip bool

	RawFilter  interface{}            `yaml:"filter"`
	RawOutput  map[string]interface{} `yaml:"output"`
	RawMinZoom interface{}            `yaml:"min_zoom"`
	Table      string                 `yaml:"table"`

	MinZoom NumExpression `yaml:"-"`
	Filter  Condition     `yaml:"-"`
	// Output  map[string]Expression `yaml:"-"`
	Output []OutputExpression `yaml:"-"`
}

A Filter is a set of matchers and the resulting tag transformation to add to the element properties if the matcher matches.

func (*Filter) Compile

func (f *Filter) Compile() error

Compile will compile the parsed yaml into the expressions and conditions. This should be called once before matching. Returns a *CompileError with details about what exactly went wrong.

func (*Filter) Match

func (f *Filter) Match(ctx *Context) bool

Match will return true/false if the ctx/element matches the feature. Must call Compile() first to initialize the filters.

func (*Filter) Properties

func (f *Filter) Properties(ctx *Context) map[string]interface{}

Properties of the element mapped to the given filter outputs. Must call Compile() first to initialize the output expressions.

type NumExpression

type NumExpression interface {
	EvalNum(*Context) float64
}

NumExpression is something to evaluates to a number.

func CompileNumExpression

func CompileNumExpression(expr interface{}) (NumExpression, error)

CompileNumExpression will compile the parsed YAML into a NumExpression that can be evaluated.

type OutputExpression added in v1.5.1

type OutputExpression struct {
	Key  string
	Expr Expression
}

OutputExpression has the key and expression value for the outputs. Using a slice vs a key value map was much cleaner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL