Skip to content

Commit

Permalink
adjustments to PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Feb 11, 2020
1 parent 3b18d33 commit 7302f25
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 35 deletions.
87 changes: 59 additions & 28 deletions filters/ReprojectionFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void ReprojectionFilter::addArgs(ProgramArgs& args)
{
args.add("out_srs", "Output spatial reference", m_outSRS).setPositional();
args.add("in_srs", "Input spatial reference", m_inSRS);
args.add("in_axis_ordering", "Axis ordering override for in_srs", m_inAxisOrdering, {} );
args.add("out_axis_ordering", "Axis ordering override for out_srs", m_outAxisOrdering, {} );
args.add("in_axis_ordering", "Axis ordering override for in_srs", m_inAxisOrderingArg, {} );
args.add("out_axis_ordering", "Axis ordering override for out_srs", m_outAxisOrderingArg, {} );
}


Expand All @@ -83,6 +83,57 @@ void ReprojectionFilter::spatialReferenceChanged(const SpatialReference& srs)
createTransform(srs);
}

void ReprojectionFilter::prepared(PointTableRef table)
{

// convert string args to integers and throw if
// we can't
auto convert = [] (const std::vector<std::string>& in)
{
std::vector<int> output;
for (auto& str: in)
{
try
{
output.push_back(std::stoi(str));
} catch (std::invalid_argument&)
{
throw pdal_error("Unable to convert axis ordering to integer");
}

}
return output;

};

// Check that the sorted vector is 1,2 or 1,2,3
auto check = [this] (const std::vector<int>& in)
{
auto test = in;
std::sort(test.begin(), test.end());
if (test.size() > 3)
throwError("Axis ordering vector is too long");
if (test.at(0) != 1 && test.at(1) != 2)
throwError("Axis ordering is invalid");
if (test.size() > 2)
if (test.at(2) != 3)
throwError("Axis ordering for 3rd dimension is invalid");

};

if (m_inAxisOrderingArg.size())
{
m_inAxisOrdering = convert(m_inAxisOrderingArg);
check(m_inAxisOrdering);
}

if (m_outAxisOrderingArg.size())
{
m_outAxisOrdering = convert(m_outAxisOrderingArg);
check(m_outAxisOrdering);
}

}

void ReprojectionFilter::createTransform(const SpatialReference& srsSRS)
{
Expand All @@ -94,38 +145,18 @@ void ReprojectionFilter::createTransform(const SpatialReference& srsSRS)
"none is specified with the 'in_srs' option.");
}


// If either vector is empty, GDAL's default ordering is used.
if (m_inAxisOrdering.size() || m_outAxisOrdering.size())
{
std::vector<int> inOrdering;
std::vector<int> outOrdering;

auto convert = [] (std::vector<std::string> in)
{
std::vector<int> output;
for (auto& str: in)
{
try
{
output.push_back(std::stoi(str));
} catch (std::invalid_argument&)
{
throw pdal_error("Unable to convert axis ordering to integer");
}

}
return output;

};
inOrdering = convert(m_inAxisOrdering);
outOrdering = convert(m_outAxisOrdering);

m_transform.reset(new SrsTransform(m_inSRS,
inOrdering,
m_inAxisOrdering,
m_outSRS,
outOrdering));
}
else
m_outAxisOrdering));
} else {
m_transform.reset(new SrsTransform(m_inSRS, m_outSRS));
}
}


Expand Down
7 changes: 5 additions & 2 deletions filters/ReprojectionFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ class PDAL_DLL ReprojectionFilter : public Filter, public Streamable
virtual PointViewSet run(PointViewPtr view);
virtual bool processOne(PointRef& point);
virtual void spatialReferenceChanged(const SpatialReference& srs);
virtual void prepared(PointTableRef table);

void createTransform(const SpatialReference& srs);

SpatialReference m_inSRS;
SpatialReference m_outSRS;
bool m_inferInputSRS;
std::unique_ptr<SrsTransform> m_transform;
std::vector<std::string> m_inAxisOrdering;
std::vector<std::string> m_outAxisOrdering;
std::vector<std::string> m_inAxisOrderingArg;
std::vector<std::string> m_outAxisOrderingArg;
std::vector<int> m_inAxisOrdering;
std::vector<int> m_outAxisOrdering;
};

} // namespace pdal
11 changes: 11 additions & 0 deletions pdal/SpatialReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,17 @@ bool SpatialReference::isProjected() const
return output;
}

std::vector<int> SpatialReference::getAxisOrdering() const
{
std::vector<int> output;
OGRScopedSpatialReference current = ogrCreateSrs(m_wkt);

output = current.get()->GetDataAxisToSRSAxisMapping();
return output;
}



int SpatialReference::calculateZone(double lon, double lat)
{
int zone = 0;
Expand Down
2 changes: 2 additions & 0 deletions pdal/SpatialReference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class PDAL_DLL SpatialReference
bool isGeocentric() const;
bool isProjected() const;

std::vector<int> getAxisOrdering() const;

int computeUTMZone(const BOX3D& box) const;

const std::string& getName() const;
Expand Down
6 changes: 1 addition & 5 deletions test/unit/SpatialReferenceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,6 @@ TEST(SpatialReferenceTest, set_srs)
// Test setting EPSG:4326 from User string
TEST(SpatialReferenceTest, axis_ordering)
{
SpatialReference wgs84("EPSG:4326");



Options o2;
o2.add("filename", Support::datapath("las/test_epsg_4326.las"));
Expand Down Expand Up @@ -554,9 +551,8 @@ TEST(SpatialReferenceTest, axis_ordering)
Support::checkXYZ(Support::temppath("axis.las"),
Support::datapath("las/test_epsg_4326_axis.las"));


}
#endif
#endif



Expand Down

0 comments on commit 7302f25

Please sign in to comment.