use of org.jkiss.dbeaver.model.gis.DBGeometry in project dbeaver by serge-rider.
the class HANAGeometryValueHandler method fetchColumnValue.
@Override
protected Object fetchColumnValue(DBCSession session, JDBCResultSet resultSet, DBSTypedObject type, int index) throws DBCException, SQLException {
byte[] wkb = resultSet.getBytes(index);
if (wkb == null) {
return null;
}
HANAWKBParser parser = new HANAWKBParser();
try {
Geometry g = parser.parse(wkb);
return new DBGeometry(g);
} catch (HANAWKBParserException e) {
throw new DBCException(e, session.getExecutionContext());
}
}
use of org.jkiss.dbeaver.model.gis.DBGeometry in project dbeaver by serge-rider.
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());
}
}
use of org.jkiss.dbeaver.model.gis.DBGeometry in project dbeaver by dbeaver.
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 dbeaver.
the class HANAGeometryValueHandler method fetchColumnValue.
@Override
protected Object fetchColumnValue(DBCSession session, JDBCResultSet resultSet, DBSTypedObject type, int index) throws DBCException, SQLException {
byte[] wkb = resultSet.getBytes(index);
if (wkb == null) {
return null;
}
HANAWKBParser parser = new HANAWKBParser();
try {
Geometry g = parser.parse(wkb);
return new DBGeometry(g);
} catch (HANAWKBParserException e) {
throw new DBCException(e, session.getExecutionContext());
}
}
use of org.jkiss.dbeaver.model.gis.DBGeometry in project dbeaver by dbeaver.
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