提交 4a353c0f authored 作者: Thomas Mueller's avatar Thomas Mueller

Spatial index (work in progress)

上级 0fd0134f
...@@ -182,9 +182,9 @@ public class IndexCursor implements Cursor { ...@@ -182,9 +182,9 @@ public class IndexCursor implements Cursor {
if (row == null) { if (row == null) {
row = table.getTemplateRow(); row = table.getTemplateRow();
} else if (row.getValue(columnId) != null) { } else if (row.getValue(columnId) != null) {
// the intersection of the two envelopes // the union of the two envelopes
ValueGeometry vg = (ValueGeometry) row.getValue(columnId).convertTo(Value.GEOMETRY); ValueGeometry vg = (ValueGeometry) row.getValue(columnId).convertTo(Value.GEOMETRY);
v = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getEnvelopeIntersection(vg); v = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getEnvelopeUnion(vg);
} }
if (columnId < 0) { if (columnId < 0) {
row.setKey(v.getLong()); row.setKey(v.getLong());
......
...@@ -88,6 +88,19 @@ public class ValueGeometry extends Value { ...@@ -88,6 +88,19 @@ public class ValueGeometry extends Value {
return geometry.getEnvelopeInternal().intersects(r.getGeometry().getEnvelopeInternal()); return geometry.getEnvelopeInternal().intersects(r.getGeometry().getEnvelopeInternal());
} }
/**
* Get the union.
*
* @param r the other geometry
* @return the union of this geometry envelope and another geometry envelope
*/
public Value getEnvelopeUnion(ValueGeometry r) {
GeometryFactory gf = new GeometryFactory();
Envelope mergedEnvelope = new Envelope(geometry.getEnvelopeInternal());
mergedEnvelope.expandToInclude(r.getGeometry().getEnvelopeInternal());
return get(gf.toGeometry(mergedEnvelope));
}
/** /**
* Get the intersection. * Get the intersection.
* *
......
...@@ -56,15 +56,14 @@ public class TestSpatial extends TestBase { ...@@ -56,15 +56,14 @@ public class TestSpatial extends TestBase {
public void test() throws SQLException { public void test() throws SQLException {
if (DataType.GEOMETRY_CLASS != null) { if (DataType.GEOMETRY_CLASS != null) {
deleteDb("spatial"); deleteDb("spatial");
// testSpatialValues(); testSpatialValues();
// testOverlap(); testOverlap();
// testNotOverlap(); testNotOverlap();
// testPersistentSpatialIndex(); testPersistentSpatialIndex();
// testSpatialIndexQueryMultipleTable(); testSpatialIndexQueryMultipleTable();
// testIndexTransaction(); testIndexTransaction();
// testJavaAlias(); testJavaAlias();
// testJavaAliasTableFunction(); testJavaAliasTableFunction();
// testPersistentSpatialIndex2();
testMemorySpatialIndex(); testMemorySpatialIndex();
testRandom(); testRandom();
deleteDb("spatial"); deleteDb("spatial");
...@@ -494,40 +493,5 @@ public class TestSpatial extends TestBase { ...@@ -494,40 +493,5 @@ public class TestSpatial extends TestBase {
throw new SQLException(ex); throw new SQLException(ex);
} }
} }
/**
* Not really a test case but show that something go crazy (in mvstore) after some seconds.
* @throws SQLException
*/
private void testPersistentSpatialIndex2() throws SQLException {
deleteDb("spatial_pers");
final long count = 150000;
Connection conn = getConnection("spatial_pers");
try {
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key auto_increment, the_geom geometry)");
PreparedStatement ps = conn.prepareStatement("insert into test(the_geom) values(?)");
Random rnd = new Random(44);
for(int i=0;i<count;i++) {
ps.setObject(1,getRandomGeometry(rnd,0,100,-50,50,3));
ps.execute();
}
stat.execute("create spatial index on test(the_geom)");
Database db = ((Session)((JdbcConnection) conn).getSession()).getDatabase();
MVStore store = db.getMvStore().getStore();
int cpt=0;
while(cpt<46) {
try {
// First it shows 610, then 5 until cpt==44, finally at cpt==45 it shows an unsaved 688 with a trace in spatial_pers.trace.db
System.out.println((cpt++)+" store.getUnsavedPageCount()=="+store.getUnsavedPageCount());
Thread.sleep(1000);
} catch (InterruptedException ex) {
throw new SQLException(ex);
}
}
} finally {
// Close the database
conn.close();
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论