最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JSTS : How to union of more then two polygons in openlayer2 using JSTS library - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 6

Looking 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]);
}
发布评论

评论列表(0)

  1. 暂无评论