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

server/2024/12/14 10:34:06/

前言

最近在做有关地理时空大数据的实验,本文将介绍如何利用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/server/150067.html

相关文章

MongoDB-单键索引与复合索引

在 MongoDB 中&#xff0c;索引是提高查询性能的一个重要手段。通过为集合中的字段创建索引&#xff0c;可以显著加快对数据的检索速度。MongoDB 支持多种类型的索引&#xff0c;其中 单键索引 和 复合索引 是最常用的两种类型。了解这两种索引的工作原理、使用场景以及区别&am…

本地体验新版springcloud-搭建工程学习笔记

为了快速体验下新版本springcloud.对照b站图灵视频简单记录下。起码入门不要钱&#xff0c;值得推荐。 基础知识&#xff1a; 会用springboot写demo。 会用mybatis操作MYSQL。 会用git拉取代码。 这都是基本操作。 环境准备&#xff1a; jdk17 demo是21.我实际测试17也可…

Nginx之配置防盗链(Configuring Anti-hotlinking in Nginx)

运维小白入门——Nginx配置防盗 什么是防盗链&#xff1a; 防盗链技术主要用于防止未经授权的第三方或域名访问网站的静态资源。例如&#xff0c;一个网站可能拥有独特的图片素材&#xff0c;为了防止其他网站通过直接链接图片URL的方式访问这些图片&#xff0c;网站管理员会采…

MedLSAM: 用于3D CT图像的局部化和分割模型|文献速递-生成式模型与transformer在医学影像中的应用

Title 题目 MedLSAM: Localize and segment anything model for 3D CT images MedLSAM: 用于3D CT图像的局部化和分割模型 01 文献速递介绍 最近&#xff0c;计算机视觉领域对开发大规模的基础模型的兴趣不断增加&#xff0c;这些模型能够同时处理多个视觉任务&#xff0c…

常见的网络命令

目录 1. ping2. netstat3. pidof 1. ping ping 命令可以用于检查两台主机是否连通&#xff08;是否可以进行通信&#xff09; ping -cn ip/域名 -cn: 指定 ping 的次数 n2. netstat netstat&#xff1a;一个查看网络状态的工具&#xff0c;常用于监听 常用选项 -n 拒绝显示别名…

pcl::PointCloud<pcl::PointXYZ>和pcl::PointCloud<pcl::PointXYZ>::Ptr 转换及新建点云显示

点云智能指针格式和非指针格式的转换 pcl::PointCloud<PointT>::Ptr cloud_ptr(new pcl::PointCloud<PointT>); pcl::PointCloud<PointT> cloud; cloud *cloud_ptr; cloud_ptr boost::make_shared<pcl::PointCloud<PointT>>(cloud);全部代码&…

电商数据API接口:安全与性能的双重挑战

随着电子商务的蓬勃发展&#xff0c;电商平台与外部服务、内部系统之间的数据交换和通信变得日益频繁。API&#xff08;应用程序编程接口&#xff09;接口作为这一过程中的关键枢纽&#xff0c;其安全性和性能表现对于电商平台的稳定运行和用户体验至关重要。然而&#xff0c;电…

期末复习-计算机网络

目录 第四章&#xff1a;网络层 1. 虚电路服务和数据报服务的对比 2. 分类的 IP 地址 3. IP 地址与硬件地址&#xff0c;地址解析协议 ARP 4. IP 数据报的格式 5. IP 层转发分组的流程 6. 划分子网&#xff08;子网掩码、划分子网、使用子网时分组的转发&#xff09; …