1

I try to store a polygon in GeoJSON format into my PostGIS table. Both are using the CRS EPSG:3857. This is how the polygon is defined. Note that I put in some whitespace to make it more readable.

{
    "type":"Polygon",
    "coordinates":[
        [-91.23046875,45.460130637921],
        [-79.8046875,49.837982453085],
        [-69.08203125,43.452918893555],
        [-88.2421875,32.694865977875],
        [-91.23046875,45.460130637921]
    ],
    "crs":{"type":"name","properties":{"name":"EPSG:3857"}}
}

To store that in my database I use the following SQL query.

INSERT INTO tablename (name, polygon)
VALUES ('name', ST_GeomFromGeoJSON('GeoJSON string comes here...'))

But for some reason the above query throws an error.

ERROR:  Geometry has Z dimension but column does not

What is wrong in my attempt?

1
  • It seems to me that the problem is in your table, probably you have a z column in it.
    – Gery
    Commented May 16, 2013 at 14:10

1 Answer 1

4

I found the solution. The GeoJSON specification says that the coordinates of a polygon are an array of line strings. Therefore I had to wrap them with additional brackets.

{
    "type":"Polygon",
    "coordinates":
    [
        [
            [-91.23046875,45.460130637921],
            [-79.8046875,49.837982453085],
            [-69.08203125,43.452918893555],
            [-88.2421875,32.694865977875],
            [-91.23046875,45.460130637921]
        ]
    ],
    "crs":{"type":"name","properties":{"name":"EPSG:3857"}}
}
1
  • 1
    I have the same error, but i don't understand the solution..... Can explain pls ?
    – Sergio_Az
    Commented Jan 30, 2016 at 16:43

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