| 295 | |
| 296 | |
| 297 | std::string Geometry::wkt(double precision, bool bOutputZ) const |
| 298 | { |
| 299 | // Important note: The precision is not always respected. Using GDAL |
| 300 | // it can only be set once. Because of this, there's no point in saving |
| 301 | // away the current OGR_WKT_PRECISION. Same for OGR_WKT_ROUND. |
| 302 | // |
| 303 | // Also note that when abs(value) < 1, f-type formatting is used. |
| 304 | // Otherwise g-type formatting is used. Precision means different things |
| 305 | // with the two format types. With f-formatting it specifies the |
| 306 | // number of places to the right of the decimal. In g-formatting, it's |
| 307 | // the minimum number of digits. Yuck. |
| 308 | |
| 309 | std::string p(std::to_string((int)precision)); |
| 310 | CPLSetConfigOption("OGR_WKT_PRECISION", p.data()); |
| 311 | CPLSetConfigOption("OGR_WKT_ROUND", "FALSE"); |
| 312 | |
| 313 | char *buf; |
| 314 | OGRErr err = m_geom->exportToWkt(&buf); |
| 315 | if (err != OGRERR_NONE) |
| 316 | throw pdal_error("Geometry::wkt: unable to export geometry to WKT."); |
| 317 | std::string wkt(buf); |
| 318 | CPLFree(buf); |
| 319 | return wkt; |
| 320 | } |
| 321 | |
| 322 | std::string Geometry::wkb() const |
| 323 | { |