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();
}
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]));
}
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);
}
}
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;
}
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]));
}
Aggregations