Search in sources :

Example 16 with DBGeometry

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

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)

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