Skip to content

Commit

Permalink
ensure WKTv1 writing for LAS 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Feb 21, 2020
1 parent 366bd3b commit c4a673b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions io/LasWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ bool LasWriter::addWktVlr()
if (wkt.empty())
return false;

// LAS 1.4 requires WKTv1
wkt = SpatialReference::convertToWKT1(wkt);
std::vector<uint8_t> wktBytes(wkt.begin(), wkt.end());
// This tacks a NULL to the end of the data, which is required by the spec.
wktBytes.resize(wktBytes.size() + 1, 0);
Expand Down
22 changes: 22 additions & 0 deletions pdal/SpatialReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,28 @@ std::string SpatialReference::prettyWkt(const std::string& wkt)
return outWkt;
}

std::string SpatialReference::convertToWKT1(const std::string& wkt)
{
std::string outWkt(wkt);

// WKT flavors only exist in GDAL 3.x+
#if GDAL_VERSION_MAJOR >= 3
OGRScopedSpatialReference srs = ogrCreateSrs(wkt);
if (!srs)
return outWkt;

char *buf = nullptr;

char **papszOptions = nullptr;
papszOptions = CSLAddNameValue(papszOptions, "FORMAT", "WKT1_GDAL");
srs->exportToWkt(&buf, papszOptions);

outWkt = buf;
CPLFree(buf);
#endif
return outWkt;
}


int SpatialReference::getUTMZone() const
{
Expand Down
1 change: 1 addition & 0 deletions pdal/SpatialReference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class PDAL_DLL SpatialReference
static int calculateZone(double lon, double lat);
static bool isWKT(const std::string& wkt);
static std::string prettyWkt(const std::string& wkt);
static std::string convertToWKT1(const std::string& wkt);

private:
std::string m_wkt;
Expand Down

0 comments on commit c4a673b

Please sign in to comment.