-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57d9aee
commit 6512d50
Showing
2 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2019, Hobu Inc. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided | ||
* with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | ||
* OF SUCH DAMAGE. | ||
****************************************************************************/ | ||
|
||
#include "SrsTransform.hpp" | ||
#include <pdal/SpatialReference.hpp> | ||
|
||
#include <ogr_spatialref.h> | ||
|
||
namespace pdal | ||
{ | ||
|
||
SrsTransform::SrsTransform(const SpatialReference& src, | ||
const SpatialReference& dst) | ||
{ | ||
OGRSpatialReference srcRef(src.getWKT().data()); | ||
OGRSpatialReference dstRef(dst.getWKT().data()); | ||
|
||
// Starting with version 3, the axes (X, Y, Z or lon, lat, h or whatever) | ||
// are mapped according to the WKT definition. In particular, this means | ||
// that for EPSG:4326 the mapping is X -> lat, Y -> lon, rather than the | ||
// more conventional X -> lon, Y -> lat. Setting this flag reverses things | ||
// such that the traditional ordering is maintained. There are other | ||
// SRSes where this comes up. See "axis order issues" in the GDAL WKT2 | ||
// discussion for more info. | ||
// | ||
#if GDAL_VERSION_MAJOR >= 3 | ||
srcRef.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); | ||
dstRef.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); | ||
#endif | ||
m_transform.reset(OGRCreateCoordinateTransformation(&srcRef, &dstRef)); | ||
} | ||
|
||
SrsTransform::~SrsTransform() | ||
{} | ||
|
||
|
||
OGRCoordinateTransformation *SrsTransform::get() const | ||
{ | ||
return m_transform.get(); | ||
} | ||
|
||
|
||
bool SrsTransform::transform(double& x, double& y, double& z) | ||
{ | ||
return m_transform && m_transform->Transform(1, &x, &y, &z); | ||
} | ||
|
||
|
||
bool SrsTransform::transform(std::vector<double>& x, std::vector<double>& y, | ||
std::vector<double>& z) | ||
{ | ||
if (x.size() != y.size() && y.size() != z.size()) | ||
throw pdal_error("SrsTransform::called with vectors of different " | ||
"sizes."); | ||
int err = m_transform->Transform(x.size(), x.data(), y.data(), z.data()); | ||
return (err == OGRERR_NONE); | ||
} | ||
|
||
} // namespace pdal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2019, Hobu Inc. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided | ||
* with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | ||
* OF SUCH DAMAGE. | ||
****************************************************************************/ | ||
#pragma once | ||
|
||
#include <pdal/pdal_internal.hpp> | ||
|
||
class OGRCoordinateTransformation; | ||
|
||
namespace pdal | ||
{ | ||
|
||
class SpatialReference; | ||
|
||
class PDAL_DLL SrsTransform | ||
{ | ||
public: | ||
/// Object that performs transformation from a \src spatial reference | ||
/// to a \dest spatial reference. | ||
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); | ||
|
||
private: | ||
std::unique_ptr<OGRCoordinateTransformation> m_transform; | ||
}; | ||
|
||
} // namespace pdal | ||
|