我如何将这些多边形元素阵列重塑为多角

发布于 2025-02-10 08:27:08 字数 19883 浏览 0 评论 0原文

我从外部API接收到我放入数组中的多边形。多边形是美国的每个县,因此我对我不感兴趣。多边形阵列还使其将它们加载到我的Web应用程序中,非常沉重和缓慢。然而,我感兴趣的是这些县 - 生产者结合的外部界限。

我希望从ST_GEOMFROMTEXT中制作多重分子或ST_EXTERIORT,但是当我这样做时,我只会在PostgreSQL中出现错误。

以下是多边形阵列的一个示例,我们称其为“多重账户”。我试图做一个st_geomfromtext(乘数),但获取错误:“错误:function st_geomfromtext(json)不存在”(安装了tostGIS,我倾向于将其作为通用错误消息)。

那么,如何在PostgreSQL中将这一大阵列多边形降低到一个多角形呢?

    [
    {
        "type": "Polygon",
        "coordinates":
        [
            [
                [
                    -96.2044982,
                    44.1972122
                ],
                [
                    -96.19869990000001,
                    44.197311400000004
                ],
                [
                    -96.07869720000001,
                    44.1966133
                ],
                [
                    -96.06369780000001,
                    44.1965103
                ],
                [
                    -96.06349940000001,
                    44.182312
                ],
                [
                    -96.0635986,
                    44.139911600000005
                ],
                [
                    -96.06389610000001,
                    44.11581030000001
                ],
                [
                    -96.06439970000001,
                    44.01391220000001
                ],
                [
                    -96.0641937,
                    44.000011400000005
                ],
                [
                    -96.0639953,
                    43.9501113
                ],
                [
                    -96.0639953,
                    43.89161300000001
                ],
                [
                    -96.0641937,
                    43.88521190000001
                ],
                [
                    -96.0641937,
                    43.87001030000001
                ],
                [
                    -96.06439970000001,
                    43.856410900000014
                ],
                [
                    -96.06369780000001,
                    43.849212600000016
                ],
                [
                    -96.07279960000001,
                    43.84901040000002
                ],
                [
                    -96.12529750000002,
                    43.84871290000002
                ],
                [
                    -96.19999690000002,
                    43.84871290000002
                ],
                [
                    -96.23219290000002,
                    43.84851070000002
                ],
                [
                    -96.28549950000001,
                    43.84881210000002
                ],
                [
                    -96.29159540000002,
                    43.84871290000002
                ],
                [
                    -96.30690000000001,
                    43.84891120000002
                ],
                [
                    -96.34439840000002,
                    43.84891120000002
                ],
                [
                    -96.38990020000001,
                    43.84931180000002
                ],
                [
                    -96.39519500000002,
                    43.849212600000016
                ],
                [
                    -96.40179440000001,
                    43.84941100000002
                ],
                [
                    -96.40569300000001,
                    43.84931180000002
                ],
                [
                    -96.45349880000002,
                    43.84961310000001
                ],
                [
                    -96.45329280000001,
                    43.85221090000001
                ],
                [
                    -96.45329280000001,
                    43.89121240000001
                ],
                [
                    -96.45349880000002,
                    43.89851370000001
                ],
                [
                    -96.45329280000001,
                    43.906612300000006
                ],
                [
                    -96.45339960000001,
                    43.944713500000006
                ],
                [
                    -96.4531936,
                    43.963413200000005
                ],
                [
                    -96.45339960000001,
                    43.9738121
                ],
                [
                    -96.45309440000001,
                    44.007713300000006
                ],
                [
                    -96.45339960000001,
                    44.02461240000001
                ],
                [
                    -96.45309440000001,
                    44.04521170000001
                ],
                [
                    -96.4531936,
                    44.09291070000001
                ],
                [
                    -96.45299530000001,
                    44.111312800000015
                ],
                [
                    -96.45269770000002,
                    44.19691080000001
                ],
                [
                    -96.44499960000002,
                    44.19721220000001
                ],
                [
                    -96.42469780000002,
                    44.19711300000001
                ],
                [
                    -96.33889770000002,
                    44.19731140000001
                ],
                [
                    -96.31189720000002,
                    44.197513500000014
                ],
                [
                    -96.28569790000002,
                    44.19741050000001
                ],
                [
                    -96.24029540000002,
                    44.197513500000014
                ],
                [
                    -96.2044982,
                    44.1972122
                ]
            ]
        ]
    },
    {
        "type": "Polygon",
        "coordinates":
        [
            [
                [
                    -95.8482971,
                    44.6307106
                ],
                [
                    -95.8287963,
                    44.6308135
                ],
                [
                    -95.7878952,
                    44.6306114
                ],
                [
                    -95.75029749999999,
                    44.6302108
                ],
                [
                    -95.68560019999998,
                    44.6299133
                ],
                [
                    -95.64429469999997,
                    44.630413
                ],
                [
                    -95.60399619999997,
                    44.6299133
                ],
                [
                    -95.60389699999998,
                    44.6157112
                ],
                [
                    -95.60409539999998,
                    44.600212
                ],
                [
                    -95.60419459999997,
                    44.5641136
                ],
                [
                    -95.60439299999997,
                    44.5550117
                ],
                [
                    -95.60429379999998,
                    44.5425109
                ],
                [
                    -95.59489439999997,
                    44.5422134
                ],
                [
                    -95.59459679999998,
                    44.5363121
                ],
                [
                    -95.59449759999998,
                    44.530014
                ],
                [
                    -95.59479519999998,
                    44.5119133
                ],
                [
                    -95.59449759999998,
                    44.5084114
                ],
                [
                    -95.59459679999998,
                    44.5003128
                ],
                [
                    -95.59479519999998,
                    44.496612500000005
                ],
                [
                    -95.59439839999997,
                    44.493911700000005
                ],
                [
                    -95.59439839999997,
                    44.472213700000005
                ],
                [
                    -95.59389489999998,
                    44.428512500000004
                ],
                [
                    -95.59409329999998,
                    44.399414
                ],
                [
                    -95.59389489999998,
                    44.355812
                ],
                [
                    -95.59399409999997,
                    44.3423118
                ],
                [
                    -95.59339899999998,
                    44.2976112
                ],
                [
                    -95.59329979999998,
                    44.2545127
                ],
                [
                    -95.59349819999998,
                    44.195713
                ],
                [
                    -95.64389799999998,
                    44.195110299999996
                ],
                [
                    -95.68359369999997,
                    44.195510799999994
                ],
                [
                    -95.70299529999997,
                    44.19591139999999
                ],
                [
                    -95.72369379999996,
                    44.19591139999999
                ],
                [
                    -95.74339289999996,
                    44.19621269999999
                ],
                [
                    -95.75449369999995,
                    44.19611349999999
                ],
                [
                    -95.78009789999996,
                    44.19631189999999
                ],
                [
                    -95.80489339999995,
                    44.19611349999999
                ],
                [
                    -95.83619679999995,
                    44.19641109999999
                ],
                [
                    -95.91689299999996,
                    44.19631189999999
                ],
                [
                    -95.94629659999995,
                    44.19651029999999
                ],
                [
                    -95.99159999999995,
                    44.19641109999999
                ],
                [
                    -96.00319669999995,
                    44.19661329999999
                ],
                [
                    -96.04369349999995,
                    44.19631189999999
                ],
                [
                    -96.06369779999994,
                    44.19651029999999
                ],
                [
                    -96.07869719999994,
                    44.196613299999996
                ],
                [
                    -96.07869719999994,
                    44.233310599999996
                ],
                [
                    -96.07919309999994,
                    44.254711099999994
                ],
                [
                    -96.07929989999994,
                    44.274810699999996
                ],
                [
                    -96.07929989999994,
                    44.3136138
                ],
                [
                    -96.07909389999993,
                    44.3363113
                ],
                [
                    -96.07929989999994,
                    44.3496131
                ],
                [
                    -96.07919309999994,
                    44.3539123
                ],
                [
                    -96.07929989999994,
                    44.364311199999996
                ],
                [
                    -96.07919309999994,
                    44.39241019999999
                ],
                [
                    -96.07939909999995,
                    44.430011699999994
                ],
                [
                    -96.07929989999995,
                    44.43311299999999
                ],
                [
                    -96.07989499999995,
                    44.45901099999999
                ],
                [
                    -96.07979579999996,
                    44.50311269999999
                ],
                [
                    -96.08020009999996,
                    44.53941339999999
                ],
                [
                    -96.08009329999996,
                    44.54341119999999
                ],
                [
                    -96.08289329999995,
                    44.54341119999999
                ],
                [
                    -96.09299459999995,
                    44.54411309999999
                ],
                [
                    -96.09289549999995,
                    44.58691019999999
                ],
                [
                    -96.09329979999995,
                    44.60411069999999
                ],
                [
                    -96.09289549999995,
                    44.61581029999999
                ],
                [
                    -96.09289549999995,
                    44.63051219999999
                ],
                [
                    -96.05309289999995,
                    44.63021079999999
                ],
                [
                    -96.01219939999996,
                    44.63011159999999
                ],
                [
                    -95.99199669999996,
                    44.63051219999999
                ],
                [
                    -95.95520009999996,
                    44.63081349999999
                ],
                [
                    -95.86939999999996,
                    44.63091269999999
                ],
                [
                    -95.8482971,
                    44.6307106
                ]
            ]
        ]
    },
    {
        "type": "Polygon",
        "coordinates":
        [
            [
                [
                    -97.8511962,
                    43.8499107
                ],
                [
                    -97.8278961,
                    43.8496131
                ],
                [
                    -97.79010000000001,
                    43.8499107
                ],
                [
                    -97.7371978,
                    43.8498115
                ],
                [
                    -97.66059870000001,
                    43.8492126
                ],
                [
                    -97.63529960000001,
                    43.8492126
                ],
                [
                    -97.60919950000002,
                    43.8489112
                ],
                [
                    -97.60869590000001,
                    43.832912400000005
                ],
                [
                    -97.60889430000002,
                    43.80101390000001
                ],
                [
                    -97.60879510000002,
                    43.76031110000001
                ],
                [
                    -97.60820000000002,
                    43.74571220000001
                ],
                [
                    -97.60729980000002,
                    43.73531340000001
                ],
                [
                    -97.60669700000003,
                    43.71661370000001
                ],
                [
                    -97.60679620000002,
                    43.710311800000014
                ],
                [
                    -97.60639950000002,
                    43.670013400000016
                ],
                [
                    -97.60659790000003,
                    43.65921020000002
                ],
                [
                    -97.60699460000002,
                    43.60061260000002
                ],
                [
                    -97.60719290000002,
                    43.54261390000002
                ],
                [
                    -97.60699460000002,
                    43.51681130000002
                ],
                [
                    -97.60709380000002,
                    43.499813000000024
                ],
                [
                    -97.62599940000001,
                    43.499813000000024
                ],
                [
                    -97.63959500000001,
                    43.49961090000002
                ],
                [
                    -97.73880000000001,
                    43.49971380000002
                ],
                [
                    -97.74639890000002,
                    43.49961090000002
                ],
                [
                    -97.75090020000002,
                    43.499813000000024
                ],
                [
                    -97.75619500000002,
                    43.49961090000002
                ],
                [
                    -97.79199980000001,
                    43.49951170000002
                ],
                [
                    -97.90519710000001,
                    43.49961090000002
                ],
                [
                    -97.93779750000002,
                    43.49931330000002
                ],
                [
                    -97.95800010000002,
                    43.49941250000002
                ],
                [
                    -97.96459960000001,
                    43.49961090000002
                ],
                [
                    -97.96489710000002,
                    43.507011400000025
                ],
                [
                    -97.96489710000002,
                    43.51341240000002
                ],
                [
                    -97.96629330000002,
                    43.57731240000002
                ],
                [
                    -97.96649930000002,
                    43.60071180000002
                ],
                [
                    -97.96709440000002,
                    43.62971110000002
                ],
                [
                    -97.96679680000003,
                    43.644210800000025
                ],
                [
                    -97.96689600000002,
                    43.648712100000026
                ],
                [
                    -97.96649930000002,
                    43.678413300000024
                ],
                [
                    -97.96829980000003,
                    43.75111380000003
                ],
                [
                    -97.96839900000002,
                    43.761413500000025
                ],
                [
                    -97.96819300000001,
                    43.76681130000002
                ],
                [
                    -97.96839900000002,
                    43.77771370000002
                ],
                [
                    -97.96839900000002,
                    43.79061120000002
                ],
                [
                    -97.96809380000002,
                    43.81261060000002
                ],
                [
                    -97.96839900000002,
                    43.81841270000002
                ],
                [
                    -97.96799460000003,
                    43.825412700000015
                ],
                [
                    -97.96749870000002,
                    43.85011290000001
                ],
                [
                    -97.95139310000002,
                    43.85061260000001
                ],
                [
                    -97.90670010000002,
                    43.85061260000001
                ],
                [
                    -97.8511962,
                    43.8499107
                ]
            ]
        ]
    }
]

