Amit Tamrakar
Amit Tamrakar

Reputation: 528

Error while inserting postgis MultiPolygon datatype using Spring JDBC

I am trying to insert data using Spring JDBC to postgres (postgis) database but getting below error:

org.postgresql.util.PSQLException: ERROR: Geometry has Z dimension but column does not
at     org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:363)
at com.springjdbc.jdbc.EutranCellGeoComputedInfoDAOImpl.save(EutranCellGeoComputedInfoDAOImpl.java:33)
at com.springjdbc.jdbc.SpringMain.main(SpringMain.java:48)

I am using Preparestatement setObject method to set the posgis datatypes.

        ps.setObject(2, cityinfo.getCellShape().toString(),java.sql.Types.OTHER);
        ps.setObject(3, cityinfo.getCellLocation().toString(),java.sql.Types.OTHER);

Table:

CREATE TABLE area_details_table
(
  area geography(MultiPolygon,4326),
  location geography(Point,4326),
  calculated_cell_radius numeric(8,2),
  latitude numeric(9,6),
  longitude numeric(9,6),
  id smallint,
)

Need help to resolve this issue or is there any other way to save the postgis datatypes using Spring JDBC.

Upvotes: 2

Views: 5051

Answers (1)

Tom-db
Tom-db

Reputation: 6868

Look at the error message:

org.postgresql.util.PSQLException: ERROR: Geometry has Z dimension but column does not

This means, you are trying to insert data with Z coordinates in column which accept only 2D data.

If all your data have Z coordinates, simply change to table to use MultiPolygonZ and PointZ instead of MultiPolygon and Point

CREATE TABLE area_details_table
(
  area geography(MultiPolygonZ,4326),
  location geography(PointZ,4326),
  calculated_cell_radius numeric(8,2),
  latitude numeric(9,6),
  longitude numeric(9,6),
  id smallint
);

Of course, this will not work, if you have mixed data, partly with Z coordinates, partly without. In this case you can use fully dynamical geometry/geography columns, this mean, without geometry type:

CREATE TABLE area_details_table
(
  area geography,
  location geography,
  calculated_cell_radius numeric(8,2),
  latitude numeric(9,6),
  longitude numeric(9,6),
  id smallint
);

Upvotes: 4

Related Questions