Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3f58272d
提交
3f58272d
authored
9月 09, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use own utilities instead of JTS
上级
9ca18311
全部展开
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
77 行增加
和
172 行删除
+77
-172
AggregateDataEnvelope.java
...in/org/h2/expression/aggregate/AggregateDataEnvelope.java
+5
-9
SpatialTreeIndex.java
h2/src/main/org/h2/index/SpatialTreeIndex.java
+7
-4
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+20
-17
GeometryUtils.java
h2/src/main/org/h2/util/geometry/GeometryUtils.java
+6
-2
DataType.java
h2/src/main/org/h2/value/DataType.java
+1
-1
ValueGeometry.java
h2/src/main/org/h2/value/ValueGeometry.java
+32
-134
TestSpatial.java
h2/src/test/org/h2/test/db/TestSpatial.java
+6
-5
没有找到文件。
h2/src/main/org/h2/expression/aggregate/AggregateDataEnvelope.java
浏览文件 @
3f58272d
...
...
@@ -14,18 +14,17 @@ import org.h2.index.Index;
import
org.h2.mvstore.db.MVSpatialIndex
;
import
org.h2.table.Column
;
import
org.h2.table.TableFilter
;
import
org.h2.util.geometry.GeometryUtils
;
import
org.h2.value.Value
;
import
org.h2.value.ValueGeometry
;
import
org.h2.value.ValueNull
;
import
org.locationtech.jts.geom.Envelope
;
import
org.locationtech.jts.geom.GeometryFactory
;
/**
* Data stored while calculating an aggregate.
*/
class
AggregateDataEnvelope
extends
AggregateData
{
private
Envelope
envelope
;
private
double
[]
envelope
;
/**
* Get the index (if any) for the column specified in the geometry
...
...
@@ -62,18 +61,15 @@ class AggregateDataEnvelope extends AggregateData {
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
;
}
if
(
envelope
==
null
)
{
envelope
=
new
Envelope
();
}
envelope
.
expandToInclude
(((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeNoCopy
());
envelope
=
GeometryUtils
.
union
(
envelope
,
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeNoCopy
());
}
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
if
(
envelope
==
null
||
envelope
.
isNull
()
)
{
if
(
envelope
==
null
)
{
return
ValueNull
.
INSTANCE
;
}
return
ValueGeometry
.
get
FromGeometry
(
new
GeometryFactory
().
toGeometry
(
envelope
));
return
ValueGeometry
.
get
(
GeometryUtils
.
envelope2wkb
(
envelope
));
}
}
h2/src/main/org/h2/index/SpatialTreeIndex.java
浏览文件 @
3f58272d
...
...
@@ -5,6 +5,11 @@
*/
package
org
.
h2
.
index
;
import
static
org
.
h2
.
util
.
geometry
.
GeometryUtils
.
MAX_X
;
import
static
org
.
h2
.
util
.
geometry
.
GeometryUtils
.
MAX_Y
;
import
static
org
.
h2
.
util
.
geometry
.
GeometryUtils
.
MIN_X
;
import
static
org
.
h2
.
util
.
geometry
.
GeometryUtils
.
MIN_Y
;
import
java.util.Iterator
;
import
org.h2.command.dml.AllColumnsForPlan
;
import
org.h2.engine.Session
;
...
...
@@ -23,7 +28,6 @@ import org.h2.table.TableFilter;
import
org.h2.value.Value
;
import
org.h2.value.ValueGeometry
;
import
org.h2.value.ValueNull
;
import
org.locationtech.jts.geom.Envelope
;
/**
* This is an index based on a MVR-TreeMap.
...
...
@@ -133,10 +137,9 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
new
SpatialKey
(
row
.
getKey
());
}
Envelope
env
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeNoCopy
();
double
[]
env
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeNoCopy
();
return
new
SpatialKey
(
row
.
getKey
(),
(
float
)
env
.
getMinX
(),
(
float
)
env
.
getMaxX
(),
(
float
)
env
.
getMinY
(),
(
float
)
env
.
getMaxY
());
(
float
)
env
[
MIN_X
],
(
float
)
env
[
MAX_X
],
(
float
)
env
[
MIN_Y
],
(
float
)
env
[
MAX_Y
]);
}
@Override
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
3f58272d
...
...
@@ -5,6 +5,11 @@
*/
package
org
.
h2
.
mvstore
.
db
;
import
static
org
.
h2
.
util
.
geometry
.
GeometryUtils
.
MAX_X
;
import
static
org
.
h2
.
util
.
geometry
.
GeometryUtils
.
MAX_Y
;
import
static
org
.
h2
.
util
.
geometry
.
GeometryUtils
.
MIN_X
;
import
static
org
.
h2
.
util
.
geometry
.
GeometryUtils
.
MIN_Y
;
import
java.util.Iterator
;
import
java.util.List
;
import
org.h2.api.ErrorCode
;
...
...
@@ -29,12 +34,11 @@ import org.h2.result.SearchRow;
import
org.h2.result.SortOrder
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.TableFilter
;
import
org.h2.util.geometry.GeometryUtils
;
import
org.h2.value.Value
;
import
org.h2.value.ValueGeometry
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueNull
;
import
org.locationtech.jts.geom.Envelope
;
import
org.locationtech.jts.geom.GeometryFactory
;
/**
* This is an index based on a MVRTreeMap.
...
...
@@ -264,8 +268,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
bmaxyf
=
maxyf
;
}
}
return
ValueGeometry
.
getFromGeometry
(
new
GeometryFactory
().
toGeometry
(
new
Envelope
(
bminxf
,
bmaxxf
,
bminyf
,
bmaxyf
)));
return
ValueGeometry
.
get
(
GeometryUtils
.
envelope2wkb
(
new
double
[]
{
bminxf
,
bmaxxf
,
bminyf
,
bmaxyf
}));
}
return
ValueNull
.
INSTANCE
;
}
...
...
@@ -275,10 +278,10 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
new
SpatialKey
(
row
.
getKey
());
}
Envelope
env
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeNoCopy
();
double
[]
env
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeNoCopy
();
return
new
SpatialKey
(
row
.
getKey
(),
(
float
)
env
.
getMinX
(),
(
float
)
env
.
getMaxX
()
,
(
float
)
env
.
getMinY
(),
(
float
)
env
.
getMaxY
()
);
(
float
)
env
[
MIN_X
],
(
float
)
env
[
MAX_X
]
,
(
float
)
env
[
MIN_Y
],
(
float
)
env
[
MAX_Y
]
);
}
@Override
...
...
@@ -467,10 +470,9 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
if
(
hasBounds
)
{
if
((
minxf
<=
bminxf
||
maxxf
>=
bmaxxf
||
minyf
<=
bminyf
||
maxyf
>=
bmaxyf
)
&&
map
.
containsKey
(
key
))
{
Envelope
env
=
((
ValueGeometry
)
mvTable
.
getRow
(
session
,
key
.
getId
()).
getValue
(
columnId
))
double
[]
env
=
((
ValueGeometry
)
mvTable
.
getRow
(
session
,
key
.
getId
()).
getValue
(
columnId
))
.
getEnvelopeNoCopy
();
double
minxd
=
env
.
getMinX
(),
maxxd
=
env
.
getMaxX
(),
minyd
=
env
.
getMinY
(),
maxyd
=
env
.
getMaxY
();
double
minxd
=
env
[
MIN_X
],
maxxd
=
env
[
MAX_X
],
minyd
=
env
[
MIN_Y
],
maxyd
=
env
[
MAX_Y
];
if
(
minxd
<
bminxd
)
{
bminxf
=
minxf
;
bminxd
=
minxd
;
...
...
@@ -490,16 +492,16 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
}
}
else
if
(
map
.
containsKey
(
key
))
{
hasBounds
=
true
;
Envelope
env
=
((
ValueGeometry
)
mvTable
.
getRow
(
session
,
key
.
getId
()).
getValue
(
columnId
))
double
[]
env
=
((
ValueGeometry
)
mvTable
.
getRow
(
session
,
key
.
getId
()).
getValue
(
columnId
))
.
getEnvelopeNoCopy
();
bminxf
=
minxf
;
bminxd
=
env
.
getMinX
()
;
bminxd
=
env
[
MIN_X
]
;
bmaxxf
=
maxxf
;
bmaxxd
=
env
.
getMaxX
()
;
bmaxxd
=
env
[
MAX_X
]
;
bminyf
=
minyf
;
bminyd
=
env
.
getMinY
()
;
bminyd
=
env
[
MIN_Y
]
;
bmaxyf
=
maxyf
;
bmaxyd
=
env
.
getMaxY
()
;
bmaxyd
=
env
[
MAX_Y
]
;
}
}
else
if
(
hasBounds
)
{
if
(
minxf
<=
bminxf
||
maxxf
>=
bmaxxf
||
minyf
<=
bminyf
||
maxyf
>=
bmaxyf
)
{
...
...
@@ -512,8 +514,9 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
}
Value
getBounds
()
{
return
hasBounds
?
ValueGeometry
.
getFromGeometry
(
new
GeometryFactory
().
toGeometry
(
new
Envelope
(
bminxd
,
bmaxxd
,
bminyd
,
bmaxyd
)))
:
ValueNull
.
INSTANCE
;
return
hasBounds
?
ValueGeometry
.
get
(
GeometryUtils
.
envelope2wkb
(
new
double
[]
{
bminxd
,
bmaxxd
,
bminyd
,
bmaxyd
}))
:
ValueNull
.
INSTANCE
;
}
}
...
...
h2/src/main/org/h2/util/geometry/GeometryUtils.java
浏览文件 @
3f58272d
...
...
@@ -550,22 +550,26 @@ public final class GeometryUtils {
}
else
if
(
envelope2
==
null
)
{
return
envelope1
;
}
double
minX1
=
envelope1
[
MIN_X
],
maxX1
=
envelope1
[
MAX_X
],
minY1
=
envelope1
[
MIN_Y
],
maxY1
=
envelope1
[
MAX_Y
];
double
minX2
=
envelope2
[
MIN_X
],
maxX2
=
envelope2
[
MAX_X
],
minY2
=
envelope2
[
MIN_Y
],
maxY2
=
envelope2
[
MAX_Y
];
boolean
modified
=
false
;
if
(
minX1
>
minX2
)
{
minX1
=
minX2
;
modified
=
true
;
}
if
(
maxX1
<
maxX2
)
{
maxX1
=
maxX2
;
modified
=
true
;
}
if
(
minY1
>
minY2
)
{
minY1
=
minY2
;
modified
=
true
;
}
if
(
maxY1
<
maxY2
)
{
maxY1
=
maxY2
;
modified
=
true
;
}
return
new
double
[]
{
minX1
,
maxX1
,
minY1
,
maxY1
}
;
return
modified
?
new
double
[]
{
minX1
,
maxX1
,
minY1
,
maxY1
}
:
envelope1
;
}
/**
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
3f58272d
...
...
@@ -898,7 +898,7 @@ public class DataType {
case
Value
.
RESULT_SET
:
return
ResultSet
.
class
.
getName
();
case
Value
.
GEOMETRY
:
return
GEOMETRY_CLASS
_NAME
;
return
GEOMETRY_CLASS
!=
null
?
GEOMETRY_CLASS_NAME
:
String
.
class
.
getName
()
;
case
Value
.
INTERVAL_YEAR
:
case
Value
.
INTERVAL_MONTH
:
case
Value
.
INTERVAL_DAY
:
...
...
h2/src/main/org/h2/value/ValueGeometry.java
浏览文件 @
3f58272d
差异被折叠。
点击展开。
h2/src/test/org/h2/test/db/TestSpatial.java
浏览文件 @
3f58272d
...
...
@@ -612,12 +612,13 @@ public class TestSpatial extends TestDb {
ValueGeometry
geom3d
=
ValueGeometry
.
get
(
ewkt
);
assertEquals
(
ewkt
,
geom3d
.
getString
());
ValueGeometry
copy
=
ValueGeometry
.
get
(
geom3d
.
getBytes
());
assertEquals
(
6
,
copy
.
getGeometry
().
getCoordinates
()[
0
].
z
);
assertEquals
(
5
,
copy
.
getGeometry
().
getCoordinates
()[
1
].
z
);
assertEquals
(
4
,
copy
.
getGeometry
().
getCoordinates
()[
2
].
z
);
Geometry
g
=
(
Geometry
)
copy
.
getGeometry
();
assertEquals
(
6
,
g
.
getCoordinates
()[
0
].
z
);
assertEquals
(
5
,
g
.
getCoordinates
()[
1
].
z
);
assertEquals
(
4
,
g
.
getCoordinates
()[
2
].
z
);
// Test SRID
copy
=
ValueGeometry
.
get
(
geom3d
.
getBytes
());
assertEquals
(
27572
,
copy
.
getGeometry
()
.
getSRID
());
assertEquals
(
27572
,
g
.
getSRID
());
Point
point
=
new
GeometryFactory
().
createPoint
((
new
Coordinate
(
1.1d
,
1.2d
)));
// SRID 0
...
...
@@ -696,7 +697,7 @@ public class TestSpatial extends TestDb {
assertFalse
(
valueGeometry
.
equals
(
valueGeometry2
));
ValueGeometry
valueGeometry3
=
ValueGeometry
.
getFromGeometry
(
geometry
);
assertEquals
(
valueGeometry
,
valueGeometry3
);
assertEquals
(
geometry
.
getSRID
(),
valueGeometry3
.
getGeometry
(
).
getSRID
());
assertEquals
(
geometry
.
getSRID
(),
((
Geometry
)
valueGeometry3
.
getGeometry
()
).
getSRID
());
// Check illegal geometry (no WKB representation)
try
{
ValueGeometry
.
get
(
"POINT EMPTY"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论