首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >7. GeoMesa数据读取篇之本地文件读取

7. GeoMesa数据读取篇之本地文件读取

作者头像
Freedom123
发布2024-03-29 10:44:40
发布2024-03-29 10:44:40
3560
举报
文章被收录于专栏:DevOpsDevOps

一. 简介

  1. 读取shapefile 单文件
  2. 读取shapefile 路径下的所有shapefile 文件
  3. 保持输出单shapefile 文件
  4. 保持输出shapefile 集合到指定文件路径
优化:
  1. 读取目录下说有shape为RDD
  2. 分区输出shapefiles时,先进行空间分区

二. 代码

1.本地Shapefile 文件读取
代码语言:javascript
复制
//读取shapefile
    def read_shapefile(shapePath: String, shapeName: String)(implicit sparkContext: SparkContext) = {
        var intpuParams: Map[String, String] = Map()
        var File = new File(shapePath)
        intpuParams += ("url" -> File.toURI.toURL.toString)
        intpuParams += ("geotools" -> "true")
        val query = new Query(shapeName)
        val inputRdd = GeoMesaSpark(intpuParams).rdd(new Configuration(), sparkContext, intpuParams, query)
        println(inputRdd.schema) //打印方案

        inputRdd
    }
2.Main调用
代码语言:javascript
复制
val shapePath: String = "D:\\jb\\gisdata"
    val shapeFile: String = "dltsb_6603"

    val shapeOutPath: String = "D:\\jb\\output"

    def main(args: Array[String]): Unit = {
        implicit val sparkContext: SparkContext = SparkUtilsScala.createSparkContext()

        //读取shapefile 单文件
        //val shapeRdd: SpatialRDD = HandleShapeFile.read_shapefile(shapePath, shapeFile)

        //读取shapefile 路径
        val shapeRdd = HandleShapeFile.read_shapePath("D:\\B工作文档\\三调共享 流入流出\\jb\\output\\local-1630396725278");
        val length: Int = shapeRdd.collect().length

        //保持输出shapefile
        HandleShapeFile.write_shapefile_single(shapeRdd, shapeOutPath)

        sparkContext.stop();
    }
3.本地Shapefile 路径读取
代码语言:javascript
复制
//测试失败,必须指定具体shapefile 文件名称,否则读取失败
    //新的思路:可以通过便利文件路径,获取所有shapefile 文件,分别读取为rdd,然后合并rdd
    def read_shapePath(shapePath: String)(implicit sparkContext: SparkContext) = {
        var intpuParams: Map[String, String] = Map()

        var File = new File(shapePath)
        intpuParams += ("url" -> File.toURI.toURL.toString)
        intpuParams += ("geotools" -> "true")
        val query = new Query("a1ee03b5-b289-4ea7-a7c2-33bd4984365c")

        val inputRdd = GeoMesaSpark(intpuParams).rdd(new Configuration(), sparkContext, intpuParams, query)
        println(inputRdd.schema) //打印方案

        inputRdd
    }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-03-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一. 简介
    • 优化:
  • 二. 代码
    • 1.本地Shapefile 文件读取
    • 2.Main调用
    • 3.本地Shapefile 路径读取
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档