use of org.jkiss.dbeaver.model.gis.DBGeometry in project dbeaver by dbeaver.
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());
}
}
Aggregations