一、Geomesa - QuickStart(教程工程包)
百度网盘下载地址:geomesa-tutorials-master.7z
二、解压后,IDEA编译如下
百度网盘下载地址:IDEA2018破解版安装
三、根据日期范围查询
@Test
public void query() throws Exception { TDriveData data = new TDriveData("taxi_gps",null);
String configXML = ResourceUtils.getFile("classpath:templates/hbase-bt.xml").getAbsolutePath();
Map<String, String> params = new HashMap<>();
params.put("hbase.catalog", "test_osm");
params.put("hbase.remote.filtering", "false");
params.put("hbase.config.paths", configXML);
HBaseDataStore dataStore = new HBaseDataStore(params, data, "");
dataStore.query();
}
public void query() throws CQLException { // String dateField = "dtg";
// String tStart = "2007-02-08T00:00:00+00:00";
// String tEnd = "2007-12-31T00:00:00+00:00";
String cqlDates = "dtg during 2008-02-02T13:30:48.000Z/2008-02-02T13:30:52.000Z"; // String cqlBbox = "BBOX(geom,
// 121.358980,31.177850,121.358988,31.177855)"; Filter filter = ECQL.toFilter(cqlDates);
// Filter filter = ECQL.toFilter("taxiId = 1288");
Query query = new Query(data.getTypeName(), filter);
System.err.println("Running query " + ECQL.toCQL(query.getFilter()));
if (query.getPropertyNames() != null) {
System.err.println("Returning attributes " + Arrays.asList(query.getPropertyNames()));
}
int n = 0; try (FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query,
Transaction.AUTO_COMMIT)) {
while (reader.hasNext()) {
SimpleFeature feature = reader.next();
if (n++ < 10) {
// use geotools data utilities to get a printable string
System.err.println(String.format("%02d", n) + " " + DataUtilities.encodeFeature(feature));
} else if (n == 10) {
System.out.println("...");
}
} System.err.println("done");
} catch (Exception e) {
System.err.println(e.getClass() + "," + e.getMessage());
}
}
正常情况下,是显示不出来结果的,但是官网的例子却可以,如下:
如果自己写的Java客户端代码,利用Geomesa服务提供的filter根据空间范围BBox和时间范围进行During查不到结果的话,别慌好吧,请看官网是怎么说的:
注意这句话:GeoMesa uses an HBase custom filter to improve processing of CQL queries
翻译一下大概是:GeoMesa使用HBase自定义过滤器来改进对CQL查询的处理
但是后面还有一句关键的话:In order to use the custom filter, you must deploy the distributed runtime jar to the HBase to the directory specified by the HBase configuration variable called hbase.dynamic.jars.dir
. This is set to ${hbase.rootdir}/lib
by default.
翻译一下大概是:为了使用自定义过滤器,必须将分布式运行时jar部署到HBase中,并将其部署到HBase配置变量HBase .dynamic.jars.dir指定的目录中。如果不指定的话,这个目录默认就是${hbase.rootdir}/lib
因为我们用的是Geomesa服务提供的过滤器进行的查询,而Geomesa用的又是HBase自定义的过滤器加以改进的,也就是上面说的意思大概是,如果不把这个分布式运行时jar包配置到${hbase.rootdir}/lib目录下,等于说,我们用的还是HBase的那一套过滤器,也就是不是加强版的查询,Ok,那这个包在哪呢,我们可以通过下面的连接进行完整项目的下载:
百度网盘下载地址:geomesa-hbase_2.11-2.0.2-bin.tar.gz
Geomesa官方主页:http://www.geomesa.org/
Geomesa项目源码GitHub开源地址:https://github.com/locationtech/geomesa/releases
Geomesa-HBase分布式运行时jar包就在这个二进制压缩包中
jar包如下:
百度网盘下载地址:geomesa-hbase-distributed-runtime_2.11-2.0.2.jar
下载后,利用hadoop的fs命令,将其存放至${hbase.rootdir}/lib下,比如我的集群中HBase的rootdir路径如下:
首先利用hadoop的fs命令在hbase_db目录下面创建一个lib目录
hadoop fs -mkdir /opt/hbase/hbase_db/lib
然后将Geomesa-HBase分布式运行时Jar包上传至hdfs文件系统中的hbase数据存放路径下面的lib目录下
hadoop fs -put geomesa-hbase_2.11-2.0.2-bin.tar.gz /opt/hbase/hbase_db/lib
效果如下:
最后重启HBase,按时间范围查询如下:
Running query dtg DURING 2008-02-02T13:30:48+00:00/2008-02-02T13:30:52+00:00 13:11:13.971 [main-SendThread(192.168.142.144:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Reading reply
01 1288=1288|2008-02-02T13:30:49.000Z|POINT (116.31412 39.89455)
02 1288=1288|2008-02-02T13:30:50.000Z|POINT (116.31412 39.89455)
03 1277=1277|2008-02-02T13:30:49.000Z|POINT (116.31412 39.89454)
done
按空间(索引)范围查询如下:
Running query BBOX(geom, 116.31412,39.89411,117.31412,40.89455)
01 1288=1288|2008-02-02T13:30:49.000Z|POINT (116.31412 39.89454)
02 1288=1288|2008-02-02T13:30:50.000Z|POINT (116.31412 39.89455)
03 1277=1277|2008-02-02T13:30:49.000Z|POINT (116.31412 39.89454)
04 1277=1277|2008-02-03T07:26:45.000Z|POINT (116.31469 39.89492)
05 1277=1277|2008-02-06T18:35:12.000Z|POINT (116.31493 39.895)
06 1277=1277|2008-02-08T13:12:39.000Z|POINT (116.31468 39.89568)
07 1277=1277|2008-02-08T17:36:39.000Z|POINT (116.31777 39.89572)
08 1277=1277|2008-02-06T18:38:46.000Z|POINT (116.32276 39.89555)
09 1277=1277|2008-02-08T12:15:59.000Z|POINT (116.31645 39.89698)
10 1277=1277|2008-02-04T12:34:38.000Z|POINT (116.31511 39.8988)
done