Skip to content

Commit

Permalink
Use polygon's contains() for points in EPT.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Nov 26, 2019
1 parent 85ece5a commit a33f359
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
32 changes: 8 additions & 24 deletions filters/OverlayFilter.cpp
Expand Up @@ -53,26 +53,6 @@ static StaticPluginInfo const s_info

CREATE_STATIC_STAGE(OverlayFilter, s_info)

struct OGRDataSourceDeleter
{
template <typename T>
void operator()(T* ptr)
{
if (ptr)
::OGR_DS_Destroy(ptr);
}
};

struct OGRFeatureDeleter
{
template <typename T>
void operator()(T* ptr)
{
if (ptr)
::OGR_F_Destroy(ptr);
}
};


void OverlayFilter::addArgs(ProgramArgs& args)
{
Expand Down Expand Up @@ -105,7 +85,7 @@ void OverlayFilter::prepared(PointTableRef table)
void OverlayFilter::ready(PointTableRef table)
{
m_ds = OGRDSPtr(OGROpen(m_datasource.c_str(), 0, 0),
OGRDataSourceDeleter());
[](void *p){ if (p) ::OGR_DS_Destroy(p); });
if (!m_ds)
throwError("Unable to open data source '" + m_datasource + "'");

Expand All @@ -119,8 +99,13 @@ void OverlayFilter::ready(PointTableRef table)
if (!m_lyr)
throwError("Unable to select layer '" + m_layer + "'");

auto featureDeleter = [](void *p)
{
if (p)
::OGR_F_Destroy(p);
};
OGRFeaturePtr feature = OGRFeaturePtr(OGR_L_GetNextFeature(m_lyr),
OGRFeatureDeleter());
featureDeleter);

int field_index(1); // default to first column if nothing was set
if (m_column.size())
Expand All @@ -139,8 +124,7 @@ void OverlayFilter::ready(PointTableRef table)
m_polygons.push_back(
{ Polygon(geom, table.anySpatialReference()), fieldVal} );

feature = OGRFeaturePtr(OGR_L_GetNextFeature(m_lyr),
OGRFeatureDeleter());
feature = OGRFeaturePtr(OGR_L_GetNextFeature(m_lyr), featureDeleter);
}
while (feature);
}
Expand Down
15 changes: 4 additions & 11 deletions io/EptReader.cpp
Expand Up @@ -47,7 +47,6 @@
#include <pdal/SrsBounds.hpp>
#include <pdal/util/Algorithm.hpp>
#include "../filters/CropFilter.hpp"
#include "../filters/private/pnp/GridPnp.hpp"

namespace pdal
{
Expand Down Expand Up @@ -280,12 +279,6 @@ void EptReader::initialize()
}
m_args->m_polys = std::move(exploded);

for (auto& p : m_args->m_polys)
{
m_queryGrids.emplace_back(
new GridPnp(p.exteriorRing(), p.interiorRings()));
}

try
{
handleOriginQuery();
Expand Down Expand Up @@ -447,7 +440,7 @@ QuickInfo EptReader::inspect()

// If we've passed a spatial query, determine an upper bound on the
// point count.
if (!m_queryBounds.contains(fullBounds) || m_queryGrids.size())
if (!m_queryBounds.contains(fullBounds) || m_args->m_polys.size())
{
log()->get(LogLevel::Debug) <<
"Determining overlapping point count" << std::endl;
Expand Down Expand Up @@ -828,11 +821,11 @@ void EptReader::process(PointView& dst, PointRef& pr, const uint64_t nodeId,

auto passesPolyFilter = [this](double x, double y)
{
if (m_queryGrids.empty())
if (m_args->m_polys.empty())
return true;

for (const auto& grid : m_queryGrids)
if (grid->inside(x, y))
for (Polygon& poly : m_args->m_polys)
if (poly.contains(x, y))
return true;
return false;
};
Expand Down
2 changes: 0 additions & 2 deletions io/EptReader.hpp
Expand Up @@ -64,7 +64,6 @@ class EptInfo;
class FixedPointLayout;
class Key;
class Pool;
class GridPnp;
class VectorPointTable;

class PDAL_DLL EptReader : public Reader, public Streamable
Expand Down Expand Up @@ -140,7 +139,6 @@ class PDAL_DLL EptReader : public Reader, public Streamable
std::unique_ptr<Args> m_args;

BOX3D m_queryBounds;
std::vector<std::unique_ptr<GridPnp>> m_queryGrids;
int64_t m_queryOriginId = -1;
std::unique_ptr<Pool> m_pool;
std::vector<std::unique_ptr<Addon>> m_addons;
Expand Down

0 comments on commit a33f359

Please sign in to comment.