一、Geomesa - QuickStart(教程工程包)
百度网盘下载地址:geomesa-tutorials-master.7z
二、解压后,IDEA编译如下
百度网盘下载地址:IDEA2018破解版安装
三、根据日期范围查询
1 @Test 2 public void query() throws Exception { 3 4 TDriveData data = new TDriveData("taxi_gps",null); 5 String configXML = ResourceUtils.getFile("classpath:templates/hbase-bt.xml").getAbsolutePath(); 6 Map<String, String> params = new HashMap<>(); 7 params.put("hbase.catalog", "test_osm"); 8 params.put("hbase.remote.filtering", "false"); 9 params.put("hbase.config.paths", configXML); 10 HBaseDataStore dataStore = new HBaseDataStore(params, data, ""); 11 dataStore.query(); 12 }
1 public void query() throws CQLException { 2 3 // String dateField = "dtg"; 4 // String tStart = "2007-02-08T00:00:00+00:00"; 5 // String tEnd = "2007-12-31T00:00:00+00:00"; 6 String cqlDates = "dtg during 2008-02-02T13:30:48.000Z/2008-02-02T13:30:52.000Z"; 7 8 // String cqlBbox = "BBOX(geom, 9 // 121.358980,31.177850,121.358988,31.177855)"; 10 11 Filter filter = ECQL.toFilter(cqlDates); 12 // Filter filter = ECQL.toFilter("taxiId = 1288"); 13 Query query = new Query(data.getTypeName(), filter); 14 System.err.println("Running query " + ECQL.toCQL(query.getFilter())); 15 if (query.getPropertyNames() != null) { 16 System.err.println("Returning attributes " + Arrays.asList(query.getPropertyNames())); 17 } 18 int n = 0; 19 20 try (FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, 21 Transaction.AUTO_COMMIT)) { 22 while (reader.hasNext()) { 23 SimpleFeature feature = reader.next(); 24 if (n++ < 10) { 25 // use geotools data utilities to get a printable string 26 System.err.println(String.format("%02d", n) + " " + DataUtilities.encodeFeature(feature)); 27 } else if (n == 10) { 28 System.out.println("..."); 29 } 30 } 31 32 System.err.println("done"); 33 } catch (Exception e) { 34 System.err.println(e.getClass() + "," + e.getMessage()); 35 } 36 }
正常情况下,是显示不出来结果的,但是官网的例子却可以,如下:
如果自己写的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