Search in sources :

Example 1 with DBGeometry

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

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 2 with DBGeometry

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

the class GISTextViewer method primeEditorValue.

@Override
public void primeEditorValue(Object value) throws DBException {
    super.primeEditorValue(value);
    valueSRID = 0;
    if (value instanceof Geometry) {
        this.valueSRID = ((Geometry) value).getSRID();
    } else if (value instanceof DBGeometry) {
        this.valueSRID = ((DBGeometry) value).getSRID();
    }
    if (valueSRID == 0) {
        DBSTypedObject column = valueController.getValueType();
        if (column instanceof GisAttribute) {
            valueSRID = ((GisAttribute) column).getAttributeGeometrySRID(new VoidProgressMonitor());
        }
    }
    updateToolBar();
}
Also used : DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) Geometry(org.locationtech.jts.geom.Geometry) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) GisAttribute(org.jkiss.dbeaver.model.gis.GisAttribute) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)

Example 3 with DBGeometry

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

the class GISGeometryValueHandler method getValueFromObject.

@NotNull
@Override
public DBGeometry getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy, boolean validateValue) throws DBCException {
    DBGeometry geometry;
    if (object == null) {
        geometry = new DBGeometry();
    } else if (object instanceof DBGeometry) {
        if (copy) {
            geometry = ((DBGeometry) object).copy();
        } else {
            geometry = (DBGeometry) object;
        }
    } else if (object instanceof Geometry) {
        geometry = new DBGeometry((Geometry) object);
    } else if (object instanceof byte[]) {
        try {
            Geometry jtsGeometry = convertGeometryFromBinaryFormat(session, (byte[]) object);
            // if (invertCoordinates) {
            // jtsGeometry.apply(GeometryConverter.INVERT_COORDINATE_FILTER);
            // }
            geometry = new DBGeometry(jtsGeometry);
        } catch (DBCException e) {
            throw new DBCException("Error parsing geometry value from binary", e);
        }
    } else if (object instanceof String) {
        try {
            Geometry jtsGeometry = GeometryConverter.getInstance().fromWKT((String) object);
            geometry = new DBGeometry(jtsGeometry);
        } catch (Exception e) {
            throw new DBCException("Error parsing geometry value from string", e);
        }
    } else {
        throw new DBCException("Unsupported geometry value: " + object);
    }
    if (geometry.getSRID() == 0) {
        geometry.setSRID(defaultSRID);
    }
    return geometry;
}
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) SQLException(java.sql.SQLException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) NotNull(org.jkiss.code.NotNull)

Example 4 with DBGeometry

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

the class GeometryPresentation method refreshData.

@Override
public void refreshData(boolean refreshMetadata, boolean append, boolean keepState) {
    controller.updateEditControls();
    List<GeometryDataUtils.GeomAttrs> result = GeometryDataUtils.extractGeometryAttributes(getController());
    ResultSetModel model = getController().getModel();
    // Now extract all geom values from data
    List<DBGeometry> geometries = new ArrayList<>();
    for (int i = 0; i < result.size(); i++) {
        GeometryDataUtils.GeomAttrs geomAttrs = result.get(i);
        Color attrColor;
        if (i == 0) {
            attrColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
        } else {
            attrColor = UIColors.getColor(i);
        }
        RGB rgb = attrColor.getRGB();
        String colorCode = String.format("#%02x%02x%02x", rgb.red, rgb.green, rgb.blue);
        for (ResultSetRow row : model.getAllRows()) {
            Object value = model.getCellValue(geomAttrs.geomAttr, row);
            DBGeometry geometry = GisTransformUtils.getGeometryValueFromObject(controller.getDataContainer(), geomAttrs.geomAttr.getValueHandler(), geomAttrs.geomAttr, value);
            if (geometry != null && !(geometry.getSRID() != 0 && geometry.isEmpty())) {
                geometries.add(geometry);
                // Now get description
                Map<String, Object> properties = new LinkedHashMap<>();
                properties.put("id", DBUtils.getObjectFullName(geomAttrs.geomAttr, DBPEvaluationContext.UI));
                properties.put("color", colorCode);
                if (!geomAttrs.descAttrs.isEmpty()) {
                    Map<String, Object> infoMap = new LinkedHashMap<>();
                    properties.put("info", infoMap);
                    for (DBDAttributeBinding da : geomAttrs.descAttrs) {
                        Object descValue = model.getCellValue(da, row);
                        if (!DBUtils.isNullValue(descValue) && !(descValue instanceof String && ((String) descValue).isEmpty())) {
                            infoMap.put(da.getName(), descValue);
                        }
                    }
                }
                geometry.setProperties(properties);
            }
        }
    }
    try {
        leafletViewer.setGeometryData(geometries.toArray(new DBGeometry[0]));
    } catch (DBException e) {
        DBWorkbench.getPlatformUI().showError("Error rendering GIS data", "Error while rendering geometry data", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) GeometryDataUtils(org.jkiss.dbeaver.ui.gis.GeometryDataUtils) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry)

Example 5 with DBGeometry

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

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