Skip to content

Commit

Permalink
More PROJ 3 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed May 30, 2019
1 parent b47aee2 commit fd3bb6a
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 38 deletions.
6 changes: 0 additions & 6 deletions io/EptReader.cpp
Expand Up @@ -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,
Expand Down Expand Up @@ -617,9 +614,7 @@ uint64_t EptReader::readLaszip(PointView& dst, const Key& key,
reader.setOptions(options);

std::lock_guard<std::mutex> 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);
Expand All @@ -633,7 +628,6 @@ uint64_t EptReader::readLaszip(PointView& dst, const Key& key,
++pointId;
}
}
std::cerr << "Done execute!\n";

return startId;
}
Expand Down
18 changes: 5 additions & 13 deletions pdal/GDALUtils.cpp
Expand Up @@ -34,6 +34,7 @@

#include <pdal/GDALUtils.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/SrsTransform.hpp>
#include <pdal/util/Algorithm.hpp>
#include <pdal/util/Utils.hpp>

Expand Down Expand Up @@ -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;
}

Expand Down
15 changes: 6 additions & 9 deletions pdal/Geometry.cpp
Expand Up @@ -33,6 +33,7 @@
****************************************************************************/

#include <pdal/Geometry.hpp>
#include <pdal/SrsTransform.hpp>
#include "cpl_string.h"

#include <ogr_geometry.h>
Expand Down Expand Up @@ -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());
}


Expand Down
8 changes: 7 additions & 1 deletion pdal/SrsTransform.cpp
Expand Up @@ -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);
}


Expand Down
6 changes: 6 additions & 0 deletions pdal/SrsTransform.hpp
Expand Up @@ -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<double>& x, std::vector<double>& y,
std::vector<double>& z);

Expand Down
2 changes: 1 addition & 1 deletion pdal/Stage.hpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/data/filters/ferry.json.in
Expand Up @@ -10,7 +10,7 @@
},
{
"type": "filters.reprojection",
"out_srs": "EPSG:4326+4326"
"out_srs": "EPSG:4326+5703"
},
"@CMAKE_SOURCE_DIR@/test/temp/colorized.las"
]
Expand Down
Binary file modified test/data/las/lots_of_vlr.las
Binary file not shown.
7 changes: 3 additions & 4 deletions test/unit/SpatialReferenceTest.cpp
Expand Up @@ -446,11 +446,10 @@ TEST(SpatialReferenceTest, test_bounds)
p.transform(wgs84);

BOX3D b2 = p.bounds();
EXPECT_FLOAT_EQ(static_cast<float>(b2.minx), -83.4275f);
EXPECT_FLOAT_EQ(static_cast<float>(b2.miny), 39.01256f);
EXPECT_FLOAT_EQ(static_cast<float>(b2.maxx), -83.4275f);
EXPECT_FLOAT_EQ(static_cast<float>(b2.minx), -83.427597f);
EXPECT_FLOAT_EQ(static_cast<float>(b2.miny), 39.0126f);
EXPECT_FLOAT_EQ(static_cast<float>(b2.maxx), -83.427551f);
EXPECT_FLOAT_EQ(static_cast<float>(b2.maxy), 39.01261f);

}

TEST(SpatialReferenceTest, identifyEPSG)
Expand Down
4 changes: 3 additions & 1 deletion test/unit/io/LasReaderTest.cpp
Expand Up @@ -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));
Expand Down
8 changes: 6 additions & 2 deletions test/unit/io/LasWriterTest.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit fd3bb6a

Please sign in to comment.