Skip to content

Commit

Permalink
computing nominal point density for tessellated polygon in filters.he…
Browse files Browse the repository at this point in the history
…xbin
  • Loading branch information
hobu committed Nov 17, 2015
1 parent d5b1140 commit 14b5c31
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/pdal/Geometry.hpp
Expand Up @@ -116,6 +116,21 @@ static std::string smoothPolygon(const std::string& wkt, double tolerance)
finish();
return outWkt;
}

static double computeArea(const std::string& wkt)
{
GEOSContextHandle_t env = init();

GEOSGeometry *geom = GEOSGeomFromWKT_r(env, wkt.c_str());
if (!geom)
return 0.0;

double output(0.0);
int er = GEOSArea_r(env, geom, &output);
GEOSGeom_destroy_r(env, geom);
finish();
return output;
}
#else

static std::string smoothPolygon(const std::string& wkt, double tolerance)
Expand Down
11 changes: 11 additions & 0 deletions plugins/hexbin/filters/HexBin.cpp
Expand Up @@ -83,6 +83,7 @@ void HexBin::filter(PointView& view)
double x = view.getFieldAs<double>(pdal::Dimension::Id::X, idx);
double y = view.getFieldAs<double>(pdal::Dimension::Id::Y, idx);
m_grid->addPoint(x, y);
m_count++;
}
}

Expand Down Expand Up @@ -151,6 +152,16 @@ void HexBin::done(PointTableRef table)
m_metadata.add("smoothed_boundary",
Geometry::smoothPolygon(polygon.str(), tolerance),
"Smoothed boundary MULTIPOLYGON of domain");
double area = Geometry::computeArea(polygon.str());

double density = (double) m_count / area ;
m_metadata.add("density",
density,
"Number of points per square unit");
m_metadata.add("area",
area,
"Area in square units of tessellated polygon");

}

} // namespace pdal
1 change: 1 addition & 0 deletions plugins/hexbin/filters/HexBin.hpp
Expand Up @@ -62,6 +62,7 @@ class PDAL_DLL HexBin : public Filter
int32_t m_density;
double m_edgeLength;
bool m_outputTesselation;
point_count_t m_count;

virtual void processOptions(const Options& options);
virtual void ready(PointTableRef table);
Expand Down

0 comments on commit 14b5c31

Please sign in to comment.