前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >7. GeoMesa数据读取篇之本地文件读取

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

作者头像
Freedom123
发布2024-03-29 10:44:40
800
发布2024-03-29 10:44:40
举报
文章被收录于专栏: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 路径读取
          相关产品与服务
          腾讯云服务器利旧
          云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档