全部產品
Search
文件中心

ApsaraDB for HBase:GeoJson格式說明

更新時間:Jul 06, 2024

HBase Ganos的REST介面採用GeoJson形式來描述時空資料,本文對GeoJson形式進行描述說明。

一個典型的時空“點”資料(可理解為軌跡點)格式如下:
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "Dinagat Islands",
    "dtg": 1536041936000,
    "id":  "1"
  }
}

整個資料可分為三部分:

  • 時間資料:作為屬性資訊儲存在properties.dtg中,樣本中為ms層級的時間戳記(13位整數)。
  • 空間資料:geometry.type表示該空間資料為”點”資料,geometry.coordinates為該”點”的經緯度座標。
  • 其他屬性資訊:儲存在properties中,如properties.name、properties.id,表示這個點的屬性資訊。

GeoJson庫

為了方便的產生GeoJson串,可使用通用的GeoJson庫。
  • Java庫geojson-jackson:geojson-jackson,基本的使用方式參考如下:
    FeatureCollection featureCollection = new FeatureCollection();
    featureCollection.add(new Feature());
    
    String json= new ObjectMapper().writeValueAsString(featureCollection);
  • python
    使用如下語句引入geojson包:
        pip install geojson
    基本使用方式為:
    
        point_feature = Feature(id="1",geometry=Point((1.6432, -19.123)),properties={"id":"1","dtg":1536041936000,"name": "Dinagat Islands"})
    
        polygon_feature = Feature(id="my_feature2",geometry=Polygon([(0,0),(0,1),(1,1),(1,0),(0,0)]),properties={"id":"2","dtg":1536041936000,"name": "Dinagat Islands"})
    
        feature_collection = FeatureCollection([point_feature,polygon_feature])
說明 有關GeoJson格式詳情請參見GEOJSON RFC