void Polygon::update(const std::string& wkt_or_json, SpatialReference ref) { bool isJson = wkt_or_json.find("{") != wkt_or_json.npos || wkt_or_json.find("}") != wkt_or_json.npos; if (!isJson) { m_geom = GEOSGeomFromWKT_r(m_ctx, wkt_or_json.c_str()); if (!m_geom) throw pdal_error("Unable to create geometry from input WKT"); } else { // Assume it is GeoJSON and try constructing from that OGRGeometryH json = OGR_G_CreateGeometryFromJson(wkt_or_json.c_str()); if (!json) throw pdal_error("Unable to create geometry from " "input GeoJSON"); char* gdal_wkt(0); OGRErr err = OGR_G_ExportToWkt(json, &gdal_wkt); m_geom = GEOSGeomFromWKT_r(m_ctx, gdal_wkt); //ABELL - Why should this ever throw? Is it worth catching if // we don't know why? if (!m_geom) throw pdal_error("Unable to create GEOS geometry from OGR WKT!"); OGRFree(gdal_wkt); OGR_G_DestroyGeometry(json); } prepare(); }
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); }