Skip to content

Commit

Permalink
Remove pdal::gdal::Geometry. (#3104)
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed May 27, 2020
1 parent 1f00a7e commit c5735c3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 90 deletions.
16 changes: 6 additions & 10 deletions io/TIndexReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "TIndexReader.hpp"
#include <pdal/GDALUtils.hpp>
#include <pdal/Polygon.hpp>
#include <pdal/util/ProgramArgs.hpp>

namespace pdal
Expand Down Expand Up @@ -179,25 +180,20 @@ void TIndexReader::initialize()
if (getSpatialReference().empty())
setSpatialReference(SpatialReference(m_out_ref->wkt()));

std::unique_ptr<gdal::Geometry> wkt_g;

// If the user set either explicit 'polygon' or 'boundary' options
// we will filter by that geometry. The user can set a 'filter_srs'
// option to override the SRS of the input geometry and we will
// reproject to the output projection as needed.
Polygon poly;
if (m_wkt.size())
{
// Reproject the given wkt to the output SRS so
// filtering/cropping works
gdal::SpatialRef assign(m_filterSRS);
gdal::Geometry before(m_wkt, assign);
before.transform(*m_out_ref);

wkt_g.reset (new gdal::Geometry(before.wkt(), *m_out_ref));
poly = Polygon(m_wkt, m_filterSRS);
poly.transform(m_out_ref->wkt());

geometry = wkt_g->get();
m_wkt = wkt_g->wkt();
OGR_L_SetSpatialFilter(m_layer, geometry);
m_wkt = poly.wkt();
OGR_L_SetSpatialFilter(m_layer, poly.getOGRHandle());
}

if (m_attributeFilter.size())
Expand Down
78 changes: 0 additions & 78 deletions pdal/GDALUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@
#include <ogr_srs_api.h>

class OGRSpatialReference;
class OGRGeometry;

namespace pdal
{

class Polygon;

namespace gdal
Expand Down Expand Up @@ -138,82 +136,6 @@ class SpatialRef
RefPtr m_ref;
};

class Geometry
{
public:
Geometry()
{}
Geometry(const std::string& wkt, const SpatialRef& srs)
{
OGRGeometryH geom;

char *p_wkt = const_cast<char *>(wkt.data());
OGRSpatialReferenceH ref = srs.get();
if (srs.empty())
{
ref = NULL;
}
bool isJson = wkt.find("{") != wkt.npos ||
wkt.find("}") != wkt.npos;

if (!isJson)
{
OGRErr err = OGR_G_CreateFromWkt(&p_wkt, ref, &geom);
if (err != OGRERR_NONE)
{
std::cout << "wkt: " << wkt << std::endl;
std::ostringstream oss;
oss << "unable to construct OGR Geometry";
oss << " '" << CPLGetLastErrorMsg() << "'";
throw pdal::pdal_error(oss.str());
}
}
else
{
// Assume it is GeoJSON and try constructing from that
geom = OGR_G_CreateGeometryFromJson(p_wkt);

if (!geom)
throw pdal_error("Unable to create geometry from "
"input GeoJSON");

OGR_G_AssignSpatialReference(geom, ref);
}

newRef(geom);
}

operator bool () const
{ return get() != NULL; }
OGRGeometryH get() const
{ return m_ref.get(); }

void transform(const SpatialRef& out_srs)
{
OGR_G_TransformTo(m_ref.get(), out_srs.get());
}

std::string wkt() const
{
char* p_wkt = 0;
OGRErr err = OGR_G_ExportToWkt(m_ref.get(), &p_wkt);
return std::string(p_wkt);
}

void setFromGeometry(OGRGeometryH geom)
{
if (geom)
newRef(OGR_G_Clone(geom));
}

private:
void newRef(void *v)
{
m_ref = RefPtr(v, [](void* t){ OGR_G_DestroyGeometry(t); } );
}
RefPtr m_ref;
};


// This is a little confusing because we have a singleton error handler with
// a single log pointer, but we set the log pointer/debug state as if we
Expand Down
2 changes: 0 additions & 2 deletions pdal/SpatialReference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

#include <pdal/pdal_internal.hpp>

using OGRSpatialReferenceH = void *;

namespace pdal
{

Expand Down

0 comments on commit c5735c3

Please sign in to comment.