void Selector::alterSchema(PointBuffer& buffer) { Schema const& original_schema = buffer.getSchema(); Schema new_schema = buffer.getSchema(); std::map<std::string, bool> const& ignoredMap = m_selectorFilter.getIgnoredMap(); // for (std::map<std::string, bool>::const_iterator i = ignoredMap.begin(); // i != ignoredMap.end(); ++i) // { // boost::optional<Dimension const&> d = original_schema.getDimensionOptional(i->first); // if (d) // { // Dimension d2(*d); // boost::uint32_t flags = d2.getFlags(); // if (i->second) // d2.setFlags(flags | dimension::IsIgnored); // new_schema.setDimension(d2); // } // } // schema::Map dimensions = original_schema.getDimensions(); schema::index_by_index const& dims = dimensions.get<schema::index>(); for (schema::index_by_index::const_iterator t = dims.begin(); t != dims.end(); ++t) { std::map<std::string, bool>::const_iterator ignored = ignoredMap.find(t->getName()); if (ignored != ignoredMap.end()) { if (ignored->second) // marked to be dropped { // set to ignored Dimension d2(*t); boost::uint32_t flags = d2.getFlags(); d2.setFlags(flags | dimension::IsIgnored); new_schema.setDimension(d2); } } else { // didn't find it in our map of specified dimensions if (m_selectorFilter.doIgnoreUnspecifiedDimensions()) { // set to ignored Dimension d2(*t); boost::uint32_t flags = d2.getFlags(); d2.setFlags(flags | dimension::IsIgnored); new_schema.setDimension(d2); } } } buffer = PointBuffer(new_schema, buffer.getCapacity()); }
boost::uint64_t Writer::write(boost::uint64_t targetNumPointsToWrite) { if (!isInitialized()) { throw pdal_error("stage not initialized"); } boost::uint64_t actualNumPointsWritten = 0; UserCallback* callback = getUserCallback(); do_callback(0.0, callback); boost::scoped_ptr<StageSequentialIterator> iter(getPrevStage().createSequentialIterator()); if (!iter) throw pdal_error("Unable to obtain iterator from previous stage!"); // if we don't have an SRS, try to forward the one from the prev stage if (m_spatialReference.empty()) m_spatialReference = getPrevStage().getSpatialReference(); writeBegin(targetNumPointsToWrite); iter->readBegin(); const Schema& schema = getPrevStage().getSchema(); PointBuffer buffer(schema, m_chunkSize); // // The user has requested a specific number of points: proceed a // chunk at a time until we reach that number. (If that number // is 0, we proceed until no more points can be read.) // // If the user requests an interrupt while we're running, we'll throw. // while (true) { // have we hit the end already? if (iter->atEnd()) break; // rebuild our PointBuffer, if it needs to hold less than the default max chunk size if (targetNumPointsToWrite != 0) { const boost::uint64_t numRemainingPointsToRead = targetNumPointsToWrite - actualNumPointsWritten; const boost::uint64_t numPointsToReadThisChunk64 = std::min<boost::uint64_t>(numRemainingPointsToRead, m_chunkSize); // this case is safe because m_chunkSize is a uint32 const boost::uint32_t numPointsToReadThisChunk = static_cast<boost::uint32_t>(numPointsToReadThisChunk64); // we are reusing the buffer, so we may need to adjust the capacity for the last (and likely undersized) chunk if (buffer.getCapacity() != numPointsToReadThisChunk) { buffer = PointBuffer(schema, numPointsToReadThisChunk); } } // read... iter->readBufferBegin(buffer); const boost::uint32_t numPointsReadThisChunk = iter->readBuffer(buffer); iter->readBufferEnd(buffer); assert(numPointsReadThisChunk == buffer.getNumPoints()); assert(numPointsReadThisChunk <= buffer.getCapacity()); // have we reached the end yet? if (numPointsReadThisChunk == 0) break; // write... writeBufferBegin(buffer); const boost::uint32_t numPointsWrittenThisChunk = writeBuffer(buffer); assert(numPointsWrittenThisChunk == numPointsReadThisChunk); writeBufferEnd(buffer); // update count actualNumPointsWritten += numPointsWrittenThisChunk; do_callback(actualNumPointsWritten, targetNumPointsToWrite, callback); if (targetNumPointsToWrite != 0) { // have we done enough yet? if (actualNumPointsWritten >= targetNumPointsToWrite) break; } // reset the buffer, so we can use it again buffer.setNumPoints(0); } iter->readEnd(); writeEnd(actualNumPointsWritten); assert((targetNumPointsToWrite == 0) || (actualNumPointsWritten <= targetNumPointsToWrite)); do_callback(100.0, callback); return actualNumPointsWritten; }