9.17. 变换函数概述¶
9.17.1. 类型转换¶
::int
or::integer
::long
::float
::double
::boolean
::r
toInt
ortoInteger
toLong
toFloat
toDouble
toBoolean
intToBoolean
9.17.2. 字符串函数¶
strip
stripPrefix
stripSuffix
stripQuotes
replace
removeChars
length
trim
capitalize
lowercase
regexReplace
concatenate
substring
toString
emptyToNull
printf
9.17.3. 日期函数¶
now
date
dateTime
basicIsoDate
isoDate
isoLocalDate
basicDateTime
isoDateTime
isoLocalDateTime
isoOffsetDateTime
basicDateTimeNoMillis
dateHourMinuteSecondMillis
millisToDate
secsToDate
dateToString
dateToMillis
9.17.4. 几何函数¶
point
pointM
multipoint
linestring
multilinestring
polygon
multipolygon
geometrycollection
geometry
projectFrom
9.17.5. ID函数¶
stringToBytes
md5
murmur3_32
murmur3_64
murmurHash3
uuid
uuidZ3
uuidZ3Centroid
9.17.6. 数学函数¶
add
subtract
multiply
divide
mean
min
max
9.17.7. List和Map函数¶
list
listItem
mapValue
parseList
parseMap
transformListItems
9.17.8. 编码函数¶
base64Encode
base64Decode
9.17.9. 控制功能¶
try
withDefault
require
9.17.10. 国家职能¶
inputFilePath
lineNo
9.17.11. 使用脚本语言定义的函数¶
您可以使用支持JSR-223的脚本语言定义函数。这一点目前仅在JavaScript中进行了测试,因为它通过Nashorn扩展在所有JRE中都得到了本地支持。若要定义在转换器框架中使用的JavaScript函数,请使用 .js
扩展名和函数定义作为文件的内容。例如,如果您定义了一个函数,如
function hello(s) {
return "hello: " + s;
}
您可以在转换表达式中将该函数引用为 js:hello($2)
9.17.12. 安装自定义脚本¶
自定义脚本函数可用于GeoMesa命令行工具或分布式(映射减少)摄取,方法是将它们包含在类路径中或设置系统属性。
对于本地使用,geomesa定义了系统属性 geomesa.convert.scripts.path
脚本文件和/或包含脚本的目录的冒号分隔列表。在使用命令行工具时,可以通过设置 CUSTOM_JAVA_OPTS
环境变量:
CUSTOM_JAVA_OPTS="-Dgeomesa.convert.scripts.path=/path/to/script.js:/path/to/script-dir/"
包含自定义脚本的一种更具弹性的方法是将它们打包为JAR或ZIP文件,并将其添加到 GEOMESA_EXTRA_CLASSPATHS
环境变量。如果使用maven,只需将它们打包到 src/main/resources/geomesa-convert-scripts/
这将在您的JAR文件中创建一个名为 geomesa-convert-scripts
里面有剧本。您也可以使用此文件夹手动创建JAR。一种更简单的方法通常是将它们打包为Zip存档文件,并使用一个类似于 geomesa-convert-scripts
在包含脚本的归档中:
$ unzip -l /tmp/scripts.zip
Archive: /tmp/scripts.zip
Length Date Time Name
--------- ---------- ----- ----
0 2017-03-09 11:33 geomesa-convert-scripts/
42 2017-03-09 11:33 geomesa-convert-scripts/my-script.js
--------- -------
42 2 files
对于ZIP或JAR文件,将它们添加到您环境中的额外类路径中,以使它们可用于工具或映射减少摄取:
GEOMESA_EXTRA_CLASSPATHS="/path/to/my-scripts.jar:/tmp/scripts.zip"
在类路径上使用脚本进行摄取的示例如下:
GEOMESA_EXTRA_CLASSPATHS="/tmp/scripts.zip:/path/to/my-scripts.jar" bin/geomesa-accumulo ingest -u <user-name>
-p <password> -s <sft-name> -C <converter-name> -c geomesa.catalog hdfs://localhost:9000/data/example.csv
您还可以使用以下工具验证是否正确配置了类路径:
GEOMESA_EXTRA_CLASSPATHS="/tmp/scripts.zip:/path/to/my-scripts.jar" bin/geomesa-accumulo classpath
9.17.13. CQL函数¶
大多数基本的CQL函数都可以作为转换使用。要使用一个函数,请像调用常规函数一样调用它,并以 cql
命名空间。例如,可以使用CQL缓冲区函数将点转换为多边形:
cql:buffer($1, 2.0)
有关各种CQL函数的详细信息,请参阅Geoserver filter function reference 。
9.17.14. JSON/Avro变换¶
9.17.15. 浓缩功能¶
转换器框架提供了一种基于从缓存中查找来设置属性的机制。缓存可以是系统中的文字缓存,也可以是外部系统(如Redis)中的文本缓存。
cacheLookup