1

嗨,我有一个 1600 个方形单元格的网格,之前将给定的值分类为组:0,1,2

val gridcells = RDD[(Int,geotrellis.vector.Polygon)] ...

其中 Int 是单元格的组

例子:

(1,POLYGON ((317212 6275938, 317212 6275963, 317237 6275963, 317237 6275938, 317212 6275938)))
(0,POLYGON ((317362 6276038, 317362 6276063, 317387 6276063, 317387 6276038, 317362 6276038)))
(0,POLYGON ((317162 6276063, 317162 6276088, 317187 6276088, 317187 6276063, 317162 6276063)))
(2,POLYGON ((317612 6276088, 317612 6276113, 317637 6276113, 317637 6276088, 317612 6276088)))
(2,POLYGON ((317662 6276138, 317662 6276163, 317687 6276163, 317687 6276138, 317662 6276138)))
(0,POLYGON ((316962 6276238, 316962 6276263, 316987 6276263, 316987 6276238, 316962 6276238)))

在此处输入图像描述

我想制作同一组单元格的 CascadedPolygonUnion

http://javadox.com/com.vividsolutions/jts/1.13/com/vividsolutions/jts/operation/union/CascadedPolygonUnion.html

我尝试使用 reduceByKey:

gridcells.reduceByKey((a,b)=>a.union(b))

但是给我错误:

 error: type mismatch;
 found   : geotrellis.vector.TwoDimensionsTwoDimensionsUnionResult
 required: geotrellis.vector.Polygon
       gridcells.reduceByKey((a,b)=>a.union(b))

问题是两个多边形的并集给了我一个 TwoDimensionsTwoDimensionsUnionResult

多边形api:

http://geotrellis.github.io/scaladocs/latest/#geotrellis.vector.Polygon

说可以做一个联合:

def union(g: TwoDimensions): TwoDimensionsTwoDimensionsUnionResult

Computes a Result that represents a Geometry made up of all the points in this Polygon and g. Uses cascaded polygon union if g is a (multi)polygon else falls back to default jts union method. 

在 python 中,我这样做:

from shapely.ops import cascaded_union
# transform QGIS geometries to a list of shapely geometries
geoms =[loads(feature.geometry().asWkb()) for feature in layer.getFeatures(request)]
# cascaded union
cu= cascaded_union(geoms)

这是在geotrellis中做的正确方法。

谢谢

4

0 回答 0