orbisgis / h2gis

A spatial extension of the H2 database.
http://www.h2gis.org
GNU Lesser General Public License v3.0
203 stars 62 forks source link

GeoJSON driver read regression #1374

Closed ebocher closed 8 months ago

ebocher commented 8 months ago

Since this PR https://github.com/orbisgis/h2gis/pull/1367, there is an error to read some king of GeoJSON.

Pseudo code

 Statement stat = connection.createStatement();
        stat.execute("CALL GEOJSONREAD('/home/ebocher/Téléchargements/road.geojson')");

returns

org.h2.jdbc.JdbcSQLDataException: Erreur lors de la conversion de données "X'00a00000020000086a00000000' (ROAD: ""THE_GEOM"" GEOMETRY(LINESTRING, 2154))"
Data conversion error converting "X'00a00000020000086a00000000' (ROAD: ""THE_GEOM"" GEOMETRY(LINESTRING, 2154))"; SQL statement:
INSERT INTO ROAD VALUES(?,?,?,?,?,?,?,?,?,?,?) [22018-224]; SQL statement:

Data : road.zip

nicolas-f commented 8 months ago

its here:

org/h2/value/Value.java

        if (extTypeInfo != null) {
            int type = extTypeInfo.getType();
            Integer srid = extTypeInfo.getSrid();
            if (type != 0 && result.getTypeAndDimensionSystem() != type || srid != null && result.getSRID() != srid) {
                StringBuilder builder = ExtTypeInfoGeometry
                        .toSQL(new StringBuilder(), result.getTypeAndDimensionSystem(), result.getSRID())
                        .append(" -> ");
                extTypeInfo.getSQL(builder, TRACE_SQL_FLAGS);
                throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, builder.toString());
            }
        }

type==2 and result.getTypeAndDimensionSystem() == 1002

It does not work because:

    if (pts == null || pts.length == 0) {
      return 3; // unknown, assume default
    }

When there is no coordinates, geometry factory don't know if it is 2d or 3d when you create an empty linestring.

The geojson driver default is 2D linestring and jts default to 3d linestring..

ebocher commented 8 months ago

fix thanks @nicolas-f