问题
I want to insert geoJSON to a geometry
column of a table.
I have already inserted CSV file to the same column following this
tutorial,
I wonder how to insert the geoJSON to any geometry column?
I tried following this
answer but could not get what is going on there.
回答1:
Just use an update with the function ST_GeomFromGeoJSON:
UPDATE mytable SET geom = ST_GeomFromGeoJSON(json_column);
The following example inserts a GeoJSON point into a JSON column and afterwards updates the geometry column with the above mentioned function.
CREATE TEMPORARY TABLE mytable(
json_column json,
geom geometry);
INSERT INTO mytable (json_column) VALUES ('{
"type": "Point",
"coordinates": [7.0069, 51.1623]
}');
UPDATE mytable SET geom = ST_GeomFromGeoJSON(json_column);
SELECT * FROM mytable;
json_column | geom
--------------------------------------+--------------------------------------------
{ +| 01010000009E5E29CB10071C400612143FC6944940
"type": "Point", +|
"coordinates": [7.0069, 51.1623]+|
} |
(1 Zeile)
来源:https://stackoverflow.com/questions/60039007/how-to-insert-geojson-data-to-geometry-field-in-postgresql