About CascadedPolygonUnion

327 views
Skip to first unread message

Ziliang Zhao

unread,
Apr 26, 2016, 2:10:46 AM4/26/16
to JSTS devs
Hello,

I'm very new to JSTS.  I want to use the CascadedPolygonUnion function but realized that it is not available in the ES5 compatible build for browsers.  I wonder if functions like this are only provided with the Node.js build, whereas the browser version just has those essential functions?

Thanks.

Björn

unread,
Apr 27, 2016, 12:55:20 AM4/27/16
to JSTS devs
Hi Ziliang, There is no (longer any) difference between the browser and the Node.js build. I didn't expose CascadedPolygonUnion because UnaryUnionOp should use CascadedPolygonUnion if the input is only polygons.
/Björn

Ziliang Zhao

unread,
Apr 28, 2016, 4:15:34 PM4/28/16
to JSTS devs
Thanks a lot. Are there sample code for this function? I assume it's different from geometry.union, right? Currently I use geometry.union to merge a bunch of polygons one by one. I wonder if I can merge an array of polygons together.

Björn

unread,
Apr 28, 2016, 4:44:21 PM4/28/16
to JSTS devs
Sorry I now realize UnaryUnionOp cannot be used directly from the ES5 build, since it requires access to emulated ArrayList.

However, you can use Geometry.union without an argument and so use it on a MultiPolygon (not sure that makes sense) or a GeometryCollection containing only polygons which should trigger the use of CascadedPolygonUnion via UnaryUnionOp. This is only what I can conclude from the source, I haven't tested it myself so I'm not sure it will work but at least it is supposed to work that way. Please report back any results.

Ziliang Zhao

unread,
Apr 29, 2016, 1:19:51 AM4/29/16
to JSTS devs
Is this the correct way to create a GeometryCollection:

var jstsPolygonColl = new jsts.geom.GeometryCollection();

By doing this, I got TypeError: t is undefined.  I also wonder if there is a non-minified version of jsts (browser version) so I can take a look at what error that is.

Thanks again.

Björn

unread,
Apr 29, 2016, 2:07:46 AM4/29/16
to JSTS devs
No, you should use GeometryFactory to create any geometry instance.

There is no non-minified build available, you'll have to create one yourself from the source. If time permits I'll try to also produce an external source map with the next release.

Ziliang Zhao

unread,
May 1, 2016, 12:10:37 AM5/1/16
to JSTS devs
I tried to use Geometry.union as suggested and it works well:

        var gf = new jsts.geom.GeometryFactory();

        var jstsPolygons = [];
        for (var i = 0; i < polygons.length; i++) {
            jstsPolygons.push(parser.read(polygons[i]));
        }

        var jstsPolygonColl = gf.createGeometryCollection(jstsPolygons);

        var mergedPolygon = jstsPolygonColl.union();

Thanks again for the advice!  Awesome tool!

Kandianne Pierre

unread,
Apr 10, 2018, 1:10:37 PM4/10/18
to JSTS devs
Ziliang, I am trying to do the exact thing you have accomplished but am wondering what exactly is the "parser.read" method doing to each of the polygons when you push them into the jstsPolygons array? 
Reply all
Reply to author
Forward
0 new messages