Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into issue-3282
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Apr 23, 2021
2 parents 417553b + a568db4 commit c12dd4e
Show file tree
Hide file tree
Showing 19 changed files with 406 additions and 224 deletions.
6 changes: 3 additions & 3 deletions cmake/gdal.cmake
Expand Up @@ -12,17 +12,17 @@ function(gdal_find_version _version)
set(${_version} ${MAJOR}.${MINOR}.${REV} PARENT_SCOPE)
endfunction(gdal_find_version)

find_package(GDAL 2.2.0 REQUIRED)
find_package(GDAL 3.0 REQUIRED)
set_package_properties(GDAL PROPERTIES TYPE REQUIRED
PURPOSE "Provides general purpose raster, vector, and reference system support")
if (GDAL_FOUND)
gdal_find_version(GDAL_VERSION)
#
# Older versions of FindGDAL.cmake don't properly set GDAL_VERSION
#
if (GDAL_VERSION VERSION_LESS 2.2.0)
if (GDAL_VERSION VERSION_LESS 3.0.0)
message(FATAL_ERROR
"Found GDAL version ${GDAL_VERSION}. Version 2.2+ is required")
"Found GDAL version ${GDAL_VERSION}. Version 3.0+ is required")
endif()
mark_as_advanced(CLEAR GDAL_INCLUDE_DIR)
mark_as_advanced(CLEAR GDAL_LIBRARY)
Expand Down
4 changes: 4 additions & 0 deletions doc/stages/readers.mrsid.rst
Expand Up @@ -3,6 +3,10 @@
readers.mrsid
=============

.. note::

The MrSID reader is deprecated and will be removed in a future release.

Implements MrSID 4.0 LiDAR Compressor. It requires the `Lidar_DSDK`_ to be able to
decompress and read data.

Expand Down
3 changes: 1 addition & 2 deletions filters/CropFilter.cpp
Expand Up @@ -202,8 +202,7 @@ void CropFilter::transform(const SpatialReference& srs)
// if it is missing we assign it from the point data.
assert(!m_args->m_assignedSrs.empty());
if (srs.empty() || m_args->m_assignedSrs.empty())
throwError("Unable to transform crop geometry to point "
"coordinate system.");
throwError("Unable to transform crop geometry to point coordinate system.");

