如何将FeatureCollection转换为GeometryCollection或MultiPolygon?

5

我可以帮助您翻译。这段文本是关于it技术的,需要手动绘制许多多边形并获取地理坐标。需要将绘制的多边形的坐标以GeoJSON格式获取。

GeoJSON格式如下:

"{"type":"MultiPolygon","coordinates":[[[[37.4653933,55.3959159]...}"
"{"type":"Polygon","coordinates":[[[37.475738525390625,55.41420507450017]...}"

在这种情况下:
"{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[-98.0419921875,39.027718840211605]...}]}"

我在http://geojson.io/上绘制多边形。 但是该网站只能提供FeatureCollection类型的数据格式。 我发现另一个网站-https://rodic.fr/blog/online-conversion-between-geometric-formats/,可以将多种格式转换为GeoJSON格式,但该网站仅支持GeometryCollection类型的转换。 我无法找到将FeatureCollection转换为GeometryCollection或MultiPolygon或Polygon的方法。
如何解决这个问题? 非常感谢!
1个回答

5
为了获取以geojson格式呈现的坐标,您可以使用以下代码片段:
WITH geojson_featurecollection AS (
    SELECT ''::json AS fc
)
SELECT (json_array_elements(fc->'features'))->>'geometry'
FROM geojson_featurecollection;

在其中您粘贴整个FeatureCollection定义(来自http://geojson.io网站,编辑后)放入引号之内。


是的!它完美地运作了!!非常感谢您!我找到了另一个转换为多边形的代码。我会测试这两个代码。再次感谢!SELECT ST_AsText(ST_Collect(ST_GeomFromGeoJSON(feat->>'geometry'))) FROM ( SELECT json_array_elements('PUT_HERE'::json->'features') AS feat ) AS f;[来源](https://gis.stackexchange.com/questions/142391/storing-geojson-featurecollection-to-postgresql-with-postgis) - Denis Or

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接