Skip to content

Commit

Permalink
support simplification without preserving topology in pdal::Polygon a…
Browse files Browse the repository at this point in the history
…nd reflect in filters.hexbin
  • Loading branch information
hobu committed Oct 7, 2019
1 parent 531b21c commit f4628b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions doc/stages/filters.hexbin.rst
Expand Up @@ -117,3 +117,9 @@ threshold
precision
Minimum number of significant digits to use in writing out the
well-known text of the boundary polygon. [Default: 8]

preserve_topology
Use GEOS SimplifyPreserveTopology instead of Simplify for polygon simplification with `smooth` option. [Default: true]

smooth
Use GEOS simplify operations to smooth boundary to a tolerance [Default: true]
1 change: 1 addition & 0 deletions filters/HexBinFilter.cpp
Expand Up @@ -83,6 +83,7 @@ void HexBin::addArgs(ProgramArgs& args)
m_cullArg = &args.add("hole_cull_area_tolerance", "Tolerance area to "
"apply to holes before cull", m_cullArea);
args.add("smooth", "Smooth boundary output", m_doSmooth, true);
args.add("preserve_topology", "Preserve topology when smoothing", m_preserve_topology, true);
}


Expand Down
1 change: 1 addition & 0 deletions filters/HexBinFilter.hpp
Expand Up @@ -71,6 +71,7 @@ class PDAL_DLL HexBin : public Filter, public Streamable
bool m_outputTesselation;
bool m_doSmooth;
point_count_t m_count;
bool m_preserve_topology;

virtual void addArgs(ProgramArgs& args);
virtual void ready(PointTableRef table);
Expand Down
9 changes: 7 additions & 2 deletions pdal/Polygon.cpp
Expand Up @@ -88,7 +88,7 @@ Polygon::Polygon(const BOX3D& box)
}


void Polygon::simplify(double distance_tolerance, double area_tolerance)
void Polygon::simplify(double distance_tolerance, double area_tolerance, bool preserve_topology)
{
throwNoGeos();

Expand All @@ -114,7 +114,12 @@ void Polygon::simplify(double distance_tolerance, double area_tolerance)
OGR_G_RemoveGeometry(gdal::toHandle(poly), i, true);
};

OGRGeometry *g = m_geom->SimplifyPreserveTopology(distance_tolerance);
OGRGeometry *g;
if (preserve_topology)
g = m_geom->SimplifyPreserveTopology(distance_tolerance);
else
g = m_geom->Simplify(distance_tolerance);

m_geom.reset(g);

OGRwkbGeometryType t = m_geom->getGeometryType();
Expand Down
2 changes: 1 addition & 1 deletion pdal/Polygon.hpp
Expand Up @@ -62,7 +62,7 @@ class PDAL_DLL Polygon : public Geometry

OGRGeometryH getOGRHandle();

void simplify(double distance_tolerance, double area_tolerance);
void simplify(double distance_tolerance, double area_tolerance, bool preserve_topology = true);
double area() const;
std::vector<Polygon> polygons() const;

Expand Down

0 comments on commit f4628b8

Please sign in to comment.