ArcServer中使用ArcOBJECT删除要素

public void delete(MapEvent event) { 

Context webContext = event.getWebContext();
 AGSLocalMapResource res2 = (AGSLocalMapResource)webContext.getResources().get("ags0");
 IServerContext sctx2 = res2.getServerContext();
 MapServer mapServer = res2.getLocalMapServer();

 IFeatureLayer flayer = (IFeatureLayer) mapServer.getLayer("Layers", 0);
 IFeatureClass featureClass = flayer.getFeatureClass();
 IWorkspace workspace = featureClass.getFeatureDataset().getWorkspace();
 IFeatureWorkspace pFeatureWorkspace = new Workspace(workspace);
 IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)pFeatureWorkspace;
   //start editing with undo redo functionality
 workspaceEdit.startEditing(true);
 workspaceEdit.startEditOperation();
 IQueryFilter filter = (IQueryFilter)sctx2.createObject(QueryFilter.getClsid());
 filter.setSubFields("*");
 filter.setWhereClause("OBJECTID=2547");
 IFeatureCursor cursor = featureClass.search(filter, false);
 IFeature feature = cursor.nextFeature();
 ISet deleteSet = (ISet)sctx2.createObject(Set.getClsid());
 while(feature != null){
    deleteSet.add(feature);
   System.out.println("delete feature id"+feature.getOID());
    feature = cursor.nextFeature();
   }
   deleteSet.reset();
   IFeatureEdit featureEdit = (IFeatureEdit)deleteSet.next();
   while(featureEdit != null){
    featureEdit.deleteSet(deleteSet);
    featureEdit = (IFeatureEdit)deleteSet.next();
   }
   workspaceEdit.stopEditOperation();   
   workspaceEdit.stopEditing(true);

}

你可能感兴趣的:(ArcServer中使用ArcOBJECT删除要素)