全部产品
Search
文档中心

云数据库 HBase:query

更新时间:Jan 22, 2024

Ganos支持属性查询、id查询、时空范围查询等,本文介绍数据查询的方式。

配置参数

说明

URL

/index/:alias/:index/features

方法

GET

URL参数

alias=[alphanumeric]表示DS名称。index=[alphanumeric]表示index名称。q=[alphanumeric]JSON表示的查询条件。

成功信息

Code: 200 Content: GeoJSON格式的要素集合。

失败信息

Code: 400,表示需要的参数未指定Content: empty。

curl\ 
'localhost:8080/geoserver/geomesa/geojson/index/:alias/:index/features' \    
--get --data-urlencode 'q=JSON格式查询条件'

HBase Ganos支持的属性查询谓词:

配置参数

说明

$lt

小于

$lte

小于等于

$gt

大于

$gte

大于等于

以下分别介绍几种常用的查询方式:

(1)属性查询HBase Ganos属性查询通过谓词运算。

示例1:查询id=0的要素。

curl \ 
'localhost:8080/geoserver/geomesa/geojson/index/my_ds/test/features' \ 
--get --data-urlencode  \ 
'q={
    "properties.id":"0"
 }'

示例2:查询name=n1的要素。

curl \ 
'localhost:8080/geoserver/geomesa/geojson/index/my_ds/test/features' \ 
--get --data-urlencode  \ 
'q={"properties.name":"n1"}'

示例3:查询age<30的所有要素。

curl \ 
'localhost:8080/geoserver/geomesa/geojson/index/my_ds/test/features' \ 
--get --data-urlencode  \ 
'q={"properties.age":{"$lt":30}}'

(2)空间查询

示例1:通过外包框BBOX查询。

q={ 
    "geometry" : 
    { 
        "$bbox" : [-180, -90, 180, 90] 
    }
}

示例2:空间相交(intersection)查询。

q={
    "geometry" : {
        "$intersects" : {
            "$geometry" : { 
                "type" : "Point", 
                "coordinates" : [30, 10] 
            }
        }
     }
}

示例3:空间包含(within)查询。

q={
    "geometry" : {
        "$within" : { "$geometry" : {
            "type" : "Polygon",
            "coordinates": [ [ [0,0], [3,6], [6,1], [0,0] ] ] 
        }}
     } 
}

示例4:空间包含(contains)查询。

q={
    "geometry" : {
        "$contains" : {
            "$geometry" : { 
                "type" : "Point", 
                "coordinates" : [30, 10] 
            }
        } 
    }
}

(3)时间查询

示例1:使用$during谓词指定时间区间。

curl \
'localhost:8080/geoserver/geomesa/geojson/index/myds/test/features' \ 
--get --data-urlencode  \ 
'q={"dtg":{"$during":"2018-01-02T08:00:00Z/2018-03-02T10:00:00Z"}}'

示例2:使用$lt(),$gt$lte和$gte。

curl \ 'localhost:8080/geoserver/geomesa/geojson/index/myds/test/features' \ 
--get --data-urlencode  \ 
'q={"dtg":{"$lt" : "2013-01-02 00:00:00"}}'

(4)组合查询

AND:创建查询条件a=5 AND b=6。

{ "a" : 5, "b" : 6 }

OR:创建查询条件a=5 OR a=6。

{ "$or" : [ { "a" : 5 }, { "b" : 6 } ] }

示例:时空查询配合属性查询。

curl /
'http://localhost:8080/geoserver/geomesa/geojson/index/tdrive_ds/tdrive_index/featu res'
--get --data-urlencode \ 
'q={
    "geometry":{"$bbox":[116.3383,39.8291,116.3384,39.8292]}, 
    "properties.taxi_num":"1131",
    "properties.dtg":{"$gt" : "2008-02-08T08:00:00.000+0000"}, 
    "properties.dtg":{"$lt" : "2008-02-08T12:21:16.000+0000"}
}'