Monday 17 July 2017

postgresql - PostGIS error reads "Geometry has Z dimension but column does not"



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?



Answer



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"}}

}

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...