void ByteSwap::initialize() { Filter::initialize(); const Stage& stage = getPrevStage(); this->setNumPoints(stage.getNumPoints()); this->setPointCountType(stage.getPointCountType()); schema::index_by_index const& dimensions = m_schema.getDimensions().get<schema::index>(); std::vector<Dimension> new_dimensions; for (schema::index_by_index::const_iterator i = dimensions.begin(); i != dimensions.end(); ++i) { pdal::Dimension d(*i); pdal::EndianType t = i->getEndianness(); if (t == Endian_Little) { d.setEndianness(Endian_Big); } else if (t == Endian_Big) { d.setEndianness(Endian_Little); } else { throw pdal_error("ByteSwapFilter can only swap big/little endian dimensions"); } new_dimensions.push_back(d); } m_schema = Schema(new_dimensions); }
void Reprojection::initialize() { Filter::initialize(); checkImpedance(); if (m_inferInputSRS) { m_inSRS = getPrevStage().getSpatialReference(); } #ifdef PDAL_HAVE_GDAL m_gdal_debug = boost::shared_ptr<pdal::gdal::Debug>( new pdal::gdal::Debug(isDebug(), log())); m_in_ref_ptr = ReferencePtr(OSRNewSpatialReference(0), OGRSpatialReferenceDeleter()); m_out_ref_ptr = ReferencePtr(OSRNewSpatialReference(0), OGRSpatialReferenceDeleter()); int result = OSRSetFromUserInput(m_in_ref_ptr.get(), m_inSRS.getWKT(pdal::SpatialReference::eCompoundOK).c_str()); if (result != OGRERR_NONE) { std::ostringstream msg; msg << "Could not import input spatial reference for ReprojectionFilter:: " << CPLGetLastErrorMsg() << " code: " << result << " wkt: '" << m_inSRS.getWKT() << "'"; throw std::runtime_error(msg.str()); } result = OSRSetFromUserInput(m_out_ref_ptr.get(), m_outSRS.getWKT(pdal::SpatialReference::eCompoundOK).c_str()); if (result != OGRERR_NONE) { std::ostringstream msg; msg << "Could not import output spatial reference for ReprojectionFilter:: " << CPLGetLastErrorMsg() << " code: " << result << " wkt: '" << m_outSRS.getWKT() << "'"; std::string message(msg.str()); throw std::runtime_error(message); } m_transform_ptr = TransformPtr(OCTNewCoordinateTransformation( m_in_ref_ptr.get(), m_out_ref_ptr.get()), OSRTransformDeleter()); if (!m_transform_ptr.get()) { std::ostringstream msg; msg << "Could not construct CoordinateTransformation in ReprojectionFilter:: "; std::string message(msg.str()); throw std::runtime_error(message); } #endif setSpatialReference(m_outSRS); updateBounds(); return; }
void InPlaceReprojection::initialize() { Filter::initialize(); if (m_inferInputSRS) { m_inSRS = getPrevStage().getSpatialReference(); } #ifdef PDAL_HAVE_GDAL pdal::GlobalEnvironment::get().getGDALDebug()->addLog(log()); m_in_ref_ptr = ReferencePtr(OSRNewSpatialReference(0), OGRSpatialReferenceDeleter()); m_out_ref_ptr = ReferencePtr(OSRNewSpatialReference(0), OGRSpatialReferenceDeleter()); int result = OSRSetFromUserInput(m_in_ref_ptr.get(), m_inSRS.getWKT(pdal::SpatialReference::eCompoundOK).c_str()); if (result != OGRERR_NONE) { std::ostringstream msg; msg << "Could not import input spatial reference for InPlaceReprojection:: " << CPLGetLastErrorMsg() << " code: " << result << " wkt: '" << m_inSRS.getWKT() << "'"; throw std::runtime_error(msg.str()); } result = OSRSetFromUserInput(m_out_ref_ptr.get(), m_outSRS.getWKT(pdal::SpatialReference::eCompoundOK).c_str()); if (result != OGRERR_NONE) { std::ostringstream msg; msg << "Could not import output spatial reference for InPlaceReprojection:: " << CPLGetLastErrorMsg() << " code: " << result << " wkt: '" << m_outSRS.getWKT() << "'"; std::string message(msg.str()); throw std::runtime_error(message); } m_transform_ptr = TransformPtr(OCTNewCoordinateTransformation(m_in_ref_ptr.get(), m_out_ref_ptr.get()), OSRTransformDeleter()); if (!m_transform_ptr.get()) { std::ostringstream msg; msg << "Could not construct CoordinateTransformation in InPlaceReprojection:: "; std::string message(msg.str()); throw std::runtime_error(message); } #endif setSpatialReference(m_outSRS); Schema& s = getSchemaRef(); s = alterSchema(s); return; }
boost::property_tree::ptree Writer::serializePipeline() const { boost::property_tree::ptree tree; tree.add("<xmlattr>.type", getName()); PipelineWriter::write_option_ptree(tree, getOptions()); const Stage& stage = getPrevStage(); boost::property_tree::ptree subtree = stage.serializePipeline(); tree.add_child(subtree.begin()->first, subtree.begin()->second); boost::property_tree::ptree root; root.add_child("Writer", tree); return root; }
boost::uint64_t Writer::write( boost::uint64_t targetNumPointsToWrite, boost::uint64_t startingPosition) { if (!isInitialized()) { throw pdal_error("stage not initialized"); } boost::uint64_t actualNumPointsWritten = 0; UserCallback* callback = getUserCallback(); do_callback(0.0, callback); const Schema& schema = getPrevStage().getSchema(); if (m_writer_buffer == 0) { boost::uint64_t capacity(targetNumPointsToWrite); if (capacity == 0) { capacity = m_chunkSize; } else { capacity = (std::min)(static_cast<boost::uint64_t>(m_chunkSize), targetNumPointsToWrite) ; } m_writer_buffer = new PointBuffer (schema, capacity); } boost::scoped_ptr<StageSequentialIterator> iter(getPrevStage().createSequentialIterator(*m_writer_buffer)); if (startingPosition) iter->skip(startingPosition); 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(); // // 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 (m_writer_buffer->getCapacity() < numPointsToReadThisChunk) { m_writer_buffer->resize(numPointsToReadThisChunk); } } // read... iter->readBufferBegin(*m_writer_buffer); const boost::uint32_t numPointsReadThisChunk = iter->readBuffer(*m_writer_buffer); iter->readBufferEnd(*m_writer_buffer); assert(numPointsReadThisChunk == m_writer_buffer->getNumPoints()); assert(numPointsReadThisChunk <= m_writer_buffer->getCapacity()); // have we reached the end yet? if (numPointsReadThisChunk == 0) break; // write... writeBufferBegin(*m_writer_buffer); const boost::uint32_t numPointsWrittenThisChunk = writeBuffer(*m_writer_buffer); assert(numPointsWrittenThisChunk == numPointsReadThisChunk); writeBufferEnd(*m_writer_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 m_writer_buffer->setNumPoints(0); } iter->readEnd(); writeEnd(actualNumPointsWritten); assert((targetNumPointsToWrite == 0) || (actualNumPointsWritten <= targetNumPointsToWrite)); do_callback(100.0, callback); return actualNumPointsWritten; }