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
...
...
@@ -32,7 +32,7 @@ import com.vividsolutions.jts.io.WKTReader;
/**
* Spatial datatype and index tests.
*
*
* @author Thomas Mueller
* @author Noel Grandin
* @author Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
...
...
@@ -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
...
...
@@ -109,13 +110,13 @@ public class TestSpatial extends TestBase {
* @param maxLength LineString maximum length
* @return A segment within this bounding box
*/
public
static
Geometry
getRandomGeometry
(
Random
geometryRand
,
double
minX
,
double
maxX
,
public
static
Geometry
getRandomGeometry
(
Random
geometryRand
,
double
minX
,
double
maxX
,
double
minY
,
double
maxY
,
double
maxLength
)
{
GeometryFactory
factory
=
new
GeometryFactory
();
// Create the start point
Coordinate
start
=
new
Coordinate
(
geometryRand
.
nextDouble
()
*
(
maxX
-
minX
)
+
minX
,
geometryRand
.
nextDouble
()
*
(
maxX
-
minX
)
+
minX
,
geometryRand
.
nextDouble
()
*
(
maxY
-
minY
)
+
minY
);
// Compute an angle
double
angle
=
geometryRand
.
nextDouble
()
*
Math
.
PI
*
2
;
...
...
@@ -135,41 +136,41 @@ public class TestSpatial extends TestBase {
testRandom
(
conn
,
44
,
3500
);
conn
.
close
();
}
private
void
testRandom
(
Connection
conn
,
long
seed
,
long
size
)
throws
SQLException
{
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
stat
.
execute
(
"create memory table test("
+
"id long primary key auto_increment, poly geometry)"
);
// Create segment generation bounding box
Envelope
bbox
=
ValueGeometry
.
get
(
"POLYGON (("
+
"301804.1049793153 2251719.1222191923
, "
+
"301804.1049793153 2254747.2888244865, "
+
"304646.87362918374 2254747.2888244865
, "
+
"304646.87362918374 2251719.1222191923, "
+
"301804.1049793153 2251719.1222191923))"
)
.
getGeometry
().
getEnvelopeInternal
();
// Create overlap test bounding box
String
testBBoxString
=
"POLYGON (("
+
"302215.44416332216 2252748, "
+
"302215.4441633221
6 2253851.781225762, "
+
"303582.85796541866 2253851.781225762, "
+
"303582.85796541866 2252748.526908161, "
+
"302215.44416332216 2252748))"
;
Envelope
testBBox
=
ValueGeometry
.
get
(
testBBoxString
).
getGeometry
().
getEnvelopeInternal
();
PreparedStatement
ps
=
conn
.
prepareStatement
(
"insert into test(poly) values (?)"
);
long
overlapCount
=
0
;
private
void
testRandom
(
Connection
conn
,
long
seed
,
long
size
)
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop table if exists test"
);
Random
geometryRand
=
new
Random
(
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
boundingBox
=
ValueGeometry
.
get
(
"POLYGON (("
+
"301804.1049793153 2251719.1222191923, "
+
"301804.1049793153 2254747.2888244865
, "
+
"304646.87362918374 2254747.2888244865, "
+
"304646.87362918374 2251719.1222191923
, "
+
"301804.1049793153 2251719.1222191923))"
)
.
getGeometry
().
getEnvelopeInternal
();
// Create overlap test bounding box
String
testBoundingBoxString
=
"POLYGON (("
+
"302215.44416332216 2252748, "
+
"302215.44416332216 2253851.781225762, "
+
"303582.8579654186
6 2253851.781225762, "
+
"303582.85796541866 2252748.526908161, "
+
"302215.44416332216 2252748))"
;
Envelope
testBBox
=
ValueGeometry
.
get
(
testBoundingBoxString
).
getGeometry
().
getEnvelopeInternal
();
PreparedStatement
ps
=
conn
.
prepareStatement
(
"insert into test(poly) values (?)"
);
long
overlapCount
=
0
;
Set
<
Integer
>
overlaps
=
new
HashSet
<
Integer
>(
680
);
for
(
int
i
=
1
;
i
<=
size
;
i
++)
{
Geometry
geometry
=
getRandomGeometry
(
geometryRand
,
b
box
.
getMinX
(),
bbox
.
getMaxX
(),
b
box
.
getMinY
(),
bb
ox
.
getMaxY
(),
200
);
geometryRand
,
b
oundingBox
.
getMinX
(),
boundingBox
.
getMaxX
(),
b
oundingBox
.
getMinY
(),
boundingB
ox
.
getMaxY
(),
200
);
ps
.
setObject
(
1
,
geometry
);
ps
.
execute
();
ResultSet
keys
=
ps
.
getGeneratedKeys
();
...
...
@@ -178,14 +179,13 @@ public class TestSpatial extends TestBase {
overlapCount
++;
overlaps
.
add
(
keys
.
getInt
(
1
));
}
}
ps
.
close
();
// 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
.
close
();
// 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
,
testBoundingBoxString
);
ResultSet
rs
=
ps
.
executeQuery
();
long
found
=
0
;
while
(
rs
.
next
())
{
...
...
@@ -194,10 +194,11 @@ public class TestSpatial extends TestBase {
}
// Index count must be the same as sequential count
assertEquals
(
overlapCount
,
found
);
// Missing id still in overlaps map
assertTrue
(
overlaps
.
isEmpty
());
stat
.
execute
(
"drop table if exists test"
);
}
// Missing id still in overlaps map
assertTrue
(
overlaps
.
isEmpty
());
stat
.
execute
(
"drop table if exists test"
);
}
private
void
testOverlap
()
throws
SQLException
{
deleteDb
(
"spatial"
);
Connection
conn
=
getConnection
(
"spatial"
);
...
...
@@ -209,7 +210,7 @@ public class TestSpatial extends TestBase {
stat
.
execute
(
"insert into test values(3, 'POLYGON ((1 3, 1 4, 2 4, 1 3))')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test "
+
"select * from test "
+
"where poly && 'POINT (1.5 1.5)'::Geometry"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
"id"
));
...
...
@@ -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)"
);
...
...
@@ -231,7 +232,7 @@ public class TestSpatial extends TestBase {
stat
.
execute
(
"create spatial index on test(poly)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test "
+
"select * from test "
+
"where poly && 'POINT (1.5 1.5)'::Geometry"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
"id"
));
...
...
@@ -240,8 +241,8 @@ public class TestSpatial extends TestBase {
// Test with multiple operator
rs
=
stat
.
executeQuery
(
"select * from test "
+
"where poly && 'POINT (1.5 1.5)'::Geometry "
+
"select * from test "
+
"where poly && 'POINT (1.5 1.5)'::Geometry "
+
"AND poly && 'POINT (1.7 1.75)'::Geometry"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
"id"
));
...
...
@@ -251,16 +252,16 @@ public class TestSpatial extends TestBase {
// Close the database
conn
.
close
();
}
if
(
config
.
memory
)
{
return
;
}
conn
=
getConnection
(
"spatial
_pers
"
);
conn
=
getConnection
(
"spatial
Persistent
"
);
try
{
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test "
+
"select * from test "
+
"where poly && 'POINT (1.5 1.5)'::Geometry"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
"id"
));
...
...
@@ -282,7 +283,7 @@ public class TestSpatial extends TestBase {
stat
.
execute
(
"insert into test values(3, 'POLYGON ((1 3, 1 4, 2 4, 1 3))')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test "
+
"select * from test "
+
"where NOT poly && 'POINT (1.5 1.5)'::Geometry"
);
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
"id"
));
...
...
@@ -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 "
+
"from area, roads "
+
"where area.the_geom && roads.the_geom "
+
"GROUP BY id
area ORDER BY ida
rea"
);
"select id
Area, COUNT(idRoad) roadCount "
+
"from area, roads "
+
"where area.the_geom && roads.the_geom "
+
"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 "
+
"from area, roads "
+
"where area.the_geom && roads.the_geom "
+
"GROUP BY id
area ORDER BY ida
rea"
);
"select id
Area, COUNT(idRoad) roadCount "
+
"from area, roads "
+
"where area.the_geom && roads.the_geom "
+
"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
);
...
...
@@ -400,10 +414,10 @@ public class TestSpatial extends TestBase {
}
}
/**
* Test the in the in-memory spatial index
*/
/**
* Test the in the in-memory spatial index
*/
private
void
testMemorySpatialIndex
()
throws
SQLException
{
deleteDb
(
"spatialIndex"
);
Connection
conn
=
getConnection
(
"spatialIndex"
);
...
...
@@ -413,42 +427,43 @@ public class TestSpatial extends TestBase {
stat
.
execute
(
"create spatial index idx_test_polygon on test(polygon)"
);
stat
.
execute
(
"insert into test values(1, 'POLYGON ((1 1, 1 2, 2 2, 1 1))')"
);
ResultSet
rs
;
// an query that can not possibly return a result
rs
=
stat
.
executeQuery
(
"select * from test "
+
rs
=
stat
.
executeQuery
(
"select * from test "
+
"where polygon && 'POLYGON ((1 1, 1 2, 2 2, 1 1))'::Geometry "
+
"and polygon && 'POLYGON ((10 10, 10 20, 20 20, 10 10))'::Geometry"
);
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"explain select * from test "
+
"explain select * from test "
+
"where polygon && 'POLYGON ((1 1, 1 2, 2 2, 1 1))'::Geometry"
);
rs
.
next
();
assertContains
(
rs
.
getString
(
1
),
"/* PUBLIC.IDX_TEST_POLYGON: POLYGON &&"
);
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 =");
// these queries actually have no meaning in the context of a spatial index, but
// these queries actually have no meaning in the context of a spatial index, but
// check them anyhow
stat
.
executeQuery
(
"select * from test where polygon > 'POLYGON ((1 1, 1 2, 2 2, 1 1))'::Geometry"
);
stat
.
executeQuery
(
"select * from test where polygon < 'POLYGON ((1 1, 1 2, 2 2, 1 1))'::Geometry"
);
rs
=
stat
.
executeQuery
(
"select * from test "
+
"select * from test "
+
"where intersects(polygon, 'POLYGON ((1 1, 1 2, 2 2, 1 1))')"
);
assertTrue
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"select * from test "
+
"select * from test "
+
"where intersects(polygon, 'POINT (1 1)')"
);
assertTrue
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"select * from test "
+
"select * from test "
+
"where intersects(polygon, 'POINT (0 0)')"
);
assertFalse
(
rs
.
next
());
...
...
@@ -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
());
...
...
@@ -486,13 +502,13 @@ public class TestSpatial extends TestBase {
Connection
conn
=
getConnection
(
"spatialIndex"
);
try
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE ALIAS T_RANDOM_GEOM_TABLE FOR \""
+
stat
.
execute
(
"CREATE ALIAS T_RANDOM_GEOM_TABLE FOR \""
+
TestSpatial
.
class
.
getName
()
+
".getRandomGeometryTable\""
);
stat
.
execute
(
"create table test as "
+
"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
{
...
...
@@ -503,7 +519,7 @@ public class TestSpatial extends TestBase {
/**
* Generate a result set with random geometry data.
*
*
* @param seed the random seed
* @param rowCount the number of rows
* @param minX the smallest x
...
...
@@ -514,21 +530,21 @@ public class TestSpatial extends TestBase {
* @return a result set
*/
public
static
ResultSet
getRandomGeometryTable
(
final
long
seed
,
final
long
rowCount
,
final
long
seed
,
final
long
rowCount
,
final
double
minX
,
final
double
maxX
,
final
double
minY
,
final
double
maxY
,
final
double
maxLength
)
{
SimpleResultSet
rs
=
new
SimpleResultSet
(
new
SimpleRowSource
()
{
private
final
Random
random
=
new
Random
(
seed
);
private
int
currentRow
;
@Override
public
Object
[]
readRow
()
throws
SQLException
{
if
(
currentRow
++
<
rowCount
)
{
return
new
Object
[]
{
getRandomGeometry
(
random
,
minX
,
maxX
,
minY
,
maxY
,
maxLength
)
};
return
new
Object
[]
{
getRandomGeometry
(
random
,
minX
,
maxX
,
minY
,
maxY
,
maxLength
)
};
}
return
null
;
}
...
...
@@ -549,9 +565,9 @@ 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
{
...
...
@@ -564,5 +580,5 @@ public class TestSpatial extends TestBase {
throw
new
SQLException
(
ex
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论