sqlite: disassociate extent calculation from rtree auto-index creation, and grab immediate lock on rtree table
This commit is contained in:
parent
3750171680
commit
a4715aa8df
2 changed files with 37 additions and 45 deletions
|
@ -245,12 +245,8 @@ void sqlite_datasource::bind() const
|
|||
dataset_->execute("attach database '" + index_db + "' as " + index_table_);
|
||||
}
|
||||
has_spatial_index_ = sqlite_utils::has_rtree(index_table_,dataset_);
|
||||
}
|
||||
|
||||
|
||||
if (! extent_initialized_
|
||||
&& !has_spatial_index_
|
||||
&& auto_index)
|
||||
if (!has_spatial_index_ && auto_index)
|
||||
{
|
||||
if (! key_field_.empty())
|
||||
{
|
||||
|
@ -261,9 +257,14 @@ void sqlite_datasource::bind() const
|
|||
<< " FROM ("
|
||||
<< geometry_table_ << ")";
|
||||
boost::shared_ptr<sqlite_resultset> rs = dataset_->execute_query(query.str());
|
||||
if (sqlite_utils::create_spatial_index(index_db,index_table_,rs,extent_))
|
||||
if (sqlite_utils::create_spatial_index(index_db,index_table_,rs))
|
||||
{
|
||||
extent_initialized_ = true;
|
||||
//extent_initialized_ = true;
|
||||
has_spatial_index_ = true;
|
||||
if (boost::filesystem::exists(index_db))
|
||||
{
|
||||
dataset_->execute("attach database '" + index_db + "' as " + index_table_);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -276,6 +277,7 @@ void sqlite_datasource::bind() const
|
|||
throw datasource_exception(s.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! extent_initialized_)
|
||||
{
|
||||
|
|
|
@ -182,8 +182,7 @@ public:
|
|||
|
||||
static bool create_spatial_index(std::string const& index_db,
|
||||
std::string const& index_table,
|
||||
boost::shared_ptr<sqlite_resultset> rs,
|
||||
mapnik::box2d<double>& extent)
|
||||
boost::shared_ptr<sqlite_resultset> rs)
|
||||
{
|
||||
/* TODO
|
||||
- speedups
|
||||
|
@ -203,8 +202,11 @@ public:
|
|||
bool existed = boost::filesystem::exists(index_db);
|
||||
boost::shared_ptr<sqlite_connection> ds = boost::make_shared<sqlite_connection>(index_db,flags);
|
||||
|
||||
bool one_success = false;
|
||||
try
|
||||
{
|
||||
ds->execute("PRAGMA synchronous=OFF");
|
||||
ds->execute("BEGIN TRANSACTION");
|
||||
ds->execute("BEGIN IMMEDIATE TRANSACTION");
|
||||
|
||||
// first drop the index if it already exists
|
||||
std::ostringstream spatial_index_drop_sql;
|
||||
|
@ -227,10 +229,6 @@ public:
|
|||
|
||||
prepared_index_statement ps(ds,insert_idx.str());
|
||||
|
||||
bool one_success = false;
|
||||
try
|
||||
{
|
||||
bool first = true;
|
||||
while (rs->is_valid() && rs->step_next())
|
||||
{
|
||||
int size;
|
||||
|
@ -246,15 +244,6 @@ public:
|
|||
mapnik::box2d<double> const& bbox = paths[i].envelope();
|
||||
if (bbox.valid())
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
extent = bbox;
|
||||
}
|
||||
else
|
||||
{
|
||||
extent.expand_to_include(bbox);
|
||||
}
|
||||
|
||||
ps.bind(bbox);
|
||||
|
||||
|
@ -397,8 +386,9 @@ public:
|
|||
return true;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
catch (std::exception const& ex)
|
||||
{
|
||||
//std::clog << "no: " << ex.what() << "\n";
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue