示例#1
0
  private void save() throws Exception {
    FeatureStore fs = (FeatureStore) ds.getFeatureSource("poly_county");
    FeatureType ft = fs.getSchema();

    MemoryDataStore memorystore = new MemoryDataStore();

    ArrayList polys = new ArrayList(resultPolygon);

    Geometry gfinal = null;
    if (polys.size() == 1) {
      gfinal = (Polygon) polys.get(0); // POLYGON
    } else {
      GeometryFactory gf = ((Polygon) polys.get(0)).getFactory();
      gfinal = new MultiPolygon((Polygon[]) polys.toArray(new Polygon[polys.size()]), gf);
    }

    gfinal = gfinal.buffer(0); // for topologic problems.

    Object[] values = new Object[5];
    values[ft.find("module")] = MODULE;
    values[ft.find("gen_full")] = gfinal;

    values[ft.find("gen_1")] = generalize(gfinal, tolerance1);
    ;
    values[ft.find("gen_2")] = generalize(gfinal, tolerance1);
    ;
    values[ft.find("gen_3")] = generalize(gfinal, tolerance1);
    ;

    Feature f = ft.create(values);
    memorystore.addFeature(f);

    fs.addFeatures(memorystore.getFeatureReader("poly_county"));
  }
    /** @see Transfer#nativeToJava */
    @SuppressWarnings("deprecation")
    public Object nativeToJava(TransferData transferData) {
      String string = (String) TextTransfer.getInstance().nativeToJava(transferData);

      WKTReader reader = new WKTReader();
      try {
        Geometry read = reader.read(string);
        FeatureType ft =
            DataUtilities.createType(
                "Temp Type", "*geom:" + read.getClass().getName()); // $NON-NLS-1$ //$NON-NLS-2$
        return ft.create(new Object[] {read});
      } catch (Exception e) {
        UiPlugin.log("", e); // $NON-NLS-1$
      }
      return null;
    }