コード例 #1
0
  /**
   * Initialzie the buffer process taking into account if the target is an existnet layer or a new
   * layer
   *
   * @param monitor
   */
  @Override
  protected void init(IProgressMonitor monitor) throws SOProcessException {

    super.init(monitor);

    if (this.paramsBufferInExistntLayer != null) {

      init(this.paramsBufferInExistntLayer);

      this.targetLayer = this.paramsBufferInExistntLayer.getTargetLayer();

      this.targetStore = getFeatureStore(this.targetLayer);

    } else if (this.paramsBufferInNewLayer != null) {

      init(this.paramsBufferInNewLayer);

      // create new layer (store and resource) with the feature type required
      SimpleFeatureType type = this.paramsBufferInNewLayer.getTargetFeatureType();

      this.targetGeoResource = AppGISMediator.createTempGeoResource(type);
      assert this.targetGeoResource != null;

      try {
        this.targetStore = this.targetGeoResource.resolve(FeatureStore.class, monitor);
      } catch (IOException e) {
        throw new SOProcessException(Messages.BufferProcess_failed_creating_temporal_store);
      }

      this.targetLayer = addLayerToMap(this.map, this.targetGeoResource);
    }
    assert this.targetLayer != null;
    assert this.targetStore != null;
  }
コード例 #2
0
  public UndoableMapCommand getCommand(EditToolHandler handler) {
    final PrimitiveShape currentShape = handler.getCurrentShape();
    final ILayer editLayer = handler.getEditLayer();

    // need to use map coordinates in order to avoid
    // possible inconsistencies between what the user
    // drawn and the projected result
    GeometryFactory gf = new GeometryFactory();
    CoordinateReferenceSystem layerCrs = LayerUtil.getCrs(editLayer);
    CoordinateReferenceSystem mapCrs = editLayer.getMap().getViewportModel().getCRS();
    Point p1 = gf.createPoint(currentShape.getCoord(0));
    Point p2 = gf.createPoint(currentShape.getCoord(1));
    Point p3 = gf.createPoint(currentShape.getCoord(2));

    try {
      p1 = (Point) GeoToolsUtils.reproject(p1, layerCrs, mapCrs);
      p2 = (Point) GeoToolsUtils.reproject(p2, layerCrs, mapCrs);
      p3 = (Point) GeoToolsUtils.reproject(p3, layerCrs, mapCrs);
    } catch (OperationNotFoundException onfe) {
      throw new IllegalStateException(
          "Could not reproject to map crs:" + onfe.getLocalizedMessage(), onfe);
    } catch (TransformException te) {
      throw new IllegalStateException(
          "Could not reproject to map crs:" + te.getLocalizedMessage(), te);
    }

    ArcBuilder builder = new ArcBuilder();
    builder.setPoints(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY());

    // TODO: especificar la cantidad de segmentos por cuadrante
    // mediante una preferencia
    Geometry geom = builder.getGeometry(15);
    if (geom == null) {
      throw new IllegalStateException("null geom");
    }

    // backproject resulting geom from map crs to layer's crs
    try {
      geom = GeoToolsUtils.reproject(geom, mapCrs, layerCrs);
    } catch (OperationNotFoundException onfe) {
      throw new IllegalStateException(
          "Could not reproject back to data crs:" + onfe.getLocalizedMessage(), onfe);
    } catch (TransformException te) {
      throw new IllegalStateException(
          "Could not reproject back to data crs:" + te.getLocalizedMessage(), te);
    }

    EditCommandFactory editCmdFac = AppGISMediator.getEditCommandFactory();

    ILayer layer = editLayer;
    SimpleFeatureType schema = layer.getSchema();
    SimpleFeature feature;
    try {
      feature = SimpleFeatureBuilder.build(schema, (Object[]) null, null);
      Class type = schema.getDefaultGeometry().getType().getBinding();
      geom = GeometryUtil.adapt(geom, type);
      feature.setDefaultGeometry(geom);
    } catch (IllegalAttributeException e) {
      // consider using the bubble feedback
      throw new IllegalStateException("Could not create Arc:" + e, e);
    }
    UndoableMapCommand command = editCmdFac.createAddFeatureCommand(feature, layer);

    handler.setCurrentShape(null);
    handler.setCurrentState(EditState.NONE);

    return command;
  }