开发者社区 > 博文 > GeoMesa-HBase操作篇——教学案例(初体验)
分享
  • 打开微信扫码分享

  • 点击前往QQ分享

  • 点击前往微博分享

  • 点击复制链接

GeoMesa-HBase操作篇——教学案例(初体验)

  • 京东城市JUST团队
  • 2021-01-18
  • IP归属:未知
  • 24960浏览

1. 下载和编译

下载:

  1. git clone https://github.com/geomesa/geomesa-tutorials.git
  2. cd geomesa-tutorials

查看pom.xml文件,修改hadoop和hbase版本,要和你已安装的版本保持一致。修改后,使用maven进行构建:

mvn clean install -pl geomesa-tutorials-hbase/geomesa-tutorials-hbase-quickstart -am  

建议在构建之前,将mvn的源多设置几个,因为国内的源(例如阿里云)虽然传输比较快,但是资源并不完整,很多jar包都不完整。

2. 运行程序

构建完成后,在命令行执行以下命令

java -cp geomesa-tutorials-hbase/geomesa-tutorials-hbase-quickstart/target/geomesa-tutorials-hbase-quickstart-$VERSION.jar org.geomesa.example.hbase.HBaseQuickStart --hbase.zookeepers "zookeepers's IPs and ports" --hbase.catalog "catalog's name"  

--hbase.zookeepers填zookeeper的位置,在单机模式下,这个值为localhost。对于已经将hbase-site.xml设为GeoMesa能够访问的情况(按照第一部分完成安装),则这一项可以不填。不过依然建议将这一项写全。
--hbase.catalog 填目录的名称,用于存放测试数据。所填的表要么为空,要么不存在,否则会出错。

注意:在填写zookeepers时,一定保证本机和其他机器的网络通畅,如果在本地测试,服务器集群内的机器只有内网地址没有外网地址的话,可能会出现找不到zookeeper node的问题。

3. 运行结果

3.1 输出结果

