Unverified 提交 197006b8 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1007 from katzyn/ValueGeometry

Copy also SRID in ValueGeometry.getGeometry()
...@@ -11,6 +11,7 @@ import java.util.Arrays; ...@@ -11,6 +11,7 @@ import java.util.Arrays;
import org.h2.engine.Mode; import org.h2.engine.Mode;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.util.Utils;
import org.locationtech.jts.geom.CoordinateSequence; import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.CoordinateSequenceFilter; import org.locationtech.jts.geom.CoordinateSequenceFilter;
import org.locationtech.jts.geom.Envelope; import org.locationtech.jts.geom.Envelope;
...@@ -140,7 +141,20 @@ public class ValueGeometry extends Value { ...@@ -140,7 +141,20 @@ public class ValueGeometry extends Value {
* @return a copy of the geometry object * @return a copy of the geometry object
*/ */
public Geometry getGeometry() { public Geometry getGeometry() {
return getGeometryNoCopy().copy(); Geometry geometry = getGeometryNoCopy();
Geometry copy = geometry.copy();
/*
* Geometry factory is not preserved in WKB format, but SRID is preserved.
*
* We use a new factory to read geometries from WKB with default SRID value of
* 0.
*
* Geometry.copy() copies the geometry factory and copied value has SRID form
* the factory instead of original SRID value. So we need to copy SRID here with
* non-recommended (but not deprecated) setSRID() method.
*/
copy.setSRID(geometry.getSRID());
return copy;
} }
public Geometry getGeometryNoCopy() { public Geometry getGeometryNoCopy() {
...@@ -221,7 +235,7 @@ public class ValueGeometry extends Value { ...@@ -221,7 +235,7 @@ public class ValueGeometry extends Value {
@Override @Override
public byte[] getBytes() { public byte[] getBytes() {
return getWKB(); return Utils.cloneByteArray(getWKB());
} }
@Override @Override
......
...@@ -648,13 +648,14 @@ public class TestSpatial extends TestBase { ...@@ -648,13 +648,14 @@ public class TestSpatial extends TestBase {
GeometryFactory geometryFactory = new GeometryFactory(); GeometryFactory geometryFactory = new GeometryFactory();
Geometry geometry = geometryFactory.createPoint(new Coordinate(0, 0)); Geometry geometry = geometryFactory.createPoint(new Coordinate(0, 0));
geometry.setSRID(27572); geometry.setSRID(27572);
ValueGeometry valueGeometry = ValueGeometry valueGeometry = ValueGeometry.getFromGeometry(geometry);
ValueGeometry.getFromGeometry(geometry);
Geometry geometry2 = geometryFactory.createPoint(new Coordinate(0, 0)); Geometry geometry2 = geometryFactory.createPoint(new Coordinate(0, 0));
geometry2.setSRID(5326); geometry2.setSRID(5326);
ValueGeometry valueGeometry2 = ValueGeometry valueGeometry2 = ValueGeometry.getFromGeometry(geometry2);
ValueGeometry.getFromGeometry(geometry2);
assertFalse(valueGeometry.equals(valueGeometry2)); assertFalse(valueGeometry.equals(valueGeometry2));
ValueGeometry valueGeometry3 = ValueGeometry.getFromGeometry(geometry);
assertEquals(valueGeometry, valueGeometry3);
assertEquals(geometry.getSRID(), valueGeometry3.getGeometry().getSRID());
// Check illegal geometry (no WKB representation) // Check illegal geometry (no WKB representation)
try { try {
ValueGeometry.get("POINT EMPTY"); ValueGeometry.get("POINT EMPTY");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论