Skip to content

geom.UnionMany fails with "internal error extracting geometry: no rings to extract" #668

@mnovicio

Description

@mnovicio

Problem:

Union of multiple geometries fails with geom.UnionMany(gs []geom.Geometry) with error that says internal error extracting geometry: no rings to extract.

Union of the same geometries is successful using geos.UnaryUnion.

Sample test code:

func TestGeomUnion(t *testing.T) {
	geoms := []geom.Geometry{
		mustGeoJSON(t, `{"type":"MultiPolygon","coordinates":[[[[-87.62421257793903,41.39764795906342],[-87.62420654296875,41.397646450042785],[-87.62420654296875,41.39764695304968],[-87.62416161596775,41.397637395918245],[-87.62415960431099,41.39764393500832],[-87.62410126626492,41.39763085682753],[-87.62410339298516,41.39762487432261],[-87.62410339336095,41.397624874409054],[-87.62421344649789,41.39764576585199],[-87.62421257793903,41.39764795906342]]],[[[-87.62404158711433,41.39745681617114],[-87.62420319020748,41.39749403877844],[-87.6242026502297,41.397495364425644],[-87.62420264993521,41.39749536435664],[-87.62413840985234,41.397482951866046],[-87.62403983775401,41.39746055108124],[-87.62404158711433,41.39745681617114]]],[[[-87.62391954660416,41.39758105911507],[-87.62392119420248,41.39757693935211],[-87.62392119442447,41.39757693941165],[-87.6239291859734,41.397578755513464],[-87.62392771482985,41.39758304634879],[-87.62391954660416,41.39758105911507]]],[[[-87.62402482330799,41.39761325158001],[-87.62396648526192,41.39760067640029],[-87.62396708180846,41.397598998302605],[-87.62396708218431,41.39759899838907],[-87.62402591965431,41.39761016753592],[-87.62402482330799,41.39761325158001]]]]}`),
		mustGeoJSON(t, `{"type":"MultiPolygon","coordinates":[[[[-87.62422129511833,41.397514159097845],[-87.6242246478796,41.39751063804239],[-87.62422859770999,41.39751063804239],[-87.62422934174538,41.39751063804239],[-87.62423202395439,41.39751315308203],[-87.62424007058144,41.397514159097845],[-87.6242434233427,41.397517177145225],[-87.6242434233427,41.39752069820032],[-87.62423946264127,41.397522678919835],[-87.62422593614133,41.39751938122142],[-87.62422129511833,41.397514159097845]]],[[[-87.62420654296875,41.39748599064894],[-87.62420654296875,41.397485487640814],[-87.62420251965523,41.39748498463269],[-87.62419891701943,41.39748048049657],[-87.624207178155,41.39748207671596],[-87.62420893681185,41.39748248885456],[-87.62421063126413,41.3974830325109],[-87.6242122442154,41.397483702135574],[-87.62421375920124,41.39748449089327],[-87.62421516075717,41.39748539073262],[-87.6242164345766,41.39748639246838],[-87.62421756765681,41.39748748587517],[-87.62421854843173,41.397488659791875],[-87.62421936688986,41.39748990223556],[-87.62422001467672,41.397491200523774],[-87.62422048517993,41.39749254140405],[-87.62422077359668,41.39749391118913],[-87.62422087698293,41.39749529589673],[-87.62422082211445,41.39749621512772],[-87.62420654296875,41.39748599064894]]],[[[-87.62420654296875,41.39765701318648],[-87.62420654296875,41.39765600717286],[-87.62421056628227,41.397653995145596],[-87.62421324849129,41.39765449815243],[-87.62421701337621,41.3976592051252],[-87.62421590008874,41.39765935988056],[-87.62421416603986,41.39765947381383],[-87.62421242546463,41.39765946270053],[-87.62421069423094,41.397659326641985],[-87.62420898812152,41.39765906687855],[-87.62420899357804,41.397659067915036],[-87.62420604474384,41.39765850813634],[-87.62420654296875,41.39765701318648]]],[[[-87.6240348815918,41.397450780070656],[-87.62402415275574,41.39746084023782],[-87.62401610612869,41.39746084023782],[-87.62401387572902,41.39745665745553],[-87.6240215021472,41.39745842680161],[-87.62402264165466,41.397455993937264],[-87.62402329666267,41.39745478277123],[-87.62402410175937,41.39745362403454],[-87.62402504963794,41.397452528243555],[-87.62402613169566,41.3974515053434],[-87.62402733811206,41.39745056461764],[-87.62402865793804,41.39744971460401],[-87.62403007919521,41.39744896301703],[-87.62403158898465,41.39744831667789],[-87.62403317360392,41.397447781452556],[-87.62403481867145,41.39744736219862],[-87.62403650925704,41.39744706272111],[-87.62403823001745,41.397446885738006],[-87.62403996533548,41.39744683285552],[-87.62404169946193,41.39744690455365],[-87.62404341665828,41.39744710018164],[-87.62404510133979,41.397447417964045],[-87.62405168073352,41.39744891314965],[-87.6240348815918,41.397450780070656]]],[[[-87.62401409447193,41.39761777864412],[-87.62403421103954,41.39761727563702],[-87.62404292821884,41.39761274857286],[-87.6240523159504,41.39761224556572],[-87.62406505644321,41.3976167726299],[-87.62407913804054,41.39761777864412],[-87.62409187853336,41.39762934780651],[-87.62410193681717,41.3976333718625],[-87.62410461902618,41.397637395918245],[-87.62410445659496,41.397639223606355],[-87.62409893975861,41.397638176342504],[-87.62409721290705,41.397637779093365],[-87.62409554671505,41.39763725516227],[-87.62409395752817,41.39763660968908],[-87.62409246093647,41.39763584900594],[-87.62409107162166,41.39763498057522],[-87.62409054781364,41.397634580966205],[-87.62403539291145,41.397621878478574],[-87.62403515702614,41.397621994791656],[-87.62403358694466,41.39762261406486],[-87.62403194441826,41.3976231156037],[-87.62403024497316,41.39762349466726],[-87.62402850467363,41.39762374767239],[-87.62402673997009,41.39762387222754],[-87.6240249675436,41.39762386715533],[-87.62402320414834,41.39762373250369],[-87.62402146645303,41.39762346954546],[-87.6240114235828,41.39762156310229],[-87.62401409447193,41.39761777864412]]],[[[-87.62397654354572,41.39745228909582],[-87.6239725202322,41.39745731917949],[-87.6239624619484,41.397458325196176],[-87.62395575642586,41.397455307146075],[-87.62395441532135,41.39745128307905],[-87.62395534881179,41.39745034941373],[-87.62395626638761,41.39744972341221],[-87.62395770979515,41.39744891829488],[-87.62395925142329,41.397448224048624],[-87.62396087630455,41.39744764741381],[-87.62396256866319,41.39744719398892],[-87.62396431206825,41.397446868176175],[-87.62396608959328,41.39744667313887],[-87.62396788398048,41.397446610770594],[-87.62396964164054,41.39744668024725],[-87.62397654354572,41.39745228909582]]],[[[-87.62397654354572,41.39760369444365],[-87.623982578516,41.39760369444365],[-87.62398861348629,41.39760822150841],[-87.62398861348629,41.39761224556572],[-87.62398229974659,41.39761603450963],[-87.62397074639594,41.3976138413312],[-87.62397654354572,41.39760369444365]]],[[[-87.62391149997711,41.397583071144595],[-87.62391552329063,41.39758105911507],[-87.62391820549965,41.397581562122454],[-87.623921403287,41.3975844406643],[-87.62392155826092,41.39758458016668],[-87.62392289936543,41.39759212527668],[-87.62391987732425,41.39759542265905],[-87.62391876331321,41.39759500328741],[-87.62391721237802,41.39759426404723],[-87.6239157680276,41.39759341111883],[-87.62391444490447,41.39759245314897],[-87.62391325642203,41.39759139984933],[-87.62391221462886,41.39759026189796],[-87.62391133008636,41.39758905083112],[-87.62391086664078,41.39758823022903],[-87.62390965476884,41.39758755564437],[-87.62390935879748,41.39758735429706],[-87.62391149997711,41.397583071144595]]]]}`),
	}

	unionedGeom, err := geom.UnionMany(geoms)
	assert.NoError(t, err)
	assert.NoError(t, unionedGeom.Validate())

	unionedGeom, err = geos.UnaryUnion(geom.NewGeometryCollection(geoms).AsGeometry())
	require.NoError(t, err)
	require.NoError(t, unionedGeom.Validate())

	require.NoError(t, unionedGeom.Validate())
	b, err := unionedGeom.MarshalJSON()
	require.NoError(t, err)
	fmt.Println(string(b))
}

func mustGeoJSON(t *testing.T, geojson string) geom.Geometry {
	var g geom.Geometry
	err := json.NewDecoder(strings.NewReader(geojson)).Decode(&g)
	require.NoError(t, err)
	return g
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions