Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
54c3fc72
提交
54c3fc72
authored
8月 12, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Formatting.
上级
dc4f999e
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
154 行增加
和
138 行删除
+154
-138
TestSpatial.java
h2/src/test/org/h2/test/db/TestSpatial.java
+154
-138
没有找到文件。
h2/src/test/org/h2/test/db/TestSpatial.java
浏览文件 @
54c3fc72
...
...
@@ -100,8 +100,9 @@ public class TestSpatial extends TestBase {
}
/**
* Generate a random linestring under the given bounding box.
* Generate a random line
string under the given bounding box.
*
* @param geometryRand the random generator
* @param minX Bounding box min x
* @param maxX Bounding box max x
* @param minY Bounding box min y
...
...
@@ -140,12 +141,11 @@ public class TestSpatial extends TestBase {
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop table if exists test"
);
Random
geometryRand
=
new
Random
(
seed
);
// Generate a set of geometry
// It is marked as random, but it generate always the same geometry set, given the same seed
// generate a set of geometry (always the same set, given the same seed)
stat
.
execute
(
"create memory table test("
+
"id long primary key auto_increment, poly geometry)"
);
// Create segment generation bounding box
Envelope
bbox
=
ValueGeometry
.
get
(
"POLYGON (("
+
Envelope
boundingBox
=
ValueGeometry
.
get
(
"POLYGON (("
+
"301804.1049793153 2251719.1222191923, "
+
"301804.1049793153 2254747.2888244865, "
+
"304646.87362918374 2254747.2888244865, "
+
...
...
@@ -153,13 +153,14 @@ public class TestSpatial extends TestBase {
"301804.1049793153 2251719.1222191923))"
)
.
getGeometry
().
getEnvelopeInternal
();
// Create overlap test bounding box
String
testBBoxString
=
"POLYGON (("
+
String
testBoundingBoxString
=
"POLYGON (("
+
"302215.44416332216 2252748, "
+
"302215.44416332216 2253851.781225762, "
+
"303582.85796541866 2253851.781225762, "
+
"303582.85796541866 2252748.526908161, "
+
"302215.44416332216 2252748))"
;
Envelope
testBBox
=
ValueGeometry
.
get
(
testBBoxString
).
getGeometry
().
getEnvelopeInternal
();
Envelope
testBBox
=
ValueGeometry
.
get
(
testBoundingBoxString
).
getGeometry
().
getEnvelopeInternal
();
PreparedStatement
ps
=
conn
.
prepareStatement
(
"insert into test(poly) values (?)"
);
...
...
@@ -168,8 +169,8 @@ public class TestSpatial extends TestBase {
for
(
int
i
=
1
;
i
<=
size
;
i
++)
{
Geometry
geometry
=
getRandomGeometry
(
geometryRand
,
b
box
.
getMinX
(),
bbox
.
getMaxX
(),
b
box
.
getMinY
(),
bb
ox
.
getMaxY
(),
200
);
b
oundingBox
.
getMinX
(),
boundingBox
.
getMaxX
(),
b
oundingBox
.
getMinY
(),
boundingB
ox
.
getMaxY
(),
200
);
ps
.
setObject
(
1
,
geometry
);
ps
.
execute
();
ResultSet
keys
=
ps
.
getGeneratedKeys
();
...
...
@@ -183,9 +184,8 @@ public class TestSpatial extends TestBase {
// Create index
stat
.
execute
(
"create spatial index idx_test_poly on test(poly)"
);
// Must find the same overlap count with index
ps
=
conn
.
prepareStatement
(
"select id from test where poly && ?::Geometry"
);
ps
.
setString
(
1
,
testBBoxString
);
ps
=
conn
.
prepareStatement
(
"select id from test where poly && ?::Geometry"
);
ps
.
setString
(
1
,
testBoundingBoxString
);
ResultSet
rs
=
ps
.
executeQuery
();
long
found
=
0
;
while
(
rs
.
next
())
{
...
...
@@ -198,6 +198,7 @@ public class TestSpatial extends TestBase {
assertTrue
(
overlaps
.
isEmpty
());
stat
.
execute
(
"drop table if exists test"
);
}
private
void
testOverlap
()
throws
SQLException
{
deleteDb
(
"spatial"
);
Connection
conn
=
getConnection
(
"spatial"
);
...
...
@@ -220,8 +221,8 @@ public class TestSpatial extends TestBase {
}
}
private
void
testPersistentSpatialIndex
()
throws
SQLException
{
deleteDb
(
"spatial
_pers
"
);
Connection
conn
=
getConnection
(
"spatial
_pers
"
);
deleteDb
(
"spatial
Persistent
"
);
Connection
conn
=
getConnection
(
"spatial
Persistent
"
);
try
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, poly geometry)"
);
...
...
@@ -256,7 +257,7 @@ public class TestSpatial extends TestBase {
return
;
}
conn
=
getConnection
(
"spatial
_pers
"
);
conn
=
getConnection
(
"spatial
Persistent
"
);
try
{
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
...
...
@@ -296,23 +297,36 @@ public class TestSpatial extends TestBase {
}
private
static
void
createTestTable
(
Statement
stat
)
throws
SQLException
{
stat
.
execute
(
"create table area(id
a
rea int primary key, the_geom geometry)"
);
stat
.
execute
(
"create table area(id
A
rea int primary key, the_geom geometry)"
);
stat
.
execute
(
"create spatial index on area(the_geom)"
);
stat
.
execute
(
"insert into area values(1, 'POLYGON ((-10 109, 90 109, 90 9, -10 9, -10 109))')"
);
stat
.
execute
(
"insert into area values(2, 'POLYGON ((90 109, 190 109, 190 9, 90 9, 90 109))')"
);
stat
.
execute
(
"insert into area values(3, 'POLYGON ((190 109, 290 109, 290 9, 190 9, 190 109))')"
);
stat
.
execute
(
"insert into area values(4, 'POLYGON ((-10 9, 90 9, 90 -91, -10 -91, -10 9))')"
);
stat
.
execute
(
"insert into area values(5, 'POLYGON ((90 9, 190 9, 190 -91, 90 -91, 90 9))')"
);
stat
.
execute
(
"insert into area values(6, 'POLYGON ((190 9, 290 9, 290 -91, 190 -91, 190 9))')"
);
stat
.
execute
(
"create table roads(idroad int primary key, the_geom geometry)"
);
stat
.
execute
(
"insert into area values(1, "
+
"'POLYGON ((-10 109, 90 109, 90 9, -10 9, -10 109))')"
);
stat
.
execute
(
"insert into area values(2, "
+
"'POLYGON ((90 109, 190 109, 190 9, 90 9, 90 109))')"
);
stat
.
execute
(
"insert into area values(3, "
+
"'POLYGON ((190 109, 290 109, 290 9, 190 9, 190 109))')"
);
stat
.
execute
(
"insert into area values(4, "
+
"'POLYGON ((-10 9, 90 9, 90 -91, -10 -91, -10 9))')"
);
stat
.
execute
(
"insert into area values(5, "
+
"'POLYGON ((90 9, 190 9, 190 -91, 90 -91, 90 9))')"
);
stat
.
execute
(
"insert into area values(6, "
+
"'POLYGON ((190 9, 290 9, 290 -91, 190 -91, 190 9))')"
);
stat
.
execute
(
"create table roads(idRoad int primary key, the_geom geometry)"
);
stat
.
execute
(
"create spatial index on roads(the_geom)"
);
stat
.
execute
(
"insert into roads values(1, 'LINESTRING (27.65595463138 -16.728733459357244, 47.61814744801515 40.435727788279806)')"
);
stat
.
execute
(
"insert into roads values(2, 'LINESTRING (17.674858223062415 55.861058601134246, 55.78449905482046 76.73062381852554)')"
);
stat
.
execute
(
"insert into roads values(3, 'LINESTRING (68.48771266540646 67.65689981096412, 108.4120982986768 88.52646502835542)')"
);
stat
.
execute
(
"insert into roads values(4, 'LINESTRING (177.3724007561437 18.65879017013235, 196.4272211720227 -16.728733459357244)')"
);
stat
.
execute
(
"insert into roads values(5, 'LINESTRING (106.5973534971645 -12.191871455576518, 143.79962192816637 30.454631379962223)')"
);
stat
.
execute
(
"insert into roads values(6, 'LINESTRING (144.70699432892252 55.861058601134246, 150.1512287334594 83.9896030245747)')"
);
stat
.
execute
(
"insert into roads values(7, 'LINESTRING (60.321361058601155 -13.099243856332663, 149.24385633270325 5.955576559546344)')"
);
stat
.
execute
(
"insert into roads values(1, "
+
"'LINESTRING (27.65595463138 -16.728733459357244, 47.61814744801515 40.435727788279806)')"
);
stat
.
execute
(
"insert into roads values(2, "
+
"'LINESTRING (17.674858223062415 55.861058601134246, 55.78449905482046 76.73062381852554)')"
);
stat
.
execute
(
"insert into roads values(3, "
+
"'LINESTRING (68.48771266540646 67.65689981096412, 108.4120982986768 88.52646502835542)')"
);
stat
.
execute
(
"insert into roads values(4, "
+
"'LINESTRING (177.3724007561437 18.65879017013235, 196.4272211720227 -16.728733459357244)')"
);
stat
.
execute
(
"insert into roads values(5, "
+
"'LINESTRING (106.5973534971645 -12.191871455576518, 143.79962192816637 30.454631379962223)')"
);
stat
.
execute
(
"insert into roads values(6, "
+
"'LINESTRING (144.70699432892252 55.861058601134246, 150.1512287334594 83.9896030245747)')"
);
stat
.
execute
(
"insert into roads values(7, "
+
"'LINESTRING (60.321361058601155 -13.099243856332663, 149.24385633270325 5.955576559546344)')"
);
}
private
void
testSpatialIndexQueryMultipleTable
()
throws
SQLException
{
...
...
@@ -330,28 +344,28 @@ public class TestSpatial extends TestBase {
}
private
void
testRoadAndArea
(
Statement
stat
)
throws
SQLException
{
ResultSet
rs
=
stat
.
executeQuery
(
"select id
area, COUNT(idroad) roadscount "
+
"select id
Area, COUNT(idRoad) roadCount "
+
"from area, roads "
+
"where area.the_geom && roads.the_geom "
+
"GROUP BY id
area ORDER BY ida
rea"
);
"GROUP BY id
Area ORDER BY idA
rea"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
3
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
1
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
3
,
rs
.
getInt
(
"road
C
ount"
));
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
4
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
2
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
4
,
rs
.
getInt
(
"road
C
ount"
));
assertTrue
(
rs
.
next
());
assertEquals
(
3
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
1
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
3
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
1
,
rs
.
getInt
(
"road
C
ount"
));
assertTrue
(
rs
.
next
());
assertEquals
(
4
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
2
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
4
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
2
,
rs
.
getInt
(
"road
C
ount"
));
assertTrue
(
rs
.
next
());
assertEquals
(
5
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
3
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
5
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
3
,
rs
.
getInt
(
"road
C
ount"
));
assertTrue
(
rs
.
next
());
assertEquals
(
6
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
1
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
6
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
1
,
rs
.
getInt
(
"road
C
ount"
));
assertFalse
(
rs
.
next
());
rs
.
close
();
}
...
...
@@ -365,31 +379,31 @@ public class TestSpatial extends TestBase {
createTestTable
(
stat
);
Savepoint
sp
=
conn
.
setSavepoint
();
// Remove a row but do not commit
stat
.
execute
(
"delete from roads where id
r
oad=7"
);
stat
.
execute
(
"delete from roads where id
R
oad=7"
);
// Check if index is updated
ResultSet
rs
=
stat
.
executeQuery
(
"select id
area, COUNT(idroad) roadscount "
+
"select id
Area, COUNT(idRoad) roadCount "
+
"from area, roads "
+
"where area.the_geom && roads.the_geom "
+
"GROUP BY id
area ORDER BY ida
rea"
);
"GROUP BY id
Area ORDER BY idA
rea"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
3
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
1
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
3
,
rs
.
getInt
(
"road
C
ount"
));
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
4
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
2
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
4
,
rs
.
getInt
(
"road
C
ount"
));
assertTrue
(
rs
.
next
());
assertEquals
(
3
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
1
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
3
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
1
,
rs
.
getInt
(
"road
C
ount"
));
assertTrue
(
rs
.
next
());
assertEquals
(
4
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
1
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
4
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
1
,
rs
.
getInt
(
"road
C
ount"
));
assertTrue
(
rs
.
next
());
assertEquals
(
5
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
2
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
5
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
2
,
rs
.
getInt
(
"road
C
ount"
));
assertTrue
(
rs
.
next
());
assertEquals
(
6
,
rs
.
getInt
(
"id
a
rea"
));
assertEquals
(
1
,
rs
.
getInt
(
"road
sc
ount"
));
assertEquals
(
6
,
rs
.
getInt
(
"id
A
rea"
));
assertEquals
(
1
,
rs
.
getInt
(
"road
C
ount"
));
assertFalse
(
rs
.
next
());
rs
.
close
();
conn
.
rollback
(
sp
);
...
...
@@ -428,7 +442,8 @@ public class TestSpatial extends TestBase {
int
todo
;
// TODO equality should probably also use the spatial index
// rs = stat.executeQuery("explain select * from test where polygon = 'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
// rs = stat.executeQuery("explain select * from test " +
// "where polygon = 'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
// rs.next();
// assertContains(rs.getString(1), "/* PUBLIC.IDX_TEST_POLYGON: POLYGON =");
...
...
@@ -465,10 +480,11 @@ public class TestSpatial extends TestBase {
Connection
conn
=
getConnection
(
"spatialIndex"
);
try
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE ALIAS T_GEOM
FROM
TEXT FOR \""
+
TestSpatial
.
class
.
getName
()
+
".geomFromText\""
);
stat
.
execute
(
"CREATE ALIAS T_GEOM
_FROM_
TEXT FOR \""
+
TestSpatial
.
class
.
getName
()
+
".geomFromText\""
);
stat
.
execute
(
"create table test(id int primary key auto_increment, the_geom geometry)"
);
stat
.
execute
(
"insert into test(the_geom) values(T_GEOMFROMTEXT('POLYGON ((62 48, 84 48, 84 42, 56 34, 62 48))',1488))"
);
stat
.
execute
(
"DROP ALIAS T_GEOMFROMTEXT"
);
stat
.
execute
(
"insert into test(the_geom) values("
+
"T_GEOM_FROM_TEXT('POLYGON ((62 48, 84 48, 84 42, 56 34, 62 48))',1488))"
);
stat
.
execute
(
"DROP ALIAS T_GEOM_FROM_TEXT"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select the_geom from test"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"POLYGON ((62 48, 84 48, 84 42, 56 34, 62 48))"
,
rs
.
getObject
(
1
).
toString
());
...
...
@@ -492,7 +508,7 @@ public class TestSpatial extends TestBase {
"create table test as "
+
"select * from T_RANDOM_GEOM_TABLE(42,20,-100,100,-100,100,4)"
);
stat
.
execute
(
"DROP ALIAS T_RANDOM_GEOM_TABLE"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select count(*)
cpt
from test"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select count(*) from test"
);
assertTrue
(
rs
.
next
());
assertEquals
(
20
,
rs
.
getInt
(
1
));
}
finally
{
...
...
@@ -550,8 +566,8 @@ public class TestSpatial extends TestBase {
/**
* Convert the text to a geometry object.
*
* @param text
Geometry in
Well Known Text
* @param srid
Projection ID
* @param text
the geometry as a
Well Known Text
* @param srid
the projection id
* @return Geometry object
*/
public
static
Geometry
geomFromText
(
String
text
,
int
srid
)
throws
SQLException
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论