Skip to content

Commit

Permalink
w00t! Rialto is now a GeoPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgerlek committed May 21, 2015
1 parent 2578f49 commit d34b3f4
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 457 deletions.
451 changes: 90 additions & 361 deletions plugins/rialto/io/RialtoDb.cpp

Large diffs are not rendered by default.

28 changes: 13 additions & 15 deletions plugins/rialto/io/RialtoDb.hpp
Expand Up @@ -112,32 +112,33 @@ class PDAL_DLL RialtoDb
// adds a tile set to the database, including its dimensions
//
// returns id of new data set
uint32_t writeTileSet(const RialtoDb::TileSetInfo& data);
void writeTileSet(const RialtoDb::TileSetInfo& data);

// returns id of new tile
uint32_t writeTile(const std::string& tileSetName, const RialtoDb::TileInfo& data);
void writeTile(const std::string& tileSetName, const RialtoDb::TileInfo& data);

// get list all the tile sets in the database, as a list of its
void readTileSetIds(std::vector<uint32_t>&, std::vector<std::string>& names) const;
void readTileSetIds(std::vector<std::string>& names) const;

// get info about a specific tile set (including its dimensions)
void readTileSetInfo(uint32_t tileSetId, std::string const& name, TileSetInfo& info) const;
void readTileSetInfo(std::string const& name, TileSetInfo& info) const;

// get info about a tile
void readTileInfo(uint32_t tileId, bool withPoints, TileInfo& tileInfo) const;
void readTileInfo(std::string const& name, uint32_t tileId, bool withPoints, TileInfo& tileInfo) const;

// use with caution for levels greater than 16 or so
void readTileIdsAtLevel(uint32_t tileSetId, uint32_t level, std::vector<uint32_t>& tileIds) const;
// DANGER: this assumes only one tile set per database, use only for testing
void readTileIdsAtLevel(std::string const& name, uint32_t level, std::vector<uint32_t>& tileIds) const;

// query for all the tiles of a tile set, bounded by bbox region
void queryForTileIds(uint32_t tileSetId,
void queryForTileIds(std::string const& name,
double minx, double miny,
double maxx, double maxy,
uint32_t level,
std::vector<uint32_t>& ids) const;

// combines query-for-tile-ids with query-for-tile-info
void queryForTileInfosBegin(uint32_t tileSetId, std::string const& name,
void queryForTileInfosBegin(std::string const& name,
double minx, double miny,
double maxx, double maxy,
uint32_t level);
Expand All @@ -158,14 +159,11 @@ class PDAL_DLL RialtoDb
void dumpStats() const;

private:
// create the req'd tables in the db
void createTileSetsTable();
void createTableGpkgContents();
void createTilesTable();
void createDimensionsTable();

void verifyTableExists(std::string const& name) const;

void createGpkgId();
void createTableGpkgSpatialRefSys();
void createTableGpkgContents();
void createTableGpkgPctileMatrixSet();
void createTableGpkgPctileMatrix();
void createTableTilePyramidUserData(const std::string& table_name);
Expand All @@ -179,7 +177,7 @@ class PDAL_DLL RialtoDb
const std::vector<DimensionInfo>& dimensions);

// get info about one of the dimensions of a tile set
void readDimensionsInfo(uint32_t tileSetId, std::string const& name, std::vector<DimensionInfo>&) const;
void readDimensionsInfo(std::string const& name, std::vector<DimensionInfo>&) const;

void matrixSizeAtLevel(uint32_t level, uint32_t& numCols, uint32_t& numRows) const;

Expand Down
27 changes: 4 additions & 23 deletions plugins/rialto/io/RialtoDbReader.cpp
Expand Up @@ -63,16 +63,14 @@ void RialtoDbReader::initialize()
m_db = std::unique_ptr<RialtoDb>(new RialtoDb(m_filename, log()));
m_db->open(false);

std::vector<uint32_t> ids;
std::vector<std::string> names;
m_db->readTileSetIds(ids, names);
assert(ids.size()==1); // TODO: always take the first one for now
m_tileSetId = ids[0];
m_db->readTileSetIds(names);
m_tileSetName = names[0];
assert(names.size()==1); // TODO: always take the first one for now

m_tileSetInfo = std::unique_ptr<RialtoDb::TileSetInfo>(new RialtoDb::TileSetInfo());

m_db->readTileSetInfo(m_tileSetId, names[0], *m_tileSetInfo);
m_db->readTileSetInfo(m_tileSetName, *m_tileSetInfo);
}
}

Expand Down Expand Up @@ -142,23 +140,7 @@ point_count_t RialtoDbReader::read(PointViewPtr view, point_count_t count)
maxLevel = m_tileSetInfo->maxLevel;
}

#if 0
std::vector<uint32_t> ids;
m_db->queryForTileIds(m_tileSetId, minx, miny, maxx, maxy, maxLevel, ids);

