Add a Well-known Text VLR associated with the spatial reference. \return Whether the VLR was added.
| 527 | /// Add a Well-known Text VLR associated with the spatial reference. |
| 528 | /// \return Whether the VLR was added. |
| 529 | bool LasWriter::addWktVlr() |
| 530 | { |
| 531 | // WKT2 and PROJJSON can be writen in PDAL VLRs |
| 532 | if (d->opts.enhancedSrsVlrs) { |
| 533 | const std::string wkt2 = m_srs.getWKT2(); |
| 534 | if (!wkt2.empty()) { |
| 535 | std::vector<char> wktBytes(wkt2.begin(), wkt2.end()); |
| 536 | wktBytes.resize(wktBytes.size() + 1, 0); |
| 537 | addVlr(las::TransformUserId, las::LASFWkt2recordId, "PDAL WKT2 Record", wktBytes); |
| 538 | } |
| 539 | |
| 540 | const std::string projjson = m_srs.getPROJJSON(); |
| 541 | if (!projjson.empty()) { |
| 542 | std::vector<char> wktBytes(projjson.begin(), projjson.end()); |
| 543 | wktBytes.resize(wktBytes.size() + 1, 0); |
| 544 | addVlr(las::PdalUserId, las::PdalProjJsonRecordId, "PDAL PROJJSON Record", wktBytes); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | // LAS 1.4 requires WKTv1 |
| 549 | std::string wkt; |
| 550 | try |
| 551 | { |
| 552 | wkt = m_srs.getWKT1(); |
| 553 | } |
| 554 | catch(const std::exception&) |
| 555 | { |
| 556 | if (!d->opts.enhancedSrsVlrs) |
| 557 | throw; |
| 558 | } |
| 559 | |
| 560 | if (wkt.empty()) |
| 561 | return false; |
| 562 | |
| 563 | std::vector<char> wktBytes(wkt.begin(), wkt.end()); |
| 564 | // This tacks a NULL to the end of the data, which is required by the spec. |
| 565 | wktBytes.resize(wktBytes.size() + 1, 0); |
| 566 | addVlr(las::TransformUserId, las::WktRecordId, "OGC Transformation Record", wktBytes); |
| 567 | |
| 568 | // The data in the vector gets moved to the VLR, so we have to recreate it. |
| 569 | std::vector<char> wktBytes2(wkt.begin(), wkt.end()); |
| 570 | wktBytes2.resize(wktBytes2.size() + 1, 0); |
| 571 | addVlr(las::LiblasUserId, las::WktRecordId, "OGR variant of OpenGIS WKT SRS", wktBytes2); |
| 572 | return true; |
| 573 | } |
| 574 | |
| 575 | |
| 576 | void LasWriter::addExtraBytesVlr() |