Hi I have a grid of 1600 square cells, that previously classiffy given values to group: 0,1,2
val gridcells = RDD[(Int,geotrellis.vector.Polygon)] ...
where the Int is the group of the cell
Example:
(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)))
I want to make a CascadedPolygonUnion of the same group cells
I try with reduceByKey:
gridcells.reduceByKey((a,b)=>a.union(b))
But give me error:
error: type mismatch;
found : geotrellis.vector.TwoDimensionsTwoDimensionsUnionResult
required: geotrellis.vector.Polygon
gridcells.reduceByKey((a,b)=>a.union(b))
The problem is that the union of two polygons give me a TwoDimensionsTwoDimensionsUnionResult
The polygon api:
http://geotrellis.github.io/scaladocs/latest/#geotrellis.vector.Polygon
say that is posible to do a union :
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.
In python shapely I do:
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)
Which is the proper way to do in geotrellis.
Thanks