for (auto id: ids)
{
RialtoDb::TileInfo info;
m_db->readTileInfo(id, true, info);

log()->get(LogLevel::Debug) << " got some points: " << info.numPoints << std::endl;

m_db->serializeToPointView(info, view);

log()->get(LogLevel::Debug) << " view now has this many: " << view->size() << std::endl;
}
#else
m_db->queryForTileInfosBegin(m_tileSetId, "myunnamedlasfile", minx, miny, maxx, maxy, maxLevel);
m_db->queryForTileInfosBegin(m_tileSetName, minx, miny, maxx, maxy, maxLevel);

RialtoDb::TileInfo info;

Expand All @@ -184,7 +166,6 @@ point_count_t RialtoDbReader::read(PointViewPtr view, point_count_t count)

log()->get(LogLevel::Debug) << " view now has this many: " << view->size() << std::endl;
} while (m_db->queryForTileInfosNext());
#endif

return view->size();
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/rialto/io/RialtoDbReader.hpp
Expand Up @@ -64,7 +64,7 @@ class PDAL_DLL RialtoDbReader : public Reader

private:
std::unique_ptr<RialtoDb> m_db;
uint32_t m_tileSetId;
std::string m_tileSetName;
uint32_t m_level;
std::unique_ptr<RialtoDb::TileSetInfo> m_tileSetInfo;
BOX3D m_query;
Expand Down
12 changes: 5 additions & 7 deletions plugins/rialto/io/RialtoDbWriter.cpp
Expand Up @@ -65,7 +65,7 @@ namespace



