Skip to content

Commit

Permalink
use SrsTransform to make sure that traditional axis order is used
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed May 26, 2020
1 parent 8379134 commit b331bb4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
24 changes: 8 additions & 16 deletions kernels/TIndexKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <pdal/GDALUtils.hpp>
#include <pdal/PDALUtils.hpp>
#include <pdal/private/SrsTransform.hpp>
#include <pdal/StageFactory.hpp>
#include <pdal/util/FileUtils.hpp>

Expand Down Expand Up @@ -679,14 +680,6 @@ TIndexKernel::FieldIndexes TIndexKernel::getFields()
indexes.m_ctime = OGR_FD_GetFieldIndex(fDefn, "created");
indexes.m_mtime = OGR_FD_GetFieldIndex(fDefn, "modified");

// /* Load in memory existing file names in SHP */
// int nExistingFiles = (int)OGR_L_GetFeatureCount(m_layer, FALSE);
// for (auto i = 0; i < nExistingFiles; i++)
// {
// OGRFeatureH hFeature = OGR_L_GetNextFeature(m_layer);
// m_files.push_back(OGR_F_GetFieldAsString(hFeature, indexes.m_filename));
// OGR_F_Destroy(hFeature);
// }
return indexes;
}

Expand All @@ -697,11 +690,9 @@ gdal::Geometry TIndexKernel::prepareGeometry(const FileInfo& fileInfo)

std::ostringstream oss;

SpatialReference tgtSrs(m_tgtSrsString);

SpatialRef srcSrs(fileInfo.m_srs);
SpatialRef tgtSrs(m_tgtSrsString);
if (!tgtSrs)
throw pdal_error("Unable to import target SRS.");
SrsTransform transform(fileInfo.m_srs, SpatialReference(m_tgtSrsString));

Geometry g;
if (fileInfo.m_boundary.empty())
Expand All @@ -712,7 +703,7 @@ gdal::Geometry TIndexKernel::prepareGeometry(const FileInfo& fileInfo)
}
try
{
g = prepareGeometry(fileInfo.m_boundary, srcSrs, tgtSrs);
g = prepareGeometry(fileInfo.m_boundary, fileInfo.m_srs, &transform);
}
catch (pdal_error& e)
{
Expand All @@ -731,14 +722,15 @@ gdal::Geometry TIndexKernel::prepareGeometry(const FileInfo& fileInfo)


gdal::Geometry TIndexKernel::prepareGeometry(const std::string& wkt,
const gdal::SpatialRef& inSrs, const gdal::SpatialRef& outSrs)
const SpatialReference& inSrs, SrsTransform* transform)
{
// Create OGR geometry from text.

gdal::Geometry g(wkt, inSrs);
gdal::SpatialRef ref(inSrs.getWKT());
gdal::Geometry g(wkt, ref);

if (g)
if (OGR_G_TransformTo(g.get(), outSrs.get()) != OGRERR_NONE)
if (OGR_G_Transform(g.get(), transform->get()) != OGRERR_NONE)
throw pdal_error("Unable to transform geometry.");

return g;
Expand Down
3 changes: 2 additions & 1 deletion kernels/TIndexKernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
namespace pdal
{

class SrsTransform;
namespace gdal
{
class Geometry;
Expand Down Expand Up @@ -91,7 +92,7 @@ class PDAL_DLL TIndexKernel : public SubcommandKernel
bool createFeature(const FieldIndexes& indexes, FileInfo& info);
gdal::Geometry prepareGeometry(const FileInfo& fileInfo);
gdal::Geometry prepareGeometry(const std::string& wkt,
const gdal::SpatialRef& inSrs, const gdal::SpatialRef& outSrs);
const SpatialReference& inSrs, SrsTransform* transform);
void createFields();
bool fastBoundary(Stage& reader, FileInfo& fileInfo);
bool slowBoundary(Stage& hexer, FileInfo& fileInfo);
Expand Down

0 comments on commit b331bb4

Please sign in to comment.