Ejemplo n.º 1
0
// Return a OGR_G_ConvexHull based on the bounds in a specified projection.
OGRGeometryH
simplet_bounds_to_ogr(simplet_bounds_t *bounds, OGRSpatialReferenceH proj) {
  OGRGeometryH tmpLine;
  if(!(tmpLine = OGR_G_CreateGeometry(wkbLineString)))
    return NULL;

  // Add all the points defining the bounds to the geometry
  OGR_G_AddPoint_2D(tmpLine, bounds->nw.x, bounds->nw.y);
  OGR_G_AddPoint_2D(tmpLine, bounds->se.x, bounds->se.y);
  OGR_G_AddPoint_2D(tmpLine, bounds->nw.x, bounds->se.y);
  OGR_G_AddPoint_2D(tmpLine, bounds->se.x, bounds->nw.y);
  OGRGeometryH tmpPoint = OGR_G_ForceToMultiPoint(tmpLine);
  // Calculate the Convex Hull
  OGRGeometryH ogrBounds;
  if(!(ogrBounds = OGR_G_ConvexHull(tmpPoint))){
    OGR_G_DestroyGeometry(tmpLine);
    return NULL;
  }

  // And assign the projection.
  OGR_G_AssignSpatialReference(ogrBounds, proj);
  OGR_G_DestroyGeometry(tmpPoint);

  return ogrBounds;
}
Ejemplo n.º 2
0
    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);
    }