I am doing a project In which I have to take union of many polygons if their edges are intersecting.Polygons maybe more then 100 but they have to make a union shape. Till now I just found that in jSTS we can by using
a=b.union(c);
But It is not working for me as its just for 2 polygons.
My code is
var strGeom = new OpenLayers.Format.WKT(geom);
var parseGeo = reader.read(strGeom.toString());
union = parseGeo.union(parseGeo);
var parser = new jsts.io.OpenLayersParser();
union = parser.write(union);
console.log(union);
var strGeom = new OpenLayers.Format.WKT(union);
I am doing a project In which I have to take union of many polygons if their edges are intersecting.Polygons maybe more then 100 but they have to make a union shape. Till now I just found that in jSTS we can by using
a=b.union(c);
But It is not working for me as its just for 2 polygons.
My code is
var strGeom = new OpenLayers.Format.WKT(geom);
var parseGeo = reader.read(strGeom.toString());
union = parseGeo.union(parseGeo);
var parser = new jsts.io.OpenLayersParser();
union = parser.write(union);
console.log(union);
var strGeom = new OpenLayers.Format.WKT(union);
Share
Improve this question
edited Mar 9, 2017 at 12:21
tousif Noor
asked Mar 9, 2017 at 8:10
tousif Noortousif Noor
3951 gold badge5 silver badges19 bronze badges
1 Answer
Reset to default 6Looking at the code for JSTS union
https://github./bjornharrtell/jsts/blob/master/src/org/locationtech/jts/operation/union/UnaryUnionOp.js (line 16/17)
you can pass a geometry collection instead of a single geometry.
Otherwise, you could perform a union for each polygon.
Something like this
for(var i = 0; i < polygonsLength; i++) {
geom = geom.union(polygons[i]);
}