From fd3bb6a3f861cba4141c5d17d920ae0351400e45 Mon Sep 17 00:00:00 2001 From: Andrew Bell Date: Thu, 30 May 2019 13:06:23 -0400 Subject: [PATCH] More PROJ 3 fixes. --- io/EptReader.cpp | 6 ------ pdal/GDALUtils.cpp | 18 +++++------------- pdal/Geometry.cpp | 15 ++++++--------- pdal/SrsTransform.cpp | 8 +++++++- pdal/SrsTransform.hpp | 6 ++++++ pdal/Stage.hpp | 2 +- test/data/filters/ferry.json.in | 2 +- test/data/las/lots_of_vlr.las | Bin 82157 -> 81919 bytes test/unit/SpatialReferenceTest.cpp | 7 +++---- test/unit/io/LasReaderTest.cpp | 4 +++- test/unit/io/LasWriterTest.cpp | 8 ++++++-- 11 files changed, 38 insertions(+), 38 deletions(-) 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 a040f5f3ded43cfa6dfcb198697e6444737b0e9f..6b84fc119e1b0169bf1054392e6c750526528d13 100644 GIT binary pat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q-=kh4 zliE;6$%uofJ!CD9^s{5!LW)12){s-A#)0uIGWQVbMKZA+b(%+xu!jGLaX0DPf!a*Y zk>;N;o+Q_6uqk>C=sBBcG9`!x-P;kq=qRdN960X8($M zo{aBB9U?=IpmvhpeWU^(rW;< zk(?zBzhiu#EEz-{Co}&*P4NZKvc?Xf4v@irqPCOrVblil38_1Q@jY^kM;4D@e2vWb z3-t^cGm6?z2Axd)p9fkM!sY`D547wj^A5atniaVM-{k2A_Okl>p|+B)D^V@vBU19m z_%@mU8tNsoo<}AHU_44jypGyK`URr4km4%T8gh!%1Y!J`N8V!1eFNi*WMVMt2pO(G z?IwLgP@Bm)vQmbzc{MmmszXt4k~wdpULX^~P>0E|w@|ytyFAh-9Ag{#j5NKC@k6pK z0`&%&y$1C>86SySv;-Vt4Sff-lk|>4Z6cqNRckSRK$b?MUXM<$7lchp)rPV>qhXJv zsn#0w!m#axkSQ4owB_Xr=WDiPN!J>k&0w??s4Es9e~Sx`$NdDs&H0dg{?GGQ7q=0c z$Na?kOBCknMUN3%t`jcL?e1~H`FLF>cr3Uw&@*`94R=Al@VZ3sT6pykX5@=s+>w+b zZeO+W<%7}<=AC<`Jhf4+GdU0H7)ue?*01m0a%97VJ!N`!@=(xGW2*Cn)Z+!)l=HVN z{`~i!Ibz%P^0z8Y8m;!lmp=cDS+7^?q+Qm`G?ikr^KXhIg;`&zH`M5@>FR2;?uE1U z);yzDC(XZ;X_O>=jaIYUsw~uNt4+?g3RMb|*|<-#D9R0nYO7UnS$cTQsL6d@ZJHox Tg)H$One+eQ@9ur7<#Oe}sPsiA 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)