Skip to content

@turf/union - throw 'null is not an object (evaluating 'this.rings.length')' #2933

@ce-zhang-mapxus

Description

@ce-zhang-mapxus

@turf/turf == 7.1.0

import * as turf from '@turf/turf'

const a = turf.multiPolygon([
                    [
                        [
                            [
                                140.386167,
                                35.774031
                            ],
                            [
                                140.3867846,
                                35.7731789
                            ],
                            [
                                140.3869928,
                                35.7728917
                            ],
                            [
                                140.3870023377,
                                35.77289619406
                            ],
                            [
                                140.38709475329,
                                35.77276708494
                            ],
                            [
                                140.3870861,
                                35.7727631
                            ],
                            [
                                140.3871728,
                                35.7726435
                            ],
                            [
                                140.3879904,
                                35.7715157
                            ],
                            [
                                140.38736209999,
                                35.7712159
                            ],
                            [
                                140.3855417,
                                35.7737332
                            ],
                            [
                                140.386167,
                                35.774031
                            ]
                        ]
                    ]
                ])

const b = turf.multiPolygon([
                    [
                        [
                            [
                                140.38678460065,
                                35.77317890012
                            ],
                            [
                                140.38717280065,
                                35.77264350012
                            ],
                            [
                                140.38710880065,
                                35.77261300012
                            ],
                            [
                                140.38711330065,
                                35.77260680012
                            ],
                            [
                                140.38675690065,
                                35.77243710012
                            ],
                            [
                                140.38675260065,
                                35.77244300012
                            ],
                            [
                                140.38672920065,
                                35.77243180012
                            ],
                            [
                                140.38670050064,
                                35.77247140012
                            ],
                            [
                                140.38651920065,
                                35.77238490012
                            ],
                            [
                                140.38615970065,
                                35.77288080012
                            ],
                            [
                                140.38636160064,
                                35.77297730012
                            ],
                            [
                                140.38635700065,
                                35.77298370011
                            ],
                            [
                                140.38671510065,
                                35.77315420012
                            ],
                            [
                                140.38671970064,
                                35.77314790012
                            ],
                            [
                                140.38678460065,
                                35.77317890012
                            ]
                        ]
                    ],
                    [
                        [
                            [
                                140.3867151,
                                35.7731542
                            ],
                            [
                                140.386357,
                                35.77298369999
                            ],
                            [
                                140.38636159999,
                                35.7729773
                            ],
                            [
                                140.3861597,
                                35.7728808
                            ],
                            [
                                140.3859927,
                                35.7731114
                            ],
                            [
                                140.3859705,
                                35.7731008
                            ],
                            [
                                140.3856325864,
                                35.77356801965
                            ],
                            [
                                140.3855184,
                                35.7737259
                            ],
                            [
                                140.3861647,
                                35.7740342
                            ],
                            [
                                140.3867846,
                                35.7731789
                            ],
                            [
                                140.38671969999,
                                35.7731479
                            ],
                            [
                                140.3867151,
                                35.7731542
                            ]
                        ]
                    ],
                    [
                        [
                            [
                                140.3867569,
                                35.7724371
                            ],
                            [
                                140.3871133,
                                35.7726068
                            ],
                            [
                                140.3871088,
                                35.772613
                            ],
                            [
                                140.3871728,
                                35.7726435
                            ],
                            [
                                140.3879933,
                                35.7715117
                            ],
                            [
                                140.3873434,
                                35.7712023
                            ],
                            [
                                140.3866907,
                                35.7721049
                            ],
                            [
                                140.3867137,
                                35.7721158
                            ],
                            [
                                140.3865477,
                                35.77234519999
                            ],
                            [
                                140.3867526,
                                35.772443
                            ],
                            [
                                140.3867569,
                                35.7724371
                            ]
                        ]
                    ]
                ])

const c = turf.multiPolygon([
                    [
                        [
                            [
                                140.38618729999,
                                35.7740451
                            ],
                            [
                                140.3865877,
                                35.7734927
                            ],
                            [
                                140.386565,
                                35.7734819
                            ],
                            [
                                140.3867846,
                                35.7731789
                            ],
                            [
                                140.3861598,
                                35.7728808
                            ],
                            [
                                140.3859927,
                                35.7731114
                            ],
                            [
                                140.3859705,
                                35.7731008
                            ],
                            [
                                140.3855184,
                                35.7737259
                            ],
                            [
                                140.38618729999,
                                35.7740451
                            ]
                        ]
                    ],
                    [
                        [
                            [
                                140.3871728,
                                35.7726435
                            ],
                            [
                                140.3873725,
                                35.772368
                            ],
                            [
                                140.38739419999,
                                35.7723784
                            ],
                            [
                                140.388015,
                                35.77152199999
                            ],
                            [
                                140.3873434,
                                35.7712023
                            ],
                            [
                                140.3866907,
                                35.7721049
                            ],
                            [
                                140.38671389999,
                                35.7721159
                            ],
                            [
                                140.3865477,
                                35.77234519999
                            ],
                            [
                                140.3871728,
                                35.7726435
                            ]
                        ]
                    ]
                ])


turf.union(turf.featureCollection([a,b,c])) // problematic

turf.union(turf.featureCollection([c,a,b])) // ok

the first union gives:

TypeError: null is not an object (evaluating 'this.rings.length')
      at afterState (......../node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1088:33)
      at beforeState (......../node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1071:31)
      at isInResult (......../node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1126:28)
      at getAvailableLinkedEvents (......../node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:579:63)
      at factory (......../node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1341:38)
      at run (......../node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1763:30)
      at union (......../node_modules/@turf/union/dist/esm/index.js:13:35)
      at ......../index5.js:305:6

upgrade to @turf/turf 7.2.0 seem to be ok, but why?

ALSO, upgrade to 7.2.0 cause problem like #2909 that also bugs me. NOT directly upgrade to the new version right now.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions