Read a field from a PointView and write its value as formatted for output to the DB schema to the location as requested. \param[in] view PointView to read from. \param[in] pos Location in which to store field value. \param[in] id ID of the dimension to read. \param[in] idx Index of point to read. \return Size of field as read.
| 176 | /// \param[in] idx Index of point to read. |
| 177 | /// \return Size of field as read. |
| 178 | size_t DbWriter::readField(const PointView& view, char *pos, |
| 179 | Dimension::Id id, PointId idx) |
| 180 | { |
| 181 | using namespace Dimension; |
| 182 | |
| 183 | DimType& dt = m_dimMap[(int)id]; |
| 184 | size_t size = Dimension::size(dt.m_type); |
| 185 | |
| 186 | // Using the ID instead of a dimType as the arugment hides the complication |
| 187 | // of the "type" of the dimension to retrieve in the case of location |
| 188 | // scaling. |
| 189 | view.getField(pos, id, dt.m_type, idx); |
| 190 | |
| 191 | auto iconvert = [pos](const XForm& xform, Dimension::Id dim) |
| 192 | { |
| 193 | double d; |
| 194 | int32_t i; |
| 195 | |
| 196 | memcpy(&d, pos, sizeof(double)); |
| 197 | |
| 198 | d = xform.toScaled(d); |
| 199 | if (!Utils::numericCast(d, i)) |
| 200 | { |
| 201 | std::ostringstream oss; |
| 202 | oss << "Unable to convert double to int32 for packed DB output: "; |
| 203 | oss << Dimension::name(dim) << ": (" << d << ")."; |
| 204 | throw pdal_error(oss.str()); |
| 205 | } |
| 206 | memcpy(pos, &i, sizeof(int32_t)); |
| 207 | }; |
| 208 | |
| 209 | if (m_locationScaling) |
| 210 | { |
| 211 | // For X, Y or Z. |
| 212 | if (id == Id::X) |
| 213 | { |
| 214 | iconvert(m_scaling.m_xXform, Id::X); |
| 215 | size = sizeof(int32_t); |
| 216 | } |
| 217 | else if (id == Id::Y) |
| 218 | { |
| 219 | iconvert(m_scaling.m_yXform, Id::Y); |
| 220 | size = sizeof(int32_t); |
| 221 | } |
| 222 | else if (id == Id::Z) |
| 223 | { |
| 224 | iconvert(m_scaling.m_zXform, Id::Z); |
| 225 | size = sizeof(int32_t); |
| 226 | } |
| 227 | } |
| 228 | return size; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | /// Read a point's data packed into a buffer. |