/**
   * Returns a mapgraphics layer by its class.
   *
   * @param theClass the class of the mapgraphics.
   * @return the layer or null, if none was found (not visible or not existing).
   */
  public static ILayer getMapgraphicLayerByClass(Class<?> theClass) {

    try {
      List<IResolve> mapgraphics =
          CatalogPlugin.getDefault().getLocalCatalog().find(MapGraphicService.SERVICE_URL, null);
      List<IResolve> members = mapgraphics.get(0).members(null);
      for (IResolve resolve : members) {
        if (resolve.canResolve(theClass)) {
          IGeoResource resolve2 = resolve.resolve(IGeoResource.class, null);
          String resName = resolve2.getInfo(new NullProgressMonitor()).getName();

          List<ILayer> mapLayers = ApplicationGIS.getActiveMap().getMapLayers();
          for (ILayer layer : mapLayers) {
            if (layer.getName().trim().equals(resName.trim())) {
              return layer;
            }
          }
        }
      }
    } catch (IOException e) {
      JGrassPlugin.log(
          "JGrassPlugin problem: eu.hydrologis.udig.catalog.utils#JGrassCatalogUtilities#getMapgraphicLayerByClass",
          e); //$NON-NLS-1$
      e.printStackTrace();
      return null;
    }
    return null;
  }
 /**
  * Override error.
  *
  * <p>Description ...
  *
  * @see org.geotools.validation.ValidationResults#error(org.geotools.feature.SimpleFeature,
  *     java.lang.String)
  * @param feature
  * @param message
  */
 public void error(SimpleFeature feature, String message) {
   // add the error to our list of failed features + failure messages
   if (message == null) message = ""; // $NON-NLS-1$
   failedFeatures.add(feature);
   failureMessages.add(feature.getID() + ": " + message); // $NON-NLS-1$
   // find the layer of the current feature
   IMap activeMap = ApplicationGIS.getActiveMap();
   List<ILayer> layers = new ArrayList<ILayer>();
   if (activeMap != ApplicationGIS.NO_MAP) {
     layers.addAll(activeMap.getMapLayers());
   }
   Layer layer = null;
   for (Iterator i = layers.listIterator(); i.hasNext(); ) {
     Layer thisLayer = (Layer) i.next();
     if (feature.getName().getLocalPart().equals(thisLayer.getName())) {
       layer = thisLayer;
       break;
     }
   }
   // add the error to the issues list
   FeatureIssue issue =
       new FeatureIssue(
           Priority.HIGH,
           message,
           layer,
           feature,
           Messages.GenericValidationResults_validationError);
   issues.add(issue);
 }
Ejemplo n.º 3
0
  /**
   * Must go places!
   *
   * @param selection
   */
  public void showLocation(Object selection) {
    // selection should be an Feture (of some sort)
    SimpleFeature feature = (SimpleFeature) selection;
    Geometry geom = (Geometry) feature.getDefaultGeometry();
    Point point = geom.getCentroid();

    IMap imap = ApplicationGIS.getActiveMap();
    if (imap == ApplicationGIS.NO_MAP) return;

    CoordinateReferenceSystem world = imap.getViewportModel().getCRS();
    CoordinateReferenceSystem wsg84 = DefaultGeographicCRS.WGS84;

    double buffer = 0.01; // how much of the wgs84 world to see
    Envelope view = point.buffer(buffer).getEnvelopeInternal();

    MathTransform transform;
    try {
      transform = CRS.findMathTransform(wsg84, world, true); // relaxed
    } catch (FactoryException e) {
      return; // no go
    }
    Envelope areaOfInterest;
    try {
      areaOfInterest = JTS.transform(view, null, transform, 10);
    } catch (TransformException e) {
      return; // no go
    }

    // NavigationCommandFactory navigate = NavigationCommandFactory.getInstance();

    NavCommand show = new SetViewportBBoxCommand(areaOfInterest, world);
    imap.sendCommandASync(show);
  }
  public boolean isTrue(Object object, String value) {
    IMap map = ApplicationGIS.getActiveMap();
    if (map == ApplicationGIS.NO_MAP || map.getMapLayers().size() == 0) return false;
    PrimitiveShape shape = (PrimitiveShape) map.getBlackboard().get(EditToolHandler.CURRENT_SHAPE);
    if (shape == null) return false;

    return shape.getEditGeom() != null
        && shape.getEditGeom().getShapeType().toString().equalsIgnoreCase(value.trim());
  }
Ejemplo n.º 5
0
 public void refreshMap() {
   IMap activeMap = ApplicationGIS.getActiveMap();
   RenderedImage image = activeMap.getRenderManager().getImage();
   if (image == null) {
     return;
   }
   List<ILayer> mapLayers = activeMap.getMapLayers();
   for (ILayer iLayer : mapLayers) {
     iLayer.refresh(null);
   }
 }
  private void checkStyle() {
    IMap activeMap = ApplicationGIS.getActiveMap();

    IBlackboard styleBlackboard = activeMap.getBlackboard();
    if (style == null) {
      style = (RasterLegendStyle) styleBlackboard.get(RasterLegendStyleContent.ID);
    }
    if (style == null) {
      style = RasterLegendStyleContent.createDefault();
      styleBlackboard.put(RasterLegendStyleContent.ID, style);
      // styleBlackboard.setSelected(new String[]{RasterLegendStyleContent.ID});
    }
  }
