9.4. 通过命令行工具使用转换器¶
GeoMesa二进制发行版附带了针对常见数据类型的预打包功能类型和转换器定义,包括Twitter、GeoName、T-Drive等。这些转换器可以与现成的GeoMesa命令行工具一起使用。看见 预打包的转换器定义 。此外,常见的文件格式,如GeoJSON、分隔文本或自描述Avro,通常可以在没有转换器的情况下获取。看见 ingest 了解更多细节。
用户可以添加其他SimpleFeatureType和转换器类型 reference.conf
中嵌入了JAR的文件 lib
目录,或通过将类型添加到 application.conf
文件中的 conf
工具分发的目录。
备注
下面的示例特定于GeoMesa Acumulo分布,但每个分布的一般原则是相同的。只有主变量和命令行工具名称将根据GeoMesa的分布而有所不同。
给定以下示例CSV文件 example.csv
:
ID,Name,Age,LastSeen,Friends,Lat,Lon
23623,Harry,20,2015-05-06,"Will, Mark, Suzan",-100.236523,23
26236,Hermione,25,2015-06-07,"Edward, Bill, Harry",40.232,-53.2356
3233,Severus,30,2015-10-23,"Tom, Riddle, Voldemort",3,-62.23
可以在GeoMesa工具配置文件中指定“Renegade”SFT和“Renegade-CSV”转换器 ($GEOMESA_ACCUMULO_HOME/conf/application.conf
),如下所示。默认情况下,将从路径下的文件加载SFT geomesa.sfts
并将在路径上加载转换器 geomesa.converters
。每个转换器和SFT定义都以可在转换器和SFT加载器中引用的名称为关键字。
$GEOMESA_ACCUMULO_HOME/conf/application.conf
:
geomesa = {
sfts = {
# other SFTs
# ...
"renegades" = {
attributes = [
{ name = "fid", type = "Integer", index = false }
{ name = "name", type = "String", index = true }
{ name = "age", type = "Integer", index = false }
{ name = "lastseen", type = "Date", index = true }
{ name = "friends", type = "List[String]", index = true }
{ name = "geom", type = "Point", index = true, srid = 4326, default = true }
]
}
}
converters = {
# other converters
# ...
"renegades-csv" = {
type = "delimited-text",
format = "CSV",
options {
skip-lines = 1
},
id-field = "toString($fid)",
fields = [
{ name = "fid", transform = "$1::int" }
{ name = "name", transform = "$2::string" }
{ name = "age", transform = "$3::int" }
{ name = "lastseen", transform = "date('yyyy-MM-dd', $4)" }
{ name = "friends", transform = "parseList('string', $5)" }
{ name = "lon", transform = "$6::double" }
{ name = "lat", transform = "$7::double" }
{ name = "geom", transform = "point($lon, $lat)" }
]
}
}
}
使用 geomesa-accumulo env
以确认 geomesa-accumulo ingest
可以正确读取更新后的文件。
$ geomesa-accumulo env
一旦注册了转换器和SFT,就可以使用它来摄取 example.csv
文件:
$ geomesa-accumulo ingest -u <user> -p <pass> -i <instance> -z <zookeepers> -s renegades -C renegades-csv example.csv