Class Functions
- java.lang.Object
-
- org.openstreetmap.josm.gui.mappaint.mapcss.Functions
-
public final class Functions extends java.lang.Object
List of functions that can be used in MapCSS expressions.First parameter can be of type
Environment(if needed). This is automatically filled in by JOSM and the user only sees the remaining arguments. When one of the user supplied arguments cannot be converted the expected type or is null, the function is not called and it returns null immediately. Add the annotationExpressionFactory.NullableArgumentsto allow null arguments. Every method must be static.- Since:
- 15245 (extracted from
ExpressionFactory)
-
-
Constructor Summary
Constructors Modifier Constructor Description privateFunctions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static floatalpha(java.awt.Color c)Get the value of the alpha channel in the rgba color modelstatic java.lang.Objectany(Environment ignored, java.lang.Object... args)Returns the first non-null object.static java.lang.Floatareasize(Environment env)Returns the area of a closed way or multipolygon in square meters ornull.static booleanat(Environment env, double lat, double lon)Determines if the object centroid lies at given lat/lon coordinates.static floatblue(java.awt.Color c)Get the value of the blue color channel in the rgb color modelstatic java.lang.Doublecardinal_to_radians(java.lang.String cardinal)Converts an angle diven in cardinal directions to radians.static LatLoncenter(Environment env)Returns the center of the environment OSM primitive.static java.lang.Stringchild_tag(Environment env, java.lang.String key)Gets the value of the keykeyfrom the object's child.static java.lang.Stringcolor2html(java.awt.Color c)Computes the HTML notation (#rrggbb) for a color value).static java.lang.Stringconcat(Environment ignored, java.lang.Object... args)Assembles the strings to one.static java.lang.Stringconvert_primitive_to_string(PrimitiveId primitive)Convert a primitive to a stringstatic java.util.List<java.lang.String>convert_primitives_to_string(java.lang.Iterable<PrimitiveId> primitives)Convert Primitives to a stringstatic java.lang.Integercount(java.util.List<?> lst)Returns the number of elements in a list.static intcount_roles(Environment env, java.lang.String... roles)Returns the number of primitives in a relation with the specified roles.static longCRC32_checksum(java.lang.String s)Calculates the CRC32 checksum from a string (based on RFC 1952).static doubledegree_to_radians(double degree)Converts an angle in degrees to radians.static doubledivided_by(double a, double b)Function associated to the numeric "/" operator.static booleanequal(java.lang.Object a, java.lang.Object b)Determines if the objectsaandbare equal.static java.lang.Objecteval(java.lang.Object o)Identity function for compatibility with MapCSS specification.static java.lang.Objectget(java.util.List<?> lst, float n)Get thenth element of the listlst(counting starts at 0).static doublegpx_distance(Environment env)Returns the lowest distance between the OSM object and a GPX pointstatic booleangreater(float a, float b)Function associated to the logical ">" operator.static booleangreater_equal(float a, float b)Function associated to the logical ">=" operator.static floatgreen(java.awt.Color c)Get the value of the green color channel in the rgb color modelstatic booleanhas_tag_key(Environment env, java.lang.String key)Determines whether the object has a tag with the given key.static java.awt.Colorhsb_color(float h, float s, float b)Create color from hsb color model.static java.awt.Colorhtml2color(java.lang.String html)Creates a color value from an HTML notation, i.e.,#rrggbb.static java.lang.Floatindex(Environment env)Returns the index of node in parent way or member in parent relation.static booleaninside(Environment env, java.lang.String codes)Determines if the object is inside territories matching given ISO3166 codes.static booleanis_anticlockwise(Environment env)Determines whether the way isclosed and oriented anticlockwise, or non-closed and the1st, 2nd and last node are in anticlockwise order.static booleanis_clockwise(Environment env)Determines whether the way isclosed and oriented clockwise, or non-closed and the1st, 2nd and last node are in clockwise order.static java.lang.Booleanis_prop_set(Environment env, java.lang.String key)Determines whether propertykeyis set.static java.lang.Booleanis_prop_set(Environment env, java.lang.String key, java.lang.String layer)Determines whether propertykeyis set on layerlayer.static booleanis_right_hand_traffic(Environment env)check if there is right-hand traffic at the current locationstatic booleanis_similar(java.lang.String string1, java.lang.String string2)Check if two strings are similar, but not identical, i.e., have a Levenshtein distance of 1 or 2.static java.lang.Stringjoin(Environment ignored, java.lang.String... args)Assembles the strings to one, where the first entry is used as separator.static java.lang.Stringjoin_list(java.lang.String separator, java.util.List<java.lang.String> values)Joins a list ofvaluesinto a single string with fields separated byseparator.static java.lang.StringJOSM_pref(Environment env, java.lang.String key, java.lang.String def)static java.lang.BooleanJOSM_search(Environment env, java.lang.String searchStr)Determines whether the JOSM search withsearchStrapplies to the object.static booleanless(float a, float b)Function associated to the logical "<" operator.static booleanless_equal(float a, float b)Function associated to the logical "<=" operator.static java.util.List<java.lang.Object>list(Environment ignored, java.lang.Object... args)Creates a list of values, e.g., for thedashesproperty.static java.lang.Stringlower(java.lang.String s)Converts stringsto lowercase.static doubleminus(double a, double b)Function associated to the numeric "-" operator.static floatmod(float a, float b)Function associated to the math modulo "%" operator.static booleannot(boolean b)Function associated to the logical "!" operator.static booleannot_equal(java.lang.Object a, java.lang.Object b)Determines if the objectsaandbare not equal.static intnumber_of_tags(Environment env)Get the number of tags for the current primitive.static intosm_changeset_id(Environment env)Returns the id of the changeset the current object was last uploaded to.static longosm_id(Environment env)Returns the OSM id of the current object.static intosm_timestamp(Environment env)Returns the time of last modification to the current object, as timestamp.static longosm_user_id(Environment env)Returns the OSM user id who last touched the current object.static java.lang.Stringosm_user_name(Environment env)Returns the OSM user name who last touched the current object.static intosm_version(Environment env)Returns the version number of the current object.static booleanoutside(Environment env, java.lang.String codes)Determines if the object is outside territories matching given ISO3166 codes.static java.lang.Longparent_osm_id(Environment env)Returns the OSM id of the object's parent.static java.util.List<IPrimitive>parent_osm_primitives(Environment env)Gets a list of all OSM id's of the object's parent(s).static java.util.List<IPrimitive>parent_osm_primitives(Environment env, java.lang.String key)Gets a list of all OSM id's of the object's parent(s) with a specified key.static java.util.List<IPrimitive>parent_osm_primitives(Environment env, java.lang.String key, java.lang.String keyValue)Gets a list of all OSM id's of the object's parent(s) with a specified key.static java.lang.Stringparent_tag(Environment env, java.lang.String key)Gets the first non-null value of the keykeyfrom the object's parent(s).static java.util.List<java.lang.String>parent_tags(Environment env, java.lang.String key)Gets a list of all non-null values of the keykeyfrom the object's parent(s).static java.lang.Doubleparent_way_angle(Environment env)Get the rotation angle of the preceding parent way segment at the node location.private static intparse_regex_flags(java.lang.String flags)Parse flags for regex usage.static doubleplus(double a, double b)Function associated to the numeric "+" operator.static java.lang.Objectprint(java.lang.Object o)Prints the object to the command line (for debugging purpose).static java.lang.Objectprintln(java.lang.Object o)Prints the object to the command line, with new line at the end (for debugging purpose).static java.lang.Objectprop(Environment env, java.lang.String key)Returns the value of the propertykey, e.g.,prop("width").static java.lang.Objectprop(Environment env, java.lang.String key, java.lang.String layer)Returns the value of the propertykeyfrom layerlayer.static floatred(java.awt.Color c)Get the value of the red color channel in the rgb color modelstatic java.util.List<java.lang.String>regexp_match(java.lang.String pattern, java.lang.String target)Tries to match string against pattern regexp and returns a list of capture groups in case of success.static java.util.List<java.lang.String>regexp_match(java.lang.String pattern, java.lang.String target, java.lang.String flags)Tries to match string against pattern regexp and returns a list of capture groups in case of success.static booleanregexp_test(java.lang.String pattern, java.lang.String target)Tests if stringtargetmatches patternpatternstatic booleanregexp_test(java.lang.String pattern, java.lang.String target, java.lang.String flags)Tests if stringtargetmatches patternpatternstatic java.lang.Stringreplace(java.lang.String s, java.lang.String target, java.lang.String replacement)Replaces insevery target} substring byreplacement.static java.awt.Colorrgb(float r, float g, float b)Creates a color value with the specified amounts ofred,green,blue (arguments from 0.0 to 1.0)static java.awt.Colorrgba(float r, float g, float b, float alpha)Creates a color value with the specified amounts ofred,green,blue,alpha(arguments from 0.0 to 1.0)static java.lang.Stringrole(Environment env)Returns the role of current object in parent relation, or role of child if current object is a relation.static java.lang.Objectsetting(Environment env, java.lang.String key)Get value of a setting.static java.lang.Stringsiunit_length(java.lang.String s)Convert a length unit to metersstatic java.util.List<java.lang.String>sort(Environment ignored, java.lang.String... sortables)Sort an array of stringsstatic java.util.List<java.lang.String>sort_list(java.util.List<java.lang.String> sortables)Sort a list of stringsstatic java.util.List<java.lang.String>split(java.lang.String sep, java.lang.String toSplit)Splits stringtoSplitat occurrences of the separator stringsepand returns a list of matches.static java.lang.Stringsubstring(java.lang.String s, float begin)Returns the substring ofsstarting at indexbegin(inclusive, 0-indexed).static java.lang.Stringsubstring(java.lang.String s, float begin, float end)Returns the substring ofsstarting at indexbegin(inclusive) and ending at indexend, (exclusive, 0-indexed).static java.lang.Stringtag(Environment env, java.lang.String key)Gets the value of the keykeyfrom the object in question.static java.util.List<java.lang.String>tag_regex(Environment env, java.lang.String keyRegex)Get keys that follow a regexstatic java.util.List<java.lang.String>tag_regex(Environment env, java.lang.String keyRegex, java.lang.String flags)Get keys that follow a regexstatic doubletimes(double a, double b)Function associated to the numeric "*" operator.static java.lang.Stringtitle(java.lang.String str)Returns a title-cased version of the string where words start with an uppercase character and the remaining characters are lowercasestatic booleanto_boolean(java.lang.String value)Parses the string argument as a boolean.static byteto_byte(java.lang.String value)Parses the string argument as a byte.static doubleto_double(java.lang.String value)Parses the string argument as a double.static floatto_float(java.lang.String value)Parses the string argument as a float.static intto_int(java.lang.String value)Parses the string argument as an int.static longto_long(java.lang.String value)Parses the string argument as a long.static shortto_short(java.lang.String value)Parses the string argument as a short.static java.lang.Stringtr(Environment ignored, java.lang.String... args)Translates some text for the current locale.static java.lang.Stringtrim(java.lang.String s)Trim whitespaces from the strings.static java.util.List<java.lang.String>trim_list(java.util.List<java.lang.String> strings)Trim whitespaces from the stringsstrings.static java.util.List<java.lang.String>uniq(Environment ignored, java.lang.String... values)Get unique valuesstatic java.util.List<java.lang.String>uniq_list(java.util.List<java.lang.String> values)Get unique valuesstatic java.lang.Stringupper(java.lang.String s)Converts stringsto uppercase.static java.lang.StringURL_decode(java.lang.String s)Percent-decode a string.static java.lang.StringURL_encode(java.lang.String s)Percent-encode a string.static java.lang.Floatwaylength(Environment env)Returns the length of the way in metres ornull.static java.lang.StringXML_encode(java.lang.String s)XML-encode a string.
-
-
-
Constructor Detail
-
Functions
private Functions()
-
-
Method Detail
-
eval
public static java.lang.Object eval(java.lang.Object o)
Identity function for compatibility with MapCSS specification.- Parameters:
o- any object- Returns:
ounchanged
-
plus
public static double plus(double a, double b)
Function associated to the numeric "+" operator.- Parameters:
a- the first operandb- the second operand- Returns:
- Sum of arguments
- See Also:
Float.sum(float, float)
-
minus
public static double minus(double a, double b)
Function associated to the numeric "-" operator.- Parameters:
a- the first operandb- the second operand- Returns:
- Subtraction of arguments
-
times
public static double times(double a, double b)
Function associated to the numeric "*" operator.- Parameters:
a- the first operandb- the second operand- Returns:
- Multiplication of arguments
-
divided_by
public static double divided_by(double a, double b)
Function associated to the numeric "/" operator.- Parameters:
a- the first operandb- the second operand- Returns:
- Division of arguments
-
mod
public static float mod(float a, float b)
Function associated to the math modulo "%" operator.- Parameters:
a- first valueb- second value- Returns:
a mod b, e.g.,mod(7, 5) = 2
-
list
public static java.util.List<java.lang.Object> list(Environment ignored, java.lang.Object... args)
Creates a list of values, e.g., for thedashesproperty.- Parameters:
ignored- The environment (ignored)args- The values to put in a list- Returns:
- list of values
- See Also:
Arrays.asList(Object[])
-
count
public static java.lang.Integer count(java.util.List<?> lst)
Returns the number of elements in a list.- Parameters:
lst- the list- Returns:
- length of the list
-
any
public static java.lang.Object any(Environment ignored, java.lang.Object... args)
Returns the first non-null object. The name originates from MapCSS standard.- Parameters:
ignored- The environment (ignored)args- arguments- Returns:
- the first non-null object
- See Also:
Utils.firstNonNull(Object[])
-
get
public static java.lang.Object get(java.util.List<?> lst, float n)
Get thenth element of the listlst(counting starts at 0).- Parameters:
lst- listn- index- Returns:
nth element of the list, ornullif index out of range- Since:
- 5699
-
split
public static java.util.List<java.lang.String> split(java.lang.String sep, java.lang.String toSplit)
Splits stringtoSplitat occurrences of the separator stringsepand returns a list of matches.- Parameters:
sep- separator stringtoSplit- string to split- Returns:
- list of matches
- Since:
- 5699
- See Also:
String.split(String)
-
rgb
public static java.awt.Color rgb(float r, float g, float b)
Creates a color value with the specified amounts ofred,green,blue (arguments from 0.0 to 1.0)- Parameters:
r- the red componentg- the green componentb- the blue component- Returns:
- color matching the given components
- See Also:
Color(float, float, float)
-
rgba
public static java.awt.Color rgba(float r, float g, float b, float alpha)
Creates a color value with the specified amounts ofred,green,blue,alpha(arguments from 0.0 to 1.0)- Parameters:
r- the red componentg- the green componentb- the blue componentalpha- the alpha component- Returns:
- color matching the given components
- See Also:
Color(float, float, float, float)
-
hsb_color
public static java.awt.Color hsb_color(float h, float s, float b)
Create color from hsb color model. (arguments form 0.0 to 1.0)- Parameters:
h- hues- saturationb- brightness- Returns:
- the corresponding color
-
html2color
public static java.awt.Color html2color(java.lang.String html)
Creates a color value from an HTML notation, i.e.,#rrggbb.- Parameters:
html- HTML notation- Returns:
- color matching the given notation
-
color2html
public static java.lang.String color2html(java.awt.Color c)
Computes the HTML notation (#rrggbb) for a color value).- Parameters:
c- color- Returns:
- HTML notation matching the given color
-
red
public static float red(java.awt.Color c)
Get the value of the red color channel in the rgb color model- Parameters:
c- color- Returns:
- the red color channel in the range [0;1]
- See Also:
Color.getRed()
-
green
public static float green(java.awt.Color c)
Get the value of the green color channel in the rgb color model- Parameters:
c- color- Returns:
- the green color channel in the range [0;1]
- See Also:
Color.getGreen()
-
blue
public static float blue(java.awt.Color c)
Get the value of the blue color channel in the rgb color model- Parameters:
c- color- Returns:
- the blue color channel in the range [0;1]
- See Also:
Color.getBlue()
-
alpha
public static float alpha(java.awt.Color c)
Get the value of the alpha channel in the rgba color model- Parameters:
c- color- Returns:
- the alpha channel in the range [0;1]
- See Also:
Color.getAlpha()
-
concat
public static java.lang.String concat(Environment ignored, java.lang.Object... args)
Assembles the strings to one.- Parameters:
ignored- The environment (ignored)args- arguments- Returns:
- assembled string
- See Also:
Collectors.joining()
-
join
public static java.lang.String join(Environment ignored, java.lang.String... args)
Assembles the strings to one, where the first entry is used as separator.- Parameters:
ignored- The environment (ignored)args- arguments. First one is used as separator- Returns:
- assembled string
- See Also:
String.join(CharSequence, CharSequence...)
-
join_list
public static java.lang.String join_list(java.lang.String separator, java.util.List<java.lang.String> values)
Joins a list ofvaluesinto a single string with fields separated byseparator.- Parameters:
separator- the separatorvalues- collection of objects- Returns:
- assembled string
- See Also:
String.join(CharSequence, Iterable)
-
prop
public static java.lang.Object prop(Environment env, java.lang.String key)
Returns the value of the propertykey, e.g.,prop("width").- Parameters:
env- the environmentkey- the property key- Returns:
- the property value
-
prop
public static java.lang.Object prop(Environment env, java.lang.String key, java.lang.String layer)
Returns the value of the propertykeyfrom layerlayer.- Parameters:
env- the environmentkey- the property keylayer- layer- Returns:
- the property value
-
is_prop_set
public static java.lang.Boolean is_prop_set(Environment env, java.lang.String key)
Determines whether propertykeyis set.- Parameters:
env- the environmentkey- the property key- Returns:
trueif the property is set,falseotherwise
-
is_prop_set
public static java.lang.Boolean is_prop_set(Environment env, java.lang.String key, java.lang.String layer)
Determines whether propertykeyis set on layerlayer.- Parameters:
env- the environmentkey- the property keylayer- layer- Returns:
trueif the property is set,falseotherwise
-
tag
public static java.lang.String tag(Environment env, java.lang.String key)
Gets the value of the keykeyfrom the object in question.- Parameters:
env- the environmentkey- the OSM key- Returns:
- the value for given key
-
tag_regex
public static java.util.List<java.lang.String> tag_regex(Environment env, java.lang.String keyRegex)
Get keys that follow a regex- Parameters:
env- the environmentkeyRegex- the pattern that the key must match- Returns:
- the values for the keys that match the pattern
- Since:
- 15315
- See Also:
tag_regex(Environment, String, String)
-
tag_regex
public static java.util.List<java.lang.String> tag_regex(Environment env, java.lang.String keyRegex, java.lang.String flags)
Get keys that follow a regex- Parameters:
env- the environmentkeyRegex- the pattern that the key must matchflags- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")- Returns:
- the values for the keys that match the pattern
- Since:
- 15315
- See Also:
Pattern.CASE_INSENSITIVE,Pattern.DOTALL,Pattern.MULTILINE
-
parse_regex_flags
private static int parse_regex_flags(java.lang.String flags)
Parse flags for regex usage. Shouldn't be used in mapcss- Parameters:
flags- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")- Returns:
- An int that can be used by a
Patternobject - See Also:
Pattern.CASE_INSENSITIVE,Pattern.DOTALL,Pattern.MULTILINE
-
parent_tag
public static java.lang.String parent_tag(Environment env, java.lang.String key)
Gets the first non-null value of the keykeyfrom the object's parent(s).- Parameters:
env- the environmentkey- the OSM key- Returns:
- first non-null value of the key
keyfrom the object's parent(s)
-
parent_tags
public static java.util.List<java.lang.String> parent_tags(Environment env, java.lang.String key)
Gets a list of all non-null values of the keykeyfrom the object's parent(s).The values are sorted according to
AlphanumComparator.- Parameters:
env- the environmentkey- the OSM key- Returns:
- a list of non-null values of the key
keyfrom the object's parent(s)
-
parent_way_angle
public static java.lang.Double parent_way_angle(Environment env)
Get the rotation angle of the preceding parent way segment at the node location. If there is no preceding parent way segment, the following way segment is used instead. Requires a parent way object matched via child selector.- Parameters:
env- the environment- Returns:
- the rotation angle of the parent way segment at the node in radians, otherwise null if there is no matching parent way or the object is not a node
- Since:
- 18664
-
child_tag
public static java.lang.String child_tag(Environment env, java.lang.String key)
Gets the value of the keykeyfrom the object's child.- Parameters:
env- the environmentkey- the OSM key- Returns:
- the value of the key
keyfrom the object's child, ornullif there is no child
-
parent_osm_id
public static java.lang.Long parent_osm_id(Environment env)
Returns the OSM id of the object's parent.Parent must be matched by child selector.
- Parameters:
env- the environment- Returns:
- the OSM id of the object's parent, if available, or
null - See Also:
PrimitiveId.getUniqueId()
-
parent_osm_primitives
public static java.util.List<IPrimitive> parent_osm_primitives(Environment env, java.lang.String key, java.lang.String keyValue)
Gets a list of all OSM id's of the object's parent(s) with a specified key.- Parameters:
env- the environmentkey- the OSM keykeyValue- the regex value of the OSM key- Returns:
- a list of non-null values of the OSM id's from the object's parent(s)
- Since:
- 18829
-
parent_osm_primitives
public static java.util.List<IPrimitive> parent_osm_primitives(Environment env, java.lang.String key)
Gets a list of all OSM id's of the object's parent(s) with a specified key.- Parameters:
env- the environmentkey- the OSM key- Returns:
- a list of non-null values of the OSM id's from the object's parent(s)
- Since:
- 18829
-
parent_osm_primitives
public static java.util.List<IPrimitive> parent_osm_primitives(Environment env)
Gets a list of all OSM id's of the object's parent(s).- Parameters:
env- the environment- Returns:
- a list of non-null values of the OSM id's from the object's parent(s)
- Since:
- 18829
-
convert_primitives_to_string
public static java.util.List<java.lang.String> convert_primitives_to_string(java.lang.Iterable<PrimitiveId> primitives)
Convert Primitives to a string- Parameters:
primitives- The primitives to convert- Returns:
- A list of strings in the format type + id (in the list order)
- Since:
- 18829
- See Also:
SimplePrimitiveId.toSimpleId(org.openstreetmap.josm.data.osm.PrimitiveId)
-
convert_primitive_to_string
public static java.lang.String convert_primitive_to_string(PrimitiveId primitive)
Convert a primitive to a string- Parameters:
primitive- The primitive to convert- Returns:
- A string in the format type + id
- Since:
- 18829
- See Also:
SimplePrimitiveId.toSimpleId(org.openstreetmap.josm.data.osm.PrimitiveId)
-
gpx_distance
public static double gpx_distance(Environment env)
Returns the lowest distance between the OSM object and a GPX point- Parameters:
env- the environment- Returns:
- the distance between the object and the closest gpx point or
Double.MAX_VALUE - Since:
- 14802
-
has_tag_key
public static boolean has_tag_key(Environment env, java.lang.String key)
Determines whether the object has a tag with the given key.- Parameters:
env- the environmentkey- the OSM key- Returns:
trueif the object has a tag with the given key,falseotherwise
-
index
public static java.lang.Float index(Environment env)
Returns the index of node in parent way or member in parent relation.- Parameters:
env- the environment- Returns:
- the index as float. Starts at 1
-
sort
public static java.util.List<java.lang.String> sort(Environment ignored, java.lang.String... sortables)
Sort an array of strings- Parameters:
ignored- The environment (ignored)sortables- The array to sort- Returns:
- The sorted list
- Since:
- 15279
-
sort_list
public static java.util.List<java.lang.String> sort_list(java.util.List<java.lang.String> sortables)
Sort a list of strings- Parameters:
sortables- The list to sort- Returns:
- The sorted list
- Since:
- 15279
-
uniq
public static java.util.List<java.lang.String> uniq(Environment ignored, java.lang.String... values)
Get unique values- Parameters:
ignored- The environment (ignored)values- A list of values that may have duplicates- Returns:
- A list with no duplicates
- Since:
- 15323
-
uniq_list
public static java.util.List<java.lang.String> uniq_list(java.util.List<java.lang.String> values)
Get unique values- Parameters:
values- A list of values that may have duplicates- Returns:
- A list with no duplicates
- Since:
- 15323
-
role
public static java.lang.String role(Environment env)
Returns the role of current object in parent relation, or role of child if current object is a relation.- Parameters:
env- the environment- Returns:
- role of current object in parent relation, or role of child if current object is a relation
- See Also:
Environment.getRole()
-
count_roles
public static int count_roles(Environment env, java.lang.String... roles)
Returns the number of primitives in a relation with the specified roles.- Parameters:
env- the environmentroles- The roles to count in the relation- Returns:
- The number of relation members with the specified role
- Since:
- 15196
-
areasize
public static java.lang.Float areasize(Environment env)
Returns the area of a closed way or multipolygon in square meters ornull.- Parameters:
env- the environment- Returns:
- the area of a closed way or multipolygon in square meters or
null - See Also:
Geometry.computeArea(IPrimitive)
-
waylength
public static java.lang.Float waylength(Environment env)
Returns the length of the way in metres ornull.- Parameters:
env- the environment- Returns:
- the length of the way in metres or
null. - See Also:
Way.getLength()
-
not
public static boolean not(boolean b)
Function associated to the logical "!" operator.- Parameters:
b- boolean value- Returns:
trueif!b
-
greater_equal
public static boolean greater_equal(float a, float b)
Function associated to the logical ">=" operator.- Parameters:
a- first valueb- second value- Returns:
trueifa >= b
-
less_equal
public static boolean less_equal(float a, float b)
Function associated to the logical "<=" operator.- Parameters:
a- first valueb- second value- Returns:
trueifa <= b
-
greater
public static boolean greater(float a, float b)
Function associated to the logical ">" operator.- Parameters:
a- first valueb- second value- Returns:
trueifa > b
-
less
public static boolean less(float a, float b)
Function associated to the logical "<" operator.- Parameters:
a- first valueb- second value- Returns:
trueifa < b
-
degree_to_radians
public static double degree_to_radians(double degree)
Converts an angle in degrees to radians.- Parameters:
degree- the angle in degrees- Returns:
- the angle in radians
- See Also:
Math.toRadians(double)
-
cardinal_to_radians
public static java.lang.Double cardinal_to_radians(java.lang.String cardinal)
Converts an angle diven in cardinal directions to radians. The following values are supported:n,north,ne,northeast,e,east,se,southeast,s,south,sw,southwest,w,west,nw,northwest.- Parameters:
cardinal- the angle in cardinal directions.- Returns:
- the angle in radians
- See Also:
RotationAngle.parseCardinalRotation(String)
-
equal
public static boolean equal(java.lang.Object a, java.lang.Object b)
Determines if the objectsaandbare equal.- Parameters:
a- First objectb- Second object- Returns:
trueif objects are equal,falseotherwise- See Also:
Object.equals(Object)
-
not_equal
public static boolean not_equal(java.lang.Object a, java.lang.Object b)
Determines if the objectsaandbare not equal.- Parameters:
a- First objectb- Second object- Returns:
falseif objects are equal,trueotherwise- See Also:
Object.equals(Object)
-
JOSM_search
public static java.lang.Boolean JOSM_search(Environment env, java.lang.String searchStr)
Determines whether the JOSM search withsearchStrapplies to the object.- Parameters:
env- the environmentsearchStr- the search string- Returns:
trueif the JOSM search withsearchStrapplies to the object- See Also:
SearchCompiler
-
JOSM_pref
public static java.lang.String JOSM_pref(Environment env, java.lang.String key, java.lang.String def)
Obtains the JOSM keyPreferencesstring for keykey, and defaults todefif that is null.If the default value can be converted to a
Color, theNamedColorPropertyis retrieved as string.- Parameters:
env- the environmentkey- Key in JOSM preferencedef- Default value- Returns:
- value for key, or default value if not found
-
regexp_test
public static boolean regexp_test(java.lang.String pattern, java.lang.String target)
Tests if stringtargetmatches patternpattern- Parameters:
pattern- The regex expressiontarget- The character sequence to be matched- Returns:
trueif, and only if, the entire region sequence matches the pattern- Since:
- 5699
- See Also:
Pattern.matches(String, CharSequence)
-
regexp_test
public static boolean regexp_test(java.lang.String pattern, java.lang.String target, java.lang.String flags)
Tests if stringtargetmatches patternpattern- Parameters:
pattern- The regex expressiontarget- The character sequence to be matchedflags- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")- Returns:
trueif, and only if, the entire region sequence matches the pattern- Since:
- 5699
- See Also:
Pattern.CASE_INSENSITIVE,Pattern.DOTALL,Pattern.MULTILINE
-
regexp_match
public static java.util.List<java.lang.String> regexp_match(java.lang.String pattern, java.lang.String target, java.lang.String flags)
Tries to match string against pattern regexp and returns a list of capture groups in case of success. The first element (index 0) is the complete match (i.e. string). Further elements correspond to the bracketed parts of the regular expression.- Parameters:
pattern- The regex expressiontarget- The character sequence to be matchedflags- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")- Returns:
- a list of capture groups if
Matcher.matches(), ornull. - Since:
- 5701
- See Also:
Pattern.CASE_INSENSITIVE,Pattern.DOTALL,Pattern.MULTILINE
-
regexp_match
public static java.util.List<java.lang.String> regexp_match(java.lang.String pattern, java.lang.String target)
Tries to match string against pattern regexp and returns a list of capture groups in case of success. The first element (index 0) is the complete match (i.e. string). Further elements correspond to the bracketed parts of the regular expression.- Parameters:
pattern- The regex expressiontarget- The character sequence to be matched- Returns:
- a list of capture groups if
Matcher.matches(), ornull. - Since:
- 5701
-
osm_id
public static long osm_id(Environment env)
Returns the OSM id of the current object.- Parameters:
env- the environment- Returns:
- the OSM id of the current object
- See Also:
PrimitiveId.getUniqueId()
-
osm_user_name
public static java.lang.String osm_user_name(Environment env)
Returns the OSM user name who last touched the current object.- Parameters:
env- the environment- Returns:
- the OSM user name who last touched the current object
- Since:
- 15246
- See Also:
IPrimitive.getUser()
-
osm_user_id
public static long osm_user_id(Environment env)
Returns the OSM user id who last touched the current object.- Parameters:
env- the environment- Returns:
- the OSM user id who last touched the current object
- Since:
- 15246
- See Also:
IPrimitive.getUser()
-
osm_version
public static int osm_version(Environment env)
Returns the version number of the current object.- Parameters:
env- the environment- Returns:
- the version number of the current object
- Since:
- 15246
- See Also:
IPrimitive.getVersion()
-
osm_changeset_id
public static int osm_changeset_id(Environment env)
Returns the id of the changeset the current object was last uploaded to.- Parameters:
env- the environment- Returns:
- the id of the changeset the current object was last uploaded to
- Since:
- 15246
- See Also:
IPrimitive.getChangesetId()
-
osm_timestamp
public static int osm_timestamp(Environment env)
Returns the time of last modification to the current object, as timestamp.- Parameters:
env- the environment- Returns:
- the time of last modification to the current object, as timestamp
- Since:
- 15246
- See Also:
IPrimitive.getRawTimestamp()
-
tr
public static java.lang.String tr(Environment ignored, java.lang.String... args)
Translates some text for the current locale. The first argument is the text to translate, and the subsequent arguments are parameters for the string indicated by{0},{1}, …- Parameters:
ignored- The environment (ignored)args- arguments- Returns:
- the translated string
-
substring
public static java.lang.String substring(java.lang.String s, float begin)
Returns the substring ofsstarting at indexbegin(inclusive, 0-indexed).- Parameters:
s- The base stringbegin- The start index- Returns:
- the substring
- See Also:
String.substring(int)
-
substring
public static java.lang.String substring(java.lang.String s, float begin, float end)
Returns the substring ofsstarting at indexbegin(inclusive) and ending at indexend, (exclusive, 0-indexed).- Parameters:
s- The base stringbegin- The start indexend- The end index. If negative, it counts from the end of the string- Returns:
- the substring
- See Also:
String.substring(int, int)
-
replace
public static java.lang.String replace(java.lang.String s, java.lang.String target, java.lang.String replacement)
Replaces insevery target} substring byreplacement.- Parameters:
s- The source stringtarget- The sequence of char values to be replacedreplacement- The replacement sequence of char values- Returns:
- The resulting string
- See Also:
String.replace(CharSequence, CharSequence)
-
upper
public static java.lang.String upper(java.lang.String s)
Converts stringsto uppercase.- Parameters:
s- The source string- Returns:
- The resulting string
- Since:
- 11756
- See Also:
String.toUpperCase(Locale)
-
lower
public static java.lang.String lower(java.lang.String s)
Converts stringsto lowercase.- Parameters:
s- The source string- Returns:
- The resulting string
- Since:
- 11756
- See Also:
String.toLowerCase(Locale)
-
title
public static java.lang.String title(java.lang.String str)
Returns a title-cased version of the string where words start with an uppercase character and the remaining characters are lowercaseAlso known as "capitalize".
- Parameters:
str- The source string- Returns:
- The resulting string
- Since:
- 17613
- See Also:
Character.toTitleCase(char)
-
trim
public static java.lang.String trim(java.lang.String s)
Trim whitespaces from the strings.- Parameters:
s- The source string- Returns:
- The resulting string
- Since:
- 11756
- See Also:
Utils.strip(java.lang.String)
-
trim_list
public static java.util.List<java.lang.String> trim_list(java.util.List<java.lang.String> strings)
Trim whitespaces from the stringsstrings.- Parameters:
strings- The list of strings to strip- Returns:
- The resulting string
- Since:
- 15591
- See Also:
Utils.strip(java.lang.String)
-
is_similar
public static boolean is_similar(java.lang.String string1, java.lang.String string2)
Check if two strings are similar, but not identical, i.e., have a Levenshtein distance of 1 or 2.- Parameters:
string1- first string to comparestring2- second string to compare- Returns:
- true if the normalized strings are different but only a "little bit"
- Since:
- 14371
- See Also:
Utils.isSimilar(java.lang.String, java.lang.String)
-
URL_decode
public static java.lang.String URL_decode(java.lang.String s)
Percent-decode a string. (See https://en.wikipedia.org/wiki/Percent-encoding)This is especially useful for wikipedia titles
- Parameters:
s- url-encoded string- Returns:
- the decoded string, or original in case of an error
- Since:
- 11756
-
URL_encode
public static java.lang.String URL_encode(java.lang.String s)
Percent-encode a string. (See https://en.wikipedia.org/wiki/Percent-encoding)This is especially useful for data urls, e.g.
concat("data:image/svg+xml,", URL_encode("<svg>...</svg>"));- Parameters:
s- arbitrary string- Returns:
- the encoded string
-
XML_encode
public static java.lang.String XML_encode(java.lang.String s)
XML-encode a string.Escapes special characters in xml. Alternative to using <![CDATA[ ... ]]> blocks.
- Parameters:
s- arbitrary string- Returns:
- the encoded string
-
siunit_length
public static java.lang.String siunit_length(java.lang.String s)
Convert a length unit to metersTries to convert a length unit to meter value or returns
nullwhen impossible- Parameters:
s- arbitrary string representing a length- Returns:
- the length converted to meters
- Since:
- 19089
-
CRC32_checksum
public static long CRC32_checksum(java.lang.String s)
Calculates the CRC32 checksum from a string (based on RFC 1952).- Parameters:
s- the string- Returns:
- long value from 0 to 2^32-1
-
is_right_hand_traffic
public static boolean is_right_hand_traffic(Environment env)
check if there is right-hand traffic at the current location- Parameters:
env- the environment- Returns:
- true if there is right-hand traffic
- Since:
- 7193
-
is_clockwise
public static boolean is_clockwise(Environment env)
Determines whether the way isclosed and oriented clockwise, or non-closed and the1st, 2nd and last node are in clockwise order.- Parameters:
env- the environment- Returns:
- true if the way is closed and oriented clockwise
-
is_anticlockwise
public static boolean is_anticlockwise(Environment env)
Determines whether the way isclosed and oriented anticlockwise, or non-closed and the1st, 2nd and last node are in anticlockwise order.- Parameters:
env- the environment- Returns:
- true if the way is closed and oriented clockwise
-
print
public static java.lang.Object print(java.lang.Object o)
Prints the object to the command line (for debugging purpose).- Parameters:
o- the object- Returns:
- the same object, unchanged
-
println
public static java.lang.Object println(java.lang.Object o)
Prints the object to the command line, with new line at the end (for debugging purpose).- Parameters:
o- the object- Returns:
- the same object, unchanged
-
number_of_tags
public static int number_of_tags(Environment env)
Get the number of tags for the current primitive.- Parameters:
env- the environment- Returns:
- number of tags
-
setting
public static java.lang.Object setting(Environment env, java.lang.String key)
Get value of a setting.- Parameters:
env- the environmentkey- setting key (given as layer identifier, e.g. setting::mykey {...})- Returns:
- the value of the setting (calculated when the style is loaded)
-
center
public static LatLon center(Environment env)
Returns the center of the environment OSM primitive.- Parameters:
env- the environment- Returns:
- the center of the environment OSM primitive
- Since:
- 11247
-
inside
public static boolean inside(Environment env, java.lang.String codes)
Determines if the object is inside territories matching given ISO3166 codes.- Parameters:
env- the environmentcodes- comma-separated list of ISO3166-1-alpha2 or ISO3166-2 country/subdivision codes- Returns:
trueif the object is inside territory matching given ISO3166 codes- Since:
- 11247
-
outside
public static boolean outside(Environment env, java.lang.String codes)
Determines if the object is outside territories matching given ISO3166 codes.- Parameters:
env- the environmentcodes- comma-separated list of ISO3166-1-alpha2 or ISO3166-2 country/subdivision codes- Returns:
trueif the object is outside territory matching given ISO3166 codes- Since:
- 11247
-
at
public static boolean at(Environment env, double lat, double lon)
Determines if the object centroid lies at given lat/lon coordinates.- Parameters:
env- the environmentlat- latitude, i.e., the north-south position in degreeslon- longitude, i.e., the east-west position in degrees- Returns:
trueif the object centroid lies at given lat/lon coordinates- Since:
- 12514
-
to_boolean
public static boolean to_boolean(java.lang.String value)
Parses the string argument as a boolean.- Parameters:
value- theStringcontaining the boolean representation to be parsed- Returns:
- the boolean represented by the string argument
- Since:
- 16110
- See Also:
Boolean.parseBoolean(java.lang.String)
-
to_byte
public static byte to_byte(java.lang.String value)
Parses the string argument as a byte.- Parameters:
value- theStringcontaining the byte representation to be parsed- Returns:
- the byte represented by the string argument
- Since:
- 16110
- See Also:
Byte.parseByte(java.lang.String, int)
-
to_short
public static short to_short(java.lang.String value)
Parses the string argument as a short.- Parameters:
value- theStringcontaining the short representation to be parsed- Returns:
- the short represented by the string argument
- Since:
- 16110
- See Also:
Short.parseShort(java.lang.String, int)
-
to_int
public static int to_int(java.lang.String value)
Parses the string argument as an int.- Parameters:
value- theStringcontaining the int representation to be parsed- Returns:
- the int represented by the string argument
- Since:
- 16110
- See Also:
Integer.parseInt(java.lang.String, int)
-
to_long
public static long to_long(java.lang.String value)
Parses the string argument as a long.- Parameters:
value- theStringcontaining the long representation to be parsed- Returns:
- the long represented by the string argument
- Since:
- 16110
- See Also:
Long.parseLong(java.lang.String, int)
-
to_float
public static float to_float(java.lang.String value)
Parses the string argument as a float.- Parameters:
value- theStringcontaining the float representation to be parsed- Returns:
- the float represented by the string argument
- Since:
- 16110
- See Also:
Float.parseFloat(java.lang.String)
-
to_double
public static double to_double(java.lang.String value)
Parses the string argument as a double.- Parameters:
value- theStringcontaining the double representation to be parsed- Returns:
- the double represented by the string argument
- Since:
- 16110
- See Also:
Double.parseDouble(java.lang.String)
-
-