首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用GeoSpark对spatialRDD进行空间分区?

如何使用GeoSpark对spatialRDD进行空间分区?
EN

Stack Overflow用户
提问于 2018-04-27 23:42:33
回答 2查看 1.5K关注 0票数 1

有没有一种方法可以在GeoSpark中有效地对spatialRDD进行空间分区?例如:使用GeoSpark或类似的方法将多个点接近的分区放在一个分区中?

EN

回答 2

Stack Overflow用户

发布于 2019-07-29 19:49:32

作为Georg comment的一个扩展,我想向您展示一个使用QuadTree的示例。我没有使用其余的分区方法,但我希望它们的行为是相同的(当然,除了实际的分区)。假设您想要分区的变量是pointsRDD (在我的例子中,它实际上是一个PointRDD类型的对象),您可以按以下方式进行分区:

代码语言:javascript
复制
import com.vividsolutions.jts.index.quadtree.Quadtree
import com.vividsolutions.jts.index.SpatialIndex

val buildOnSpatialPartitionedRDD = true // Set to TRUE only if run join query
val numPartitions = 48
pointsRDD.analyze()
pointsRDD.spatialPartitioning(GridType.QUADTREE, numPartitions)
pointsRDD.buildIndex(IndexType.QUADTREE, buildOnSpatialPartitionedRDD)

您将在pointsRDD.spatialPartitionedRDD.rdd中找到分区的数据

代码语言:javascript
复制
pointsRDD
  .spatialPartitionedRDD
  .rdd
  .mapPartitions(yourFunctionYouWantToRunOnEachPartition)

您可以通过查看分区树来检查分区:

代码语言:javascript
复制
pointsRDD.partitionTree.getAllZones.asScala.foreach(println)

这将产生类似于

代码语言:javascript
复制
x: 15.857028 y: 53.36364 w: 9.872338000000003 h: 2.7383549999999985 PartitionId: null Lineage: null
x: 15.857028 y: 54.732817499999996 w: 4.936169000000001 h: 1.3691774999999993 PartitionId: null Lineage: null
x: 15.857028 y: 55.41740625 w: 2.4680845000000007 h: 0.6845887499999996 PartitionId: null Lineage: null
x: 15.857028 y: 55.759700625 w: 1.2340422500000003 h: 0.3422943749999998 PartitionId: null Lineage: null
x: 15.857028 y: 55.9308478125 w: 0.6170211250000002 h: 0.1711471874999999 PartitionId: 0 Lineage: null
...

这可以用你最喜欢的绘图工具可视化(不能包含代码,抱歉):

要检查分区统计信息,请使用以下代码:

代码语言:javascript
复制
import org.apache.spark.sql.functions._
pointsRDD
  .spatialPartitionedRDD
  .rdd
  .mapPartitionsWithIndex{case (i,rows) => Iterator((i,rows.size))}
  .toDF("partition_number","number_of_records")
  .show()

这将为您提供:

代码语言:javascript
复制
+----------------+-----------------+
|partition_number|number_of_records|
+----------------+-----------------+
|               0|             8240|
|               1|             7472|
|               2|             5837|
|               3|             3753|
+----------------+-----------------+
only showing top 4 rows
票数 4
EN

Stack Overflow用户

发布于 2018-06-03 22:51:37

请参阅http://datasystemslab.github.io/GeoSpark/tutorial/rdd/#use-spatial-partitioning

  • KDB-Tree
  • Quad-Tree
  • R-Tree

都是实现的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50065930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档