bool LandsatGeotiffImporter::createRasterPager(RasterElement* pRaster) const
{
   VERIFY(pRaster != NULL);
   DataDescriptor* pDescriptor = pRaster->getDataDescriptor();
   VERIFY(pDescriptor != NULL);
   FileDescriptor* pFileDescriptor = pDescriptor->getFileDescriptor();
   VERIFY(pFileDescriptor != NULL);

   std::string filename = pRaster->getFilename();
   std::string datasetName = pFileDescriptor->getDatasetLocation();
   Progress* pProgress = getProgress();

   FactoryResource<Filename> pFilename;
   pFilename->setFullPathAndName(filename);

   ExecutableResource pagerPlugIn("Landsat GeoTIFF Raster Pager", std::string(), pProgress);
   pagerPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedElementArg(), pRaster);
   pagerPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedFilenameArg(), pFilename.get());

   bool success = pagerPlugIn->execute();

   RasterPager* pPager = dynamic_cast<RasterPager*>(pagerPlugIn->getPlugIn());
   if (!success || pPager == NULL)
   {
      std::string message = "Execution of Landsat Geotiff Raster Pager failed!";
      if (pProgress != NULL) pProgress->updateProgress(message, 0, ERRORS);
      return false;
   }

   pRaster->setPager(pPager);
   pagerPlugIn->releasePlugIn();

   return true;
}
示例#2
0
bool Nitf::NitfImporterShell::createRasterPager(RasterElement *pRaster) const
{
   VERIFY(pRaster != NULL);

   DataDescriptor* pDd = pRaster->getDataDescriptor();
   VERIFY(pDd != NULL);
   FileDescriptor* pFd = pDd->getFileDescriptor();
   VERIFY(pFd != NULL);

   const string& datasetLocation = pFd->getDatasetLocation();
   if (datasetLocation.empty() == true)
   {
      return false;
   }

   stringstream imageNameStream(datasetLocation.substr(1));
   int imageSegment;
   imageNameStream >> imageSegment;

   FactoryResource<Filename> pFn;
   pFn->setFullPathAndName(pFd->getFilename());

   ExecutableResource pPlugIn("NitfPager");
   pPlugIn->getInArgList().setPlugInArgValue("Segment Number", &imageSegment);
   pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedElementArg(), pRaster);
   pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedFilenameArg(), pFn.get());

   if (pPlugIn->execute() == true)
   {
      RasterPager* pPager = dynamic_cast<RasterPager*>(pPlugIn->getPlugIn());
      if (pPager != NULL)
      {
         pRaster->setPager(pPager);
         pPlugIn->releasePlugIn();
         return true;
      }
   }

   return false;
}
bool SignatureSetImporter::execute(PlugInArgList* pInArgList, PlugInArgList* OutArgList)
{
   VERIFY(pInArgList != NULL);
   Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg());
   ProgressTracker progress(pProgress, "Loading spectral signature library", "spectral", "7B21EE8A-D2E1-4325-BB9F-F4E521BFD5ED");

   SignatureSet* pSignatureSet = pInArgList->getPlugInArgValue<SignatureSet>(Importer::ImportElementArg());
   VERIFY(pSignatureSet != NULL);
   DataDescriptor* pDataDescriptor = pSignatureSet->getDataDescriptor();
   VERIFY(pDataDescriptor != NULL);
   FileDescriptor* pFileDescriptor = pDataDescriptor->getFileDescriptor();
   VERIFY(pFileDescriptor != NULL);
   const string& filename = pFileDescriptor->getFilename().getFullPathAndName();

   progress.getCurrentStep()->addProperty("signature set", pSignatureSet->getName());
   progress.getCurrentStep()->addProperty("dataset location", pFileDescriptor->getDatasetLocation());

   // locate the spot in the tree for this dataset
   try
   {
      string expr;
      vector<string> parts = StringUtilities::split(pFileDescriptor->getDatasetLocation(), '/');
      for (vector<string>::iterator part = parts.begin(); part != parts.end(); ++part)
      {
         if (!part->empty())
         {
            expr += "/signature_set[metadata/@name='Name' and metadata/@value='" + *part + "']";
         }
      }
      expr += "/signature";
      loadDoc(filename);
      DOMXPathResult* pResult = mXml[filename]->query(expr, DOMXPathResult::SNAPSHOT_RESULT_TYPE);
      VERIFY(pResult != NULL);
      int nodeTotal = pResult->getSnapshotLength();
      for (int nodeNum = 0; nodeNum < nodeTotal; ++nodeNum)
      {
         if (isAborted())
         {
            progress.report("Aborted file " + pFileDescriptor->getFilename().getFullPathAndName(), 0, WARNING, true);
            progress.report("User aborted the operation.", 0, ABORT, true);
            return false;
         }
         int percent = static_cast<int>(100.0 * nodeNum / nodeTotal);
         progress.report("Importing signature library", percent, NORMAL);
         if (!pResult->snapshotItem(nodeNum) || !pResult->isNode())
         {
            continue;
         }
         const DOMElement* pElmnt = static_cast<const DOMElement*>(pResult->getNodeValue());
         string filename = A(pElmnt->getAttribute(X("filename")));
         if (filename.empty() == false)
         {
            string path = pFileDescriptor->getFilename().getPath();

            QString tempFilename = QString::fromStdString(filename);
            if (tempFilename.startsWith("./") == true)
            {
               tempFilename.replace(0, 1, QString::fromStdString(path));
               filename = tempFilename.toStdString();
            }
            else
            {
               QFileInfo fileInfo(tempFilename);
               if (fileInfo.isRelative() == true)
               {
                  filename = path + SLASH + filename;
               }
            }
         }

         // don't pass progress to importer - the individual signature imports are rapid and passing progress will
         // cause isAborted() to not function properly.
         ImporterResource importer("Auto Importer", filename, NULL);
         if (importer->getPlugIn() == NULL)
         {
            progress.report("The \"Auto Importer\" is not available and is required to import signature sets.", 0, ERRORS, true);
            return false;
         }
         if (importer->execute())
         {
            vector<DataElement*> elements = importer->getImportedElements();
            vector<Signature*> sigs(elements.size(), NULL);
            for (vector<DataElement*>::iterator element = elements.begin(); element != elements.end(); ++element)
            {
               Signature* pSig = dynamic_cast<Signature*>(*element);
               if (pSig != NULL)
               {
                  pSignatureSet->insertSignature(pSig);
                  // reparent the signature
                  Service<ModelServices>()->setElementParent(pSig, pSignatureSet);
               }
            }
         }
         else
         {
            progress.report("Unable to import signature " + filename, percent, WARNING, true);
         }
      }
   }
   catch(DOMException &exc)
   {
      progress.report(A(exc.getMessage()), 0, ERRORS, true);
      return false;
   }
   SignatureSet* pParent = dynamic_cast<SignatureSet*>(pSignatureSet->getParent());
   if (pParent != NULL && pParent->getFilename() == pSignatureSet->getFilename())
   {
      pParent->insertSignature(pSignatureSet);
   }

   progress.report("Spectral signature library loaded", 100, NORMAL);
   progress.upALevel();
   return true;
}
示例#4
0
bool Nitf::NitfImporterShell::createRasterPager(RasterElement* pRaster) const
{
   if (pRaster == NULL)
   {
      return false;
   }

   // Get the filename
   string filename = pRaster->getFilename();

   FactoryResource<Filename> pFilename;
   pFilename->setFullPathAndName(filename);

   // Get the image segment corresponding to this raster element
   DataDescriptor* pDescriptor = pRaster->getDataDescriptor();
   VERIFY(pDescriptor != NULL);

   FileDescriptor* pFileDescriptor = pDescriptor->getFileDescriptor();
   VERIFY(pFileDescriptor != NULL);

   const string& datasetLocation = pFileDescriptor->getDatasetLocation();
   if (datasetLocation.empty() == true)
   {
      return false;
   }

   string imageSegmentText = datasetLocation.substr(1);
   unsigned int imageSegment = StringUtilities::fromDisplayString<unsigned int>(imageSegmentText) - 1;

   // Create the resource to execute the pager
   ExecutableResource pPlugIn;

   // Check for J2K compression in the metadata of the raster element being imported and not the given raster
   // element, because the given raster element may be a temporary raster element used by RasterElementImporterShell
   // when the processing location is IN_MEMORY, which does not contain the metadata or the parent information
   // (see RasterUtilities::generateUnchippedRasterDataDescriptor())
   string imageCompression;

   const RasterElement* pElement = getRasterElement();
   if (pElement != NULL)
   {
      const DynamicObject* pMetadata = pElement->getMetadata();
      VERIFYRV(pMetadata, NULL);

      const string attributePath[] =
      {
         Nitf::NITF_METADATA,
         Nitf::IMAGE_SUBHEADER,
         Nitf::ImageSubheaderFieldNames::COMPRESSION,
         END_METADATA_NAME
      };

      imageCompression = pMetadata->getAttributeByPath(attributePath).toDisplayString();
   }

   if ((imageCompression == Nitf::ImageSubheaderFieldValues::IC_C8) ||
      (imageCompression == Nitf::ImageSubheaderFieldValues::IC_M8))
   {
      // Get the offset and size of the image segment in the file
      uint64_t offset = getImageOffset(filename, imageSegment);
      uint64_t size = getImageSize(filename, imageSegment);

      // Use the JPEG2000 pager
      pPlugIn->setPlugIn("JPEG2000 Pager");
      pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedElementArg(), pRaster);
      pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedFilenameArg(), pFilename.get());
      pPlugIn->getInArgList().setPlugInArgValue("Offset", &offset);
      pPlugIn->getInArgList().setPlugInArgValue("Size", &size);
   }
   else
   {
      // Use the NITF Pager
      pPlugIn->setPlugIn("NitfPager");
      pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedElementArg(), pRaster);
      pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedFilenameArg(), pFilename.get());
      pPlugIn->getInArgList().setPlugInArgValue("Segment Number", &imageSegment);
   }

   if (pPlugIn->execute() == true)
   {
      RasterPager* pPager = dynamic_cast<RasterPager*>(pPlugIn->getPlugIn());
      if (pPager != NULL)
      {
         pRaster->setPager(pPager);
         pPlugIn->releasePlugIn();
         return true;
      }
   }

   return false;
}