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