利用GeoWave导入矢量数据到HBase/Accumulo数据库

embedded/2024/12/27 13:27:34/

前言

最近在做有关地理时空大数据的实验,本文将介绍如何利用geowave框架,将矢量数据导入到HBase或Accumulo等NoSQL数据库中。

软件版本:

Hadoop: 2.10.2

Zookeeper: 3.6.4

geowave: 1.2.0

Accumulo:1.9.3

HBase: 1.4.0

Java: 1.8

准备工作

从GeoWave官网下载geowave-hbase-1.2.0-apache.jar导入到HBase的lib文件夹下。(Accumulo数据库导入geowave-accumulo-1.2.0-apache-accumulo1.7.jar包)

代码

1、引入依赖

<dependency><groupId>org.locationtech.geowave</groupId><artifactId>geowave-datastore-hbase</artifactId><version>1.2.0</version>
</dependency>
<dependency><groupId>org.locationtech.geowave</groupId><artifactId>geowave-adapter-vector</artifactId><version>1.2.0</version>
</dependency>
<dependency><groupId>org.locationtech.geowave</groupId><artifactId>geowave-format-vector</artifactId><version>1.2.0</version>
</dependency>
<dependency><groupId>org.locationtech.geowave</groupId><artifactId>geowave-datastore-accumulo</artifactId><version>1.2.0</version>
</dependency>
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>4.6.10</version>
</dependency>
<dependency><groupId>org.apache.accumulo</groupId><artifactId>accumulo-core</artifactId><version>1.9.3</version>
</dependency>

2、HBase数据库导入矢量数据

本文选取AIS数据,文件为JSON格式如下:

 首先需要写代码构建SimpleFeatureTypeBuilder对象,该对象用于创建SimpleFeatureType,其实 用于定义你的矢量数据的Geometry类型,有哪些属性字段。

java">public static SimpleFeatureTypeBuilder getSimpleFeatureBuilder (String typeName) throws IOException, JSONException {// 创建 SimpleFeatureTypeBuilder 对象SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();AttributeTypeBuilder attributeBuilder = new AttributeTypeBuilder();featureTypeBuilder.add(attributeBuilder.binding(Point.class).nillable(false).buildDescriptor("the_geom"));// 添加属性featureTypeBuilder.add("uuid", String.class);featureTypeBuilder.add("mmsi", Integer.class);featureTypeBuilder.add("timestamp", Date.class);featureTypeBuilder.add("system_timestamp", Date.class);featureTypeBuilder.add("nav_status", Integer.class);featureTypeBuilder.add("rot", Double.class);featureTypeBuilder.add("sog", Double.class);featureTypeBuilder.add("pos_acc", Double.class);featureTypeBuilder.add("longitude", Double.class);featureTypeBuilder.add("latitude", Double.class);featureTypeBuilder.add("cog", Double.class);featureTypeBuilder.add("true_head", Double.class);featureTypeBuilder.add("eta", String.class);featureTypeBuilder.add("destid", Integer.class);featureTypeBuilder.add("dest", String.class);featureTypeBuilder.add("srcid", Integer.class);featureTypeBuilder.add("distance", Double.class);featureTypeBuilder.add("speed", Double.class);featureTypeBuilder.add("draught", Double.class);featureTypeBuilder.add("ship_type", Integer.class);featureTypeBuilder.setCRS(DefaultGeographicCRS.WGS84);featureTypeBuilder.setName(typeName);return featureTypeBuilder;}

导入数据,这里的typeName参数是定义矢量数据名称,indexName参数定义索引名称

