Skip to content

Commit

Permalink
Remove GeomPkg from crop filter.
Browse files Browse the repository at this point in the history
Update SRS transforms in crop filter.
  • Loading branch information
abellgithub committed Dec 21, 2016
1 parent ea269ec commit 67e3741
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
43 changes: 23 additions & 20 deletions filters/CropFilter.cpp
Expand Up @@ -71,9 +71,10 @@ void CropFilter::addArgs(ProgramArgs& args)
args.add("a_srs", "Spatial reference for bounding region", m_assignedSrs);
args.add("bounds", "Point box for cropped points", m_bounds);
args.add("point", "Crop within 'distance' from a 2D or 3D point", m_points).
setErrorText("Invalid point specification must be in the form \"(1.00, 1.00)\""
"or \"(1.00, 1.00, 1.00)\"");
args.add("distance", "Crop with this distance from 2D or 3D 'point'", m_distance);
setErrorText("Invalid point specification must be in the "
"form \"(1.00, 1.00)\" or \"(1.00, 1.00, 1.00)\"");
args.add("distance", "Crop with this distance from 2D or 3D 'point'",
m_distance);
args.add("polygon", "Bounding polying for cropped points", m_polys).
setErrorText("Invalid polygon specification. "
"Must be valid GeoJSON/WKT");
Expand All @@ -82,24 +83,17 @@ void CropFilter::addArgs(ProgramArgs& args)

void CropFilter::initialize()
{

// Set geometry from polygons.
if (m_polys.size())
{
m_geoms.clear();
for (Polygon& poly : m_polys)
{
GeomPkg g;

// Throws if invalid.
poly.valid();
if (!m_assignedSrs.empty())
poly.setSpatialReference(m_assignedSrs);
g.m_geom = poly;
m_geoms.push_back(g);
m_geoms.push_back(poly);
}
}

}


Expand All @@ -109,7 +103,9 @@ void CropFilter::ready(PointTableRef table)
{
// If we already overrode the SRS, use that instead
if (m_assignedSrs.empty())
geom.m_geom.setSpatialReference(table.anySpatialReference());
geom.setSpatialReference(table.anySpatialReference());
else
geom.setSpatialReference(m_assignedSrs);
}
}

Expand Down Expand Up @@ -137,16 +133,22 @@ PointViewSet CropFilter::run(PointViewPtr view)
{
// If this is the first time through or the SRS has changed,
// prepare the crop polygon.
if (srs != m_lastSrs)
if (!srs.empty() || !geom.getSpatialReference().empty())
{
geom.m_geom = geom.m_geom.transform(srs);
try
{
geom = geom.transform(srs);
}
catch (pdal_error& err)
{
throw pdal_error(getName() + ": " + err.what());
}
}

PointViewPtr outView = view->makeNew();
crop(geom, *view, *outView);
viewSet.insert(outView);
}
m_lastSrs = srs;

for (auto& box : m_bounds)
{
Expand Down Expand Up @@ -187,27 +189,28 @@ void CropFilter::crop(const BOX2D& box, PointView& input, PointView& output)
}
}

bool CropFilter::crop(PointRef& point, const GeomPkg& g)
bool CropFilter::crop(PointRef& point, const Polygon& g)
{
bool covers = g.m_geom.covers(point);
bool covers = g.covers(point);
bool keep = (m_cropOutside != covers);
return keep;
}

void CropFilter::crop(const GeomPkg& g, PointView& input, PointView& output)
void CropFilter::crop(const Polygon& g, PointView& input, PointView& output)
{
PointRef point = input.point(0);
for (PointId idx = 0; idx < input.size(); ++idx)
{
point.setPointId(idx);
bool covers = g.m_geom.covers(point);
bool covers = g.covers(point);
bool keep = (m_cropOutside != covers);
if (keep)
output.appendPoint(input, idx);
}
}

void CropFilter::crop(const cropfilter::Point& point, double distance, PointView& input, PointView& output)
void CropFilter::crop(const cropfilter::Point& point, double distance,
PointView& input, PointView& output)
{

bool bIs3D = point.is3d();
Expand Down
16 changes: 3 additions & 13 deletions filters/CropFilter.hpp
Expand Up @@ -63,20 +63,10 @@ class PDAL_DLL CropFilter : public Filter
bool m_cropOutside;
std::vector<Polygon> m_polys;
SpatialReference m_assignedSrs;
SpatialReference m_lastSrs;
double m_distance;
std::vector<cropfilter::Point> m_points;

struct GeomPkg
{
GeomPkg()
{}

Polygon m_geom;
Polygon m_geomXform;
};

std::vector<GeomPkg> m_geoms;
std::vector<Polygon> m_geoms;

void addArgs(ProgramArgs& args);
virtual void initialize();
Expand All @@ -85,8 +75,8 @@ class PDAL_DLL CropFilter : public Filter
virtual PointViewSet run(PointViewPtr view);
bool crop(PointRef& point, const BOX2D& box);
void crop(const BOX2D& box, PointView& input, PointView& output);
bool crop(PointRef& point, const GeomPkg& g);
void crop(const GeomPkg& g, PointView& input, PointView& output);
bool crop(PointRef& point, const Polygon& g);
void crop(const Polygon& g, PointView& input, PointView& output);
void crop(const cropfilter::Point& point, double distance, PointView& input, PointView& output);

CropFilter& operator=(const CropFilter&); // not implemented
Expand Down
8 changes: 6 additions & 2 deletions pdal/Geometry.cpp
Expand Up @@ -194,9 +194,13 @@ Geometry::Geometry(OGRGeometryH g, const SpatialReference& srs)
Geometry Geometry::transform(const SpatialReference& ref) const
{
if (m_srs.empty())
throw pdal_error("Geometry::transform failed due to m_srs being empty");
throw pdal_error("Geometry::transform failed. "
"Source missing spatial reference.");
if (ref.empty())
throw pdal_error("Geometry::transform failed due to ref being empty");
throw pdal_error("Geometry::transform failed. "
"Invalid destination spatial reference.");
if (ref == m_srs)
return *this;

gdal::SpatialRef fromRef(m_srs.getWKT());
gdal::SpatialRef toRef(ref.getWKT());
Expand Down
3 changes: 3 additions & 0 deletions pdal/SpatialReference.cpp
Expand Up @@ -243,6 +243,9 @@ std::string SpatialReference::getHorizontalUnits() const

bool SpatialReference::equals(const SpatialReference& input) const
{
if (getWKT() == input.getWKT())
return true;

OGRSpatialReferenceH current = OSRNewSpatialReference(getWKT().c_str());
OGRSpatialReferenceH other = OSRNewSpatialReference(input.getWKT().c_str());

Expand Down

0 comments on commit 67e3741

Please sign in to comment.