正常情况下,可以得到如下结果:

  1. Loading datastore
  2. Creating schema: GLOBALEVENTID:String,Actor1Name:String,Actor1CountryCode:String,Actor2Name:String,Actor2CountryCode:String,EventCode:String,NumMentions:Integer,NumSources:Integer,NumArticles:Integer,ActionGeo_Type:Integer,ActionGeo_FullName:String,ActionGeo_CountryCode:String,dtg:Date,geom:Point:srid=4326
  3. Generating test data
  4. Writing test data
  5. Wrote 2356 features
  6. Running test queries
  7. Running query BBOX(geom, -120.0,30.0,-75.0,55.0) AND dtg DURING 2017-12-31T00:00:00+00:00/2018-01-02T00:00:00+00:00
  8. 01 719027236=719027236|UNITED STATES|USA|INDUSTRY||012|1|1|1|3|Central Valley, California, United States|US|2018-01-01T00:00:00.000Z|POINT (-119.682 34.0186)
  9. 02 719027005=719027005|UNITED STATES|USA|||172|2|2|2|3|Long Beach, California, United States|US|2018-01-01T00:00:00.000Z|POINT (-118.189 33.767)
  10. 03 719026204=719026204|JUDGE||||0214|6|1|6|3|Los Angeles, California, United States|US|2018-01-01T00:00:00.000Z|POINT (-118.244 34.0522)
  11. 04 719025745=719025745|KING||||051|4|2|4|2|California, United States|US|2018-01-01T00:00:00.000Z|POINT (-119.746 36.17)
  12. 05 719026858=719026858|UNITED STATES|USA|||010|20|2|20|2|California, United States|US|2018-01-01T00:00:00.000Z|POINT (-119.746 36.17)
  13. 06 719026964=719026964|UNITED STATES|USA|||081|2|2|2|2|California, United States|US|2018-01-01T00:00:00.000Z|POINT (-119.746 36.17)
  14. 07 719026965=719026965|CALIFORNIA|USA|||081|8|1|8|2|California, United States|US|2018-01-01T00:00:00.000Z|POINT (-119.746 36.17)
  15. 08 719025635=719025635|PARIS|FRA|||010|2|1|2|3|Las Vegas, Nevada, United States|US|2018-01-01T00:00:00.000Z|POINT (-115.137 36.175)
  16. 09 719026918=719026918|UNITED STATES|USA|||042|20|5|20|3|Las Vegas, Nevada, United States|US|2018-01-01T00:00:00.000Z|POINT (-115.137 36.175)
  17. 10 719027141=719027141|ALABAMA|USA|JUDGE||172|8|1|8|2|Nevada, United States|US|2018-01-01T00:00:00.000Z|POINT (-117.122 38.4199)
  18. Returned 669 total features
  19. Running query BBOX(geom, -120.0,30.0,-75.0,55.0) AND dtg DURING 2017-12-31T00:00:00+00:00/2018-01-02T00:00:00+00:00
  20. Returning attributes [GLOBALEVENTID, dtg, geom]
  21. 01 719027208=719027208|2018-01-01T00:00:00.000Z|POINT (-89.6812 32.7673)
  22. 02 719026313=719026313|2018-01-01T00:00:00.000Z|POINT (-84.388 33.749)
  23. 03 719026419=719026419|2018-01-01T00:00:00.000Z|POINT (-84.388 33.749)
  24. 04 719026316=719026316|2018-01-01T00:00:00.000Z|POINT (-83.6487 32.9866)
  25. 05 719027132=719027132|2018-01-01T00:00:00.000Z|POINT (-81.2793 33.4968)
  26. 06 719026819=719026819|2018-01-01T00:00:00.000Z|POINT (-81.9296 33.7896)
  27. 07 719026952=719026952|2018-01-01T00:00:00.000Z|POINT (-81.9296 33.7896)
  28. 08 719026881=719026881|2018-01-01T00:00:00.000Z|POINT (-82.0193 34.146)
  29. 09 719026909=719026909|2018-01-01T00:00:00.000Z|POINT (-82.0193 34.146)
  30. 10 719026951=719026951|2018-01-01T00:00:00.000Z|POINT (-82.0193 34.146)
  31. Returned 669 total features
  32. Running query EventCode = '051'
  33. 01 719024909=719024909|||MELBOURNE|AUS|051|10|1|10|4|Melbourne, Victoria, Australia|AS|2018-01-01T00:00:00.000Z|POINT (144.967 -37.8167)
  34. 02 719025178=719025178|AUSTRALIA|AUS|COMMUNITY||051|20|2|20|4|Sydney, New South Wales, Australia|AS|2018-01-01T00:00:00.000Z|POINT (151.217 -33.8833)
  35. 03 719025965=719025965|MIDWIFE||||051|10|1|10|4|Sydney, New South Wales, Australia|AS|2018-01-01T00:00:00.000Z|POINT (151.217 -33.8833)
  36. 04 719025509=719025509|COMMUNITY||AUSTRALIA|AUS|051|2|1|2|1|Australia|AS|2018-01-01T00:00:00.000Z|POINT (135 -25)
  37. 05 719025742=719025742|KING||||051|22|3|22|3|San Diego, California, United States|US|2018-01-01T00:00:00.000Z|POINT (-117.157 32.7153)
  38. 06 719025745=719025745|KING||||051|4|2|4|2|California, United States|US|2018-01-01T00:00:00.000Z|POINT (-119.746 36.17)
  39. 07 719025743=719025743|AUTHORITIES||||051|60|12|60|3|Wichita, Kansas, United States|US|2018-01-01T00:00:00.000Z|POINT (-97.3375 37.6922)
  40. 08 719027205=719027205|UNITED STATES|USA|SIOUX||051|4|1|4|3|Sioux City, Iowa, United States|US|2018-01-01T00:00:00.000Z|POINT (-96.4003 42.5)
  41. 09 719025111=719025111|||UNITED STATES|USA|051|2|1|2|3|Pickens County, South Carolina, United States|US|2018-01-01T00:00:00.000Z|POINT (-82.7165 34.9168)
  42. 10 719026938=719026938|PITTSBURGH|USA|||051|5|1|5|3|York County, Pennsylvania, United States|US|2018-01-01T00:00:00.000Z|POINT (-77 40.1254)
  43. Returned 138 total features
  44. Running query EventCode = '051' AND dtg DURING 2017-12-31T00:00:00+00:00/2018-01-02T00:00:00+00:00
  45. Returning attributes [GLOBALEVENTID, dtg, geom]
  46. 01 719024909=719024909|2018-01-01T00:00:00.000Z|POINT (144.967 -37.8167)
  47. 02 719025178=719025178|2018-01-01T00:00:00.000Z|POINT (151.217 -33.8833)
  48. 03 719025965=719025965|2018-01-01T00:00:00.000Z|POINT (151.217 -33.8833)
  49. 04 719025509=719025509|2018-01-01T00:00:00.000Z|POINT (135 -25)
  50. 05 719025742=719025742|2018-01-01T00:00:00.000Z|POINT (-117.157 32.7153)
  51. 06 719025745=719025745|2018-01-01T00:00:00.000Z|POINT (-119.746 36.17)
  52. 07 719025743=719025743|2018-01-01T00:00:00.000Z|POINT (-97.3375 37.6922)
  53. 08 719027205=719027205|2018-01-01T00:00:00.000Z|POINT (-96.4003 42.5)
  54. 09 719025111=719025111|2018-01-01T00:00:00.000Z|POINT (-82.7165 34.9168)
  55. 10 719026938=719026938|2018-01-01T00:00:00.000Z|POINT (-77 40.1254)
  56. Returned 138 total features
  57. Cleaning up test data
  58. Done

如果出错,说明GeoMesa没有安装成功,或者是底层的HDFS、Hbase出了问题,要根据错误提示具体分析。

从输出结果看,这一实例程序完成了创建schema、写入features、空间查询、属性查询等操作。具体实现可以查看教程中的源代码文件。

3.2 HBase中的表结构

查看hbase当中的数据,相关的表共有5个

  1. hbase(main):019:0> list
  2. TABLE
  3. geomesa-hbase-test01
  4. geomesa-hbase-test01_gdelt_2dquickstart_attr_v5
  5. geomesa-hbase-test01_gdelt_2dquickstart_id
  6. geomesa-hbase-test01_gdelt_2dquickstart_z2_v2
  7. geomesa-hbase-test01_gdelt_2dquickstart_z3_v2

其中geomesa-hbase-test01表记录表的信息

geomesa-hbase-test01_gdelt_2dquickstart_attr_v5 表是属性索引表

geomesa-hbase-test01_gdelt_2dquickstart_id表是id索引表

geomesa-hbase-test01_gdelt_2dquickstart_z2_v2是空间索引表(经纬度)

geomesa-hbase-test01_gdelt_2dquickstart_z3_v2是时间空间索引表

共0条评论