java">public static void IngestData(String typeName, String indexName) throwsIOException, JSONException, ParseException {HBaseRequiredOptions hBaseRequiredOptions = new HBaseRequiredOptions();//Zookeeper IPhBaseRequiredOptions.setZookeeper("localhost:2181");HBaseDataStore hBaseDataStore = (HBaseDataStore) DataStoreFactory.createDataStore(hBaseRequiredOptions);// JSON 数据 文件路径String filePath = "D:\\轨迹数据\\5h.json";long startTimeStamp = System.currentTimeMillis();// 转换 JSON 文件为 SimpleFeatureTypeSimpleFeatureTypeBuilder featureTypeBuilder = getSimpleFeatureBuilder(typeName);SimpleFeatureType pointType = featureTypeBuilder.buildFeatureType();//创建SimpleFeatureBuilderSimpleFeatureBuilder pointFeatureBuilder = new SimpleFeatureBuilder(pointType);// Create an adapter for point typeFeatureDataAdapter pointTypeAdapter = new FeatureDataAdapter(pointType);//创建索引Index spatialTemporalIndex = new SpatialTemporalIndexBuilder().setMaxDuplicates(-1).setNumPartitions(3).setPeriodicity(TemporalBinningStrategy.Unit.DAY).setPartitionStrategy(IndexPluginOptions.PartitionStrategy.HASH).setName(indexName).createIndex();//Add the point type to the data store in the spatial indexhbaseStore.addType(pointTypeAdapter, spatialTemporalIndex);hbaseStore.getIndexStore().addIndex(spatialTemporalIndex);Writer<SimpleFeature> writer = hbaseStore.createWriter(pointTypeAdapter.getTypeName());// 读取 JSON 文件BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath));String line;SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");while ((line = bufferedReader.readLine()) != null) {JSONObject jsonObject = JSONObject.parseObject(line);// Write some features to the data storeGeometryFactory factory = new GeometryFactory();String uuId = jsonObject.get("uuid").toString();String mmsi = jsonObject.get("mmsi").toString();pointFeatureBuilder.set("the_geom", factory.createPoint(new Coordinate(Double.parseDouble(jsonObject.get("longitude").toString()),Double.parseDouble(jsonObject.get("latitude").toString()))));pointFeatureBuilder.set("uuid", uuId);pointFeatureBuilder.set("mmsi", mmsi);String timestamp_str = jsonObject.get("timestamp").toString();pointFeatureBuilder.set("timestamp", sdf.parse(timestamp_str));String system_timestamp_str = jsonObject.get("system_timestamp").toString();pointFeatureBuilder.set("system_timestamp", sdf.parse(system_timestamp_str));pointFeatureBuilder.set("nav_status", jsonObject.get("nav_status"));pointFeatureBuilder.set("rot", jsonObject.get("rot"));pointFeatureBuilder.set("sog", jsonObject.get("sog"));pointFeatureBuilder.set("pos_acc", jsonObject.get("pos_acc"));pointFeatureBuilder.set("cog", jsonObject.get("cog"));pointFeatureBuilder.set("true_head", jsonObject.get("true_head"));pointFeatureBuilder.set("eta", jsonObject.get("eta"));pointFeatureBuilder.set("destid", jsonObject.get("destid"));pointFeatureBuilder.set("dest", jsonObject.get("dest"));pointFeatureBuilder.set("srcid", jsonObject.get("srcid"));pointFeatureBuilder.set("distance", jsonObject.get("distance"));pointFeatureBuilder.set("speed", jsonObject.get("speed"));pointFeatureBuilder.set("draught", jsonObject.get("draught"));pointFeatureBuilder.set("ship_type", jsonObject.get("ship_type"));//取UUID 前三位 + 后三位  + 船舶编号String id = uuId.substring(0, 3) + uuId.substring(uuId.length() -3) + "-" + mmsi;writer.write(pointFeatureBuilder.buildFeature(id));}System.out.println("ingest finished!!!!");Long endTimeStamp = System.currentTimeMillis();System.out.println("导入耗时:" + (endTimeStamp - startTimeStamp) + "毫秒");bufferedReader.close();writer.flush();writer.close();}

3、Accumulo数据库导入矢量数据

代码和上面基本相同,把HBaseDataStore换成AccumuloDataStore即可。


http://www.ppmy.cn/embedded/145600.html

相关文章

高级java每日一道面试题-2024年12月12日-数据库篇-mysql 深度分页如何优化?

如果有遗漏,评论区告诉我进行补充 面试官: mysql 深度分页如何优化? 我回答: 在Java高级面试中&#xff0c;关于MySQL深度分页优化的提问&#xff0c;是一个考察数据库性能优化能力和对MySQL索引、查询机制理解深度的问题。以下是对MySQL深度分页优化的详细解答&#xff1a…

可信AI与零知识证明的概念

可信AI 可信AI是指人工智能的设计、开发和部署遵循一系列原则和方法,以确保其行为和决策是可靠、可解释、公平、安全且符合人类价值观和社会利益的.以下是关于可信AI的举例说明、实现方式及主流方案: 举例说明 医疗诊断领域:一个可信AI的医疗诊断系统,不仅能够准确地识别…

学习maven(添加依赖坐标,maven的常用命令,依赖传递,解决依赖冲突)

目录 前言 添加依赖坐标 maven 的常用命令 如下图所示&#xff1a;重点是标红的 如何使用这些maven的常用命令呢&#xff1f; 实例 maven常用的命令可以在IDEA中有自带插件来完成 打开IDEA的命令行终端 依赖传递 什么是依赖传递呢&#xff1f; 解决依赖冲突问题 什么…

Vue前端开发-axios对象实例创建和配置的过程

在Vue 3中&#xff0c;由于所有的组件都可能去请求数据&#xff0c;因此&#xff0c;针对axios模块的配置应该是全局性的&#xff0c;在进行axios模块的全局配置之前&#xff0c;需要了解axios实例的创建、配置对象和响应对象的结构内容&#xff0c;接下来我们分别来进行介绍。…

Nacos 3.0 Alpha 发布,在安全、泛用、云原生更进一步

自 2021 年发布以来&#xff0c;Nacos 2.0 在社区的支持下已走过近三年&#xff0c;期间取得了诸多成就。在高性能与易扩展性方面&#xff0c;Nacos 2.0 取得了显著进展&#xff0c;同时在易用性和安全性上也不断提升。想了解更多详细信息&#xff0c;欢迎阅读我们之前发布的回…

STM32 USB通信知识与应用详解

在嵌入式系统开发中&#xff0c;STM32作为一款性能卓越的微控制器&#xff0c;其USB通信功能的应用十分广泛。本文将深入探讨STM32 USB的相关知识&#xff0c;从基础概念到实际应用&#xff0c;为读者呈现一个全面的STM32 USB通信知识体系。 一、USB基础知识 USB&#xff08;…

【AIStarter】告别复杂转换 - MinerU整合包实现PDF到Markdown的无缝转变

在数字化时代&#xff0c;信息的传递与共享变得愈发重要。文档格式之间的转换成为了日常工作中不可或缺的一部分。为了满足用户对高效工作流程的需求&#xff0c;新版MinerU整合包应运而生&#xff0c;它不仅简化了从PDF到Markdown的转换过程&#xff0c;还为用户带来了前所未有…

C#调用Python脚本的方式(一),以PaddleOCR-GUI为例

前言 每种语言都有每种语言的优势&#xff0c;Python由于其强大的生态&#xff0c;很多任务通过调用包就可以实现&#xff0c;那么学会从C#项目中调用Python脚本完成任务就很重要。C#调用Python代码有多种方式&#xff0c;如果Python那边内容比较多&#xff0c;可以考虑起一个…