1

I've seen this solution which may works in ArcObjects for VB/.Net:

How to overwrite a shapefile or feature class using arcobjects

When I try to convert it into Java, I get a ClassCastException on the IDataset cast.

Here is my code:

IWorkspace workspace = ...
IWorkspace2 workspace2 = (IWorkspace2)workspace;
if(workspace2.isNameExists(esriDatasetType.esriDTFeatureClass, featureClassName)) {
    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
     // ClassCastException here
    IDataset featureClassDataset = (IDataset)featureWorkspace.openFeatureClass(featureClassName);
    if(featureClassDataset.canDelete()) {
        featureClassDataset.delete();
    } else {
        // alert: the feature class exists but couldn't be deleted
    }
}
IFeatureClass featureClass = featureDataset.createFeatureClass(...);

Does anyone know how we can't use the IDataset interface for a feature class as in VB?

How to delete a feature class in Java else?

1

I found a solution: the problem came from the way I created the IWorkspace object. The best way to do it in ArcObjects API for Java is:

    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
    IWorkspaceName workspaceName = workspaceFactory.create(parentDirectory, gdbName, null, 0);
    IName name = (IName)workspaceName;
    IWorkspace workspace = new Workspace(name.open());

even if in the ESRI documentation, it's written to use new IWorkspaceProxy(name.open()) (I think that's en error).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.