Search in sources :

Example 11 with DBGeometry

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

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

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

the class GISBrowserViewer method primeEditorValue.

@Override
public void primeEditorValue(@Nullable Object value) throws DBException {
    List<DBGeometry> geometries = new ArrayList<>();
    IDataController dataController = valueController.getDataController();
    if (dataController instanceof IResultSetController) {
        IResultSetController resultSetController = (IResultSetController) dataController;
        DBSTypedObject valueType = valueController.getValueType();
        List<GeometryDataUtils.GeomAttrs> geomAttrs = null;
        if (valueType instanceof DBSAttributeBase) {
            geomAttrs = GeometryDataUtils.extractGeometryAttributes(resultSetController);
        }
        IResultSetSelection selection = resultSetController.getSelection();
        Object[] selectedValues = selection.toArray();
        if (ArrayUtils.isEmpty(selectedValues)) {
            selectedValues = new Object[] { value };
        }
        for (Object cell : selectedValues) {
            DBGeometry geometry;
            DBDAttributeBinding attr;
            ResultSetRow row;
            if (cell instanceof DBGeometry) {
                attr = resultSetController.getActivePresentation().getCurrentAttribute();
                row = resultSetController.getCurrentRow();
                geometry = (DBGeometry) cell;
            } else {
                attr = selection.getElementAttribute(cell);
                row = selection.getElementRow(cell);
                Object cellValue = resultSetController.getModel().getCellValue(attr, row);
                geometry = GisTransformUtils.getGeometryValueFromObject(valueController.getDataController().getDataContainer(), valueController.getValueHandler(), valueController.getValueType(), cellValue);
            }
            if (geometry != null) {
                geometries.add(geometry);
                // Set properties
                if (valueType instanceof DBSAttributeBase) {
                    for (GeometryDataUtils.GeomAttrs ga : geomAttrs) {
                        if (ga.geomAttr.matches(attr, false)) {
                            GeometryDataUtils.setGeometryProperties(resultSetController, ga, geometry, row);
                            break;
                        }
                    }
                }
                if (geometry.getProperties() == null) {
                    geometry.setProperties(Collections.singletonMap("Object", geometry.getSRID()));
                }
            }
        }
    }
    leafletViewer.setGeometryData(geometries.toArray(new DBGeometry[0]));
}
Also used : GeometryDataUtils(org.jkiss.dbeaver.ui.gis.GeometryDataUtils) ArrayList(java.util.ArrayList) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) IDataController(org.jkiss.dbeaver.ui.data.IDataController) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject)

Example 13 with DBGeometry

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

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

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

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

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

the class GISBrowserViewer method primeEditorValue.

@Override
public void primeEditorValue(@Nullable Object value) throws DBException {
    List<DBGeometry> geometries = new ArrayList<>();
    IDataController dataController = valueController.getDataController();
    if (dataController instanceof IResultSetController) {
        IResultSetController resultSetController = (IResultSetController) dataController;
        DBSTypedObject valueType = valueController.getValueType();
        List<GeometryDataUtils.GeomAttrs> geomAttrs = null;
        if (valueType instanceof DBSAttributeBase) {
            geomAttrs = GeometryDataUtils.extractGeometryAttributes(resultSetController);
        }
        IResultSetSelection selection = resultSetController.getSelection();
        Object[] selectedValues = selection.toArray();
        if (ArrayUtils.isEmpty(selectedValues)) {
            selectedValues = new Object[] { value };
        }
        for (Object cell : selectedValues) {
            DBGeometry geometry;
            DBDAttributeBinding attr;
            ResultSetRow row;
            if (cell instanceof DBGeometry) {
                attr = resultSetController.getActivePresentation().getCurrentAttribute();
                row = resultSetController.getCurrentRow();
                geometry = (DBGeometry) cell;
            } else {
                attr = selection.getElementAttribute(cell);
                row = selection.getElementRow(cell);
                Object cellValue = resultSetController.getModel().getCellValue(attr, row);
                geometry = GisTransformUtils.getGeometryValueFromObject(valueController.getDataController().getDataContainer(), valueController.getValueHandler(), valueController.getValueType(), cellValue);
            }
            if (geometry != null) {
                geometries.add(geometry);
                // Set properties
                if (valueType instanceof DBSAttributeBase) {
                    for (GeometryDataUtils.GeomAttrs ga : geomAttrs) {
                        if (ga.geomAttr.matches(attr, false)) {
                            GeometryDataUtils.setGeometryProperties(resultSetController, ga, geometry, row);
                            break;
                        }
                    }
                }
                if (geometry.getProperties() == null) {
                    geometry.setProperties(Collections.singletonMap("Object", geometry.getSRID()));
                }
            }
        }
    }
    leafletViewer.setGeometryData(geometries.toArray(new DBGeometry[0]));
}
Also used : GeometryDataUtils(org.jkiss.dbeaver.ui.gis.GeometryDataUtils) ArrayList(java.util.ArrayList) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) IDataController(org.jkiss.dbeaver.ui.data.IDataController) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject)

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