基於Geomesa服務查詢軌跡資料無法根據空間和時間範圍進行查詢的問題解決辦法

appleyk發表於2018-07-13

 

一、Geomesa (教程包)

 

 

百度網盤下載地址: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-distributed-runtime_2.11-2.0.2.jar /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

 

 

 

 

 

 

相關文章