Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
573e605d
提交
573e605d
authored
9月 10, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support of empty points to GEOMETRY data type
上级
000f7bb6
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
59 行增加
和
34 行删除
+59
-34
AggregateDataEnvelope.java
...in/org/h2/expression/aggregate/AggregateDataEnvelope.java
+0
-3
SpatialTreeIndex.java
h2/src/main/org/h2/index/SpatialTreeIndex.java
+3
-2
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+3
-2
EWKTUtils.java
h2/src/main/org/h2/util/geometry/EWKTUtils.java
+15
-4
GeometryUtils.java
h2/src/main/org/h2/util/geometry/GeometryUtils.java
+3
-3
JTSUtils.java
h2/src/main/org/h2/util/geometry/JTSUtils.java
+9
-1
ValueGeometry.java
h2/src/main/org/h2/value/ValueGeometry.java
+3
-3
TestSpatial.java
h2/src/test/org/h2/test/db/TestSpatial.java
+0
-9
TestGeometryUtils.java
h2/src/test/org/h2/test/unit/TestGeometryUtils.java
+23
-7
没有找到文件。
h2/src/main/org/h2/expression/aggregate/AggregateDataEnvelope.java
浏览文件 @
573e605d
...
...
@@ -66,9 +66,6 @@ class AggregateDataEnvelope extends AggregateData {
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
if
(
envelope
==
null
)
{
return
ValueNull
.
INSTANCE
;
}
return
ValueGeometry
.
fromEnvelope
(
envelope
);
}
...
...
h2/src/main/org/h2/index/SpatialTreeIndex.java
浏览文件 @
573e605d
...
...
@@ -134,10 +134,11 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
return
null
;
}
Value
v
=
row
.
getValue
(
columnIds
[
0
]);
if
(
v
==
ValueNull
.
INSTANCE
)
{
double
[]
env
;
if
(
v
==
ValueNull
.
INSTANCE
||
(
env
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeNoCopy
())
==
null
)
{
return
new
SpatialKey
(
row
.
getKey
());
}
double
[]
env
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeNoCopy
();
return
new
SpatialKey
(
row
.
getKey
(),
(
float
)
env
[
MIN_X
],
(
float
)
env
[
MAX_X
],
(
float
)
env
[
MIN_Y
],
(
float
)
env
[
MAX_Y
]);
}
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
573e605d
...
...
@@ -274,10 +274,11 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
private
SpatialKey
getKey
(
SearchRow
row
)
{
Value
v
=
row
.
getValue
(
columnIds
[
0
]);
if
(
v
==
ValueNull
.
INSTANCE
)
{
double
[]
env
;
if
(
v
==
ValueNull
.
INSTANCE
||
(
env
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeNoCopy
())
==
null
)
{
return
new
SpatialKey
(
row
.
getKey
());
}
double
[]
env
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeNoCopy
();
return
new
SpatialKey
(
row
.
getKey
(),
(
float
)
env
[
MIN_X
],
(
float
)
env
[
MAX_X
],
(
float
)
env
[
MIN_Y
],
(
float
)
env
[
MAX_Y
]);
...
...
h2/src/main/org/h2/util/geometry/EWKTUtils.java
浏览文件 @
573e605d
...
...
@@ -44,6 +44,8 @@ public final class EWKTUtils {
private
int
level
;
private
int
type
;
private
boolean
inMulti
;
/**
...
...
@@ -104,6 +106,7 @@ public final class EWKTUtils {
}
private
void
writeHeader
(
int
type
,
int
srid
)
{
this
.
type
=
type
;
// Never write SRID in inner objects
if
(
level
==
0
&&
srid
!=
0
)
{
output
.
append
(
"SRID="
).
append
(
srid
).
append
(
';'
);
...
...
@@ -177,6 +180,10 @@ public final class EWKTUtils {
@Override
protected
void
addCoordinate
(
double
x
,
double
y
,
double
z
,
double
m
,
int
index
,
int
total
)
{
if
(
type
==
POINT
&&
Double
.
isNaN
(
x
)
&&
Double
.
isNaN
(
y
)
&&
Double
.
isNaN
(
z
)
&&
Double
.
isNaN
(
m
))
{
output
.
append
(
"EMPTY"
);
return
;
}
if
(
index
==
0
)
{
output
.
append
(
'('
);
}
else
{
...
...
@@ -572,13 +579,17 @@ public final class EWKTUtils {
}
switch
(
type
)
{
case
"POINT"
:
if
(
parentType
!=
0
&&
parentType
!=
MULTI_POINT
&&
parentType
!=
GEOMETRY_COLLECTION
||
empty
)
{
if
(
parentType
!=
0
&&
parentType
!=
MULTI_POINT
&&
parentType
!=
GEOMETRY_COLLECTION
)
{
throw
new
IllegalArgumentException
();
}
empty
=
source
.
readEmpty
(
empty
);
target
.
startPoint
(
source
.
srid
);
source
.
read
(
'('
);
if
(
empty
)
{
target
.
addCoordinate
(
Double
.
NaN
,
Double
.
NaN
,
Double
.
NaN
,
Double
.
NaN
,
0
,
1
);
}
else
{
addCoordinate
(
source
,
target
,
useZ
,
useM
,
0
,
1
);
source
.
read
(
')'
);
}
break
;
case
"LINESTRING"
:
{
if
(
parentType
!=
0
&&
parentType
!=
MULTI_LINE_STRING
&&
parentType
!=
GEOMETRY_COLLECTION
)
{
...
...
h2/src/main/org/h2/util/geometry/GeometryUtils.java
浏览文件 @
573e605d
...
...
@@ -191,7 +191,7 @@ public final class GeometryUtils {
@Override
protected
void
addCoordinate
(
double
x
,
double
y
,
double
z
,
double
m
,
int
index
,
int
total
)
{
if
(
enabled
)
{
if
(
enabled
&&
!
Double
.
isNaN
(
x
)
&&
!
Double
.
isNaN
(
y
)
)
{
if
(!
set
)
{
minX
=
maxX
=
x
;
minY
=
maxY
=
y
;
...
...
@@ -318,7 +318,7 @@ public final class GeometryUtils {
if
(!
hasM
&&
!
Double
.
isNaN
(
m
))
{
hasM
=
true
;
}
if
(
enabled
)
{
if
(
enabled
&&
!
Double
.
isNaN
(
x
)
&&
!
Double
.
isNaN
(
y
)
)
{
if
(!
set
)
{
minX
=
maxX
=
x
;
minY
=
maxY
=
y
;
...
...
@@ -467,7 +467,7 @@ public final class GeometryUtils {
* @return envelope, or null
*/
public
static
double
[]
getEnvelope
(
byte
[]
ewkb
)
{
Envelope
AndDimensionSystemTarget
target
=
new
EnvelopeAndDimensionSystem
Target
();
Envelope
Target
target
=
new
Envelope
Target
();
EWKBUtils
.
parseEWKB
(
ewkb
,
target
);
return
target
.
getEnvelope
();
}
...
...
h2/src/main/org/h2/util/geometry/JTSUtils.java
浏览文件 @
573e605d
...
...
@@ -149,6 +149,10 @@ public final class JTSUtils {
@Override
protected
void
addCoordinate
(
double
x
,
double
y
,
double
z
,
double
m
,
int
index
,
int
total
)
{
if
(
type
==
POINT
&&
Double
.
isNaN
(
x
)
&&
Double
.
isNaN
(
y
)
&&
Double
.
isNaN
(
z
)
&&
Double
.
isNaN
(
m
))
{
this
.
coordinates
=
createCoordinates
(
0
);
return
;
}
CoordinateSequence
coordinates
=
innerOffset
<
0
?
this
.
coordinates
:
innerCoordinates
[
innerOffset
];
coordinates
.
setOrdinate
(
index
,
X
,
x
);
coordinates
.
setOrdinate
(
index
,
Y
,
y
);
...
...
@@ -287,7 +291,11 @@ public final class JTSUtils {
}
target
.
startPoint
(
srid
);
Point
p
=
(
Point
)
geometry
;
if
(
p
.
isEmpty
())
{
target
.
addCoordinate
(
Double
.
NaN
,
Double
.
NaN
,
Double
.
NaN
,
Double
.
NaN
,
0
,
1
);
}
else
{
addCoordinate
(
p
.
getCoordinateSequence
(),
target
,
0
,
1
);
}
}
else
if
(
geometry
instanceof
LineString
)
{
if
(
parentType
!=
0
&&
parentType
!=
MULTI_LINE_STRING
&&
parentType
!=
GEOMETRY_COLLECTION
)
{
throw
new
IllegalArgumentException
();
...
...
h2/src/main/org/h2/value/ValueGeometry.java
浏览文件 @
573e605d
...
...
@@ -155,9 +155,9 @@ public class ValueGeometry extends Value {
* @param envelope envelope. May not be modified.
* @return the value
*/
public
static
Value
Geometry
fromEnvelope
(
double
[]
envelope
)
{
return
(
ValueGeometry
)
Value
.
cache
(
new
ValueGeometry
(
GeometryUtils
.
envelope2wkb
(
envelope
),
GeometryUtils
.
DIMENSION_SYSTEM_XY
,
envelope
));
public
static
Value
fromEnvelope
(
double
[]
envelope
)
{
return
envelope
!=
null
?
Value
.
cache
(
new
ValueGeometry
(
GeometryUtils
.
envelope2wkb
(
envelope
),
GeometryUtils
.
DIMENSION_SYSTEM_XY
,
envelope
))
:
ValueNull
.
INSTANCE
;
}
/**
...
...
h2/src/test/org/h2/test/db/TestSpatial.java
浏览文件 @
573e605d
...
...
@@ -13,12 +13,10 @@ import java.sql.Statement;
import
java.sql.Types
;
import
java.util.Random
;
import
org.h2.api.Aggregate
;
import
org.h2.message.DbException
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestDb
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.tools.SimpleRowSource
;
import
org.h2.util.StringUtils
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueGeometry
;
...
...
@@ -700,13 +698,6 @@ public class TestSpatial extends TestDb {
ValueGeometry
valueGeometry3
=
ValueGeometry
.
getFromGeometry
(
geometry
);
assertEquals
(
valueGeometry
,
valueGeometry3
);
assertEquals
(
geometry
.
getSRID
(),
((
Geometry
)
valueGeometry3
.
getGeometry
()).
getSRID
());
// Check illegal geometry (no WKB representation)
try
{
ValueGeometry
.
get
(
"POINT EMPTY"
);
fail
(
"expected exception"
);
}
catch
(
IllegalArgumentException
|
DbException
ex
)
{
// expected
}
}
/**
...
...
h2/src/test/org/h2/test/unit/TestGeometryUtils.java
浏览文件 @
573e605d
...
...
@@ -58,6 +58,7 @@ public class TestGeometryUtils extends TestBase {
testMultiLineString
();
testMultiPolygon
();
testGeometryCollection
();
testEmptyPoint
();
testDimensionM
();
testDimensionZM
();
testSRID
();
...
...
@@ -144,7 +145,8 @@ public class TestGeometryUtils extends TestBase {
// Test WKB->Geometry conversion
Geometry
geometryFromH2
=
JTSUtils
.
ewkb2geometry
(
wkbFromJTS
);
// JTS has locale-specific bugs with NaNs, also such geometries are not fully valid
// JTS has locale-specific bugs with NaNs, also such geometries are not
// fully valid
if
(!
wkt
.
contains
(
"NaN"
))
{
assertEquals
(
jtsWkt
.
replaceAll
(
" Z"
,
""
),
new
WKTWriter
(
numOfDimensions
).
write
(
geometryFromH2
));
}
...
...
@@ -171,18 +173,32 @@ public class TestGeometryUtils extends TestBase {
}
else
{
double
minX
=
envelopeFromJTS
.
getMinX
(),
maxX
=
envelopeFromJTS
.
getMaxX
();
double
minY
=
envelopeFromJTS
.
getMinY
(),
maxY
=
envelopeFromJTS
.
getMaxY
();
if
(
Double
.
isNaN
(
minX
)
||
Double
.
isNaN
(
maxX
)
||
Double
.
isNaN
(
minY
)
||
Double
.
isNaN
(
maxY
))
{
assertNull
(
envelopeFromH2
);
assertNull
(
GeometryUtils
.
envelope2wkb
(
envelopeFromH2
));
}
else
{
assertEquals
(
minX
,
envelopeFromH2
[
0
]);
assertEquals
(
maxX
,
envelopeFromH2
[
1
]);
assertEquals
(
minY
,
envelopeFromH2
[
2
]);
assertEquals
(
maxY
,
envelopeFromH2
[
3
]);
// TODO determine what to do with NaNs in dimensions X and Y
if
(!
Double
.
isNaN
(
minX
)
&&
!
Double
.
isNaN
(
maxX
)
&&
!
Double
.
isNaN
(
minY
)
&&
!
Double
.
isNaN
(
maxY
))
{
assertEquals
(
new
WKBWriter
(
2
).
write
(
new
GeometryFactory
().
toGeometry
(
envelopeFromJTS
)),
GeometryUtils
.
envelope2wkb
(
envelopeFromH2
));
}
}
}
private
void
testEmptyPoint
()
{
String
ewkt
=
"POINT EMPTY"
;
byte
[]
ewkb
=
EWKTUtils
.
ewkt2ewkb
(
ewkt
);
assertEquals
(
StringUtils
.
convertHexToBytes
(
"00000000017ff80000000000007ff8000000000000"
),
ewkb
);
assertEquals
(
ewkt
,
EWKTUtils
.
ewkb2ewkt
(
ewkb
));
assertNull
(
GeometryUtils
.
getEnvelope
(
ewkb
));
Point
p
=
(
Point
)
JTSUtils
.
ewkb2geometry
(
ewkb
);
assertTrue
(
p
.
isEmpty
());
assertEquals
(
ewkt
,
new
WKTWriter
().
write
(
p
));
assertEquals
(
ewkb
,
JTSUtils
.
geometry2ewkb
(
p
));
}
private
void
testDimensionM
()
{
byte
[]
ewkb
=
EWKTUtils
.
ewkt2ewkb
(
"POINT M (1 2 3)"
);
assertEquals
(
"POINT M (1 2 3)"
,
EWKTUtils
.
ewkb2ewkt
(
ewkb
));
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论