locked
Is there a way to convert GEOMETRYCOLLECTION(LINESTING.., CIRCULARSTRING...), closed, to POLYGON? RRS feed

  • Question

  • Thanks for your help.

    I asked a question in T-SQL group and got pointed to this group.

    Here are details.

    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/432632fb-2644-41b1-87a1-5dea6fa32f98/is-there-a-way-to-convert-geometrycollection-to-polygon?forum=transactsql

    Since then I leared how to use polygon and create exterior ring from it, but not the other way. For example

    SELECT
        v.G
        ,Area = v.G.STArea()  -- 998452.893427388
        ,Perimeter = v.G.STExteriorRing()
        ,PerimeterLen = v.G.STExteriorRing().STLength() -- 4948.48159253663
    FROM
    (VALUES(geometry::Parse('POLYGON((
        2.0 2.0,1942.0 2.0
        1942 2, 1944.9441496002612 2.0719836214672149, 1947.8812193946646 2.2883618395944509
        , 1950.8041318865926 2.6486132448769482, 1953.7058436944699 3.1518697346542588, 1956.5793625242945 3.7969186049889245
        , 1959.4177640190637 4.582205472935474, 1962.2142084444893 5.5058380221579171, 1964.9619571707981 6.565590562869918
        , 1967.6543889108984 7.7589093951094057, 1970.285015675785 9.0829189624237578, 1972.8474984087329 10.534428781136892
        , 1975.3356622606086 12.109941128500729, 1977.7435114694865 13.805659471204763, 1980.0652438087175 15.617497613933502
        , 1982.2952645686319 17.541089545926308, 1984.4282000381877 19.571799961812303, 1986.4589104540737 21.704735431368107
        , 1988.3825023860666 23.934756191282531, 1990.1943405287952 26.256488530513391, 1991.8900588714994 28.664337739391346
        , 1993.465571218863 31.152501591267104, 1994.9170810375763 33.714984324215067, 1996.2410906048906 36.345611089101567
        , 1997.4344094371302 39.0380428292019, 1998.4941619778422 41.785791555510684, 1999.4177945270644 44.5822359809363
        , 2000.2030813950112 47.420637475705462, 2000.8481302653458 50.294156305530151, 2001.351386755123 53.195868113407386
        , 2001.7116381604055 56.118780605335445, 2001.9280163785327 59.0558503997389, 2002 62
        2002.0 62.0,2002.0 442.0
        2002 442, 2001.9279841455932 444.9441396593557, 2001.7115763101394 447.88119809694786, 2001.3512979594061 450.80409804854895
        , 2000.8480172358352 453.70579636683755, 2000.2029468666283 456.57930099287324, 1999.4176412415079 459.41768780446728
        , 1998.4939926671902 462.21411730084975, 1997.4342268076016 464.961851083429, 1996.2408973208207 467.6542680929312
        , 1994.9168797056739 470.28488056379371, 1993.4653643728057 472.84734965736834, 1991.8898489569274 475.33550073626355
        , 1990.1941298887641 477.74333824302022, 1988.3822932470082 480.06506014726881, 1986.4587049123268 482.2950719265549
        , 1984.4280000471447 484.42800004714474, 1982.2950719265548 486.45870491232677, 1980.0650601472687 488.38229324700814
        , 1977.7433382430202 490.19412988876405, 1975.3355007362636 491.88984895692738, 1972.8473496573683 493.46536437280554
        , 1970.2848805637936 494.91687970567386, 1967.6542680929313 496.24089732082086, 1964.9618510834291 497.43422680760153
        , 1962.2141173008497 498.49399266719018, 1959.4176878044673 499.41764124150791, 1956.5793009928732 500.20294686662834
        , 1953.7057963668376 500.84801723583507, 1950.8040980485489 501.35129795940617, 1947.8811980969479 501.71157631013944
        , 1944.9441396593556 501.9279841455932, 1942 502
        1942.0 502.0,2.0 502.0
        2.0 502.0,2.0 2.0
    ))'))) v(G)

    Is there simple way to go from geometry collection to polygon?

    SELECT G = geometry::Parse('GEOMETRYCOLLECTION(LINESTRING(2.0 2.0,1942.0 2.0),CIRCULARSTRING(1942.0 2.0,1984.43 19.5736,2002.0 62.0),LINESTRING(2002.0 62.0,2002.0 442.0),CIRCULARSTRING(2002.0 442.0,1984.43 484.426,1942.0 502.0),LINESTRING(1942.0 502.0,2.0 502.0),LINESTRING(2.0 502.0,2.0 2.0))')

    Thanks a lot.

    Vladimir


    Vladimir Moldovanenko

    Wednesday, April 22, 2020 12:38 AM

Answers

  • See T-SQL forum, I figured it out myself, after some tinkering, not the exact conversion but very close

    Vladimir Moldovanenko

    Wednesday, April 22, 2020 11:55 AM

All replies

  • See T-SQL forum, I figured it out myself, after some tinkering, not the exact conversion but very close

    Vladimir Moldovanenko

    Wednesday, April 22, 2020 11:55 AM
  • There is almost an answer... but does not account for CIRCULARSTRINGS

    STEnvelope()

    DECLARE @gc geometry = geometry::Parse('GEOMETRYCOLLECTION(LINESTRING(2.0 2.0,1942.0 2.0),CIRCULARSTRING(1942.0 2.0,1984.43 19.5736,2002.0 62.0),LINESTRING(2002.0 62.0,2002.0 442.0),CIRCULARSTRING(2002.0 442.0,1984.43 484.426,1942.0 502.0),LINESTRING(1942.0 502.0,2.0 502.0),LINESTRING(2.0 502.0,2.0 2.0))')
    SELECT GCollection = @gc, GPolygon = @gc.STEnvelope()


    Vladimir Moldovanenko

    Saturday, April 25, 2020 5:00 PM