for (auto& box : m_boxes)
{
Expand Down
6 changes: 4 additions & 2 deletions pdal/Geometry.cpp
Expand Up @@ -159,7 +159,8 @@ Utils::StatusWithReason Geometry::transform(SpatialReference out)
return StatusWithReason(-2,
"Geometry::transform() failed. NULL target SRS.");

SrsTransform transform(getSpatialReference(), out);
OGRSpatialReference *inSrs = m_geom->getSpatialReference();
SrsTransform transform(*inSrs, OGRSpatialReference(out.getWKT().data()));
if (m_geom->transform(transform.get()) != OGRERR_NONE)
return StatusWithReason(-1, "Geometry::transform() failed.");
modified();
Expand Down Expand Up @@ -187,7 +188,8 @@ SpatialReference Geometry::getSpatialReference() const
if (srsValid())
{
char *buf;
m_geom->getSpatialReference()->exportToWkt(&buf);
const char *options[] = { "FORMAT=WKT2", nullptr };
m_geom->getSpatialReference()->exportToWkt(&buf, options);
srs.set(buf);
CPLFree(buf);
}
Expand Down
18 changes: 8 additions & 10 deletions pdal/private/SrsTransform.cpp
Expand Up @@ -36,24 +36,24 @@
namespace pdal
{

SrsTransform::SrsTransform(const SpatialReference& src,
const SpatialReference& dst)
{
OGRSpatialReference srcRef(src.getWKT().data());
OGRSpatialReference dstRef(dst.getWKT().data());
SrsTransform::SrsTransform(const SpatialReference& src, const SpatialReference& dst) :
SrsTransform(OGRSpatialReference(src.getWKT().data()),
OGRSpatialReference(dst.getWKT().data()))
{}

// Starting with version 3, the axes (X, Y, Z or lon, lat, h or whatever)

SrsTransform::SrsTransform(OGRSpatialReference srcRef, OGRSpatialReference dstRef)
{
// Starting with version 3 of GDAL, 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));
}

Expand All @@ -74,12 +74,10 @@ SrsTransform::SrsTransform(const SpatialReference& src,
// SRSes where this comes up. See "axis order issues" in the GDAL WKT2
// discussion for more info.
//
#if GDAL_VERSION_MAJOR >= 3
if (srcOrder.size())
srcRef.SetDataAxisToSRSAxisMapping(srcOrder);
if (dstOrder.size())
dstRef.SetDataAxisToSRSAxisMapping(dstOrder);
#endif
m_transform.reset(OGRCreateCoordinateTransformation(&srcRef, &dstRef));
}

Expand Down
2 changes: 2 additions & 0 deletions pdal/private/SrsTransform.hpp
Expand Up @@ -32,6 +32,7 @@
#include <pdal/pdal_internal.hpp>

class OGRCoordinateTransformation;
class OGRSpatialReference;

namespace pdal
{
Expand All @@ -43,6 +44,7 @@ class PDAL_DLL SrsTransform
public:
/// Object that performs transformation from a \src spatial reference
/// to a \dest spatial reference.
SrsTransform(OGRSpatialReference src, OGRSpatialReference dst);
SrsTransform(const SpatialReference& src, const SpatialReference& dst);
SrsTransform(const SpatialReference& src,
std::vector<int> srcOrder,
Expand Down
2 changes: 1 addition & 1 deletion pdal/private/gdal/GDALUtils.cpp
Expand Up @@ -359,7 +359,7 @@ std::vector<Polygon> getPolygons(const NL::json& ogr)
ds->ReleaseResultSet(poLayer);

poly.update(options.at("geometry").get<std::string>());
if (poly.getSpatialReference().valid())
if (poly.srsValid())
{
auto ok = poly.transform(sref.wkt());
if (!ok)
Expand Down
1 change: 1 addition & 0 deletions pdal/util/CMakeLists.txt
Expand Up @@ -28,6 +28,7 @@ set(PDAL_UTIL_SOURCES
"${PDAL_UTIL_DIR}/ThreadPool.cpp"
"${PDAL_UTIL_DIR}/Utils.cpp"
"${PDAL_UTIL_DIR}/Backtrace.cpp"
"${PDAL_UTIL_DIR}/Random.cpp"
"${PDAL_UTIL_DIR}/private/${BACKTRACE_SOURCE}"
)

Expand Down
98 changes: 98 additions & 0 deletions pdal/util/Random.cpp
@@ -0,0 +1,98 @@
/******************************************************************************
* Copyright (c) 2021, Hobu Inc. (info@hobu.co)
*
* 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.
* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* 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 "Random.hpp"

namespace pdal
{
namespace Utils
{

Random::Random()
{
std::vector<int32_t> seed;
std::random_device rd;
for (size_t i = 0; i < std::mt19937::state_size; ++i)
seed.push_back(rd());
std::seed_seq seedSeq(seed.begin(), seed.end());
m_generator.seed(seedSeq);
}

Random::Random(int32_t seed)
{
std::seed_seq seedSeq {seed};
m_generator.seed(seedSeq);
}

Random::Random(const std::vector<int32_t> seed)
{
std::seed_seq seedSeq(seed.begin(), seed.end());
m_generator.seed(seedSeq);
}

Random::Random(const std::string& seed)
{
std::vector<int32_t> v;
int32_t s = 0;
int i = 0;
for (char c : seed)
{
s |= c << (8 * i++);
if (i == 4)
{
v.push_back(s);
i = 0;
s = 0;
}
}
if (i)
v.push_back(s);
std::seed_seq seedSeq(v.begin(), v.end());
m_generator.seed(seedSeq);
}

std::mt19937& Random::generator()
{
return m_generator;
}

unsigned int Random::quick()
{
std::random_device rd;

return rd();
}

} // namespace Utils
} // namespace pdal
66 changes: 66 additions & 0 deletions pdal/util/Random.hpp
@@ -0,0 +1,66 @@
/******************************************************************************
* Copyright (c) 2021, 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.
* * Neither the name of Hobu, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* 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 <cstdint>
#include <random>
#include <string>
#include <vector>

#include "pdal_util_export.hpp"

namespace pdal
{
namespace Utils
{

class Random
{
public:
PDAL_DLL Random();
PDAL_DLL Random(int32_t seed);
PDAL_DLL Random(const std::vector<int32_t> seed);
PDAL_DLL Random(const std::string& seed);

PDAL_DLL std::mt19937& generator();

PDAL_DLL static unsigned int quick();

private:
std::mt19937 m_generator;
};

} // namespace Utils
} // namespace pdal
2 changes: 1 addition & 1 deletion plugins/mrsid/io/MrsidReader.cpp
Expand Up @@ -45,7 +45,7 @@ namespace pdal
static PluginInfo const s_info
{
"readers.mrsid",
"MrSID Reader",
"MrSID Reader [deprecated]",
"http://pdal.io/stages/readers.mrsid.html"
};

Expand Down
3 changes: 1 addition & 2 deletions test/unit/SpatialReferenceTest.cpp
Expand Up @@ -248,8 +248,7 @@ TEST(SpatialReferenceTest, test_writing_vlr)
LasReader readerx;
Options readerOpts;

readerOpts.add("filename",
::Support::datapath("las/1.2-with-color.las"));
readerOpts.add("filename", Support::datapath("las/1.2-with-color.las"));
readerx.setOptions(readerOpts);

Options writerOpts;
Expand Down

0 comments on commit c12dd4e

Please sign in to comment.