2

Why are these two overlapping polygons not dissolving?

I would expect the smaller polygon to dissolve into the larger but instead two individual features remain.

See fiddle for code example.

http://jsfiddle.net/dejz01v4/1/

var fc = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              150.17271290842746,
              -29.193230273074025
            ],
            [
              150.17257345522282,
              -29.193108533004093
            ],
            [
              150.1727182733164,
              -29.192982109706982
            ],
            [
              150.17270215866807,
              -29.192968041897586
            ],
            [
              150.17271288752295,
              -29.19295867580919
            ],
            [
              150.1727021587057,
              -29.192949309735507
            ],
            [
              150.17270752313314,
              -29.192944626690444
            ],
            [
              150.17270215872455,
              -29.192939943653187
            ],
            [
              150.17272897728134,
              -29.192916531551397
            ],
            [
              150.1727236093082,
              -29.192911845401085
            ],
            [
              150.17273433816308,
              -29.192902479307552
            ],
            [
              150.17272360934587,
              -29.192893113228752
            ],
            [
              150.17273433820074,
              -29.19288374713351
            ],
            [
              150.1727236093835,
              -29.192874381052984
            ],
            [
              150.17273433823837,
              -29.192865014956038
            ],
            [
              150.17272360942113,
              -29.192855648873806
            ],
            [
              150.172734338276,
              -29.192846282775147
            ],
            [
              150.17272360945876,
              -29.192836916691203
            ],
            [
              150.1727289738862,
              -29.192832233641017
            ],
            [
              150.17272360947757,
              -29.19282755059861
            ],
            [
              150.17292964332185,
              -29.1926476866836
            ],
            [
              150.1731356771661,
              -29.19282755059861
            ],
            [
              150.17313031275748,
              -29.192832233641017
            ],
            [
              150.17313567718492,
              -29.192836916691203
            ],
            [
              150.17312494836767,
              -29.192846282775147
            ],
            [
              150.17313567722255,
              -29.192855648873806
            ],
            [
              150.17312494840533,
              -29.192865014956027
            ],
            [
              150.1731356772602,
              -29.192874381052984
            ],
            [
              150.17312494844296,
              -29.19288374713351
            ],
            [
              150.17313567729784,
              -29.192893113228752
            ],
            [
              150.1731249484806,
              -29.192902479307563
            ],
            [
              150.17313567733547,
              -29.192911845401085
            ],
            [
              150.17310885885686,
              -29.19293525748209
            ],
            [
              150.17311200495152,
              -29.192938003964272
            ],
            [
              150.17312269806632,
              -29.192928669089078
            ],
            [
              150.17312806069813,
              -29.1929333505593
            ],
            [
              150.17313342332992,
              -29.192928669089078
            ],
            [
              150.1733394577387,
              -29.193108533004093
            ],
            [
              150.17313342332992,
              -29.19328839723457
            ],
            [
              150.17312806069813,
              -29.193283715756138
            ],
            [
              150.17312269806632,
              -29.19328839723457
            ],
            [
              150.17310664054025,
              -29.193274379311145
            ],
            [
              150.17310349870607,
              -29.193277122070054
            ],
            [
              150.17311422756094,
              -29.19328648812936
            ],
            [
              150.17308740551783,
              -29.193309903236564
            ],
            [
              150.17311422765505,
              -29.193333318374158
            ],
            [
              150.17309277002056,
              -29.19335205045138
            ],
            [
              150.1731142277303,
              -29.193370782554606
            ],
            [
              150.17310349891306,
              -29.19338014858978
            ],
            [
              150.17311422776794,
              -29.193389514639673
            ],
            [
              150.17310886335932,
              -29.19339419765641
            ],
            [
              150.17311422778675,
              -29.19339888068093
            ],
            [
              150.1730981345609,
              -29.193412929729856
            ],
            [
              150.17311422784323,
              -29.19342697879959
            ],
            [
              150.17309277020874,
              -29.19344571085969
            ],
            [
              150.1731142279185,
              -29.193464442945796
            ],
            [
              150.17308740587538,
              -29.19348785801237
            ],
            [
              150.1731142280126,
              -29.193511273109337
            ],
            [
              150.17310886360397,
              -29.193515956120518
            ],
            [
              150.1731142280314,
              -29.19352063913948
            ],
            [
              150.1731088636228,
              -29.193525322150222
            ],
            [
              150.17311422805022,
              -29.193530005168746
            ],
            [
              150.17310349923298,
              -29.19353937118939
            ],
            [
              150.17311422808785,
              -29.193548737224752
            ],
            [
              150.1731034992706,
              -29.19355810324369
            ],
            [
              150.17311422812548,
              -29.19356746927734
            ],
            [
              150.1729081927946,
              -29.193747333507826
            ],
            [
              150.17270215746373,
              -29.19356746927734
            ],
            [
              150.1727128863186,
              -29.19355810324369
            ],
            [
              150.17270215750136,
              -29.193548737224752
            ],
            [
              150.17271288635627,
              -29.19353937118938
            ],
            [
              150.17270215753902,
              -29.193530005168746
            ],
            [
              150.17270752196643,
              -29.193525322150233
            ],
            [
              150.1727021575578,
              -29.19352063913948
            ],
            [
              150.17270752198525,
              -29.193515956120518
            ],
            [
              150.17270215757662,
              -29.193511273109337
            ],
            [
              150.17272897971384,
              -29.19348785801237
            ],
            [
              150.17270215767073,
              -29.193464442945796
            ],
            [
              150.17272361538048,
              -29.19344571085969
            ],
            [
              150.172702157746,
              -29.19342697879959
            ],
            [
              150.17271825102833,
              -29.193412929729856
            ],
            [
              150.17270215780246,
              -29.19339888068093
            ],
            [
              150.1727075222299,
              -29.19339419765641
            ],
            [
              150.17270215782128,
              -29.193389514639673
            ],
            [
              150.17271288667615,
              -29.19338014858978
            ],
            [
              150.1727021578589,
              -29.193370782554606
            ],
            [
              150.17272361556866,
              -29.19335205045138
            ],
            [
              150.17270215793417,
              -29.193333318374158
            ],
            [
              150.17272898007135,
              -29.193309903236564
            ],
            [
              150.17270215802827,
              -29.19328648812936
            ],
            [
              150.17271288688315,
              -29.193277122070054
            ],
            [
              150.1727021580659,
              -29.19326775602546
            ],
            [
              150.17270752249337,
              -29.193263072994938
            ],
            [
              150.17270215808475,
              -29.193258389972222
            ],
            [
              150.17271288693962,
              -29.193249023910344
            ],
            [
              150.17270215812238,
              -29.193239657863177
            ],
            [
              150.17271290842746,
              -29.193230273074025
            ]
          ]
        ]
      },
      "properties": {
        "color": "#1F77B4"
      }
    },
    {
      "type": "Feature",
      "properties": {
        "color": "#1F77B4"
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              150.1730713119909,
              -29.193174095428574
            ],
            [
              150.17311422741042,
              -29.193211559693207
            ],
            [
              150.1729081927946,
              -29.193391423923693
            ],
            [
              150.1727021581788,
              -29.193211559693207
            ],
            [
              150.17274507359832,
              -29.193174095428585
            ],
            [
              150.17270215832934,
              -29.193136631202304
            ],
            [
              150.1727075227568,
              -29.19313194816578
            ],
            [
              150.1727021583482,
              -29.19312726513707
            ],
            [
              150.1729081927946,
              -29.192947401222064
            ],
            [
              150.17311422724103,
              -29.19312726513707
            ],
            [
              150.1731088628324,
              -29.193131948165796
            ],
            [
              150.17311422725984,
              -29.193136631202304
            ],
            [
              150.1730713119909,
              -29.193174095428574
            ]
          ]
        ]
      }
    }
  ]
}

var r = turf.dissolve(fc)

1 Answer 1

1

Replace your code

var r = turf.dissolve(fc)

with

var r = turf.union(fc.features[0], fc.features[1])

The "dissolve" you expect is named "union" in Turf term. It takes two features and not an array contrary to dissolve. You will need to loop if you want to combine more than 2 features

1
  • Thanks - I found that running union on the whole featureGroup with turf 7 give me exactly what I need.
    – Ben
    Jul 15, 2020 at 2:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.