Search in sources :

Example 6 with DBGeometry

use of org.jkiss.dbeaver.model.gis.DBGeometry in project dbeaver by serge-rider.

the class HANAGeometryValueHandler method fetchColumnValue.

@Override
protected Object fetchColumnValue(DBCSession session, JDBCResultSet resultSet, DBSTypedObject type, int index) throws DBCException, SQLException {
    byte[] wkb = resultSet.getBytes(index);
    if (wkb == null) {
        return null;
    }
    HANAWKBParser parser = new HANAWKBParser();
    try {
        Geometry g = parser.parse(wkb);
        return new DBGeometry(g);
    } catch (HANAWKBParserException e) {
        throw new DBCException(e, session.getExecutionContext());
    }
}
Also used : DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) Geometry(org.locationtech.jts.geom.Geometry) HANAWKBParserException(org.jkiss.dbeaver.ext.hana.model.data.wkb.HANAWKBParserException) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) DBCException(org.jkiss.dbeaver.model.exec.DBCException) HANAWKBParser(org.jkiss.dbeaver.ext.hana.model.data.wkb.HANAWKBParser)

Example 7 with DBGeometry

use of org.jkiss.dbeaver.model.gis.DBGeometry in project dbeaver by serge-rider.

the class PostgreGeometryValueHandler method makeGeometryFromWKT.

private DBGeometry makeGeometryFromWKT(DBCSession session, String pgString, int dimensions) throws DBCException {
    if (CommonUtils.isEmpty(pgString)) {
        return new DBGeometry();
    }
    // Convert from PostGIS EWKT to Geometry type
    try {
        int divPos = pgString.indexOf(';');
        if (divPos == -1) {
            // No SRID
            if (dimensions == 2) {
                try {
                    Geometry geometry = new WKTReader().read(pgString);
                    return new DBGeometry(geometry);
                } catch (ParseException e) {
                    // Can't parse
                    return new DBGeometry(pgString);
                }
            } else {
                return new DBGeometry(pgString);
            }
        }
        String sridString = pgString.substring(0, divPos);
        String wktString = pgString.substring(divPos + 1);
        int srid = 0;
        if (sridString.startsWith("SRID=")) {
            srid = CommonUtils.toInt(sridString.substring(5));
        }
        if (dimensions == 2) {
            Geometry geometry = new WKTReader().read(wktString);
            if (srid > 0) {
                geometry.setSRID(srid);
            }
            return new DBGeometry(geometry);
        } else {
            return new DBGeometry(wktString, srid);
        }
    } catch (Throwable e) {
        throw new DBCException(e, session.getExecutionContext());
    }
}
Also used : DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) Geometry(org.locationtech.jts.geom.Geometry) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) DBCException(org.jkiss.dbeaver.model.exec.DBCException) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Example 8 with DBGeometry

use of org.jkiss.dbeaver.model.gis.DBGeometry in project dbeaver by dbeaver.

the class GISTextViewer method setValueSRID.

@Override
public void setValueSRID(int srid) {
    this.valueSRID = srid;
    try {
        Object geometry = extractEditorValue();
        if (geometry instanceof DBGeometry) {
            ((DBGeometry) geometry).setSRID(valueSRID);
        } else if (geometry instanceof Geometry) {
            ((Geometry) geometry).setSRID(valueSRID);
        }
        valueController.updateValue(geometry, false);
    } catch (DBCException e) {
        log.error(e);
    }
    updateToolBar();
}
Also used : DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) Geometry(org.locationtech.jts.geom.Geometry) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 9 with DBGeometry

use of org.jkiss.dbeaver.model.gis.DBGeometry in project dbeaver by dbeaver.

the class HANAGeometryValueHandler method fetchColumnValue.

@Override
protected Object fetchColumnValue(DBCSession session, JDBCResultSet resultSet, DBSTypedObject type, int index) throws DBCException, SQLException {
    byte[] wkb = resultSet.getBytes(index);
    if (wkb == null) {
        return null;
    }
    HANAWKBParser parser = new HANAWKBParser();
    try {
        Geometry g = parser.parse(wkb);
        return new DBGeometry(g);
    } catch (HANAWKBParserException e) {
        throw new DBCException(e, session.getExecutionContext());
    }
}
Also used : DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) Geometry(org.locationtech.jts.geom.Geometry) HANAWKBParserException(org.jkiss.dbeaver.ext.hana.model.data.wkb.HANAWKBParserException) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) DBCException(org.jkiss.dbeaver.model.exec.DBCException) HANAWKBParser(org.jkiss.dbeaver.ext.hana.model.data.wkb.HANAWKBParser)

Example 10 with DBGeometry

use of org.jkiss.dbeaver.model.gis.DBGeometry in project dbeaver by dbeaver.

the class HANAGeometryValueHandler method bindParameter.

@Override
protected void bindParameter(JDBCSession session, JDBCPreparedStatement statement, DBSTypedObject paramType, int paramIndex, Object value) throws DBCException, SQLException {
    Object geometry = value;
    int srid = 0;
    if (geometry instanceof DBGeometry) {
        srid = ((DBGeometry) geometry).getSRID();
        geometry = ((DBGeometry) geometry).getRawValue();
    }
    if (srid == 0 && paramType instanceof GisAttribute) {
        srid = ((GisAttribute) paramType).getAttributeGeometrySRID(session.getProgressMonitor());
    }
    if (geometry == null) {
        statement.setNull(paramIndex, paramType.getTypeID());
    } else if (geometry instanceof Geometry) {
        Geometry g = (Geometry) geometry;
        if (g.getSRID() == 0) {
            g.setSRID(srid);
        }
        try {
            statement.setBytes(paramIndex, HANAWKBWriter.write(g, HANAXyzmModeFinder.findXyzmMode(g)));
        } catch (HANAWKBWriterException e) {
            throw new DBCException(e, session.getExecutionContext());
        }
    } else {
        throw new DBCException("Could not bind the value because the value type is not a known geometry type");
    }
}
Also used : DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) Geometry(org.locationtech.jts.geom.Geometry) HANAWKBWriterException(org.jkiss.dbeaver.ext.hana.model.data.wkb.HANAWKBWriterException) GisAttribute(org.jkiss.dbeaver.model.gis.GisAttribute) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Aggregations

DBGeometry (org.jkiss.dbeaver.model.gis.DBGeometry)16 Geometry (org.locationtech.jts.geom.Geometry)12 DBCException (org.jkiss.dbeaver.model.exec.DBCException)10 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)8 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)4 GisAttribute (org.jkiss.dbeaver.model.gis.GisAttribute)4 GeometryDataUtils (org.jkiss.dbeaver.ui.gis.GeometryDataUtils)4 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Color (org.eclipse.swt.graphics.Color)2 RGB (org.eclipse.swt.graphics.RGB)2 NotNull (org.jkiss.code.NotNull)2 DBException (org.jkiss.dbeaver.DBException)2 HANAWKBParser (org.jkiss.dbeaver.ext.hana.model.data.wkb.HANAWKBParser)2 HANAWKBParserException (org.jkiss.dbeaver.ext.hana.model.data.wkb.HANAWKBParserException)2 HANAWKBWriterException (org.jkiss.dbeaver.ext.hana.model.data.wkb.HANAWKBWriterException)2 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)2 DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)2 IResultSetController (org.jkiss.dbeaver.ui.controls.resultset.IResultSetController)2 IResultSetSelection (org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection)2