首页 / 浏览问题 / 其他 / 问题详情
通过spark组件如何将包含wkt字符的数组构建成FeatureRDD
9EXP 2021年04月07日
spark 10.1.0

1个回答

示例如下

def makeFeature(): FeatureRDD = {
  import org.geotools.geometry.jts.WKTReader2
  val reader2 = new WKTReader2()
  val polygon = "POLYGON ((40383253.19039666 3562393.269857523, 40383251.84649411 3562379.624985929, 40383247.86643188 3562366.5044790986, 40383241.40316152 3562354.412550751, 40383232.705062896 3562343.813886911, 40383222.10639905 3562335.115788286, 40383210.014470704 3562328.652517929, 40383196.89396387 3562324.672455695, 40383183.24909228 3562323.328553143, 40383169.60422069 3562324.672455695, 40383156.48371386 3562328.652517929, 40383144.39178551 3562335.115788286, 40383133.793121666 3562343.813886911, 40383125.09502304 3562354.412550751, 40383118.631752685 3562366.5044790986, 40383114.65169045 3562379.624985929, 40383113.3077879 3562393.269857523, 40383114.65169045 3562406.914729117, 40383118.631752685 3562420.0352359475, 40383125.09502304 3562432.127164295, 40383133.793121666 3562442.725828135, 40383144.39178551 3562451.42392676, 40383156.48371386 3562457.887197117, 40383169.60422069 3562461.867259351, 40383183.24909228 3562463.211161903, 40383196.89396387 3562461.867259351, 40383210.014470704 3562457.887197117, 40383222.10639905 3562451.42392676, 40383232.705062896 3562442.725828135, 40383241.40316152 3562432.127164295, 40383247.86643188 3562420.0352359475, 40383251.84649411 3562406.914729117, 40383253.19039666 3562393.269857523))"
  val geom = reader2.read(polygon)
  import org.geotools.feature.simple.SimpleFeatureTypeBuilder
  val builder = new SimpleFeatureTypeBuilder
  //名称
  builder.setName("test")
  //    builder.setNamespaceURI("http://www.geotools.org/")
  //    builder.setSRS("EPSG:4326")
  //设置要素类型
  builder.add("geom", classOf[Polygon])
  val featureType = builder.buildFeatureType
  val sfb = new SimpleFeatureBuilder(featureType)
  sfb.set("geom", geom)
  val sf = sfb.buildFeature("1")
  val aRdd = sc.parallelize(Array(sf), 2)
  val fRdd = FeatureRDD.apply(aRdd, featureType, true)
  val filePath="D:\\IdeaWorkspace\\bdt10.1.0alphaTest\\resultdata\\t0408.udbx"
  val params = new java.util.HashMap[String, java.io.Serializable]()
  params.put(SDXFeatureRDDProviderParams.DBType.key, "UDBX")
  params.put(SDXFeatureRDDProviderParams.Server.key, filePath)
  new SDXFeatureRDDProvider().save(fRdd, params, "test1")
  println("1024")
  fRdd
}
1,520EXP 2021年04月12日
...