I have a legacy areas data, where some records are in Polygon
and some in MultiPolygon
format stored in noSQL DB in JSON format. I need to migrate that data to a PostGIS database with area
column, which has type of ST_MultiPolygon.
So, my question is: how can I convert Polygon
areas into MultiPolygon
using RGeo gem or something similar?
Right now, I'm converting MultiPolygons like that:
multipolygon = RGeo::GeoJSON.decode(location.area)
PostgisLocation.create(area: multipolygon)
But when area is not multipolygon, but polygon, DB throws exception: PG::InternalError: ERROR: parse error - invalid geometry
Example of polygon's text representation:
POLYGON ((-6.00606009808446 54.5901007810674, -6.01003269079491 54.5928954129105, -5.97732358111394 54.5870863982436, -6.00606009808446 54.5901007810674))
The stupidest thing that comes to my mind is to replace POLYGON
with MULTIPOLYGON
word, and add extra ()
parentheses. But, I believe there should be a better way to convert that using RGeo library. I spent some time reading documentation for RGeo but didn't find anything that could help me.