示例#1
0
  public void rollback(IProgressMonitor monitor) throws Exception {
    editBlackboard.removeGeometries(Collections.singleton(first));

    EditGeom newGeom =
        editBlackboard.newGeom(
            oldshape.getEditGeom().getFeatureIDRef().get(), oldshape.getEditGeom().getShapeType());

    for (int i = 0; i < oldshape.getNumCoords(); i++) {
      editBlackboard.addCoordinate(oldshape.getCoord(i), newGeom.getShell());
    }

    if (currentShapeSet) setCurrentShape(newGeom.getShell());

    FeatureStore<SimpleFeatureType, SimpleFeature> store =
        layer.getResource(FeatureStore.class, new SubProgressMonitor(monitor, 1));

    FilterFactory factory = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
    Set<FeatureId> ids = new HashSet<FeatureId>();
    for (FeatureId id : newFids) {
      ids.add(id);
    }
    Id filter = factory.id(ids);

    store.removeFeatures(filter);
    Geometry oldType = (Geometry) oldFeature.getDefaultGeometry();
    GeometryDescriptor newType = store.getSchema().getGeometryDescriptor();
    store.modifyFeatures(
        newType, oldType, factory.id(FeatureUtils.stringToId(factory, oldFeature.getID())));
    oldFeature.setDefaultGeometry(oldGeometry);
    newFids.clear();
  }
  /**
   * Creates a query that requests the features in sourceLayer as dictated by filter. Query only
   * requests the attributes that can be mapped from sourceLayer to targetLayer.
   *
   * @param queryAttributes populates with a mapping of attributeTypeNames from targetLayer to
   *     sourcelayer
   * @return
   */
  @SuppressWarnings("unchecked")
  private Query createQuery(
      ILayer sourceLayer, Filter filter, Layer targetLayer, Map<String, String> queryAttributes) {
    SimpleFeatureType sourceSchema = sourceLayer.getSchema();
    SimpleFeatureType targetSchema = targetLayer.getSchema();
    // Maps type names to type names since we are ignoring case

    queryAttributes.putAll(FeatureUtils.createAttributeMapping(sourceSchema, targetSchema));
    Set<String> properties = new HashSet(queryAttributes.values());
    return new DefaultQuery(
        sourceSchema.getName().getLocalPart(),
        filter,
        properties.toArray(new String[properties.size()]));
  }
示例#3
0
  @SuppressWarnings({"unchecked"})
  private void modifyOldFeature(final FeatureStore<SimpleFeatureType, SimpleFeature> store)
      throws IOException, IllegalAttributeException {
    FilterFactory fac = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
    Filter filter = fac.id(FeatureUtils.stringToId(fac, oldFeature.getID()));

    Geometry g = GeometryCreationUtil.createGeom(LineString.class, first.getShell(), true);
    if (store
        .getSchema()
        .getGeometryDescriptor()
        .getType()
        .getBinding()
        .isAssignableFrom(MultiLineString.class))
      g = new GeometryFactory().createMultiLineString(new LineString[] {(LineString) g});

    store.modifyFeatures(store.getSchema().getGeometryDescriptor(), g, filter);
    oldFeature.setDefaultGeometry(g);
  }
  private void selectFeature(final int index, boolean reveal) throws Exception {

    final Table tree = table.getViewer().getTable();

    FilterFactory fac = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
    final String fid = "feature" + (index + 1); // $NON-NLS-1$
    Set<Identifier> ids = FeatureUtils.stringToId(fac, fid);
    Id selection = fac.id(ids);
    table.setSelection(new StructuredSelection(selection), reveal);
    UDIGTestUtil.inDisplayThreadWait(
        3000,
        new WaitCondition() {

          public boolean isTrue() {
            TableItem item = tree.getItem(index);
            if (item.getData() == null) return false;
            return fid.equals(((SimpleFeature) item.getData()).getID());
          }
        },
        false);
  }