Please tell me how to convert GeoJSON coordinates to PostGIS coordinates suitable for a column with type Geometry? I have a table with data imported from an xml file and its coordinates in GeoJSON. I read, read - roughly understand what I need to use.
UPDATE
SELECT
ST_GeomFromGeoJSON
ST_SetSRID - 4326
I can get the data with such a request
SELECT ST_SetSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[38.1985294,55.4073349],[38.198862,55.4068537],[38.1994716,55.4055054],[38.1996559,55.4048253],[38.1997417,55.40474],[38.2006751,55.4047278],[38.2016515,55.4049654],[38.2014634,55.4057021],[38.2025811,55.4056548],[38.2045338,55.405984],[38.2039045,55.4068781],[38.2011687,55.4084618],[38.1997954,55.4081938],[38.1985294,55.4073349]]]}'),4326);
Answer:
0103000020E6100000010000000E000000B2255069691943407D02CD8C23B44B4065355D4F74194340D8E033C813B44B408B3D0F4988194340FBACD799E7B34B400B7A14538E194340F40BC050D1B34B40DF92D2229119434007B13385CEB34B408ECFBFB8AF1943401A64DC1ECEB34B403CD862B7CF1943407B81FEE7D5B34B40A52B7D8DC919434092B5E10BEEB34B40D4A46F2DEE19434093BB197FECB34B409BF6DE292E1A43408159A148F7B34B40ED80EB8A191A4340B47AE29414B44B404ABD5DE5BF1943402855EC7948B44B4014724AE59219434009B7C6B13FB44B40B2255069691943407D02CD8C23B44B40
It seems like this is what I need, but I don’t understand how to change it in the whole table.
How can I convert geodata? Geo Column geo_coordinates
And is it possible to change the column type in geometry after the conversion or do I need to create a new table and copy the data?
You should be able to just add the column and update:
ALTER TABLE your_table
ADD COLUMN geom geometry(Geometry,4326);
UPDATE your_table SET geom = ST_SetSRID(ST_GeomFromGeoJSON(geo_coordinates), 4326);
When that is done, you can drop the geo_coordinates column if you want. If the new column should be named geo_coordinates, you could rename it after dropping the old column.