TagId TypeConfig::RegisterTagForExternalUse(const std::string& tagName) { OSMSCOUT_HASHMAP<std::string,TagId>::const_iterator mapping=stringToTagMap.find(tagName); if (mapping!=stringToTagMap.end()) { tags[mapping->second].SetToExternal(); return mapping->second; } TagInfo tagInfo(tagName,false); if (tagInfo.GetId()==0) { tagInfo.SetId(nextTagId); nextTagId++; } else { nextTagId=std::max(nextTagId,(TagId)(tagInfo.GetId()+1)); } tags.push_back(tagInfo); stringToTagMap[tagInfo.GetName()]=tagInfo.GetId(); return tagInfo.GetId(); }
bool Message :: getTestCaseMsgTagInfo(DataSet<TextSerializer> &dSet) { //Get the testcase message Id int* testMsgID = dSet.get<int>(req_, testCaseMId_); if(! testMsgID) { dSet.add<std::string>(req_, stat_, "false"); std::ostringstream oss; oss << "TestCaseMsgId not found" <<std::endl; dSet.add<std::string>(req_, statMsg_, oss.str()); LOG_ERROR(oss.str()); return false; } MessageTagInfoListPtr msgTagInfoListPtr( new std::vector< TagInfoPtr> ); if(! msgTagInfoListPtr) { dSet.add<std::string>(req_, stat_, "false"); std::ostringstream oss; oss << "TagList not initialized" <<std::endl; dSet.add<std::string>(req_, statMsg_, oss.str()); LOG_ERROR(oss.str()); return false; } Connection* conn=Connection::getInstance(); ConnPtr dbHandle=conn->getConnection(); // execute the transaction try { // giving it a scope { if(! dbHandle) { dSet.add<std::string>(req_, stat_, "false"); std::ostringstream oss; oss << "Database connection not successful" <<std::endl; dSet.add<std::string>(req_, statMsg_, oss.str()); LOG_ERROR(oss.str()); return false; } pqxx::work w(*dbHandle); std::ostringstream msgId; msgId << *testMsgID; std::string query = "select test_case_msg_tags_id, tag_name, dest_data_type, tag_length, justify_with, justify_leftright, " "off_set, default_value, required, value_user from dbo.task_details where test_case_msgs_id = " + msgId.str(); std::cout << "\t getTestCaseMsgTagInfo : QUERY = " << query<< std::endl; pqxx::result R = w.exec(query); for( pqxx::result::const_iterator row = R.begin();row != R.end(); row++) { TagInfoPtr tagInfo( new TagInfo); //pqxx::from_string(row[4].c_str(), tagInfo->justifyWith_); //tagInfo->justifyWith_ = row[4].as<char>(); pqxx::from_string(row[0].c_str(), tagInfo->testCaseMsgTagId_); //int tagInfo->tagName_ = row[1].c_str(); tagInfo->destDataType_ = row[2].c_str(); pqxx::from_string(row[3].c_str(), tagInfo->tagLength_); tagInfo->justifyWith_ = (row[4].c_str())[0]; //char tagInfo->justifyLeftRight_ = (row[5].c_str())[0]; //char pqxx::from_string(row[6].c_str(), tagInfo->offset_); tagInfo->defaultValue_ = row[7].c_str(); tagInfo->required_ = row[8].c_str(); tagInfo->userValue_ = row[9].c_str(); msgTagInfoListPtr->push_back(tagInfo); } } //scope dSet.add<MessageTagInfoListPtr>(req_, tagInfoList_, msgTagInfoListPtr); dSet.add<std::string>(req_, stat_, "true"); return true; } //try catch(pqxx::broken_connection& e) { std::ostringstream oss; oss << "Connection to database broken try again" <<std::endl; dSet.add<std::string>(req_, stat_, "false"); dSet.add<std::string>(req_, statMsg_, oss.str()); LOG_ERROR(oss.str()); return false; } catch(pqxx::sql_error& e) { std::ostringstream oss; oss << e.what() << std::endl; dSet.add<std::string>(req_, stat_, "false"); dSet.add<std::string>(req_, statMsg_, std::string(e.what())); LOG_ERROR(oss.str()); return false; } catch(...) { std::ostringstream oss; oss << "Unknown error while fetching data" << std::endl; dSet.add<std::string>(req_, stat_, "false"); dSet.add<std::string>(req_, statMsg_, oss.str()); LOG_ERROR(oss.str()); return false; } return true; }
bool ossimKakaduNitfWriter::writeStream() { static const char MODULE[] = "ossimKakaduNitfWriter::writeStream"; if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered..." << endl; } if ( !theInputConnection || !m_outputStream || !theInputConnection->isMaster() ) { return false; } const ossim_uint32 TILES = theInputConnection->getNumberOfTiles(); const ossim_uint32 BANDS = theInputConnection->getNumberOfOutputBands(); const ossimScalarType SCALAR = theInputConnection->getOutputScalarType(); if (m_compressor->getAlphaChannelFlag()) { //--- // Someone can set this through the generic setProperty interface. // Unset, currently only supported in jp2 writer. // Could be used here but I think we would have to update the // nitf tags. //--- m_compressor->setAlphaChannelFlag(false); } // Create the compressor. Can through an exception. try { m_compressor->create(m_outputStream, SCALAR, BANDS, theInputConnection->getAreaOfInterest(), DEFAULT_TILE_SIZE, TILES, false); } catch (const ossimException& e) { ossimNotify(ossimNotifyLevel_WARN) << e.what() << std::endl; return false; } std::streampos endOfFileHdrPos; std::streampos endOfImgHdrPos; std::streampos endOfFilePos; // Container record withing NITF file header. ossimNitfImageInfoRecordV2_1 imageInfoRecord; // NITF file header. ossimRefPtr<ossimNitfFileHeaderV2_1> fHdr = new ossimNitfFileHeaderV2_1(); // Note the sub header length and image length will be set later. fHdr->addImageInfoRecord(imageInfoRecord); fHdr->setDate(ossimDate()); fHdr->setTitle(ossimString("")); // ??? // Write to stream capturing the stream position for later. fHdr->writeStream(*m_outputStream); endOfFileHdrPos = m_outputStream->tellp(); // NITF image header. ossimRefPtr<ossimNitfImageHeaderV2_1> iHdr = new ossimNitfImageHeaderV2_1(); // Set the compression type: iHdr->setCompression(ossimString("C8")); // Set the Image Magnification (IMAG) field. iHdr->setImageMagnification(ossimString("1.0")); // Set the pixel type (PVTYPE) field. iHdr->setPixelType(ossimNitfCommon::getNitfPixelType(SCALAR)); // Set the actual bits per pixel (ABPP) field. ossim_uint32 abpp = ossim::getActualBitsPerPixel(SCALAR); iHdr->setActualBitsPerPixel( abpp ); // Set the bits per pixel (NBPP) field. iHdr->setBitsPerPixel(ossim::getBitsPerPixel(SCALAR)); iHdr->setNumberOfBands(BANDS); iHdr->setImageMode('B'); // IMODE field to blocked. if( (BANDS == 3) && (SCALAR == OSSIM_UCHAR) ) { iHdr->setRepresentation("RGB"); iHdr->setCategory("VIS"); } else if(BANDS == 1) { iHdr->setRepresentation("MONO"); iHdr->setCategory("MS"); } else { iHdr->setRepresentation("MULTI"); iHdr->setCategory("MS"); } ossimNitfImageBandV2_1 bandInfo; for(ossim_uint32 band = 0; band < BANDS; ++band) { std::ostringstream out; out << std::setfill('0') << std::setw(2) << band; bandInfo.setBandRepresentation(out.str().c_str()); iHdr->setBandInfo(band, bandInfo); } ossim_uint32 outputTilesWide = theInputConnection->getNumberOfTilesHorizontal(); ossim_uint32 outputTilesHigh = theInputConnection->getNumberOfTilesVertical(); iHdr->setBlocksPerRow(outputTilesWide); iHdr->setBlocksPerCol(outputTilesHigh); iHdr->setNumberOfPixelsPerBlockRow(DEFAULT_TILE_SIZE.y); iHdr->setNumberOfPixelsPerBlockCol(DEFAULT_TILE_SIZE.x); iHdr->setNumberOfRows(theInputConnection->getAreaOfInterest().height()); iHdr->setNumberOfCols(theInputConnection->getAreaOfInterest().width()); // Write the geometry info to the image header. writeGeometry(iHdr.get(), theInputConnection.get()); // Add the J2KLRA TRE: ossimRefPtr<ossimNitfJ2klraTag> j2klraTag = new ossimNitfJ2klraTag(); m_compressor->initialize( j2klraTag.get(), abpp ); j2klraTag->setBandsO( BANDS ); ossimRefPtr<ossimNitfRegisteredTag> tag = j2klraTag.get(); ossimNitfTagInformation tagInfo( tag ); iHdr->addTag( tagInfo ); // Write the image header to stream capturing the stream position. iHdr->writeStream(*m_outputStream); endOfImgHdrPos = m_outputStream->tellp(); if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG:" << "\noutputTilesWide: " << outputTilesWide << "\noutputTilesHigh: " << outputTilesHigh << "\nnumberOfTiles: " << TILES << "\nimageRect: " << theInputConnection->getAreaOfInterest() << std::endl; } // Tile loop in the line direction. ossim_uint32 tileNumber = 0; bool result = true; for(ossim_uint32 y = 0; y < outputTilesHigh; ++y) { // Tile loop in the sample (width) direction. for(ossim_uint32 x = 0; x < outputTilesWide; ++x) { // Grab the resampled tile. ossimRefPtr<ossimImageData> t = theInputConnection->getNextTile(); if (t.valid() && ( t->getDataObjectStatus() != OSSIM_NULL ) ) { if ( ! m_compressor->writeTile( *(t.get()) ) ) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " ERROR:" << "Error returned writing tile: " << tileNumber << std::endl; result = false; } } else { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " ERROR:" << "Error returned writing tile: " << tileNumber << std::endl; result = false; } if ( !result ) { // This will bust out of both loops. x = outputTilesWide; y = outputTilesHigh; } // Increment tile number for percent complete. ++tileNumber; } // End of tile loop in the sample (width) direction. if (needsAborting()) { setPercentComplete(100.0); break; } else { ossim_float64 tile = tileNumber; ossim_float64 numTiles = TILES; setPercentComplete(tile / numTiles * 100.0); } } // End of tile loop in the line (height) direction. m_compressor->finish(); // Get the file length. endOfFilePos = m_outputStream->tellp(); //--- // Seek back to set some things that were not know until now and // rewrite the nitf file and image header. //--- m_outputStream->seekp(0, std::ios_base::beg); // Set the file length. std::streamoff length = endOfFilePos; fHdr->setFileLength(static_cast<ossim_uint64>(length)); // Set the file header length. length = endOfFileHdrPos; fHdr->setHeaderLength(static_cast<ossim_uint64>(length)); // Set the image sub header length. length = endOfImgHdrPos - endOfFileHdrPos; imageInfoRecord.setSubheaderLength(static_cast<ossim_uint64>(length)); // Set the image length. length = endOfFilePos - endOfImgHdrPos; imageInfoRecord.setImageLength(static_cast<ossim_uint64>(length)); fHdr->replaceImageInfoRecord(0, imageInfoRecord); setComplexityLevel(length, fHdr.get()); // Rewrite the header. fHdr->writeStream(*m_outputStream); // Set the compression rate now that the image size is known. ossimString comrat = ossimNitfCommon::getCompressionRate( theInputConnection->getAreaOfInterest(), BANDS, SCALAR, static_cast<ossim_uint64>(length)); iHdr->setCompressionRateCode(comrat); // Rewrite the image header. iHdr->writeStream(*m_outputStream); close(); if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exit status = " << (result?"true":"false\n") << std::endl; } return result; }