Ejemplo n.º 7
0
  public void addPages() {
    super.addPages();

    if (ApplicationGIS.getActiveMap() == ApplicationGIS.NO_MAP) {
      return; // no pages no go!
    }
    page =
        new MapExportPage(
            Messages.ContextExportWizard_page_name,
            Messages.ContextExportWizard_page_title,
            ContextPlugin.getImageDescriptor(
                "icons/wizban/import_owscontext_wiz_gif")); //$NON-NLS-1$
    addPage(page);
  }
Ejemplo n.º 8
0
  public static void load(String mapname) {
    if (JGrassPlugin.getDefault() != null) {
      JGrassMapGeoResource addedMap =
          JGrassCatalogUtilities.addMapToCatalog(
              p_locationPath, p_mapsetName, mapname, JGrassConstants.GRASSBINARYRASTERMAP);
      if (addedMap == null)
        p_err.println("An error occurred while trying to add the map to the catalog.");

      IMap activeMap = ApplicationGIS.getActiveMap();
      ApplicationGIS.addLayersToMap(
          activeMap,
          Collections.singletonList((IGeoResource) addedMap),
          activeMap.getMapLayers().size());
    }
  }
  private void updateBlackboard() {
    IMap activeMap = ApplicationGIS.getActiveMap();
    IBlackboard styleBlackboard = activeMap.getBlackboard();
    style = (RasterLegendStyle) styleBlackboard.get(RasterLegendStyleContent.ID);

    if (style == null) {
      style = RasterLegendStyleContent.createDefault();
      styleBlackboard.put(RasterLegendStyleContent.ID, style);
      // styleBlackboard.setSelected(new String[]{RasterLegendStyleContent.ID});
    }

    RGB bg = backgroundColour.getColorValue();
    try {
      int bAlpha = Integer.parseInt(backgroundAlphaText.getText());
      style.backgroundColor = new Color(bg.red, bg.green, bg.blue, bAlpha);
    } catch (Exception e) {
      style.backgroundColor = new Color(bg.red, bg.green, bg.blue);
    }
    bg = foregroundColor.getColorValue();
    try {
      int fAlpha = Integer.parseInt(forgroundAlphaText.getText());
      style.foregroundColor = new Color(bg.red, bg.green, bg.blue, fAlpha);
    } catch (Exception e) {
      style.foregroundColor = new Color(bg.red, bg.green, bg.blue);
    }
    bg = fontColour.getColorValue();
    style.fontColor = new Color(bg.red, bg.green, bg.blue);

    style.titleString = titleText.getText();
    style.xPos = Integer.parseInt(xposText.getText());
    style.yPos = Integer.parseInt(yposText.getText());
    style.legendHeight = Integer.parseInt(legHeightText.getText());
    style.legendWidth = Integer.parseInt(legWidthText.getText());
    style.boxWidth = Integer.parseInt(boxWidthText.getText());
    style.isRoundedRectangle = isroundedButton.getSelection();

    styleBlackboard.put(RasterLegendStyleContent.ID, style);
  }
 /**
  * Override warning.
  *
  * <p>Description ...
  *
  * @see org.geotools.validation.ValidationResults#warning(org.geotools.feature.SimpleFeature,
  *     java.lang.String)
  * @param feature
  * @param message
  */
 public void warning(SimpleFeature feature, String message) {
   // add the warning to our list of warned features + warning messages
   warningFeatures.add(feature);
   warningMessages.add(feature.getID() + ": " + message); // $NON-NLS-1$
   // find the layer of the current feature
   List<ILayer> layers = ApplicationGIS.getActiveMap().getMapLayers();
   ILayer layer = null;
   for (Iterator i = layers.listIterator(); i.hasNext(); ) {
     layer = (ILayer) i.next();
     if (feature.getName().getLocalPart().equals(layer.getName())) {
       break;
     }
   }
   // add the error to the issues list
   FeatureIssue issue =
       new FeatureIssue(
           Priority.WARNING,
           message,
           layer,
           feature,
           Messages.GenericValidationResults_validationWarning);
   issues.add(issue);
 }
Ejemplo n.º 11
0
  public static List<SimpleFeature> fromFeatureLayer(String mapName) throws IOException {

    ILayer selectedLayer = ApplicationGIS.getActiveMap().getEditManager().getSelectedLayer();
    FeatureSource<SimpleFeatureType, SimpleFeature> featureSource =
        selectedLayer.getResource(FeatureSource.class, new NullProgressMonitor());
    FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = null;
    Filter filter = selectedLayer.getFilter();
    if (filter.equals(Filter.EXCLUDE)) {
      featureCollection = featureSource.getFeatures();
    } else {
      featureCollection = featureSource.getFeatures(filter);
    }

    List<SimpleFeature> featuresList = new ArrayList<SimpleFeature>();
    FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
    while (featureIterator.hasNext()) {
      SimpleFeature feature = featureIterator.next();
      featuresList.add(feature);
    }
    featureCollection.close(featureIterator);

    return featuresList;
  }