Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8097e478
Unverified
提交
8097e478
authored
5月 01, 2018
作者:
Evgenij Ryazanov
提交者:
GitHub
5月 01, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1111 from katzyn/geometry
Use a better fix for issue with SRID
上级
c433682f
05c0d6d6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
53 行增加
和
13 行删除
+53
-13
ValueGeometry.java
h2/src/main/org/h2/value/ValueGeometry.java
+31
-13
TestSpatial.java
h2/src/test/org/h2/test/db/TestSpatial.java
+22
-0
没有找到文件。
h2/src/main/org/h2/value/ValueGeometry.java
浏览文件 @
8097e478
...
...
@@ -10,6 +10,7 @@ import java.sql.SQLException;
import
java.util.Arrays
;
import
org.h2.engine.Mode
;
import
org.h2.message.DbException
;
import
org.h2.util.Bits
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
import
org.locationtech.jts.geom.CoordinateSequence
;
...
...
@@ -71,7 +72,11 @@ public class ValueGeometry extends Value {
* @return the value
*/
public
static
ValueGeometry
getFromGeometry
(
Object
o
)
{
return
get
((
Geometry
)
o
);
/*
* Do not pass untrusted source geometry object to a cache, use only its WKB
* representation. Geometries are not fully immutable.
*/
return
get
(
convertToWKB
((
Geometry
)
o
));
}
private
static
ValueGeometry
get
(
Geometry
g
)
{
...
...
@@ -143,24 +148,37 @@ public class ValueGeometry extends Value {
public
Geometry
getGeometry
()
{
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
()
{
if
(
geometry
==
null
)
{
try
{
geometry
=
new
WKBReader
().
read
(
bytes
);
int
srid
=
0
;
getSRID:
if
(
bytes
.
length
>=
9
)
{
boolean
bigEndian
;
switch
(
bytes
[
0
])
{
case
0
:
bigEndian
=
true
;
break
;
case
1
:
bigEndian
=
false
;
break
;
default
:
break
getSRID
;
}
if
((
bytes
[
bigEndian
?
1
:
4
]
&
0x20
)
!=
0
)
{
srid
=
Bits
.
readInt
(
bytes
,
5
);
if
(!
bigEndian
)
{
srid
=
Integer
.
reverseBytes
(
srid
);
}
}
}
/*
* No-arg WKBReader() constructor instantiates a new GeometryFactory and a new
* PrecisionModel anyway, so special case for srid == 0 is not needed.
*/
geometry
=
new
WKBReader
(
new
GeometryFactory
(
new
PrecisionModel
(),
srid
)).
read
(
bytes
);
}
catch
(
ParseException
ex
)
{
throw
DbException
.
convert
(
ex
);
}
...
...
h2/src/test/org/h2/test/db/TestSpatial.java
浏览文件 @
8097e478
...
...
@@ -26,7 +26,9 @@ import org.locationtech.jts.geom.GeometryFactory;
import
org.locationtech.jts.geom.Point
;
import
org.locationtech.jts.geom.Polygon
;
import
org.locationtech.jts.geom.util.AffineTransformation
;
import
org.locationtech.jts.io.ByteOrderValues
;
import
org.locationtech.jts.io.ParseException
;
import
org.locationtech.jts.io.WKBWriter
;
import
org.locationtech.jts.io.WKTReader
;
/**
...
...
@@ -604,6 +606,26 @@ public class TestSpatial extends TestBase {
// Test SRID
copy
=
ValueGeometry
.
get
(
geom3d
.
getBytes
());
assertEquals
(
27572
,
copy
.
getGeometry
().
getSRID
());
Point
point
=
new
GeometryFactory
().
createPoint
((
new
Coordinate
(
1.1d
,
1.2d
)));
// SRID 0
checkSRID
(
ValueGeometry
.
getFromGeometry
(
point
).
getBytes
(),
0
);
checkSRID
(
new
WKBWriter
(
2
,
ByteOrderValues
.
BIG_ENDIAN
,
false
).
write
(
point
),
0
);
checkSRID
(
new
WKBWriter
(
2
,
ByteOrderValues
.
BIG_ENDIAN
,
true
).
write
(
point
),
0
);
checkSRID
(
new
WKBWriter
(
2
,
ByteOrderValues
.
LITTLE_ENDIAN
,
false
).
write
(
point
),
0
);
checkSRID
(
new
WKBWriter
(
2
,
ByteOrderValues
.
LITTLE_ENDIAN
,
true
).
write
(
point
),
0
);
// SRID 1,000,000,000
point
.
setSRID
(
1_000_000_000
);
checkSRID
(
ValueGeometry
.
getFromGeometry
(
point
).
getBytes
(),
1_000_000_000
);
checkSRID
(
new
WKBWriter
(
2
,
ByteOrderValues
.
BIG_ENDIAN
,
true
).
write
(
point
),
1_000_000_000
);
checkSRID
(
new
WKBWriter
(
2
,
ByteOrderValues
.
LITTLE_ENDIAN
,
true
).
write
(
point
),
1_000_000_000
);
}
private
void
checkSRID
(
byte
[]
bytes
,
int
srid
)
{
Point
point
=
(
Point
)
ValueGeometry
.
get
(
bytes
).
getGeometry
();
assertEquals
(
1.1
,
point
.
getX
());
assertEquals
(
1.2
,
point
.
getY
());
assertEquals
(
srid
,
point
.
getSRID
());
assertEquals
(
srid
,
point
.
getFactory
().
getSRID
());
}
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论