Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Oct 25, 2016
2 parents c5214a2 + 3ed3a60 commit 6997b1c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
30 changes: 27 additions & 3 deletions include/pdal/GDALUtils.hpp
Expand Up @@ -136,9 +136,33 @@ class Geometry
{
ref = NULL;
}
OGRErr err = OGR_G_CreateFromWkt(&p_wkt, ref, &geom);
if (err != OGRERR_NONE)
throw pdal::pdal_error("Unable to construct OGR geometry from wkt");
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);
}

Expand Down
9 changes: 9 additions & 0 deletions include/pdal/Polygon.hpp
Expand Up @@ -62,6 +62,9 @@ class PDAL_DLL Polygon
Polygon(OGRGeometryH g, const SpatialReference& srs,
geos::ErrorHandler& ctx);
Polygon& operator=(const Polygon&);

OGRGeometryH getOGRHandle();

private:
Polygon(const std::string& wkt_or_json, SpatialReference ref,
GEOSContextHandle_t ctx);
Expand Down Expand Up @@ -92,6 +95,12 @@ class PDAL_DLL Polygon

bool covers(PointRef& ref) const;
bool equal(const Polygon& p) const;
bool covers(const Polygon& p) const;
bool overlaps(const Polygon& p) const;
bool contains(const Polygon& p) const;
bool touches(const Polygon& p) const;
bool within(const Polygon& p) const;
bool crosses(const Polygon& p) const;

bool valid() const;
std::string validReason() const;
Expand Down
30 changes: 30 additions & 0 deletions src/Polygon.cpp
Expand Up @@ -413,6 +413,36 @@ bool Polygon::equals(const Polygon& p, double tolerance) const
return (bool) GEOSEqualsExact_r(m_ctx, m_geom, p.m_geom, tolerance);
}

bool Polygon::covers(const Polygon& p) const
{
return (bool) GEOSCovers_r(m_ctx, m_geom, p.m_geom);
}

bool Polygon::overlaps(const Polygon& p) const
{
return (bool) GEOSOverlaps_r(m_ctx, m_geom, p.m_geom);
}

bool Polygon::contains(const Polygon& p) const
{
return (bool) GEOSContains_r(m_ctx, m_geom, p.m_geom);
}

bool Polygon::touches(const Polygon& p) const
{
return (bool) GEOSTouches_r(m_ctx, m_geom, p.m_geom);
}

bool Polygon::within(const Polygon& p) const
{
return (bool) GEOSWithin_r(m_ctx, m_geom, p.m_geom);
}

bool Polygon::crosses(const Polygon& p) const
{
return (bool) GEOSCrosses_r(m_ctx, m_geom, p.m_geom);
}



bool Polygon::operator==(const Polygon& input) const
Expand Down

0 comments on commit 6997b1c

Please sign in to comment.