I have a large geoJSON file containing polygons and multi-polygons, totaling 2.5 MB in size.
My goal is to merge all these shapes to display them on a map within a web browser environment.
In my Python workflow, I am using shapely.ops.unary_union
which processes the operation in less than a second.
However, when attempting the same task in JavaScript with turf.union
(see documentation), it takes nearly a minute to complete with the identical file...
Are there any methods to achieve rapid polygon unions in JavaScript without resorting to server-side processing?
Python code:
from shapely.ops import unary_union
from shapely.geometry import shape
geoJSON=json.load(open(filename,'rb'))
shapes=[]
for feature in geoJSON['features']:
shapes.append(shape(feature['geometry']))
union = unary_union(shapes)
Javascript code:
function union(geojson){
features = geojson.features
union = turf.union(...features)
}