Skip to content

Commit

Permalink
Remove OGR code for EPT (#2777)
Browse files Browse the repository at this point in the history
* Remove OGR code for EPT

* Consolidate code.
  • Loading branch information
abellgithub committed Oct 7, 2019
1 parent 531b21c commit 1806d35
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
19 changes: 3 additions & 16 deletions io/EptReader.cpp
Expand Up @@ -250,22 +250,9 @@ void EptReader::initialize()

if (!m_args->m_ogr.is_null())
{
std::vector<OGRGeometry*> ogr_geoms = pdal::gdal::fetchOGRGeometries(m_args->m_ogr);

debug << "Number of OGR filter geometries: "
<< ogr_geoms.size()
<< std::endl;

for (auto g: ogr_geoms)
{
OGRSpatialReference* srs = g->getSpatialReference();
char *poWKT = 0;
srs->exportToWkt(&poWKT);
Polygon p = pdal::Polygon(g, std::string(poWKT));
p.transform(getSpatialReference());
m_args->m_polys.emplace_back(p);
CPLFree(poWKT);
}
auto& plist = m_args->m_polys;
std::vector<Polygon> ogrPolys = gdal::getPolygons(m_args->m_ogr);
plist.insert(plist.end(), ogrPolys.begin(), ogrPolys.end());
}

// Transform query bounds to match point source SRS.
Expand Down
14 changes: 6 additions & 8 deletions pdal/GDALUtils.cpp
Expand Up @@ -32,6 +32,7 @@
* OF SUCH DAMAGE.
****************************************************************************/

#include <pdal/Polygon.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/private/SrsTransform.hpp>
#include <pdal/util/Algorithm.hpp>
Expand Down Expand Up @@ -778,7 +779,7 @@ OGRGeometry *createFromGeoJson(const std::string& s, std::string& srs)
}


std::vector<OGRGeometry*> fetchOGRGeometries(const NL::json ogr)
std::vector<Polygon> getPolygons(const NL::json& ogr)
{
registerDrivers();
const NL::json& datasource = ogr.at("datasource");
Expand Down Expand Up @@ -826,8 +827,6 @@ std::vector<OGRGeometry*> fetchOGRGeometries(const NL::json ogr)
throw pdal_error("Unable to read layer in fetchOGRGeometries " + layer.dump() );
}

std::vector<OGRGeometry*> output;

OGRFeature *poFeature (nullptr);
OGRGeometry* filterGeometry(nullptr);
std::string dialect("OGRSQL");
Expand Down Expand Up @@ -891,14 +890,13 @@ std::vector<OGRGeometry*> fetchOGRGeometries(const NL::json ogr)
throw pdal_error("unable to execute sql query!");
}

while( (poFeature = poLayer->GetNextFeature()) != NULL )
std::vector<Polygon> polys;
while ((poFeature = poLayer->GetNextFeature()) != NULL)
{
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
OGRGeometry* clone = poGeometry->clone();
output.emplace_back(clone);
polys.emplace_back(poFeature->GetGeometryRef());
OGRFeature::DestroyFeature( poFeature );
}
return output;
return polys;
}

} // namespace gdal
Expand Down
6 changes: 4 additions & 2 deletions pdal/GDALUtils.hpp
Expand Up @@ -43,8 +43,8 @@
#include <pdal/pdal_internal.hpp>
#include <pdal/Dimension.hpp>
#include <pdal/Log.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/util/Bounds.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/JsonFwd.hpp>

#include <cpl_conv.h>
Expand All @@ -59,6 +59,8 @@ class OGRGeometry;
namespace pdal
{

class Polygon;

namespace gdal
{

Expand Down Expand Up @@ -867,7 +869,7 @@ OGRGeometry *createFromGeoJson(const char *s);
OGRGeometry *createFromWkt(const std::string& s, std::string& srs);
OGRGeometry *createFromGeoJson(const std::string& s, std::string& srs);

std::vector<OGRGeometry*> fetchOGRGeometries(const NL::json json);
std::vector<Polygon> getPolygons(const NL::json& ogr);

inline OGRGeometry *fromHandle(OGRGeometryH geom)
{ return reinterpret_cast<OGRGeometry *>(geom); }
Expand Down
5 changes: 5 additions & 0 deletions pdal/Geometry.cpp
Expand Up @@ -67,6 +67,11 @@ Geometry::Geometry(Geometry&& input) : m_geom(std::move(input.m_geom))
{}


Geometry::Geometry(OGRGeometryH g) :
m_geom((reinterpret_cast<OGRGeometry *>(g))->clone())
{}


Geometry::Geometry(OGRGeometryH g, const SpatialReference& srs) :
m_geom((reinterpret_cast<OGRGeometry *>(g))->clone())
{
Expand Down
1 change: 1 addition & 0 deletions pdal/Geometry.hpp
Expand Up @@ -56,6 +56,7 @@ class PDAL_DLL Geometry
Geometry(Geometry&&);
Geometry(const std::string& wkt_or_json,
SpatialReference ref = SpatialReference());
Geometry(OGRGeometryH g);
Geometry(OGRGeometryH g, const SpatialReference& srs);

public:
Expand Down
12 changes: 12 additions & 0 deletions pdal/Polygon.cpp
Expand Up @@ -38,7 +38,19 @@
namespace pdal
{

Polygon::Polygon(OGRGeometryH g) : Geometry(g)
{
init();
}


Polygon::Polygon(OGRGeometryH g, const SpatialReference& srs) : Geometry(g, srs)
{
init();
}


void Polygon::init()
{
// If the handle was null, we need to create an empty polygon.
if (!m_geom)
Expand Down
4 changes: 4 additions & 0 deletions pdal/Polygon.hpp
Expand Up @@ -58,6 +58,7 @@ class PDAL_DLL Polygon : public Geometry

Polygon(const BOX2D&);
Polygon(const BOX3D&);
Polygon(OGRGeometryH g);
Polygon(OGRGeometryH g, const SpatialReference& srs);

OGRGeometryH getOGRHandle();
Expand All @@ -78,6 +79,9 @@ class PDAL_DLL Polygon : public Geometry
bool crosses(const Polygon& p) const;
Ring exteriorRing() const;
std::vector<Ring> interiorRings() const;

private:
void init();
};

} // namespace pdal
Expand Down

0 comments on commit 1806d35

Please sign in to comment.