uint32_t RialtoDbWriter::writeHeader(const std::string& tileSetName,
void RialtoDbWriter::writeHeader(const std::string& tileSetName,
MetadataNode tileSetNode,
PointLayoutPtr layout)
{
Expand All @@ -74,24 +74,22 @@ uint32_t RialtoDbWriter::writeHeader(const std::string& tileSetName,
RialtoDb::TileSetInfo tileSetInfo;
serializeToTileSetInfo(tileSetName, tileSetNode, layout, tileSetInfo);

const uint32_t tileSetId = m_rialtoDb->writeTileSet(tileSetInfo);

return tileSetId;
m_rialtoDb->writeTileSet(tileSetInfo);
}


void RialtoDbWriter::writeTile(uint32_t tileSetId, const std::string& tileSetName, PointView* view, uint32_t level, uint32_t col, uint32_t row, uint32_t mask)
void RialtoDbWriter::writeTile(const std::string& tileSetName, PointView* view, uint32_t level, uint32_t col, uint32_t row, uint32_t mask)
{
//log()->get(LogLevel::Debug1) << "RialtoDbWriter::writeTile()" << std::endl;

//printf("writing tile %d/%d/%d\n", level, col, row);

RialtoDb::TileInfo tileInfo;
serializeToTileInfo(tileSetId, view, tileInfo, level, col, row, mask);
serializeToTileInfo(view, tileInfo, level, col, row, mask);

if (tileInfo.patch.buf.size())
{
uint32_t id = m_rialtoDb->writeTile(tileSetName, tileInfo);
m_rialtoDb->writeTile(tileSetName, tileInfo);
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/rialto/io/RialtoDbWriter.hpp
Expand Up @@ -62,10 +62,10 @@ class PDAL_DLL RialtoDbWriter : public RialtoWriter
Options getDefaultOptions();

virtual void localStart();
virtual uint32_t writeHeader(const std::string& tileSetName,
virtual void writeHeader(const std::string& tileSetName,
MetadataNode tileSetNode,
PointLayoutPtr layout);
virtual void writeTile(uint32_t tileSetId, const std::string& tileSetName, PointView*, uint32_t level, uint32_t col, uint32_t row, uint32_t mask);
virtual void writeTile(const std::string& tileSetName, PointView*, uint32_t level, uint32_t col, uint32_t row, uint32_t mask);
virtual void localFinish();

private:
Expand Down
8 changes: 3 additions & 5 deletions plugins/rialto/io/RialtoFileWriter.cpp
Expand Up @@ -61,7 +61,7 @@ namespace
} // anonymous namespace


uint32_t RialtoFileWriter::writeHeader(const std::string& tileSetName,
void RialtoFileWriter::writeHeader(const std::string& tileSetName,
MetadataNode tileSetNode,
PointLayoutPtr layout)
{
Expand Down Expand Up @@ -98,16 +98,14 @@ uint32_t RialtoFileWriter::writeHeader(const std::string& tileSetName,
fprintf(fp, "}\n");

fclose(fp);

return 0; // tile set id not used for files
}

void RialtoFileWriter::writeTile(uint32_t tileSetId, const std::string& tileSetName, PointView* view, uint32_t level, uint32_t col, uint32_t row, uint32_t mask)
void RialtoFileWriter::writeTile(const std::string& tileSetName, PointView* view, uint32_t level, uint32_t col, uint32_t row, uint32_t mask)
{
log()->get(LogLevel::Debug) << "RialtoFileWriter::writeTile()" << std::endl;

RialtoDb::TileInfo tileInfo;
serializeToTileInfo(tileSetId, view, tileInfo, level, col, row, mask);
serializeToTileInfo(view, tileInfo, level, col, row, mask);

std::ostringstream os;

Expand Down
4 changes: 2 additions & 2 deletions plugins/rialto/io/RialtoFileWriter.hpp
Expand Up @@ -61,10 +61,10 @@ class PDAL_DLL RialtoFileWriter : public RialtoWriter
Options getDefaultOptions();

virtual void localStart();
virtual uint32_t writeHeader(const std::string& tileSetName,
virtual void writeHeader(const std::string& tileSetName,
MetadataNode tileSetNode,
PointLayoutPtr layout);
virtual void writeTile(uint32_t tileSetId, const std::string& tileSetName, PointView*, uint32_t level, uint32_t col, uint32_t row, uint32_t mask);
virtual void writeTile(const std::string& tileSetName, PointView*, uint32_t level, uint32_t col, uint32_t row, uint32_t mask);
virtual void localFinish();

private:
Expand Down
12 changes: 5 additions & 7 deletions plugins/rialto/io/RialtoWriter.cpp
Expand Up @@ -148,11 +148,9 @@ void RialtoWriter::serializeToPatch(const PointView& view, Patch& patch)
}


void RialtoWriter::serializeToTileInfo(uint32_t tileSetId, PointView* view, RialtoDb::TileInfo& tileInfo,
void RialtoWriter::serializeToTileInfo(PointView* view, RialtoDb::TileInfo& tileInfo,
uint32_t level, uint32_t col, uint32_t row, uint32_t mask)
{
tileInfo.tileSetId = tileSetId;

{
tileInfo.level = level;
tileInfo.column = col;
tileInfo.row = row;
Expand Down Expand Up @@ -233,7 +231,7 @@ void RialtoWriter::ready(PointTableRef table)
throw pdal_error("RialtoWriter: \"filters.tiler\" metadata not found");
}

m_tileSetId = writeHeader(m_tileSetName, tileSetNode, m_table->layout());
writeHeader(m_tileSetName, tileSetNode, m_table->layout());

makePointViewMap(tileSetNode);
}
Expand All @@ -254,7 +252,7 @@ void RialtoWriter::write(const PointViewPtr viewPtr)
uint32_t pvid = m_tileMetadata[idx+4];
assert(pvid == 0xffffffff || pvid == (uint32_t)viewPtr->id());

writeTile(m_tileSetId, m_tileSetName, view, level, col, row, mask);
writeTile(m_tileSetName, view, level, col, row, mask);
}


Expand Down Expand Up @@ -317,7 +315,7 @@ void RialtoWriter::writeEmptyTiles()

if (pvid == 0xffffffff)
{
writeTile(m_tileSetId, m_tileSetName, NULL, level, col, row, mask);
writeTile(m_tileSetName, NULL, level, col, row, mask);
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions plugins/rialto/io/RialtoWriter.hpp
Expand Up @@ -71,7 +71,7 @@ class PDAL_DLL RialtoWriter : public Writer
PointLayoutPtr layout,
std::vector<RialtoDb::DimensionInfo>& infoList);
static void serializeToPatch(const PointView& view, Patch& patch);
static void serializeToTileInfo(uint32_t tileSetId, PointView* view, RialtoDb::TileInfo& tileInfo,
static void serializeToTileInfo(PointView* view, RialtoDb::TileInfo& tileInfo,
uint32_t level, uint32_t col, uint32_t row, uint32_t mask);

static uint32_t getMetadataU32(const MetadataNode& parent, const std::string& name);
Expand All @@ -89,10 +89,10 @@ class PDAL_DLL RialtoWriter : public Writer

// implemented in derived classes
virtual void localStart() = 0;
virtual uint32_t writeHeader(const std::string& tileSetName,
virtual void writeHeader(const std::string& tileSetName,
MetadataNode tileSetNode,
PointLayoutPtr layout) = 0;
virtual void writeTile(uint32_t tileSetId, const std::string& tileSetName, PointView*, uint32_t level, uint32_t col, uint32_t row, uint32_t mask) = 0;
virtual void writeTile(const std::string& tileSetName, PointView*, uint32_t level, uint32_t col, uint32_t row, uint32_t mask) = 0;
virtual void localFinish() = 0;

std::string m_tileSetName;
Expand All @@ -109,8 +109,6 @@ class PDAL_DLL RialtoWriter : public Writer
BasePointTable *m_table;
std::string m_directory;

uint32_t m_tileSetId;

std::map<uint32_t, uint32_t> m_pointViewMap2; // PV id to array index
uint32_t* m_tileMetadata;
uint32_t m_numTiles;
Expand Down

0 comments on commit d34b3f4

Please sign in to comment.