4

I wrote code to join (union) geometries. I wrapped it into Java8 streams Collector. Inside it it just uses Geometry#union to union geometries:

geometries[0] = geometries[0].union(geometry);

Unfortunately, it works rather slow.

Is it possible to make it faster with some usage of prepared geometry or some other hacks?

UPDATE

Geometries are like this:enter image description here

and they are of very different scales.

Dims
  • 47,675
  • 117
  • 331
  • 600
  • Can you provide some data? how much slow with how many geometries? – Yu Jiaao Jun 01 '17 at 12:37
  • I have approximately 8000 geometries in total, but I build complex tree to join them hierarchically (these are regions on map, blocks, census areas etc and I want to handle different zooms) and it takes approximately 3 geomteries per second to join. So, I will require 40+ minutes to process them all. – Dims Jun 01 '17 at 12:47

2 Answers2

3

Consider using unary union. See http://bjornharrtell.github.io/jsts/1.2.1/apidocs/org/locationtech/jts/operation/union/UnaryUnionOp.html

Ohlsen1980
  • 294
  • 5
  • 11
1

Your stated approach will be slow, because it merges each geometry sequentially into the result, which likely gets larger and larger with each union.

Unary union uses a spatial index to cluster the geometries and merge them hierarchically, which provides better performance. Unfortunately this might not work well with the sequential nature of Java streams.

PreparedGeometry doesn't offer any speedup for overlay operations like union.

dr_jts
  • 211
  • 1
  • 5