diff --git a/io/EptReader.cpp b/io/EptReader.cpp index bc1fb7d4ea..de9e0d454d 100644 --- a/io/EptReader.cpp +++ b/io/EptReader.cpp @@ -194,9 +194,6 @@ void EptReader::initialize() setSpatialReference(m_info->srs()); m_queryBounds = m_args->m_bounds.to3d(); - std::cerr << "Reproject bounds from = " << boundsSrs.getWKT() << "!\n"; - std::cerr << "Reproject bounds to = " << m_info->srs().getWKT() << "!\n"; - std::cerr << "Query bounds = " << m_queryBounds << "!\n"; if (boundsSrs.valid()) gdal::reprojectBounds(m_queryBounds, @@ -617,9 +614,7 @@ uint64_t EptReader::readLaszip(PointView& dst, const Key& key, reader.setOptions(options); std::lock_guard lock(m_mutex); - std::cerr << "Prepare laszip!\n"; reader.prepare(table); - std::cerr << "Done prepare laszip!\n"; const uint64_t startId(dst.size()); uint64_t pointId(0); @@ -633,7 +628,6 @@ uint64_t EptReader::readLaszip(PointView& dst, const Key& key, ++pointId; } } - std::cerr << "Done execute!\n"; return startId; } diff --git a/pdal/GDALUtils.cpp b/pdal/GDALUtils.cpp index 00111b2f4e..f6a46e9fed 100644 --- a/pdal/GDALUtils.cpp +++ b/pdal/GDALUtils.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -153,20 +154,11 @@ GDALDataType toGdalType(Dimension::Type t) bool reprojectBounds(BOX3D& box, const std::string& srcSrs, const std::string& dstSrs) { - OGRSpatialReference src; - OGRSpatialReference dst; + SrsTransform transform(srcSrs, dstSrs); - OGRErr srcOk = OSRSetFromUserInput(&src, srcSrs.c_str()); - OGRErr dstOk = OSRSetFromUserInput(&dst, dstSrs.c_str()); - if (srcOk != OGRERR_NONE || dstOk != OGRERR_NONE) - return false; - - OGRCoordinateTransformationH transform = - OCTNewCoordinateTransformation(&src, &dst); - - bool ok = (OCTTransform(transform, 1, &box.minx, &box.miny, &box.minz) && - OCTTransform(transform, 1, &box.maxx, &box.maxy, &box.maxz)); - OCTDestroyCoordinateTransformation(transform); + bool ok = transform.transform(box.minx, box.miny, box.minz); + if (ok) + ok = transform.transform(box.maxx, box.maxy, box.maxz); return ok; } diff --git a/pdal/Geometry.cpp b/pdal/Geometry.cpp index dd1f5ab3f5..c3bfa32d3c 100644 --- a/pdal/Geometry.cpp +++ b/pdal/Geometry.cpp @@ -33,6 +33,7 @@ ****************************************************************************/ #include +#include #include "cpl_string.h" #include @@ -122,22 +123,18 @@ bool Geometry::srsValid() const } -void Geometry::transform(const SpatialReference& ref) const +void Geometry::transform(const SpatialReference& out) const { - if (!srsValid() && ref.empty()) + if (!srsValid() && out.empty()) return; if (!srsValid()) throw pdal_error("Geometry::transform() failed. NULL source SRS."); - if (ref.empty()) + if (out.empty()) throw pdal_error("Geometry::transform() failed. NULL target SRS."); - OGRSpatialReference *input = m_geom->getSpatialReference(); - OGRSpatialReference output(ref.getWKT().data()); - OGRCoordinateTransformation *xform = OGRCreateCoordinateTransformation( - input, &output); - m_geom->transform(xform); - delete xform; + SrsTransform transform(getSpatialReference(), out); + m_geom->transform(transform.get()); } diff --git a/pdal/SrsTransform.cpp b/pdal/SrsTransform.cpp index d56f9dc3f5..615aa332e6 100644 --- a/pdal/SrsTransform.cpp +++ b/pdal/SrsTransform.cpp @@ -62,9 +62,15 @@ SrsTransform::~SrsTransform() {} +OGRCoordinateTransformation *SrsTransform::get() const +{ + return m_transform.get(); +} + + bool SrsTransform::transform(double& x, double& y, double& z) { - return m_transform->Transform(1, &x, &y, &z); + return m_transform && m_transform->Transform(1, &x, &y, &z); } diff --git a/pdal/SrsTransform.hpp b/pdal/SrsTransform.hpp index 40026a11eb..f482e37355 100644 --- a/pdal/SrsTransform.hpp +++ b/pdal/SrsTransform.hpp @@ -46,16 +46,22 @@ class PDAL_DLL SrsTransform SrsTransform(const SpatialReference& src, const SpatialReference& dst); ~SrsTransform(); + /// Get the underlying transformation. + /// \return Pointer to the underlying coordinate transform. + OGRCoordinateTransformation *get() const; + /// Transform the X, Y and Z of a point in place. /// \param x X coordinate /// \param y Y coordinate /// \param z Z coordinate + /// \return True if the transformation was successful bool transform(double& x, double& y, double& z); /// Transform a set of points in place. /// \param x X coordinates /// \param y Y coordinates /// \param z Z coordinates + /// \return True if the transformation was successful bool transform(std::vector& x, std::vector& y, std::vector& z); diff --git a/pdal/Stage.hpp b/pdal/Stage.hpp index 0c716ed7fe..e78d790640 100644 --- a/pdal/Stage.hpp +++ b/pdal/Stage.hpp @@ -298,7 +298,7 @@ class PDAL_DLL Stage MetadataNode. Used to dump a pipeline specification in a portable format. - \param root Node to which a stages meatdata should be added. + \param root Node to which a stages metadata should be added. \param tags Pipeline writer's current list of stage tags. */ void serialize(MetadataNode root, PipelineWriter::TagMap& tags) const; diff --git a/test/data/filters/ferry.json.in b/test/data/filters/ferry.json.in index a21100347b..d59d931406 100644 --- a/test/data/filters/ferry.json.in +++ b/test/data/filters/ferry.json.in @@ -10,7 +10,7 @@ }, { "type": "filters.reprojection", - "out_srs": "EPSG:4326+4326" + "out_srs": "EPSG:4326+5703" }, "@CMAKE_SOURCE_DIR@/test/temp/colorized.las" ] diff --git a/test/data/las/lots_of_vlr.las b/test/data/las/lots_of_vlr.las index a040f5f3de..6b84fc119e 100644 Binary files a/test/data/las/lots_of_vlr.las and b/test/data/las/lots_of_vlr.las differ diff --git a/test/unit/SpatialReferenceTest.cpp b/test/unit/SpatialReferenceTest.cpp index 91bcbc4af4..82ffb07892 100644 --- a/test/unit/SpatialReferenceTest.cpp +++ b/test/unit/SpatialReferenceTest.cpp @@ -446,11 +446,10 @@ TEST(SpatialReferenceTest, test_bounds) p.transform(wgs84); BOX3D b2 = p.bounds(); - EXPECT_FLOAT_EQ(static_cast(b2.minx), -83.4275f); - EXPECT_FLOAT_EQ(static_cast(b2.miny), 39.01256f); - EXPECT_FLOAT_EQ(static_cast(b2.maxx), -83.4275f); + EXPECT_FLOAT_EQ(static_cast(b2.minx), -83.427597f); + EXPECT_FLOAT_EQ(static_cast(b2.miny), 39.0126f); + EXPECT_FLOAT_EQ(static_cast(b2.maxx), -83.427551f); EXPECT_FLOAT_EQ(static_cast(b2.maxy), 39.01261f); - } TEST(SpatialReferenceTest, identifyEPSG) diff --git a/test/unit/io/LasReaderTest.cpp b/test/unit/io/LasReaderTest.cpp index af57215a33..8fc47684da 100644 --- a/test/unit/io/LasReaderTest.cpp +++ b/test/unit/io/LasReaderTest.cpp @@ -198,8 +198,10 @@ TEST(LasReaderTest, inspect) QuickInfo qi = reader.preview(); + // This string is common for WKT1 and WKT2. When we move to WKT2 + // completely, this can be fixed. std::string testWkt { - R"(GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]])" + R"(GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433)" }; EXPECT_TRUE(Utils::startsWith(qi.m_srs.getWKT(), testWkt)); diff --git a/test/unit/io/LasWriterTest.cpp b/test/unit/io/LasWriterTest.cpp index 21e7ea97a0..4dff415233 100644 --- a/test/unit/io/LasWriterTest.cpp +++ b/test/unit/io/LasWriterTest.cpp @@ -1089,8 +1089,12 @@ TEST(LasWriterTest, fix1063_1064_1065) // https://github.com/PDAL/PDAL/issues/1065 SpatialReference ref = v->spatialReference(); - std::string wkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"; - EXPECT_EQ(ref.getWKT(), wkt); + // This WKT is the leading common bit of WKT1 and WKT2 resolution. When + // we're just doing WKT2, this can be improved. + std::string wkt { + R"(GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]])" + }; + EXPECT_TRUE(Utils::startsWith(ref.getWKT(), wkt)); } TEST(LasWriterTest, pdal_metadata)