提交 5ab38b31 编写于 作者: S serge-rider

#5832 Spatial viewer: flip coordinates command

上级 771dfa7b
......@@ -78,6 +78,7 @@ public class GISLeafletViewer {
private List<Integer> recentSRIDs = new ArrayList<>();
private boolean toolsVisible = true;
private boolean flipCoordinates = false;
private final Composite composite;
public GISLeafletViewer(Composite parent, IValueController valueController) {
......@@ -195,6 +196,13 @@ public class GISLeafletViewer {
boolean showMap = false;
for (int i = 0; i < values.length; i++) {
DBGeometry value = values[i];
if (flipCoordinates) {
try {
value = value.flipCoordinates();
} catch (DBException e) {
log.error(e);
}
}
Object targetValue = value.getRawValue();
int srid = sourceSRID == 0 ? value.getSRID() : sourceSRID;
if (srid == 0) {
......@@ -425,9 +433,34 @@ public class GISLeafletViewer {
}
});
toolBarManager.add(new Separator());
Action crsSelectorAction = new ChangeCRSAction();
toolBarManager.add(ActionUtils.makeActionContribution(crsSelectorAction, true));
toolBarManager.add(new Action("Flip coordinates", Action.AS_CHECK_BOX) {
{
setToolTipText("Flip latitude/longitude coordinates in source data");
setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.LINK_TO_EDITOR));
}
@Override
public boolean isChecked() {
return flipCoordinates;
}
@Override
public void run() {
flipCoordinates = !flipCoordinates;
try {
reloadGeometryData(lastValue, true);
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Render error", "Error rendering geometry", e);
}
updateToolbar();
}
});
toolBarManager.add(new Separator());
toolBarManager.add(new Action("Show/Hide controls", Action.AS_CHECK_BOX) {
......
......@@ -17,9 +17,13 @@
package org.jkiss.dbeaver.model.gis;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.data.gis.handlers.GeometryConverter;
import org.jkiss.dbeaver.model.data.DBDValue;
import org.jkiss.utils.CommonUtils;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import java.util.Map;
......@@ -91,6 +95,21 @@ public class DBGeometry implements DBDValue {
this.srid = srid;
}
public DBGeometry flipCoordinates() throws DBException {
Geometry jtsGeometry = getGeometry();
if (jtsGeometry == null) {
try {
jtsGeometry = new WKTReader().read(getString());
} catch (ParseException e) {
throw new DBException("Error parsing geometry WKT", e);
}
} else {
jtsGeometry = jtsGeometry.copy();
}
jtsGeometry.apply(GeometryConverter.INVERT_COORDINATE_FILTER);
return new DBGeometry(jtsGeometry, srid);
}
public Map<String, Object> getProperties() {
return properties;
}
......@@ -98,4 +117,5 @@ public class DBGeometry implements DBDValue {
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册