bool GetPrimaryRasterLayer::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   StepResource pStep("Execute Wizard Item", "app", "5D20DF72-1C71-4a5d-9B1A-398A91154EBD");
   pStep->addProperty("Item", getName());
   mpStep = pStep.get();

   if (pInArgList == NULL || pOutArgList == NULL)
   {
      reportError("Invalid Plug-In Arg List specified.", "8161F92F-124F-4118-8E24-532187A442AA");
      return false;
   }

   if (extractInputArgs(pInArgList) == false)
   {
      return false;
   }

   LayerList* pLayerList = mpSpatialDataView->getLayerList();
   VERIFY(pLayerList != NULL);

   RasterElement* pElement = pLayerList->getPrimaryRasterElement();
   RasterLayer* pLayer = dynamic_cast<RasterLayer*>(pLayerList->getLayer(RASTER, pElement));
   if (pOutArgList->setPlugInArgValue(Executable::LayerArg(), pLayer) == false)
   {
      reportError("Unable to set output argument.", "B4DE1827-3B96-4a96-89BB-62431B6E81CF");
      return false;
   }

   reportComplete();
   return true;
}
Beispiel #2
0
bool BandMath::createReturnGuiElement()
{
   bool bSuccess = false;

   if (mbInteractive || (mbDisplayResults && Service<ApplicationServices>()->isBatch() == false))
   {
      SpatialDataWindow* pWindow = NULL;
      if (mbAsLayerOnExistingView)
      {
         pWindow = static_cast<SpatialDataWindow*>(mpDesktop->getWindow(mpCube->getName(), SPATIAL_DATA_WINDOW));
      }
      else
      {
         pWindow = static_cast<SpatialDataWindow*>(mpDesktop->createWindow(mResultsName.c_str(), SPATIAL_DATA_WINDOW));
      }

      if (pWindow == NULL)
      {
         return false;
      }

      SpatialDataView* pView = pWindow->getSpatialDataView();
      VERIFYRV(pView != NULL, NULL);

      UndoLock lock(pView);

      if (!mbAsLayerOnExistingView)
      {
         pView->setPrimaryRasterElement(mpResultData);
      }

      LayerList* pLayerList = pView->getLayerList();
      if (pLayerList != NULL)
      {
         Layer* pLayer = pLayerList->getLayer(RASTER, mpResultData);
         if (pLayer == NULL)
         {
            if (pView->createLayer(RASTER, mpResultData) != NULL)
            {
               bSuccess = true;
            }
            if (!mbAsLayerOnExistingView)
            {
               Service<ModelServices> pModel;
               vector<DataElement*> elements = pModel->getElements(mpResultData, "GcpList");
               for_each(elements.begin(), elements.end(), 
                  boost::bind(&SpatialDataView::createLayer, pView, GCP_LAYER, _1));
            }
         }
      }
   }
   else // no GUI required, method has successfully noop'd
   {
      bSuccess = true;
   }
   return bSuccess;
}
Beispiel #3
0
void OverviewWindow::updateSelectionBox()
{
   if ((mpView == NULL) || (mpSelectionWidget == NULL))
   {
      return;
   }

   // Get the pixel coordinates at the view corners
   LocationType lowerLeft;
   LocationType upperLeft;
   LocationType upperRight;
   LocationType lowerRight;
   mpView->getVisibleCorners(lowerLeft, upperLeft, upperRight, lowerRight);

   // Disconnect the signal to update the view since the values are obtained from the view
   disconnect(mpSelectionWidget, SIGNAL(selectionChanged(const std::vector<LocationType>&)), this,
      SLOT(updateView(const std::vector<LocationType>&)));

   LayerList* pLayerList = mpView->getLayerList();
   VERIFYNRV(pLayerList != NULL);
   Layer* pLayer = pLayerList->getLayer(RASTER, pLayerList->getPrimaryRasterElement());
   VERIFYNRV(pLayer != NULL);

   // Set the selection area
   vector<LocationType> selectionArea;
   LocationType dataCoord;
   pLayer->translateWorldToData(lowerLeft.mX, lowerLeft.mY, dataCoord.mX, dataCoord.mY);
   selectionArea.push_back(dataCoord);
   pLayer->translateWorldToData(lowerRight.mX, lowerRight.mY, dataCoord.mX, dataCoord.mY);
   selectionArea.push_back(dataCoord);
   pLayer->translateWorldToData(upperRight.mX, upperRight.mY, dataCoord.mX, dataCoord.mY);
   selectionArea.push_back(dataCoord);
   pLayer->translateWorldToData(upperLeft.mX, upperLeft.mY, dataCoord.mX, dataCoord.mY);
   selectionArea.push_back(dataCoord);

   // update snail trail if zoom factor greater than or equal zoom threshold
   if ((mpTrail != NULL) && (static_cast<int>(mpView->getZoomPercentage() + 0.5) >= mZoomThreshold))
   {
      // Translate each point into a screen location
      if (mpOverview != NULL)
      {
         mpOverview->translateWorldToScreen(lowerLeft.mX, lowerLeft.mY, lowerLeft.mX, lowerLeft.mY);
         mpOverview->translateWorldToScreen(lowerRight.mX, lowerRight.mY, lowerRight.mX, lowerRight.mY);
         mpOverview->translateWorldToScreen(upperLeft.mX, upperLeft.mY, upperLeft.mX, upperLeft.mY);
         mpOverview->translateWorldToScreen(upperRight.mX, upperRight.mY, upperRight.mX, upperRight.mY);

         mpTrail->addToStencil(lowerLeft, lowerRight, upperLeft, upperRight);
      }
   }

   mpSelectionWidget->setSelection(selectionArea);

   // Reconnect the signal to update the view
   connect(mpSelectionWidget, SIGNAL(selectionChanged(const std::vector<LocationType>&)), this,
      SLOT(updateView(const std::vector<LocationType>&)));
}
Beispiel #4
0
SpatialDataViewImp* OverviewWindow::createOverview()
{
   SpatialDataViewImp* pOverview = NULL;
   if (mpView != NULL)
   {
      pOverview = dynamic_cast<SpatialDataViewImp*>(mpView->copy());
      VERIFYRV(pOverview != NULL, NULL);
      pOverview->installEventFilter(this);

      LayerList* pLayerList = NULL;
      pLayerList = pOverview->getLayerList();
      if (pLayerList != NULL)
      {
         // get primary raster layer from data view
         LayerList* pSDVlist = mpView->getLayerList();
         VERIFYRV(pSDVlist != NULL, NULL);
         DataElement* pPrimElem = pSDVlist->getPrimaryRasterElement();
         VERIFYRV(pPrimElem != NULL, NULL);
         Layer* pPrimLayer = pSDVlist->getLayer(RASTER, pPrimElem);
         VERIFYRV(pPrimLayer != NULL, NULL);
         string primName(pPrimLayer->getName());

         vector<Layer*> layers;
         pLayerList->getLayers(layers);
         for (unsigned int i = 0; i < layers.size(); i++)
         {
            Layer* pLayer = NULL;
            pLayer = layers.at(i);
            string layerName(pLayer->getName());
            if (pLayer->getLayerType()==RASTER && layerName==primName)
            {
               pPrimLayer->linkLayer(pLayer);

               // reset the scale to what is in the model
               DataElement* pElement = pLayer->getDataElement();
               VERIFYRV(pElement != NULL, NULL);

               const RasterDataDescriptor* pDescriptor =
                  dynamic_cast<const RasterDataDescriptor*>(pElement->getDataDescriptor());
               VERIFYRV(pDescriptor != NULL, NULL);

               pLayer->setYScaleFactor(pDescriptor->getYPixelSize());
               pLayer->setXScaleFactor(pDescriptor->getXPixelSize());
            }
            else
            {
               pOverview->deleteLayer(pLayer);
            }
         }
         pOverview->resetOrientation();
      }
   }

   return pOverview;
}
Beispiel #5
0
bool GeocoordLinkFunctor::initialize()
{
   if (mInitialized)
   {
      return true;
   }

   if (mpSrcView != NULL)
   {
      LayerList* pSrcLayerList = mpSrcView->getLayerList();
      if (pSrcLayerList == NULL)
      {
         return false;
      }

      mpSrcGeo = pSrcLayerList->getPrimaryRasterElement();
      if (mpSrcGeo == NULL || !mpSrcGeo->isGeoreferenced())
      {
         return false;
      }

      mpSrcLayer = pSrcLayerList->getLayer(RASTER, mpSrcGeo);
      if (mpSrcLayer == NULL)
      {
         return false;
      }

      LocationType srcWorldCenter(mpSrcView->getVisibleCenter());

      LocationType srcScreenCenter;
      mpSrcView->translateWorldToScreen(srcWorldCenter.mX, srcWorldCenter.mY, 
         srcScreenCenter.mX, srcScreenCenter.mY);
      mSrcScreenCenter = complex<double>(srcScreenCenter.mX, srcScreenCenter.mY);

      LocationType srcDataCenter;
      mpSrcLayer->translateWorldToData(srcWorldCenter.mX, srcWorldCenter.mY, 
         srcDataCenter.mX, srcDataCenter.mY);
      mCenterGeocoord = mpSrcGeo->convertPixelToGeocoord(srcDataCenter);

      mTightness = findResolution(mpSrcGeo, mpSrcLayer, mCenterGeocoord) * LINK_TIGHTNESS;

      mInitialized = true;
      return true;
   }

   return false;
}
Beispiel #6
0
void OverviewWindow::updateView(const vector<LocationType>& selectionArea)
{
   if ((mpView == NULL) || (selectionArea.size() != 4))
   {
      return;
   }

   LayerList* pLayerList = mpView->getLayerList();
   VERIFYNRV(pLayerList != NULL);
   Layer* pLayer = pLayerList->getLayer(RASTER, pLayerList->getPrimaryRasterElement());
   VERIFYNRV(pLayer != NULL);
   LocationType worldLl;
   LocationType worldUr;
   pLayer->translateDataToWorld(selectionArea[0].mX, selectionArea[0].mY, worldLl.mX, worldLl.mY);
   pLayer->translateDataToWorld(selectionArea[2].mX, selectionArea[2].mY, worldUr.mX, worldUr.mY);
   
   // Update the view
   mpView->zoomToBox(worldLl, worldUr);
   mpView->repaint();
}
Beispiel #7
0
QWidget* ResultsExporter::getExportOptionsWidget(const PlugInArgList *pInArgList)
{
    const DataDescriptor* pDescriptor = NULL;
    if (pInArgList != NULL)
    {
        RasterElement* pElement = pInArgList->getPlugInArgValue<RasterElement>(Exporter::ExportItemArg());
        if (pElement != NULL)
        {
            pDescriptor = pElement->getDataDescriptor();
        }
    }
    if (mpOptionsWidget == NULL)
    {
        Service<DesktopServices> pDesktop;
        VERIFY(pDesktop.get() != NULL);

        mpOptionsWidget = new ResultsOptionsWidget(pDesktop->getMainWidget());
    }

    if (mpOptionsWidget != NULL)
    {
        const string& name = pDescriptor->getName();
        const string& type = pDescriptor->getType();
        DataElement* pParent = pDescriptor->getParent();

        RasterElement* pResults = dynamic_cast<RasterElement*>(mpModel->getElement(name, type, pParent));
        if (pResults != NULL)
        {
            PassArea passArea = MIDDLE;
            double dFirstThreshold = 0.0;
            double dSecondThreshold = 0.0;

            SpatialDataWindow* pWindow = dynamic_cast<SpatialDataWindow*>(mpDesktop->getCurrentWorkspaceWindow());
            if (pWindow != NULL)
            {
                SpatialDataView* pView = pWindow->getSpatialDataView();
                if (pView != NULL)
                {
                    LayerList* pLayerList = pView->getLayerList();
                    if (pLayerList != NULL)
                    {
                        ThresholdLayer* pThresholdLayer =
                            static_cast<ThresholdLayer*>(pLayerList->getLayer(THRESHOLD, pResults));
                        if (pThresholdLayer != NULL)
                        {
                            passArea = pThresholdLayer->getPassArea();
                            dFirstThreshold = pThresholdLayer->getFirstThreshold();
                            dSecondThreshold = pThresholdLayer->getSecondThreshold();
                        }
                        else
                        {
                            Statistics* pStatistics = pResults->getStatistics();
                            if (pStatistics != NULL)
                            {
                                dFirstThreshold = pStatistics->getMin();
                                dSecondThreshold = pStatistics->getMax();
                            }
                        }
                    }

                    LatLonLayer* pLatLonLayer = static_cast<LatLonLayer*>(pView->getTopMostLayer(LAT_LONG));
                    if (pLatLonLayer != NULL)
                    {
                        GeocoordType geocoordType = pLatLonLayer->getGeocoordType();
                        mpOptionsWidget->setGeocoordType(geocoordType);
                    }
                }
            }

            mpOptionsWidget->setPassArea(passArea);
            mpOptionsWidget->setFirstThreshold(dFirstThreshold);
            mpOptionsWidget->setSecondThreshold(dSecondThreshold);
        }
    }

    return mpOptionsWidget;
}
void ChippingWindow::createView()
{
   if (mpChippingWidget == NULL)
   {
      return;
   }

   RasterElement* pRaster = getRasterElement();
   if (pRaster == NULL)
   {
      return;
   }

   // Create the new raster element from the primary element of the source.
   // Note that this does not chip displayed elements if they differ from the primary element.
   // This causes a special case below where the stretch values are being applied to the chipped layer.
   RasterElement* pRasterChip = pRaster->createChip(pRaster->getParent(), "_chip",
      mpChippingWidget->getChipRows(), mpChippingWidget->getChipColumns(), mpChippingWidget->getChipBands());
   if (pRasterChip == NULL)
   {
      QMessageBox::critical(this, windowTitle(), "Unable to create a new cube!");
      return;
   }

   const RasterDataDescriptor* pDescriptor =
      dynamic_cast<const RasterDataDescriptor*>(pRasterChip->getDataDescriptor());
   VERIFYNRV(pDescriptor != NULL);

   // Create a view for the new chip
   SpatialDataWindow* pWindow = dynamic_cast<SpatialDataWindow*>(
      Service<DesktopServices>()->createWindow(pRasterChip->getName(), SPATIAL_DATA_WINDOW));
   if (pWindow == NULL)
   {
      return;
   }

   SpatialDataView* pView = pWindow->getSpatialDataView();
   if (pView == NULL)
   {
      Service<DesktopServices>()->deleteWindow(pWindow);
      return;
   }

   UndoLock lock(pView);
   if (pView->setPrimaryRasterElement(pRasterChip) == false)
   {
      Service<DesktopServices>()->deleteWindow(pWindow);
      return;
   }

   // RasterLayerImp is needed for the call to setCurrentStretchAsOriginalStretch().
   RasterLayerImp* pLayer = dynamic_cast<RasterLayerImp*>(pView->createLayer(RASTER, pRasterChip));
   if (pLayer == NULL)
   {
      Service<DesktopServices>()->deleteWindow(pWindow);
      return;
   }

   string origName = pRaster->getName();

   SpatialDataWindow* pOrigWindow = dynamic_cast<SpatialDataWindow*>(
      Service<DesktopServices>()->getWindow(origName, SPATIAL_DATA_WINDOW));
   if (pOrigWindow != NULL)
   {
      SpatialDataView* pOrigView = pOrigWindow->getSpatialDataView();
      if (pOrigView != NULL)
      {
         LayerList* pLayerList = pOrigView->getLayerList();
         if (pLayerList != NULL)
         {
            RasterLayer* pOrigLayer = static_cast<RasterLayer*>(pLayerList->getLayer(RASTER, pRaster));
            if (pOrigLayer != NULL)
            {
               // Set the stretch type first so that stretch values are interpreted correctly.
               pLayer->setStretchType(GRAYSCALE_MODE, pOrigLayer->getStretchType(GRAYSCALE_MODE));
               pLayer->setStretchType(RGB_MODE, pOrigLayer->getStretchType(RGB_MODE));
               pLayer->setDisplayMode(pOrigLayer->getDisplayMode());

               // Set the properties of the cube layer in the new view.
               // For each channel, display the first band if the previously displayed band was chipped.
               vector<RasterChannelType> channels = StringUtilities::getAllEnumValues<RasterChannelType>();
               for (vector<RasterChannelType>::const_iterator iter = channels.begin(); iter != channels.end(); ++iter)
               {
                  bool bandCopied = true;
                  DimensionDescriptor newBand;
                  DimensionDescriptor oldBand = pOrigLayer->getDisplayedBand(*iter);
                  if (oldBand.isOriginalNumberValid() == true)
                  {
                     newBand = pDescriptor->getOriginalBand(oldBand.getOriginalNumber());
                  }

                  if (newBand.isValid() == false)
                  {
                     bandCopied = false;
                     newBand = pDescriptor->getBands().front();
                  }

                  // No need to explicitly set the RasterElement here since the new view only has one RasterElement.
                  pLayer->setDisplayedBand(*iter, newBand);

                  // Use the default stretch properties if the displayed band was removed from the view or
                  // if the non-primary raster element was displayed. Otherwise, copy the stretch properties.
                  if (bandCopied && pRaster == pOrigLayer->getDisplayedRasterElement(*iter))
                  {
                     // Set the stretch units first so that stretch values are interpreted correctly.
                     pLayer->setStretchUnits(*iter, pOrigLayer->getStretchUnits(*iter));

                     double lower;
                     double upper;
                     pOrigLayer->getStretchValues(*iter, lower, upper);
                     pLayer->setStretchValues(*iter, lower, upper);
                  }
               }

               pLayer->setCurrentStretchAsOriginalStretch();
               pView->refresh();
            }
         }
      }
   }

   // Create a GCP layer
   if (pRaster->isGeoreferenced() == true)
   {
      const vector<DimensionDescriptor>& rows = mpChippingWidget->getChipRows();
      const vector<DimensionDescriptor>& columns = mpChippingWidget->getChipColumns();
      if ((rows.empty() == false) && (columns.empty() == false))
      {
         // Get the geocoordinates at the chip corners
         VERIFYNRV(rows.front().isActiveNumberValid() == true);
         VERIFYNRV(rows.back().isActiveNumberValid() == true);
         VERIFYNRV(columns.front().isActiveNumberValid() == true);
         VERIFYNRV(columns.back().isActiveNumberValid() == true);

         unsigned int startRow = rows.front().getActiveNumber();
         unsigned int endRow = rows.back().getActiveNumber();
         unsigned int startCol = columns.front().getActiveNumber();
         unsigned int endCol = columns.back().getActiveNumber();

         GcpPoint ulPoint;
         ulPoint.mPixel = LocationType(startCol, startRow);
         ulPoint.mCoordinate = pRaster->convertPixelToGeocoord(ulPoint.mPixel);

         GcpPoint urPoint;
         urPoint.mPixel = LocationType(endCol, startRow);
         urPoint.mCoordinate = pRaster->convertPixelToGeocoord(urPoint.mPixel);

         GcpPoint llPoint;
         llPoint.mPixel = LocationType(startCol, endRow);
         llPoint.mCoordinate = pRaster->convertPixelToGeocoord(llPoint.mPixel);

         GcpPoint lrPoint;
         lrPoint.mPixel = LocationType(endCol, endRow);
         lrPoint.mCoordinate = pRaster->convertPixelToGeocoord(lrPoint.mPixel);

         GcpPoint centerPoint;
         centerPoint.mPixel = LocationType((startCol + endCol) / 2, (startRow + endRow) / 2);
         centerPoint.mCoordinate = pRaster->convertPixelToGeocoord(centerPoint.mPixel);

         // Reset the coordinates to be in active numbers relative to the chip
         const vector<DimensionDescriptor>& chipRows = pDescriptor->getRows();
         const vector<DimensionDescriptor>& chipColumns = pDescriptor->getColumns();

         VERIFYNRV(chipRows.front().isActiveNumberValid() == true);
         VERIFYNRV(chipRows.back().isActiveNumberValid() == true);
         VERIFYNRV(chipColumns.front().isActiveNumberValid() == true);
         VERIFYNRV(chipColumns.back().isActiveNumberValid() == true);

         unsigned int chipStartRow = chipRows.front().getActiveNumber();
         unsigned int chipEndRow = chipRows.back().getActiveNumber();
         unsigned int chipStartCol = chipColumns.front().getActiveNumber();
         unsigned int chipEndCol = chipColumns.back().getActiveNumber();
         ulPoint.mPixel = LocationType(chipStartCol, chipStartRow);
         urPoint.mPixel = LocationType(chipEndCol, chipStartRow);
         llPoint.mPixel = LocationType(chipStartCol, chipEndRow);
         lrPoint.mPixel = LocationType(chipEndCol, chipEndRow);
         centerPoint.mPixel = LocationType((chipStartCol + chipEndCol) / 2, (chipStartRow + chipEndRow) / 2);

         // Create the GCP list
         Service<ModelServices> pModel;

         GcpList* pGcpList = static_cast<GcpList*>(pModel->createElement("Corner Coordinates",
            TypeConverter::toString<GcpList>(), pRasterChip));
         if (pGcpList != NULL)
         {
            list<GcpPoint> gcps;
            gcps.push_back(ulPoint);
            gcps.push_back(urPoint);
            gcps.push_back(llPoint);
            gcps.push_back(lrPoint);
            gcps.push_back(centerPoint);

            pGcpList->addPoints(gcps);

            // Create the layer
            if (pView->createLayer(GCP_LAYER, pGcpList) == NULL)
            {
               QMessageBox::warning(this, windowTitle(), "Could not create a GCP layer.");
            }
         }
         else
         {
            QMessageBox::warning(this, windowTitle(), "Could not create a GCP list.");
         }
      }
   }
}
string MeasurementObjectImp::generateGeoStrings() const
{
   LocationType llCorner = getLlCorner();
   LocationType urCorner = getUrCorner();
   LocationType llCornerLatLon;
   LocationType urCornerLatLon;
   bool unitsValid = false;

   // Get lat lon coordinates and terrain raster
   const RasterElement* pTerrain = NULL;

   bool geoValid(false);
   if (mpGeoreference.get() != NULL)
   {
      GraphicLayer* pLayer = getLayer();
      if (pLayer != NULL)
      {
         SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pLayer->getView());
         if (pView != NULL)
         {
            LayerList* pLayerList = pView->getLayerList();
            VERIFYRV(pLayerList != NULL, "");
            VERIFYRV(pLayerList->getPrimaryRasterElement() == mpGeoreference.get(), "");

            pTerrain = mpGeoreference->getTerrain();

            Layer* pPrimaryRasterLayer = pLayerList->getLayer(RASTER, mpGeoreference.get());
            if (pPrimaryRasterLayer != NULL)
            {
               pPrimaryRasterLayer->translateWorldToData(llCorner.mX, llCorner.mY, llCorner.mX, llCorner.mY);
               pPrimaryRasterLayer->translateWorldToData(urCorner.mX, urCorner.mY, urCorner.mX, urCorner.mY);
            }
         }
      }

      if (mpGeoreference->isGeoreferenced())
      {
         bool llValid(false);
         bool urValid(false);
         llCornerLatLon = mpGeoreference->convertPixelToGeocoord(llCorner, false, &llValid);
         urCornerLatLon = mpGeoreference->convertPixelToGeocoord(urCorner, false, &urValid);
         geoValid = llValid && urValid;
      }
   }

   mUsingInaccurateGeocoords = !geoValid;
   unitsValid = geoValid;

   //String Variables
   string startLoc = "";
   string endLoc = "";
   string distance = "";
   string bearing = "";
   string distanceUnit = "";

   GeoAlgorithms algs;
   double distanceVal = 0;
   double azimuthVal = 0;

   // Create GeoPoint objects
   LatLonPoint startLlPoint = llCornerLatLon;
   LatLonPoint endLlPoint = urCornerLatLon;
   UtmPoint startUtmPoint = startLlPoint;
   UtmPoint endUtmPoint = endLlPoint;
   MgrsPoint startMgrsPoint = startLlPoint;
   MgrsPoint endMgrsPoint = endLlPoint;

   // find elevations
   double elevation1(0.0);
   double elevation2(0.0);
   if (pTerrain != NULL)
   {
      const RasterDataDescriptor* pDescriptor =
         dynamic_cast<const RasterDataDescriptor*>(pTerrain->getDataDescriptor());
      if (pDescriptor != NULL)
      {
         const vector<DimensionDescriptor>& activeRows = pDescriptor->getRows();
         const vector<DimensionDescriptor>& activeColumns = pDescriptor->getColumns();
         if ( llCorner.mY >= 0 && llCorner.mY < activeRows.size() &&
              llCorner.mX >= 0 && llCorner.mX < activeColumns.size() &&
              urCorner.mY >= 0 && urCorner.mY < activeRows.size() &&
              urCorner.mX >= 0 && urCorner.mX < activeColumns.size() )
         {
            DimensionDescriptor llRowDim(activeRows[llCorner.mY]);
            DimensionDescriptor llColumnDim(activeColumns[llCorner.mX]);
            DimensionDescriptor urRowDim(activeRows[urCorner.mY]);
            DimensionDescriptor urColumnDim(activeColumns[urCorner.mX]);
            elevation1 = pTerrain->getPixelValue(llColumnDim, llRowDim, DimensionDescriptor(), COMPLEX_MAGNITUDE);
            elevation2 = pTerrain->getPixelValue(urColumnDim, urRowDim, DimensionDescriptor(), COMPLEX_MAGNITUDE);
            const Units* pElevationUnits = pDescriptor->getUnits();
            if (pElevationUnits != NULL)
            {
               double scale = pElevationUnits->getScaleFromStandard();
               elevation1 *= scale;
               elevation2 *= scale;
            }
         }
      }
   }

   if (unitsValid == true)
   {
      // Calculate bearing and distance
      distanceVal = algs.getPythagoreanOrVincentyDistance(startLlPoint.getLatitude().getValue(),
         startLlPoint.getLongitude().getValue(), endLlPoint.getLatitude().getValue(),
         endLlPoint.getLongitude().getValue(), elevation1, elevation2);
      azimuthVal = algs.getVincentyAzimuth(startLlPoint.getLatitude().getValue(),
         startLlPoint.getLongitude().getValue(), endLlPoint.getLatitude().getValue(),
         endLlPoint.getLongitude().getValue());
      azimuthVal = GeoConversions::convertRadToDeg(azimuthVal);

      // Set distance text
      if (mDrawnDistanceUnit == KILOMETER)
      {
         distanceUnit = "km";
         distanceVal = distanceVal/1000;
      }
      else if (mDrawnDistanceUnit == MILE)
      {
         distanceUnit = "mi";
         distanceVal = GeoConversions::convertMetersToMiles(distanceVal);
      }
      else if (mDrawnDistanceUnit == NAUTICAL_MILE)
      {
         distanceUnit = "Nm";
         distanceVal = GeoConversions::convertMetersToNm(distanceVal);
      }
      else if (mDrawnDistanceUnit == METER)
      {
         distanceUnit = "m";
      }
      else if (mDrawnDistanceUnit == YARD)
      {
         distanceUnit = "yd";
         distanceVal = GeoConversions::convertMetersToFeet(distanceVal)/3;
      }
      else if (mDrawnDistanceUnit == FOOT)
      {
         distanceUnit = "ft";
         distanceVal = GeoConversions::convertMetersToFeet(distanceVal);
      }

      // set location text
      switch (mDrawnGeocoord)
      {
      case GEOCOORD_LATLON:
         startLoc = startLlPoint.getText(mDrawnDmsFormat, mEndPointsPrecision);
         endLoc = endLlPoint.getText(mDrawnDmsFormat, mEndPointsPrecision);
         break;

      case GEOCOORD_UTM:
         startLoc = startUtmPoint.getText();
         endLoc = endUtmPoint.getText();
         break;

      case GEOCOORD_MGRS:
         startLoc = startMgrsPoint.getText();
         endLoc = endMgrsPoint.getText();
         break;

      default:
         startLoc = "(" + QString::number(llCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " +
            QString::number(llCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")";
         endLoc = "(" + QString::number(urCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " +
            QString::number(urCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")";
         break;
      }
   }
   else
   {
      startLoc = "(" + QString::number(llCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " +
         QString::number(llCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")";
      endLoc = "(" + QString::number(urCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " +
         QString::number(urCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")";
      azimuthVal = algs.getPythagoreanAzimuth(llCorner.mX, llCorner.mY, urCorner.mX, urCorner.mY);
      azimuthVal = GeoConversions::convertRadToDeg(azimuthVal);
      distanceVal = algs.getPythagoreanDistance(urCorner.mX, urCorner.mY, llCorner.mX, llCorner.mY);
      distanceUnit = "pix";
   }

   bearing = QString::number(azimuthVal, 'f', mBearingPrecision).toStdString();
   distance = QString::number(distanceVal, 'f', mDistancePrecision).toStdString();

   QString bearingText = QString::fromStdString(bearing) + " deg";
   QString distanceText = QString::fromStdString(distance) + " " + QString::fromStdString(distanceUnit);
   QString startLocText = QString::fromStdString(startLoc);
   QString endLocText = QString::fromStdString(endLoc);

   // Final strings
   if (bearingText != mBearingText)
   {
      mBearingText = bearingText;
      mBearingTextTexture.invalidate();
   }

   if (distanceText != mDistanceText)
   {
      mDistanceText = distanceText;
      mDistanceTextTexture.invalidate();
   }
   if (startLocText != mStartLocText)
   {
      mStartLocText = startLocText;
      mStartLocTextTexture.invalidate();
   }
   if (endLocText != mEndLocText)
   {
      mEndLocText = endLocText;
      mEndLocTextTexture.invalidate();
   }

   string rtnVal = "DISTANCE: " + distanceText.toStdString() + " : LOCATION: " + startLoc + " to " +
      endLoc + " at " + bearingText.toStdString();
   return rtnVal;
}
Beispiel #10
0
void GeocoordLinkFunctor::operator()(ViewImp *pDestView) const
{
   // lazily prepare the functor with the source information
   if (!const_cast<GeocoordLinkFunctor*>(this)->initialize())
   {
      return;
   }

   SpatialDataViewImp* pDstViewSpatial = dynamic_cast<SpatialDataViewImp*>(pDestView);
   if (pDstViewSpatial == NULL)
   {
      return;
   }

   LayerList* pDstLayerList = pDstViewSpatial->getLayerList();
   if (pDstLayerList == NULL)
   {
      return;
   }

   RasterElement* pDstGeo = pDstLayerList->getPrimaryRasterElement();
   if (pDstGeo == NULL || !pDstGeo->isGeoreferenced())
   {
      return;
   }

   Layer* pDstLayer = pDstLayerList->getLayer(RASTER, pDstGeo);
   if (pDstLayer == NULL)
   {
      return;
   }

   pDstViewSpatial->setPanLimit(NO_LIMIT);
   pDstViewSpatial->setMinimumZoom(0);
   pDstViewSpatial->setMaximumZoom(0);

   LocationType dstDataCenter = pDstGeo->convertGeocoordToPixel(mCenterGeocoord);
   LocationType dstWorldCenter;
   pDstLayer->translateDataToWorld(dstDataCenter.mX, dstDataCenter.mY, 
      dstWorldCenter.mX, dstWorldCenter.mY);
   LocationType dstScreenCenter(pDstViewSpatial->width() / 2.0, pDstViewSpatial->height() / 2.0);

   // Determined zoom and rotation are relative to the view's current state.
   // Reset the zoom and rotation to prevent cascading rounding errors
   pDstViewSpatial->resetOrientation();
   if (pDstViewSpatial->getDataOrigin() == UPPER_LEFT)
   {
      pDstViewSpatial->flipVertical();
   }
   pDstViewSpatial->panTo(dstWorldCenter);
   pDstViewSpatial->zoomTo(100);

   double localTightness = mTightness / findResolution(pDstGeo, pDstLayer, mCenterGeocoord);

   vector<LocationType> dstScreen(NUM_POINTS);
   dstScreen[0] = dstScreenCenter + LocationType(0, localTightness);
   dstScreen[1] = dstScreenCenter + LocationType(0, -localTightness);
   dstScreen[2] = dstScreenCenter + LocationType(localTightness, 0);
   dstScreen[3] = dstScreenCenter + LocationType(-localTightness, 0);

   // (Desired screen offset) / (world offset) yields zoom (magnitude) and rotation (phase).
   vector<complex<double> > transformVec(NUM_POINTS);
   for (unsigned int i = 0; i < NUM_POINTS; ++i)
   {
      // dst: screen -> world -> data -> geo
      LocationType dstWorld;
      pDstViewSpatial->translateScreenToWorld(dstScreen[i].mX, dstScreen[i].mY, dstWorld.mX, dstWorld.mY);
      LocationType dstData;
      pDstLayer->translateWorldToData(dstWorld.mX, dstWorld.mY, dstData.mX, dstData.mY);
      LocationType dstGeo = pDstGeo->convertPixelToGeocoord(dstData);

      // src: geo -> data -> screen
      LocationType srcData = mpSrcGeo->convertGeocoordToPixel(dstGeo);
      LocationType srcScreen;
      mpSrcLayer->translateDataToScreen(srcData.mX, srcData.mY, srcScreen.mX, srcScreen.mY);
      complex<double> srcScreenOffset = complex<double>(srcScreen.mX, srcScreen.mY) - mSrcScreenCenter;
      LocationType dstDataOffset = dstWorld - dstWorldCenter;
      transformVec[i] = srcScreenOffset / complex<double>(dstDataOffset.mX, dstDataOffset.mY);
   }

   // find average zoom and rotation for each axis
   complex<double> vertical = (transformVec[0] + transformVec[1]) / complex<double>(2);
   complex<double> horizontal = (transformVec[2] + transformVec[3]) / complex<double>(2);

   // find the aspects from the relative zoom, and correct the
   // vector to get a better rotation and zoom
   double aspect = abs(horizontal) / abs(vertical);
   if (aspect > 1)
   {
      horizontal /= aspect;
   }
   else
   {
      vertical *= aspect;
   }

   complex<double> total = (horizontal + vertical) / complex<double>(2);
   complex<double> totalFlipped = (horizontal - vertical) / complex<double>(2);
   if (abs(totalFlipped) > abs(total))
   {
      total = conj(totalFlipped);
      pDstViewSpatial->flipVertical();
   }

   double zoom = 100 * abs(total);
   double rot = 360 - (arg(total) * 180/PI);

   pDstViewSpatial->rotateTo(fmod(rot, 360));
   pDstViewSpatial->zoomTo(zoom);
   pDstViewSpatial->setPixelAspect(aspect);

}
Beispiel #11
0
bool SaveLayerFromDataSet::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   StepResource pStep("Execute Wizard Item", "app", "A1205468-4950-4c8f-9821-60063CC4B31B");
   pStep->addProperty("Item", getName());
   mpStep = pStep.get();

   if (!extractInputArgs(pInArgList))
   {
      reportError("Unable to extract input arguments.", "9A496CD9-5068-4b12-A4C4-AB561CD49523");
      return false;
   }

   // Check for valid input values
   string filename;
   if (mpOutputFilename != NULL)
   {
      filename = mpOutputFilename->getFullPathAndName();
   }

   if (filename.empty())
   {
      reportError(" The filename input value is invalid!", "DA76EB21-7E5A-45aa-A60D-0B99C72585EC");
      return false;
   }

   if (mpStep != NULL)
   {
      mpStep->addProperty("filename", filename);
   }

   if (mpRasterElement == NULL)
   {
      reportError("The data set input value is invalid!", "E11D0EC5-97E6-41a5-8F1F-937290CA102F");
      return false;
   }

   if (mpStep != NULL)
   {
      mpStep->addProperty("dataSet", mpRasterElement->getName());
   }

   if (mLayerName.empty())
   {
      reportError("The layer name input value is invalid!", "0DF331B8-05FF-4178-82D3-9A9CF2851DCF");
      return false;
   }

   if (mpStep != NULL)
   {
      mpStep->addProperty("layerName", mLayerName);
   }

   // Get the view
   SpatialDataView* pView = NULL;

   vector<Window*> windows;
   Service<DesktopServices> pDesktop;
   if (pDesktop.get() != NULL)
   {
      pDesktop->getWindows(SPATIAL_DATA_WINDOW, windows);
   }

   for (vector<Window*>::iterator iter = windows.begin(); iter != windows.end(); ++iter)
   {
      SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(*iter);
      if (pWindow != NULL)
      {
         SpatialDataView* pCurrentView = pWindow->getSpatialDataView();
         if (pCurrentView != NULL)
         {
            LayerList* pLayerList = pCurrentView->getLayerList();
            if (pLayerList != NULL)
            {
               RasterElement* pRasterElement = pLayerList->getPrimaryRasterElement();
               if (pRasterElement == mpRasterElement)
               {
                  pView = pCurrentView;
                  break;
               }
            }
         }
      }
   }

   if (pView == NULL)
   {
      reportError("Could not get the view!", "830E3C55-561A-4c49-8269-06E1E04B1BFA");
      return false;
   }

   // Get the spectral element
   LayerType eType = getLayerType();
   string modelType = getModelType(eType);

   DataElement* pElement = NULL;
   Service<ModelServices> pModel;
   if ((pModel.get() != NULL) && !modelType.empty())
   {
      pElement = pModel->getElement(mLayerName, modelType, mpRasterElement);
   }

   // Save the layer
   bool bSaved = false;

   LayerList* pLayerList = pView->getLayerList();
   if (pLayerList != NULL)
   {
      Layer* pLayer = pLayerList->getLayer(eType, pElement, mLayerName.c_str());
      if (pLayer == NULL)
      {
         reportError("Could not get the layer to save!", "02F03D56-7CA8-4052-894D-BFDDFC3A814F");
         return false;
      }

      FactoryResource<FileDescriptor> pFileDescriptor;
      VERIFY(pFileDescriptor.get() != NULL);
      pFileDescriptor->setFilename(filename);
      ExporterResource exporter("Layer Exporter", pLayer, pFileDescriptor.get());
      VERIFY(exporter->getPlugIn() != NULL);
      bSaved = exporter->execute();
   }

   if (!bSaved)
   {
      reportError("Could not save the layer to the file: " + filename, "CAFF2CD5-E6CB-4e90-80E7-87E094F2CB1C");
      return false;
   }

   reportComplete();
   return true;
}
bool SampleGeoref::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
    // Do any kind of setup we need before converting coordinates.
    // In this case, get our X and Y factors.

    StepResource pStep("Run Sample Georef", "app", "CFCB8AA9-D504-42e9-86F0-547DF9B4798A");
    Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg());

    FAIL_IF(!isBatch(), "Interactive mode is not supported.", return false);

    // Default values
    bool animated = false;

    // get factors from pInArgList
    pInArgList->getPlugInArgValue("XSize", mXSize);
    pInArgList->getPlugInArgValue("YSize", mYSize);
    pInArgList->getPlugInArgValue("Extrapolate", mExtrapolate);
    pInArgList->getPlugInArgValue("Animated", animated);
    pInArgList->getPlugInArgValue("Rotate", mRotate);

    View* pView = pInArgList->getPlugInArgValue<View>(Executable::ViewArg());
    mpRaster = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg());
    FAIL_IF(mpRaster == NULL, "Could not find raster element", return false);

    if (mpGui != NULL)
    {
        mXSize = mpGui->getXSize();
        mYSize = mpGui->getYSize();
        animated = mpGui->getAnimated();
        mRotate = mpGui->getRotate();
        mExtrapolate = mpGui->getExtrapolate();
    }

    if (animated)
    {
        SpatialDataView* pSpatialView = dynamic_cast<SpatialDataView*>(pView);
        FAIL_IF(pSpatialView == NULL, "Could not find spatial data view.", return false);

        LayerList* pLayerList = pSpatialView->getLayerList();
        FAIL_IF(pLayerList == NULL, "Could not find layer list.", return false);

        RasterLayer* pLayer = dynamic_cast<RasterLayer*>(pLayerList->getLayer(RASTER, mpRaster));
        FAIL_IF(pLayer == NULL, "Could not find raster layer", return false);

        Animation* pAnim = pLayer->getAnimation();
        FAIL_IF(pAnim == NULL, "Could not find animation", return false);

        const std::vector<AnimationFrame>& frames = pAnim->getFrames();
        FAIL_IF(frames.empty(), "No frames in animation.", return false);

        mpAnimation.reset(pAnim);
        mFrames = frames.size();
        mCurrentFrame = 0;
    }

    RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor());
    FAIL_IF(pDescriptor == NULL, "Could not get data descriptor.", return false);

    unsigned int rows = pDescriptor->getRowCount();
    unsigned int cols = pDescriptor->getColumnCount();
    unsigned int bands = pDescriptor->getBandCount();

    mXScale = static_cast<double>(mXSize) / rows;
    mYScale = static_cast<double>(mYSize) / cols;

    mpRaster->setGeoreferencePlugin(this);

    mpGui = NULL; // Pointer not guaranteed to be valid after execute() is called
    return true;
}
Beispiel #13
0
void AlgorithmPattern::displayPseudocolorResults(RasterElement* pRasterElement, std::vector<std::string>& sigNames,
                                                 Opticks::PixelOffset offset)
{
   REQUIRE(pRasterElement != NULL);

   SpatialDataView* pView = NULL;

   vector<Window*> windows;
   mpDesktopServices->getWindows(SPATIAL_DATA_WINDOW, windows);
   for (unsigned int j = 0; j < windows.size() && pView == NULL; j++)
   {
      SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(windows[j]);
      if (pWindow != NULL)
      {
         SpatialDataView* pCurrentView = pWindow->getSpatialDataView();
         if (pCurrentView != NULL)
         {
            LayerList* pLList = pCurrentView->getLayerList();
            REQUIRE(pLList != NULL);
            vector<Layer*> layers;
            pLList->getLayers(RASTER, layers);
            for (vector<Layer*>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
            {
               if (*layer != NULL && static_cast<RasterElement*>((*layer)->getDataElement()) == getRasterElement())
               {
                  pView = pCurrentView;
                  break;
               }
            }
         }
      }
   }

   REQUIRE(pView != NULL);

   PseudocolorLayer* pLayer = NULL;

   // Get or create a valid pseudocolor layer
   LayerList* pLayerList = pView->getLayerList();
   if (pLayerList != NULL)
   {
      pLayer = static_cast<PseudocolorLayer*>(pLayerList->getLayer(PSEUDOCOLOR, pRasterElement));
      if (pLayer == NULL)
      {
         pLayer = static_cast<PseudocolorLayer*>(pView->createLayer(PSEUDOCOLOR, pRasterElement));
      }

      // Remove existing layers of other types
      if (pLayer != NULL)
      {
         Layer* pThresholdLayer = pLayerList->getLayer(THRESHOLD, pRasterElement);
         if (pThresholdLayer != NULL)
         {
            pView->deleteLayer(pThresholdLayer);
         }

         Layer* pRasterLayer = pLayerList->getLayer(RASTER, pRasterElement);
         if (pRasterLayer != NULL)
         {
            pView->deleteLayer(pRasterLayer);
         }
      }
   }

   INVARIANT(pLayer != NULL);

   UndoLock lock(pView);

   int iSignatureCount = sigNames.size();

   vector<ColorType> layerColors;
   vector<ColorType> excludeColors;
   excludeColors.push_back(ColorType(0, 0, 0));
   excludeColors.push_back(ColorType(255, 255, 255));
   // 1 for each sig + no sigs + multiple sigs
   ColorType::getUniqueColors(iSignatureCount + 2, layerColors, excludeColors);

   pLayer->clear();

   for (int i = 0; i < iSignatureCount; i++)
   {
      pLayer->addInitializedClass(sigNames[i], i + 1, layerColors[i], true);
   }

   pLayer->addInitializedClass(std::string("Indeterminate"), -1, layerColors[iSignatureCount], true);
   pLayer->addInitializedClass(std::string("No match"), 0, layerColors[iSignatureCount + 1], false);
   pLayer->setXOffset(offset.mX);
   pLayer->setYOffset(offset.mY);
}
Beispiel #14
0
void AlgorithmPattern::displayThresholdResults(RasterElement* pRasterElement, ColorType color, PassArea passArea,
                                               double firstThreshold, double secondThreshold,
                                               Opticks::PixelOffset offset)
{
   REQUIRE(pRasterElement != NULL);

   SpatialDataView* pView = NULL;

   vector<Window*> windows;
   mpDesktopServices->getWindows(SPATIAL_DATA_WINDOW, windows);
   for (unsigned int i = 0; i < windows.size() && pView == NULL; i++)
   {
      SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(windows[i]);
      if (pWindow != NULL)
      {
         SpatialDataView* pCurrentView = pWindow->getSpatialDataView();
         if (pCurrentView != NULL)
         {
            LayerList* pLList = pCurrentView->getLayerList();
            REQUIRE(pLList != NULL);
            vector<Layer*> layers;
            pLList->getLayers(RASTER, layers);
            for (vector<Layer*>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
            {
               if (*layer != NULL && static_cast<RasterElement*>((*layer)->getDataElement()) == getRasterElement())
               {
                  pView = pCurrentView;
                  break;
               }
            }
         }
      }
   }

   REQUIRE(pView != NULL);

   ThresholdLayer* pLayer = NULL;

   // Get or create a valid threshold layer
   LayerList* pLayerList = pView->getLayerList();
   if (pLayerList != NULL)
   {
      pLayer = static_cast<ThresholdLayer*>(pLayerList->getLayer(THRESHOLD, pRasterElement));
      if (pLayer == NULL)
      {
         pLayer = static_cast<ThresholdLayer*>(pView->createLayer(THRESHOLD, pRasterElement));
      }

      // Remove existing layers of other types
      if (pLayer != NULL)
      {
         Layer* pRasterLayer = pLayerList->getLayer(RASTER, pRasterElement);
         if (pRasterLayer != NULL)
         {
            pView->deleteLayer(pRasterLayer);
         }

         Layer* pPseudocolorLayer = pLayerList->getLayer(PSEUDOCOLOR, pRasterElement);
         if (pPseudocolorLayer != NULL)
         {
            pView->deleteLayer(pPseudocolorLayer);
         }
      }
   }

   INVARIANT(pLayer != NULL);

   UndoLock lock(pView);

   if (color.isValid())
   {
      pLayer->setColor(color);
   }

   pLayer->setRegionUnits(RAW_VALUE);
   pLayer->setPassArea(passArea);
   pLayer->setFirstThreshold(firstThreshold);
   pLayer->setSecondThreshold(secondThreshold);
   pLayer->setXOffset(offset.mX);
   pLayer->setYOffset(offset.mY);
}
Beispiel #15
0
 Layer* getLayer(const char* pName, const char* pType)
 {
    Layer* pLayer = NULL;
    const std::string name(pName == NULL ? std::string() : pName);
    const std::string type(pType == NULL ? std::string() : pType);
    SessionItem* pSessionItem = Service<SessionManager>()->getSessionItem(name);
    if (pSessionItem != NULL)
    {
       pLayer = dynamic_cast<Layer*>(pSessionItem);
       if (pLayer == NULL || (!type.empty() && !pLayer->isKindOf(type)))
       {
          setLastError(SIMPLE_WRONG_TYPE);
          return NULL;
       }
    }
    else
    {
       std::vector<std::string> id = splitIdentifier(name);
       SpatialDataView* pView = static_cast<SpatialDataView*>(getView(id.size() == 0 ? NULL : id.front().c_str(),
          TypeConverter::toString<SpatialDataView>()));
       LayerList* pLayerList = (pView == NULL) ? NULL : pView->getLayerList();
       if (pLayerList == NULL)
       {
          setLastError(SIMPLE_NOT_FOUND);
          return NULL;
       }
       if (id.size() < 2)
       {
          if (!type.empty() && type == TypeConverter::toString<RasterLayer>())
          {
             pLayer = pLayerList->getLayer(RASTER, pLayerList->getPrimaryRasterElement());
          }
          else
          {
             pLayer = pView->getActiveLayer();
             if (pLayer != NULL && !type.empty() && !pLayer->isKindOf(type))
             {
                pLayer = NULL;
             }
             if (pLayer == NULL)
             {
                if (type.empty())
                {
                   pLayer = pView->getTopMostLayer();
                }
                else
                {
                   pLayer = pView->getTopMostLayer(StringUtilities::fromDisplayString<LayerType>(type));
                }
             }
          }
       }
       if (pLayer == NULL)
       {
          std::vector<Layer*> layers;
          pLayerList->getLayers(layers);
          for (std::vector<Layer*>::reverse_iterator layer = layers.rbegin();
             layer != layers.rend();
             ++layer)
          {
             if ((type.empty() || (*layer)->isKindOf(type)) && 
                (id.empty() || (*layer)->getName() == id.back() || (*layer)->getDisplayName() == id.back()))
             {
                pLayer = *layer;
                break;
             }
          }
       }
       if (pLayer == NULL)
       {
          setLastError(SIMPLE_NOT_FOUND);
          return NULL;
       }
    }
    setLastError(SIMPLE_NO_ERROR);
    return pLayer;
 }