From an external API I am receiving polygons which I put into an array. The polygons are, each of them, counties in the USA and as such are of no interest to me. The array of polygons also makes loading them onto my web application very heavy and slow. What I am interested in, however, is the outer bounds of what these county-polygons combine.

I would have hope to make a MultiPolygon or ST_ExteriorRing from a ST_GeomFromText but I only get errors in my Postgresql when I do that.

Below is an example of an array of Polygons, let's call it "multipleCounties". I have tried to do a ST_GeomFromText(multipleCounties) but get error: "ERROR: function st_geomfromtext(json) does not exist" (Postgis is installed, I tend to get this as a generic error message).

So, how can I reduce this large array of Polygons into one MultiPolygon in Postgresql?

    [
    {
        "type": "Polygon",
        "coordinates":
        [
            [
                [
                    -96.2044982,
                    44.1972122
                ],
                [
                    -96.19869990000001,
                    44.197311400000004
                ],
                [
                    -96.07869720000001,
                    44.1966133
                ],
                [
                    -96.06369780000001,
                    44.1965103
                ],
                [
                    -96.06349940000001,
                    44.182312
                ],
                [
                    -96.0635986,
                    44.139911600000005
                ],
                [
                    -96.06389610000001,
                    44.11581030000001
                ],
                [
                    -96.06439970000001,
                    44.01391220000001
                ],
                [
                    -96.0641937,
                    44.000011400000005
                ],
                [
                    -96.0639953,
                    43.9501113
                ],
                [
                    -96.0639953,
                    43.89161300000001
                ],
                [
                    -96.0641937,
                    43.88521190000001
                ],
                [
                    -96.0641937,
                    43.87001030000001
                ],
                [
                    -96.06439970000001,
                    43.856410900000014
                ],
                [
                    -96.06369780000001,
                    43.849212600000016
                ],
                [
                    -96.07279960000001,
                    43.84901040000002
                ],
                [
                    -96.12529750000002,
                    43.84871290000002
                ],
                [
                    -96.19999690000002,
                    43.84871290000002
                ],
                [
                    -96.23219290000002,
                    43.84851070000002
                ],
                [
                    -96.28549950000001,
                    43.84881210000002
                ],
                [
                    -96.29159540000002,
                    43.84871290000002
                ],
                [
                    -96.30690000000001,
                    43.84891120000002
                ],
                [
                    -96.34439840000002,
                    43.84891120000002
                ],
                [
                    -96.38990020000001,
                    43.84931180000002
                ],
                [
                    -96.39519500000002,
                    43.849212600000016
                ],
                [
                    -96.40179440000001,
                    43.84941100000002
                ],
                [
                    -96.40569300000001,
                    43.84931180000002
                ],
                [
                    -96.45349880000002,
                    43.84961310000001
                ],
                [
                    -96.45329280000001,
                    43.85221090000001
                ],
                [
                    -96.45329280000001,
                    43.89121240000001
                ],
                [
                    -96.45349880000002,
                    43.89851370000001
                ],
                [
                    -96.45329280000001,
                    43.906612300000006
                ],
                [
                    -96.45339960000001,
                    43.944713500000006
                ],
                [
                    -96.4531936,
                    43.963413200000005
                ],
                [
                    -96.45339960000001,
                    43.9738121
                ],
                [
                    -96.45309440000001,
                    44.007713300000006
                ],
                [
                    -96.45339960000001,
                    44.02461240000001
                ],
                [
                    -96.45309440000001,
                    44.04521170000001
                ],
                [
                    -96.4531936,
                    44.09291070000001
                ],
                [
                    -96.45299530000001,
                    44.111312800000015
                ],
                [
                    -96.45269770000002,
                    44.19691080000001
                ],
                [
                    -96.44499960000002,
                    44.19721220000001
                ],
                [
                    -96.42469780000002,
                    44.19711300000001
                ],
                [
                    -96.33889770000002,
                    44.19731140000001
                ],
                [
                    -96.31189720000002,
                    44.197513500000014
                ],
                [
                    -96.28569790000002,
                    44.19741050000001
                ],
                [
                    -96.24029540000002,
                    44.197513500000014
                ],
                [
                    -96.2044982,
                    44.1972122
                ]
            ]
        ]
    },
    {
        "type": "Polygon",
        "coordinates":
        [
            [
                [
                    -95.8482971,
                    44.6307106
                ],
                [
                    -95.8287963,
                    44.6308135
                ],
                [
                    -95.7878952,
                    44.6306114
                ],
                [
                    -95.75029749999999,
                    44.6302108
                ],
                [
                    -95.68560019999998,
                    44.6299133
                ],
                [
                    -95.64429469999997,
                    44.630413
                ],
                [
                    -95.60399619999997,
                    44.6299133
                ],
                [
                    -95.60389699999998,
                    44.6157112
                ],
                [
                    -95.60409539999998,
                    44.600212
                ],
                [
                    -95.60419459999997,
                    44.5641136
                ],
                [
                    -95.60439299999997,
                    44.5550117
                ],
                [
                    -95.60429379999998,
                    44.5425109
                ],
                [
                    -95.59489439999997,
                    44.5422134
                ],
                [
                    -95.59459679999998,
                    44.5363121
                ],
                [
                    -95.59449759999998,
                    44.530014
                ],
                [
                    -95.59479519999998,
                    44.5119133
                ],
                [
                    -95.59449759999998,
                    44.5084114
                ],
                [
                    -95.59459679999998,
                    44.5003128
                ],
                [
                    -95.59479519999998,
                    44.496612500000005
                ],
                [
                    -95.59439839999997,
                    44.493911700000005
                ],
                [
                    -95.59439839999997,
                    44.472213700000005
                ],
                [
                    -95.59389489999998,
                    44.428512500000004
                ],
                [
                    -95.59409329999998,
                    44.399414
                ],
                [
                    -95.59389489999998,
                    44.355812
                ],
                [
                    -95.59399409999997,
                    44.3423118
                ],
                [
                    -95.59339899999998,
                    44.2976112
                ],
                [
                    -95.59329979999998,
                    44.2545127
                ],
                [
                    -95.59349819999998,
                    44.195713
                ],
                [
                    -95.64389799999998,
                    44.195110299999996
                ],
                [
                    -95.68359369999997,
                    44.195510799999994
                ],
                [
                    -95.70299529999997,
                    44.19591139999999
                ],
                [
                    -95.72369379999996,
                    44.19591139999999
                ],
                [
                    -95.74339289999996,
                    44.19621269999999
                ],
                [
                    -95.75449369999995,
                    44.19611349999999
                ],
                [
                    -95.78009789999996,
                    44.19631189999999
                ],
                [
                    -95.80489339999995,
                    44.19611349999999
                ],
                [
                    -95.83619679999995,
                    44.19641109999999
                ],
                [
                    -95.91689299999996,
                    44.19631189999999
                ],
                [
                    -95.94629659999995,
                    44.19651029999999
                ],
                [
                    -95.99159999999995,
                    44.19641109999999
                ],
                [
                    -96.00319669999995,
                    44.19661329999999
                ],
                [
                    -96.04369349999995,
                    44.19631189999999
                ],
                [
                    -96.06369779999994,
                    44.19651029999999
                ],
                [
                    -96.07869719999994,
                    44.196613299999996
                ],
                [
                    -96.07869719999994,
                    44.233310599999996
                ],
                [
                    -96.07919309999994,
                    44.254711099999994
                ],
                [
                    -96.07929989999994,
                    44.274810699999996
                ],
                [
                    -96.07929989999994,
                    44.3136138
                ],
                [
                    -96.07909389999993,
                    44.3363113
                ],
                [
                    -96.07929989999994,
                    44.3496131
                ],
                [
                    -96.07919309999994,
                    44.3539123
                ],
                [
                    -96.07929989999994,
                    44.364311199999996
                ],
                [
                    -96.07919309999994,
                    44.39241019999999
                ],
                [
                    -96.07939909999995,
                    44.430011699999994
                ],
                [
                    -96.07929989999995,
                    44.43311299999999
                ],
                [
                    -96.07989499999995,
                    44.45901099999999
                ],
                [
                    -96.07979579999996,
                    44.50311269999999
                ],
                [
                    -96.08020009999996,
                    44.53941339999999
                ],
                [
                    -96.08009329999996,
                    44.54341119999999
                ],
                [
                    -96.08289329999995,
                    44.54341119999999
                ],
                [
                    -96.09299459999995,
                    44.54411309999999
                ],
                [
                    -96.09289549999995,
                    44.58691019999999
                ],
                [
                    -96.09329979999995,
                    44.60411069999999
                ],
                [
                    -96.09289549999995,
                    44.61581029999999
                ],
                [
                    -96.09289549999995,
                    44.63051219999999
                ],
                [
                    -96.05309289999995,
                    44.63021079999999
                ],
                [
                    -96.01219939999996,
                    44.63011159999999
                ],
                [
                    -95.99199669999996,
                    44.63051219999999
                ],
                [
                    -95.95520009999996,
                    44.63081349999999
                ],
                [
                    -95.86939999999996,
                    44.63091269999999
                ],
                [
                    -95.8482971,
                    44.6307106
                ]
            ]
        ]
    },
    {
        "type": "Polygon",
        "coordinates":
        [
            [
                [
                    -97.8511962,
                    43.8499107
                ],
                [
                    -97.8278961,
                    43.8496131
                ],
                [
                    -97.79010000000001,
                    43.8499107
                ],
                [
                    -97.7371978,
                    43.8498115
                ],
                [
                    -97.66059870000001,
                    43.8492126
                ],
                [
                    -97.63529960000001,
                    43.8492126
                ],
                [
                    -97.60919950000002,
                    43.8489112
                ],
                [
                    -97.60869590000001,
                    43.832912400000005
                ],
                [
                    -97.60889430000002,
                    43.80101390000001
                ],
                [
                    -97.60879510000002,
                    43.76031110000001
                ],
                [
                    -97.60820000000002,
                    43.74571220000001
                ],
                [
                    -97.60729980000002,
                    43.73531340000001
                ],
                [
                    -97.60669700000003,
                    43.71661370000001
                ],
                [
                    -97.60679620000002,
                    43.710311800000014
                ],
                [
                    -97.60639950000002,
                    43.670013400000016
                ],
                [
                    -97.60659790000003,
                    43.65921020000002
                ],
                [
                    -97.60699460000002,
                    43.60061260000002
                ],
                [
                    -97.60719290000002,
                    43.54261390000002
                ],
                [
                    -97.60699460000002,
                    43.51681130000002
                ],
                [
                    -97.60709380000002,
                    43.499813000000024
                ],
                [
                    -97.62599940000001,
                    43.499813000000024
                ],
                [
                    -97.63959500000001,
                    43.49961090000002
                ],
                [
                    -97.73880000000001,
                    43.49971380000002
                ],
                [
                    -97.74639890000002,
                    43.49961090000002
                ],
                [
                    -97.75090020000002,
                    43.499813000000024
                ],
                [
                    -97.75619500000002,
                    43.49961090000002
                ],
                [
                    -97.79199980000001,
                    43.49951170000002
                ],
                [
                    -97.90519710000001,
                    43.49961090000002
                ],
                [
                    -97.93779750000002,
                    43.49931330000002
                ],
                [
                    -97.95800010000002,
                    43.49941250000002
                ],
                [
                    -97.96459960000001,
                    43.49961090000002
                ],
                [
                    -97.96489710000002,
                    43.507011400000025
                ],
                [
                    -97.96489710000002,
                    43.51341240000002
                ],
                [
                    -97.96629330000002,
                    43.57731240000002
                ],
                [
                    -97.96649930000002,
                    43.60071180000002
                ],
                [
                    -97.96709440000002,
                    43.62971110000002
                ],
                [
                    -97.96679680000003,
                    43.644210800000025
                ],
                [
                    -97.96689600000002,
                    43.648712100000026
                ],
                [
                    -97.96649930000002,
                    43.678413300000024
                ],
                [
                    -97.96829980000003,
                    43.75111380000003
                ],
                [
                    -97.96839900000002,
                    43.761413500000025
                ],
                [
                    -97.96819300000001,
                    43.76681130000002
                ],
                [
                    -97.96839900000002,
                    43.77771370000002
                ],
                [
                    -97.96839900000002,
                    43.79061120000002
                ],
                [
                    -97.96809380000002,
                    43.81261060000002
                ],
                [
                    -97.96839900000002,
                    43.81841270000002
                ],
                [
                    -97.96799460000003,
                    43.825412700000015
                ],
                [
                    -97.96749870000002,
                    43.85011290000001
                ],
                [
                    -97.95139310000002,
                    43.85061260000001
                ],
                [
                    -97.90670010000002,
                    43.85061260000001
                ],
                [
                    -97.8511962,
                    43.8499107
                ]
            ]
        ]
    }
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不…忘初心 2025-02-17 08:27:08

您的数据值是一个JSON数组,其中包含Geojson Polygon特征对象。 ST_GEOMFROMTEXT()期望A wkt string 。为了将此JSON数组转换为后几何形状,您首先需要从数组中获取一组Polygon功能,然后使用ST_GEOMFROMGEOJSON(POLY_JSON)将每个功能从集合转换为

SELECT 
  st_geomfromgeojson(poly_json) as multipoly
FROM 
  json_array_elements(counties_json) polys(poly_json)

:单个(多)多边形,您可以使用 st_union溶解连续多边形之间的边界。
“

SELECT 
  st_asgeojson(st_union(st_geomfromgeojson(poly_json))) as multipoly
FROM 
  json_array_elements(counties_json) polys(poly_json)

ST_UNION的大小将使您提供的数据样本降低约70%。请记住,只有在您的县多边形连续的情况下,才会发生显着尺寸。

如果您只需要对该区域的粗略近似,则可以使用 st_envelope() /a>以获取每个县多边形的最小边界矩形,然后st_union()一起:

SELECT 
  st_asgeojson(st_union(st_envelope(st_geomfromgeojson(poly_json)))) as multipoly 
FROM 
  json_array_elements(counties_json) polys(poly_json)

这种方法将您的样本数据的大小降低约98%,但如果会导致误报匹配,如果您将其与其他数据相结合。

如果您仅使用这些边界来确定某个点/多边形/线数据他们,您可以考虑将县直接保存为表格几何形状,并使用 noreferrer“ /a>确定县和其他特征之间是否存在交集。这将使您完全不需要将GeoJson表示形式加载到应用程序层中 - 只需确保您在几何列上创建GIST索引,如果您可以使用此路线,以进行有效的索引查找。

Your data value is a JSON array which contains geojson polygon feature objects. st_GeomFromText() expects a WKT String. In order to transform this JSON array into a postgis geometry you first need to get the set of polygon features from the array, then use the st_geomfromgeojson(poly_json) to convert each feature from the set:

SELECT 
  st_geomfromgeojson(poly_json) as multipoly
FROM 
  json_array_elements(counties_json) polys(poly_json)

To generate a single (multi)polygon, you can use the st_union aggregate which will dissolve boundaries between contiguous polygons.
Image

SELECT 
  st_asgeojson(st_union(st_geomfromgeojson(poly_json))) as multipoly
FROM 
  json_array_elements(counties_json) polys(poly_json)

st_union will reduce the size by about 70% for the data sample you provided. Keep in mind though that significant size reduction will only only occur when where your county polygons are contiguous.

If you only need a rough approximation of the area, you can use st_envelope() to get the minimum bounding rectangle of each county polygon and then st_union() those together:

SELECT 
  st_asgeojson(st_union(st_envelope(st_geomfromgeojson(poly_json)))) as multipoly 
FROM 
  json_array_elements(counties_json) polys(poly_json)

This approach reduces the size of your sample data by about 98%, but will result in false positive matches if you intersect it with other data.

If you are only using these boundaries to determine if some point/polygon/line data intersects them, you could consider saving the counties directly as postgis geometries in a table and using st_intersects(county_geom,some_other_geom) to determine if an intersection exists between the counties and other features. This will prevent you from needing to load the geojson representation in your application layer at all -just make sure you create a GIST INDEX on the geometry column for efficient index lookups if you go this route.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文