/**
  * Create new instance
  *
  * @param blackboard blackboard to add selected features
  * @param layer layer used to obtain features. Must have a FeatureStore resource.
  * @param filter filter used to select features
  */
 public SelectFeaturesInFilterCommand(EditBlackboard blackboard, ILayer layer, Filter filter) {
   if (!layer.hasResource(FeatureStore.class))
     throw new IllegalArgumentException("Layer must have a FeatureStore resource"); // $NON-NLS-1$
   this.filter = filter;
   this.layer = layer;
   this.bb = blackboard;
 }
  /**
   * Creates A geometry filter for the given layer.
   *
   * @param boundingBox in the same crs as the viewport model.
   * @return a Geometry filter in the correct CRS or null if an exception occurs.
   */
  public Filter createBBoxFilter(
      ReferencedEnvelope boundingBox, ILayer layer, Class<? extends Filter> filterType) {
    FilterFactory2 factory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    if (!layer.hasResource(FeatureSource.class)) return Filter.EXCLUDE;
    try {

      SimpleFeatureType schema = layer.getSchema();
      Name geom = getGeometryAttDescriptor(schema).getName();

      Filter bboxFilter = factory.bbox(factory.property(geom), boundingBox);

      return bboxFilter;
    } catch (Exception e) {
      ProjectPlugin.getPlugin().log(e);
      return Filter.EXCLUDE;
    }
  }
Ejemplo n.º 3
0
  public boolean canAddLayer(ILayer layer) {

    if (!layer.hasResource(Layer.class)) return false;

    try {
      if (!layer
          .findGeoResource(Layer.class)
          .parent(ProgressManager.instance().get())
          .equals(getRenderContext().getGeoResource().parent(ProgressManager.instance().get())))
        return false;
    } catch (IOException e2) {
      return false;
    }

    double opacity = Double.NaN;

    ICompositeRenderContext context1 = (ICompositeRenderContext) context;

    IRenderContext[] contexts =
        context1.getContexts().toArray(new IRenderContext[context1.getContexts().size()]);
    Arrays.sort(contexts);
    List<Layer> owsLayers = new ArrayList<Layer>();
    IService currentService;
    try {
      owsLayers.add(layer.getResource(Layer.class, new NullProgressMonitor()));
      currentService = layer.getResource(IService.class, null);
    } catch (IOException e1) {
      WMSPlugin.log("", e1); // $NON-NLS-1$
      return false;
    }
    for (IRenderContext renderContext : contexts) {
      ILayer previousLayer = renderContext.getLayer();

      try {
        owsLayers.add(previousLayer.getResource(Layer.class, new NullProgressMonitor()));
        IService previousService = previousLayer.getResource(IService.class, null);
        if (currentService != previousService) {
          return false;
        }
      } catch (IOException e) {
        WMSPlugin.log("Error while retrieving service.", e); // $NON-NLS-1$
        return false;
      }

      if (BasicWMSRenderer2.findRequestCRS(owsLayers, context.getCRS(), context.getMap()) == null)
        return false;

      Style style = (Style) previousLayer.getStyleBlackboard().get(SLDContent.ID);
      if (style != null) {
        opacity = SLDs.rasterOpacity(SLDs.rasterSymbolizer(style));
      }
    }

    Style style = (Style) layer.getStyleBlackboard().get(SLDContent.ID);
    if (style == null && Double.isNaN(opacity)) {
      return true;
    }

    double result = SLDs.rasterOpacity(SLDs.rasterSymbolizer(style));

    if (result == opacity) {
      return true;
    }
    return false;
  }