LocationType* LocationManager::CreateLocationType(iDataConnection* db, const csString &locationName) { LocationType* locationType = new LocationType(-1,locationName); if(locationType->CreateUpdate(db)) { loctypes.Put(locationName, locationType); return locationType; } delete locationType; return NULL; }
bool LocationManager::RemoveLocationType(const csString &locationName) { LocationType* locationType = FindLocation(locationName); if(locationType) { loctypes.Delete(locationType->GetName(),locationType); delete locationType; return true; } return false; }
bool LocationManager::Load(iEngine* engine, iDataConnection* db) { Result rs(db->Select("select * from sc_location_type")); if(!rs.IsValid()) { Error2("Could not load locations from db: %s",db->GetLastError()); return false; } for(int i=0; i<(int)rs.Count(); i++) { LocationType* loctype = new LocationType(); if(loctype->Load(rs[i],engine,db)) { loctypes.Put(loctype->name, loctype); CPrintf(CON_DEBUG, "Added location type '%s'(%d)\n",loctype->name.GetDataSafe(),loctype->id); } else { Error2("Could not load location: %s",db->GetLastError()); delete loctype; return false; } } CPrintf(CON_WARNING, "Loaded %d locations \n",rs.Count()); // Create a cache of all the locations. csHash<LocationType*, csString>::GlobalIterator iter(loctypes.GetIterator()); LocationType* loc; while(iter.HasNext()) { loc = iter.Next(); for(size_t i = 0; i < loc->locs.GetSize(); i++) { all_locations.Push(loc->locs[i]); } } return true; }
bool CombatManager::InitializePVP() { Result rs(db->Select("select * from sc_location_type where name = 'pvp_region'")); if (!rs.IsValid()) { Error2("Could not load locations from db: %s",db->GetLastError() ); return false; } // no PVP defined if (rs.Count() == 0) { return true; } if (rs.Count() > 1) { Error1("More than one pvp_region defined!"); // return false; // not really fatal } LocationType *loctype = new LocationType(); if (loctype->Load(rs[0],NULL,db)) { pvp_region = loctype; } else { Error2("Could not load location: %s",db->GetLastError() ); delete loctype; // return false; // not fatal } return true; }
bool GeoTIFFExporter::CreateGeoTIFF(TIFF *pOut) { if (mpFileDescriptor == NULL) { return false; } GTIF* pGtif = GTIFNew(pOut); if (pGtif == NULL) { return false; } // Get the exported lower left corner location const vector<DimensionDescriptor>& rows = mpFileDescriptor->getRows(); const vector<DimensionDescriptor>& columns = mpFileDescriptor->getColumns(); unsigned int startRow = 0; if (rows.empty() == false) { DimensionDescriptor rowDim = rows.front(); if (rowDim.isActiveNumberValid() == true) { startRow = rowDim.getActiveNumber(); } } unsigned int startColumn = 0; if (columns.empty() == false) { DimensionDescriptor columnDim = columns.front(); if (columnDim.isActiveNumberValid() == true) { startColumn = columnDim.getActiveNumber(); } } LocationType llPixel(startColumn, startRow); LocationType urPixel = llPixel + 1.0; LocationType llGeoCoord; LocationType lrGeoCoord; LocationType ulGeoCoord; LocationType urGeoCoord; bool bGeocoords = false; if (mpRaster->isGeoreferenced()) { // Get the lat/long values from the RasterElement LocationType pixel = llPixel; LocationType latLong = mpRaster->convertPixelToGeocoord(pixel); llGeoCoord.mY = latLong.mY; llGeoCoord.mX = latLong.mX; pixel.mX = urPixel.mX; pixel.mY = llPixel.mY; latLong = mpRaster->convertPixelToGeocoord(pixel); lrGeoCoord.mY = latLong.mY; lrGeoCoord.mX = latLong.mX; pixel.mX = llPixel.mX; pixel.mY = urPixel.mY; latLong = mpRaster->convertPixelToGeocoord(pixel); ulGeoCoord.mY = latLong.mY; ulGeoCoord.mX = latLong.mX; pixel = urPixel; latLong = mpRaster->convertPixelToGeocoord(pixel); urGeoCoord.mY = latLong.mY; urGeoCoord.mX = latLong.mX; bGeocoords = true; } bool isOrthoRectified = false; DynamicObject* pMetaData = mpRaster->getMetadata(); bool hasMetaDataTag = false; if (pMetaData != NULL) { try { isOrthoRectified = dv_cast<bool>(pMetaData->getAttribute("orthorectified")); hasMetaDataTag = true; } catch (bad_cast&) { // attribute is not present or is not a bool, so calculate isOrthoRectified } } if (!hasMetaDataTag) { // calculate the value of isOrthoRectified if (mpRaster->isGeoreferenced() && !rows.empty() && !columns.empty()) { int endRow(-1); int endColumn(-1); for (vector<DimensionDescriptor>::const_reverse_iterator rowIt = rows.rbegin(); rowIt != rows.rend(); ++rowIt) { if (rowIt->isActiveNumberValid()) { endRow = rowIt->getActiveNumber(); break; } } for (vector<DimensionDescriptor>::const_reverse_iterator colIt = columns.rbegin(); colIt != columns.rend(); ++colIt) { if (colIt->isActiveNumberValid()) { endColumn = colIt->getActiveNumber(); break; } } if (endRow != -1 && endColumn != -1 && static_cast<unsigned int>(endRow) > startRow && static_cast<unsigned int>(endColumn) > startColumn) { // the chip's (0,0) LocationType startPixel = llPixel; LocationType startGeo = llGeoCoord; // the chip's (0,max) LocationType rowMax(startPixel.mX, endRow); LocationType rowMaxGeo = mpRaster->convertPixelToGeocoord(rowMax); // the chip's (max,0) LocationType colMax(endColumn, startPixel.mY); LocationType colMaxGeo = mpRaster->convertPixelToGeocoord(colMax); // LocationType rowMaxCheckGeo(rowMaxGeo.mX, startGeo.mY); LocationType rowMaxCheck = mpRaster->convertGeocoordToPixel(rowMaxCheckGeo); LocationType colMaxCheckGeo(startGeo.mX, colMaxGeo.mY); LocationType colMaxCheck = mpRaster->convertGeocoordToPixel(colMaxCheckGeo); LocationType deltaRowMax = rowMaxCheck - rowMax; LocationType deltaColMax = colMaxCheck - colMax; isOrthoRectified = (deltaRowMax.length() < 0.5) && (deltaColMax.length() < 0.5); } } } if (bGeocoords == false) { GTIFFree(pGtif); return false; } LocationType geoCoordCenter((llGeoCoord.mX + lrGeoCoord.mX + ulGeoCoord.mX + urGeoCoord.mX) / 4.0, (llGeoCoord.mY + lrGeoCoord.mY + ulGeoCoord.mY + urGeoCoord.mY) / 4.0); // if the data is orthorectified, write out the appropriate tags if (isOrthoRectified) { double pTiepoints[6] = {0.0, 0.0, 0.0, llGeoCoord.mY, llGeoCoord.mX, 0.0}; TIFFSetField(pOut, TIFFTAG_GEOTIEPOINTS, 6, pTiepoints); /* The following calculation can result in a negative scale for the latitude and/or longitude. This is correct and is explicitly called out in the GeoTIFF spec (GeoTIFF Format Specification version 1.8.1, section 2.6.1) as the proper way to handle flipping of the image. A negative latitude scale corresponds to an image with its origin in the lower left or lower right corner, while a positive latitude scale corresponds to an image with its origin in the upper left or upper right corner. Similarly for longitude scale. */ double pPixelSize[3] = {urGeoCoord.mY - llGeoCoord.mY, llGeoCoord.mX - urGeoCoord.mX, 0.0}; TIFFSetField(pOut, TIFFTAG_GEOPIXELSCALE, 3, pPixelSize); } else { //compute transformation Matrix values double a = lrGeoCoord.mY - llGeoCoord.mY; double b = ulGeoCoord.mY - llGeoCoord.mY; double d = llGeoCoord.mY; double e = lrGeoCoord.mX - llGeoCoord.mX; double f = ulGeoCoord.mX - llGeoCoord.mX; double h = llGeoCoord.mX; double k = 1.0; double p = 1.0; double tMatrix[16] = {a, b, 0.0, d, e, f, 0.0, h, 0.0, 0.0, k, 0.0, 0.0, 0.0, 0.0, p }; TIFFSetField(pOut, GTIFF_TRANSMATRIX, 16, tMatrix); } GTIFKeySet(pGtif, GTModelTypeGeoKey, TYPE_SHORT, 1, ModelGeographic); GTIFKeySet(pGtif, GTRasterTypeGeoKey, TYPE_SHORT, 1, RasterPixelIsArea); GTIFKeySet(pGtif, GeogAngularUnitsGeoKey, TYPE_SHORT, 1, Angular_Degree); GTIFKeySet(pGtif, GeogLinearUnitsGeoKey, TYPE_SHORT, 1, Linear_Meter); GTIFKeySet(pGtif, GeographicTypeGeoKey, TYPE_SHORT, 1, GCS_WGS_84); GTIFKeySet(pGtif, ProjCenterLongGeoKey, TYPE_DOUBLE, 1, geoCoordCenter.mY); GTIFKeySet(pGtif, ProjCenterLatGeoKey, TYPE_DOUBLE, 1, geoCoordCenter.mX); ///* Here we violate the GTIF abstraction to retarget on another file. // We should just have a function for copying tags from one GTIF object // to another. pGtif->gt_tif = pOut; pGtif->gt_flags |= FLAG_FILE_MODIFIED; //* Install keys and tags GTIFWriteKeys(pGtif); GTIFFree(pGtif); return true; }