public boolean isEnabled() {
   boolean isEnabled = false;
   MapEditorPlugIn mapEditor = null;
   if ((mapEditor = getPlugInContext().getMapEditor()) != null) {
     MapContext map = (MapContext) mapEditor.getElement().getObject();
     ILayer activeLayer = map.getActiveLayer();
     if (activeLayer != null && activeLayer.getSelection().length > 0) isEnabled = true;
   }
   btn.setEnabled(isEnabled);
   return isEnabled;
 }
  @Override
  public boolean isEnabled(MapContext vc, ToolManager tm) {
    if (vc.getSelectedLayers().length == 1) {
      try {
        if (vc.getSelectedLayers()[0].isVectorial()) {
          return vc.getSelectedLayers()[0].isVisible();
        }
      } catch (DriverException e) {
        return false;
      }
    }

    return false;
  }
 public boolean execute(PlugInContext context) throws Exception {
   IEditor editor = getPlugInContext().getActiveEditor();
   MapContext map = (MapContext) editor.getElement().getObject();
   ILayer activeLayer = map.getActiveLayer();
   int[] sel = activeLayer.getSelection().clone();
   Arrays.sort(sel);
   DataSource dataSource = activeLayer.getDataSource();
   try {
     dataSource.setDispatchingMode(DataSource.STORE);
     for (int i = sel.length - 1; i >= 0; i--) {
       dataSource.deleteRow(sel[i]);
     }
     dataSource.setDispatchingMode(DataSource.DISPATCH);
   } catch (DriverException e) {
     ErrorMessages.error(ErrorMessages.CannotDeleteSelectedRow, e);
   }
   return true;
 }
示例#4
0
  @Override
  protected void polygonDone(com.vividsolutions.jts.geom.Polygon pol, MapContext mc, ToolManager tm)
      throws TransitionException {
    Geometry g = pol;
    if (ToolUtilities.geometryTypeIs(mc, GeometryConstraint.MULTI_POLYGON)) {
      g = ToolManager.toolsGeometryFactory.createMultiPolygon(new Polygon[] {pol});
    }

    SpatialDataSourceDecorator sds = mc.getActiveLayer().getDataSource();
    try {
      Value[] row = new Value[sds.getMetadata().getFieldCount()];
      row[sds.getSpatialFieldIndex()] = ValueFactory.createValue(g);
      row = ToolUtilities.populateNotNullFields(sds, row);
      sds.insertFilledRow(row);
    } catch (DriverException e) {
      throw new TransitionException("Cannot insert polygon", e);
    }
  }
  @Override
  protected void rectangleDone(
      Rectangle2D rect, boolean smallerThanTolerance, MapContext vc, ToolManager tm)
      throws TransitionException {
    ILayer layer = vc.getSelectedLayers()[0];
    DataSource sds = layer.getDataSource();
    String sql = null;
    try {
      GeometryFactory gf = ToolManager.toolsGeometryFactory;
      double minx = rect.getMinX();
      double miny = rect.getMinY();
      double maxx = rect.getMaxX();
      double maxy = rect.getMaxY();

      Coordinate lowerLeft = new Coordinate(minx, miny);
      Coordinate upperRight = new Coordinate(maxx, maxy);
      LinearRing envelopeShell =
          gf.createLinearRing(
              new Coordinate[] {
                lowerLeft,
                new Coordinate(minx, maxy),
                upperRight,
                new Coordinate(maxx, miny),
                lowerLeft,
              });
      Geometry geomEnvelope = gf.createPolygon(envelopeShell, new LinearRing[0]);
      WKTWriter writer = new WKTWriter();
      sql =
          "select * from "
              + layer.getName()
              + " where ST_intersects("
              + sds.getMetadata().getFieldName(sds.getSpatialFieldIndex())
              + ", ST_geomfromtext('"
              + writer.write(geomEnvelope)
              + "'));";
      BackgroundManager bm = (BackgroundManager) Services.getService(BackgroundManager.class);
      bm.backgroundOperation(
          new DefaultJobId("org.orbisgis.jobs.InfoTool"), new PopulateViewJob(sql));
    } catch (DriverException e) {
      throw new TransitionException(e);
    } catch (DriverLoadException e) {
      throw new RuntimeException(e);
    }
  }
  public void execute(MapContext mapContext, ILayer layer) {
    try {

      final String geoRasterResult = evaluateResult(layer, mapContext);

      if (null != geoRasterResult) {
        // save the computed GeoRaster in a tempFile
        final DataSourceFactory dsf =
            ((DataManager) Services.getService(DataManager.class)).getDSF();

        DataSource dsResult = dsf.getDataSourceFromSQL(geoRasterResult);

        // populate the GeoView TOC with a new RasterLayer
        DataManager dataManager = (DataManager) Services.getService(DataManager.class);
        final ILayer newLayer = dataManager.createLayer(dsResult);
        mapContext.getLayerModel().insertLayer(newLayer, 0);
      }
    } catch (IOException e) {
      Services.getErrorManager().error("Cannot compute " + layer.getName(), e);
    } catch (LayerException e) {
      Services.getErrorManager()
          .error("Cannot insert resulting layer based on " + layer.getName(), e);
    } catch (DriverException e) {
      Services.getErrorManager().error("Cannot read the raster from the layer ", e);
    } catch (DriverLoadException e) {
      Services.getErrorManager().error("Cannot create the resulting layer of raster type ", e);
    } catch (OperationException e) {
      Services.getErrorManager().error("Error during the raster operation", e);
    } catch (DataSourceCreationException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      e.printStackTrace();
    } catch (SemanticException e) {
      e.printStackTrace();
    }
  }