【问题标题】:Error while inserting postgis MultiPolygon datatype using Spring JDBC使用 Spring JDBC 插入 postgis MultiPolygon 数据类型时出错
【发布时间】:2015-11-10 06:13:54
【问题描述】:

我正在尝试使用 Spring JDBC 将数据插入到 postgres (postgis) 数据库,但出现以下错误:

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)

我正在使用 Preparestatement setObject 方法来设置 posgis 数据类型。

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

表:

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,
)

需要帮助来解决此问题,或者是否有任何其他方法可以使用 Spring JDBC 保存 postgis 数据类型。

【问题讨论】:

    标签: java postgresql postgis spring-jdbc


    【解决方案1】:

    查看错误信息:

    org.postgresql.util.PSQLException: 错误: 几何有 Z 维度但是 列没有

    这意味着,您试图在仅接受 2D 数据的列中插入具有 Z 坐标的数据。

    如果您的所有数据都有 Z 坐标,只需更改为表格以使用 MultiPolygonZPointZ 而不是 MultiPolygonPoint

    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
    );
    

    当然,如果您有混合数据,部分有 Z 坐标,部分没有,这当然行不通。在这种情况下,您可以使用完全动态的几何/地理列,这意味着没有几何类型:

    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
    );
    

    【讨论】:

    • 如果不使用/不需要 Z 坐标,则使用 ST_Force_2D(geom)(或 ST_Force2D(geom) 更新版本)制作二维几何图形
    猜你喜欢
    • 2012-05-19
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    • 1970-01-01
    • 2023-03-06
    • 2013-10-12
    相关资源
    最近更新 更多