MWWorld::Ptr Miscellaneous::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const { MWWorld::Ptr newPtr; const ESMS::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); if (MWWorld::Class::get(ptr).getName(ptr) == store.gameSettings.search("sGold")->str) { int goldAmount = ptr.getRefData().getCount(); std::string base = "Gold_001"; if (goldAmount >= 100) base = "Gold_100"; else if (goldAmount >= 25) base = "Gold_025"; else if (goldAmount >= 10) base = "Gold_010"; else if (goldAmount >= 5) base = "Gold_005"; // Really, I have no idea why moving ref out of conditional // scope causes list::push_back throwing std::bad_alloc MWWorld::ManualRef newRef(store, base); MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = newRef.getPtr().get<ESM::Miscellaneous>(); newPtr = MWWorld::Ptr(&cell.miscItems.insert(*ref), &cell); } else { MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>(); newPtr = MWWorld::Ptr(&cell.miscItems.insert(*ref), &cell); } return newPtr; }
void setFromLayer(OGRLayerH layer) { if (layer) { OGRSpatialReferenceH s = OGR_L_GetSpatialRef(layer); if (s) { OGRSpatialReferenceH clone = OSRClone(s); newRef(clone); } } }
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); }
SpatialRef(const std::string& srs) { newRef(OSRNewSpatialReference("")); OSRSetFromUserInput(get(), srs.data()); }
SpatialRef() { newRef(OSRNewSpatialReference("")); }
void setFromGeometry(OGRGeometryH geom) { if (geom) newRef(OGR_G_Clone(geom)); }