When the stage is intialized, the schema needs to be populated with the dimensions in order to allow subsequent stages to be aware of or append to the dimensions in the PointView.
| 138 | // dimensions in order to allow subsequent stages to be aware of or append to |
| 139 | // the dimensions in the PointView. |
| 140 | void BpfReader::initialize() |
| 141 | { |
| 142 | if (m_filename.empty()) |
| 143 | throwError("Can't read BPF file without filename."); |
| 144 | |
| 145 | if (Utils::isRemote(m_filename)) |
| 146 | { |
| 147 | // swap our filename for a tmp file |
| 148 | std::string tmpname = Utils::tempFilename(m_filename); |
| 149 | m_remoteFilename = m_filename; |
| 150 | m_filename = tmpname; |
| 151 | arbiter::Arbiter a; |
| 152 | a.put(m_filename, a.getBinary(m_remoteFilename)); |
| 153 | } |
| 154 | |
| 155 | // Logfile doesn't get set until options are processed. |
| 156 | m_header.setLog(log()); |
| 157 | |
| 158 | m_istreamPtr = Utils::openFile(m_filename); |
| 159 | if (!m_istreamPtr) |
| 160 | throwError("Can't open file '" + m_filename + "'."); |
| 161 | m_stream = ILeStream(m_istreamPtr); |
| 162 | |
| 163 | // Resets the stream position in case it was already open. |
| 164 | m_stream.seek(0); |
| 165 | // In order to know the dimensions we must read the file header. |
| 166 | try |
| 167 | { |
| 168 | if (!m_header.read(m_stream)) |
| 169 | return; |
| 170 | if (!m_header.readDimensions(m_stream, m_dims, m_args->m_fixNames)) |
| 171 | return; |
| 172 | } |
| 173 | catch (const BpfHeader::error& err) |
| 174 | { |
| 175 | throwError(err.what()); |
| 176 | } |
| 177 | #ifndef PDAL_HAVE_ZLIB |
| 178 | if (m_header.m_compression) |
| 179 | throwError("Can't read compressed BPF. PDAL wasn't built with " |
| 180 | "Zlib support."); |
| 181 | #endif |
| 182 | |
| 183 | SpatialReference srs; |
| 184 | if (m_header.m_coordType == static_cast<int>(BpfCoordType::Cartesian)) |
| 185 | { |
| 186 | srs.set("EPSG:4326"); |
| 187 | } |
| 188 | else if (m_header.m_coordType == static_cast<int>(BpfCoordType::UTM)) |
| 189 | { |
| 190 | srs = SpatialReference::wgs84FromZone(m_header.m_coordId); |
| 191 | if (!srs.valid()) |
| 192 | throwError("BPF file contains an invalid UTM zone " + |
| 193 | Utils::toString(m_header.m_coordId)); |
| 194 | } |
| 195 | else if (m_header.m_coordType == static_cast<int>(BpfCoordType::TCR)) |
| 196 | { |
| 197 | // TCR is ECEF meters, or EPSG:4978 |
no test coverage detected