How to convert FeatureCollection to GeometryCollection or MultiPolygon?

老子叫甜甜 提交于 2020-01-16 08:38:10

问题


I have many polygons that need to be drawn manually and then get geo-coordinates. I need to get the coordinates of the drawn polygons in GeoJSON format.

In this format:

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

Or in this:

"{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[-98.0419921875,39.027718840211605]...}]}"

I draw polygons at http://geojson.io/. But from this site I can only get data in the format with the FeatureCollection type. I found another site - https://rodic.fr/blog/online-conversion-between-geometric-formats/, on which I can convert to GeoJSON format, but this site can only convert type GeometryCollection.

I cannot find how to convert FeatureCollection to GeometryCollection or MultiPolygon or to Polygon.

How to solve? Many thx!


回答1:


To get the coordinates in the geojson format, you can use the following snippet:

WITH geojson_featurecollection AS (
    SELECT ''::json AS fc
)
SELECT (json_array_elements(fc->'features'))->>'geometry'
FROM geojson_featurecollection;

in which you paste your entire FeatureCollection definition (coming from the http://geojson.io website after your edits) inside of the quotes



来源:https://stackoverflow.com/questions/57795511/how-to-convert-featurecollection-to-geometrycollection-or-multipolygon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!