2

I have this column Multipolygon which has data stored in this format which is in TEXT:

MULTIPOLYGON(-115.528984981578 51.2006109579736, -115.526434407604 51.1974145241941, -115.546464451 51.1829871710806, -115.550742857 51.1811679580806, -115.553744470846 51.1774015011275, -115.555832234 51.1721837870805, -115.554786455 51.1622000020805, -115.555224178 51.1614472730805, -115.555944264 51.1610654680805, -115.562343333 51.1605351540804, -115.56378839 51.1627737510805, -115.56474867 51.1633405150805, -115.565514534 51.1637801920805, -115.566251065 51.1640867590805, -115.569573964129 51.1647997677008, -115.590143361 51.1644759770805, -115.592124654 51.1682185420805, -115.581962807 51.1831234430806, -115.572065302636 51.1872314983322, -115.563133431 51.1914924190807, -115.561930802 51.1918677000807, -115.535909179968 51.2067716415175, -115.528984981578 51.2006109579736)

How can I convert this column data-type into geometry data EPSG:4326 type so that I can plot this in QGIS?

when I do this:

SELECT ST_GeomFromText(multipolygon,4326) FROM transient.crea_multipolygon_data;

I get an error:

[XX000] ERROR: parse error - invalid geometry Hint: "MULTIPOLYGON(-115.528984981578 " <-- parse error at position 31 within geometry

But the same Multipolygon text when I plot over here https://arthur-e.github.io/Wicket/sandbox-gmaps3.html looks great so not sure what's going on:

Example

1 Answer 1

5

From the documentation of ST_GeomFromText, if you use MULTIPOLYGON, your SQL in PostGIS lack of brackets as part of a multipolygon is into two brackets.

Here is a working code:

SELECT ST_GeomFromText('MULTIPOLYGON(((-115.528984981578 51.2006109579736, -115.526434407604 51.1974145241941, -115.546464451 51.1829871710806, -115.550742857 51.1811679580806, -115.553744470846 51.1774015011275, -115.555832234 51.1721837870805, -115.554786455 51.1622000020805, -115.555224178 51.1614472730805, -115.555944264 51.1610654680805, -115.562343333 51.1605351540804, -115.56378839 51.1627737510805, -115.56474867 51.1633405150805, -115.565514534 51.1637801920805, -115.566251065 51.1640867590805, -115.569573964129 51.1647997677008, -115.590143361 51.1644759770805, -115.592124654 51.1682185420805, -115.581962807 51.1831234430806, -115.572065302636 51.1872314983322, -115.563133431 51.1914924190807, -115.561930802 51.1918677000807, -115.535909179968 51.2067716415175, -115.528984981578 51.2006109579736)))', 4326);

1
  • This is actually not multipolygon but polygon, so POLYGON(( ... )) with double brackets would be also OK.
    – TomazicM
    May 1, 2019 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.