1. 下载和编译
下载:
- git clone https://github.com/geomesa/geomesa-tutorials.git
- 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 输出结果
正常情况下,可以得到如下结果:
- Loading datastore
-
- 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
-
- Generating test data
- Writing test data
- Wrote 2356 features
-
- Running test queries
- 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
- 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)
- 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)
- 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)
- 04 719025745=719025745|KING||||051|4|2|4|2|California, United States|US|2018-01-01T00:00:00.000Z|POINT (-119.746 36.17)
- 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)
- 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)
- 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)
- 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)
- 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)
- 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)
-
- Returned 669 total features
-
- 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
- Returning attributes [GLOBALEVENTID, dtg, geom]
- 01 719027208=719027208|2018-01-01T00:00:00.000Z|POINT (-89.6812 32.7673)
- 02 719026313=719026313|2018-01-01T00:00:00.000Z|POINT (-84.388 33.749)
- 03 719026419=719026419|2018-01-01T00:00:00.000Z|POINT (-84.388 33.749)
- 04 719026316=719026316|2018-01-01T00:00:00.000Z|POINT (-83.6487 32.9866)
- 05 719027132=719027132|2018-01-01T00:00:00.000Z|POINT (-81.2793 33.4968)
- 06 719026819=719026819|2018-01-01T00:00:00.000Z|POINT (-81.9296 33.7896)
- 07 719026952=719026952|2018-01-01T00:00:00.000Z|POINT (-81.9296 33.7896)
- 08 719026881=719026881|2018-01-01T00:00:00.000Z|POINT (-82.0193 34.146)
- 09 719026909=719026909|2018-01-01T00:00:00.000Z|POINT (-82.0193 34.146)
- 10 719026951=719026951|2018-01-01T00:00:00.000Z|POINT (-82.0193 34.146)
-
- Returned 669 total features
-
- Running query EventCode = '051'
- 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)
- 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)
- 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)
- 04 719025509=719025509|COMMUNITY||AUSTRALIA|AUS|051|2|1|2|1|Australia|AS|2018-01-01T00:00:00.000Z|POINT (135 -25)
- 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)
- 06 719025745=719025745|KING||||051|4|2|4|2|California, United States|US|2018-01-01T00:00:00.000Z|POINT (-119.746 36.17)
- 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)
- 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)
- 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)
- 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)
-
- Returned 138 total features
-
- Running query EventCode = '051' AND dtg DURING 2017-12-31T00:00:00+00:00/2018-01-02T00:00:00+00:00
- Returning attributes [GLOBALEVENTID, dtg, geom]
- 01 719024909=719024909|2018-01-01T00:00:00.000Z|POINT (144.967 -37.8167)
- 02 719025178=719025178|2018-01-01T00:00:00.000Z|POINT (151.217 -33.8833)
- 03 719025965=719025965|2018-01-01T00:00:00.000Z|POINT (151.217 -33.8833)
- 04 719025509=719025509|2018-01-01T00:00:00.000Z|POINT (135 -25)
- 05 719025742=719025742|2018-01-01T00:00:00.000Z|POINT (-117.157 32.7153)
- 06 719025745=719025745|2018-01-01T00:00:00.000Z|POINT (-119.746 36.17)
- 07 719025743=719025743|2018-01-01T00:00:00.000Z|POINT (-97.3375 37.6922)
- 08 719027205=719027205|2018-01-01T00:00:00.000Z|POINT (-96.4003 42.5)
- 09 719025111=719025111|2018-01-01T00:00:00.000Z|POINT (-82.7165 34.9168)
- 10 719026938=719026938|2018-01-01T00:00:00.000Z|POINT (-77 40.1254)
-
- Returned 138 total features
-
- Cleaning up test data
- Done
如果出错,说明GeoMesa没有安装成功,或者是底层的HDFS、Hbase出了问题,要根据错误提示具体分析。
从输出结果看,这一实例程序完成了创建schema、写入features、空间查询、属性查询等操作。具体实现可以查看教程中的源代码文件。
3.2 HBase中的表结构
查看hbase当中的数据,相关的表共有5个
- hbase(main):019:0> list
-
- TABLE
- geomesa-hbase-test01
- geomesa-hbase-test01_gdelt_2dquickstart_attr_v5
- geomesa-hbase-test01_gdelt_2dquickstart_id
- geomesa-hbase-test01_gdelt_2dquickstart_z2_v2
- 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是时间空间索引表