Ejemplo n.º 1
0
 public void createArc() {
   List<Point> points = drawingPane.getDrawObjectsAsGeoPoints();
   ApplicationContainer<?> appCont = digitizerModule.getApplicationContainer();
   if (points.size() >= 3) {
     try {
       Curve curve =
           GeometryUtils.calcCircleCoordinates(
               points.get(0).getPosition(),
               getRadius(),
               getNoOfVertices(),
               points.get(1).getPosition(),
               points.get(2).getPosition(),
               points.get(1).getCoordinateSystem());
       MapModel mapModel = appCont.getMapModel(null);
       Layer layer = mapModel.getLayersSelectedForAction(MapModel.SELECTION_EDITING).get(0);
       FeatureAdapter featureAdapter = (FeatureAdapter) layer.getDataAccess().get(0);
       FeatureType ft = featureAdapter.getSchema();
       Feature feat = featureAdapter.getDefaultFeature(ft.getName());
       feat = feat.cloneDeep();
       QualifiedName geomProperty = ft.getGeometryProperties()[0].getName();
       feat.getProperties(geomProperty)[0].setValue(curve);
       Command cmd = new InsertFeatureCommand(featureAdapter, feat);
       appCont.getCommandProcessor().executeSychronously(cmd, true);
     } catch (Exception ex) {
       LOG.logError(ex);
       DialogFactory.openErrorDialog(
           appCont.getViewPlatform(),
           DrawArcDialog.this,
           Messages.getMessage(getLocale(), "$MD11628"),
           Messages.getMessage(getLocale(), "$MD11629"),
           ex);
     }
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see org.deegree.igeo.modules.remotecontrol.RequestHandler#perform(java.util.Map,
   * org.deegree.igeo.ApplicationContainer)
   */
  public String perform(Map<String, String> paramater, ApplicationContainer<?> appContainer)
      throws ModuleException {
    String tmp = paramater.get("OBJECTIDS");
    if (tmp == null || tmp.length() == 0) {
      throw new ModuleException(Messages.get("$DG10091"));
    }
    List<String> objIds = StringTools.toList(tmp, ",;", true);
    tmp = paramater.get("LAYER");
    if (tmp == null) {
      throw new ModuleException(Messages.get("$DG10092"));
    }

    MapModel mapModel = appContainer.getMapModel(null);
    LocalMapModelVisitor mv = new LocalMapModelVisitor(tmp);
    try {
      mapModel.walkLayerTree(mv);
    } catch (Exception e) {
      LOG.logError(e.getMessage(), e);
      throw new ModuleException(e.getMessage());
    }

    Layer layer = mv.getResult();
    if (layer == null) {
      throw new ModuleException(Messages.get("$DG10093", tmp));
    }
    layer.setVisible(true);

    // first select features in layer
    List<Identifier> ids = new ArrayList<Identifier>();
    for (String id : objIds) {
      ids.add(new Identifier(id));
    }
    SelectFeatureCommand cmd = new SelectFeatureCommand(layer, ids, false);
    try {
      appContainer.getCommandProcessor().executeSychronously(cmd, true);
    } catch (Exception e) {
      LOG.logError(e.getMessage(), e);
      throw new ModuleException(e.getMessage());
    }

    // get selected features as FeatureCollection and so their common bounding box
    FeatureCollection fc = layer.getSelectedFeatures();
    if (fc.size() == 0) {
      throw new ModuleException(Messages.get("$DG10094", paramater.get("OBJECTIDS")));
    }
    Envelope env = null;
    try {
      env = fc.getBoundedBy();
      if (env.getWidth() < 0.0001) {
        // feature collection just contains one point; set fix bbox width/height
        // 25 map units
        env = env.getBuffer(25);
      }
    } catch (GeometryException e) {
      LOG.logError(e.getMessage(), e);
      throw new ModuleException(e.getMessage());
    }

    // zoom to common bounding box of selected features
    ZoomCommand zcmd = new ZoomCommand(mapModel);
    zcmd.setZoomBox(
        env,
        mapModel.getTargetDevice().getPixelWidth(),
        mapModel.getTargetDevice().getPixelHeight());
    if ("TRUE".equalsIgnoreCase(paramater.get("sync"))) {
      try {
        appContainer.getCommandProcessor().executeSychronously(zcmd, true);
      } catch (Exception e) {
        LOG.logError(e.getMessage(), e);
        throw new ModuleException(e.getMessage());
      }
    } else {
      appContainer.getCommandProcessor().executeASychronously(zcmd);
    }

    return "feature selected";
  }