Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am facing some problems while exporting in_memory group layers to shapefile. but this code is successfully exporting any single in_memory layer to any type like shapefile gdb etc. here is my code.

public static ILayer exportLayer(IPropertySet properties, WorkspaceType type, IFeatureLayer featureLayer) throws Exception
{
    IFeatureClass featureClass = featureLayer.getFeatureClass();

    IWorkspace sourceWorkspace = new Workspace(((IDataset)featureLayer).getWorkspace());
    IWorkspace targetWorkspace = WorkspaceFactory.getFactory(type, properties);

    IWorkspaceName sourceWorkspaceName = getWorkspaceName(sourceWorkspace);
    IWorkspaceName targetWorkspaceName = getWorkspaceName(targetWorkspace);

    IFeatureClassName sourceFeatureClassName = new FeatureClassName();
    IDatasetName sourceDatasetName = (IDatasetName) sourceFeatureClassName;
    sourceDatasetName.setName(((IDataset)featureLayer).getName());
    sourceDatasetName.setWorkspaceNameByRef(sourceWorkspaceName);

    // Create a name object for the FGDB feature class and cast it to the
    // IDatasetName interface.
    IFeatureClassName targetFeatureClassName = new FeatureClassName();
    IDatasetName targetDatasetName = (IDatasetName) targetFeatureClassName;
    targetDatasetName.setName((String) properties.getProperty("LAYER"));
    targetDatasetName.setWorkspaceNameByRef(targetWorkspaceName);

    // Create the objects and references necessary for field validation.
    IFieldChecker fieldChecker = new FieldChecker();
    IFields sourceFields = featureClass.getFields();
    IFields[] targetFields = new IFields[1];
    IEnumFieldError[] enumFieldError = new IEnumFieldError[1];

    // Set the required properties for the IFieldChecker interface.
    fieldChecker.setInputWorkspace(sourceWorkspace);
    fieldChecker.setValidateWorkspaceByRef(targetWorkspace);

    // Validate the fields and check for errors.
    fieldChecker.validate(sourceFields, enumFieldError, targetFields);
    if (enumFieldError != null)
    {
        /* handle the field errors */
    }

    // Find the shape field.
    String shapeFieldName = featureClass.getShapeFieldName();
    int shapeFieldIndex = featureClass.findField(shapeFieldName);
    IField shapeField = sourceFields.getField(shapeFieldIndex);

    // Get the geometry definition from the shape field and clone it.
    IGeometryDef geometryDef = shapeField.getGeometryDef();
    IClone geometryDefClone = (IClone) geometryDef;
    IClone targetGeometryDefClone = geometryDefClone.esri_clone();
    IGeometryDef targetGeometryDef = new GeometryDef(targetGeometryDefClone);

    // Create the converter and run the conversion.
    IFeatureDataConverter featureDataConverter = new FeatureDataConverter();
    IEnumInvalidObject enumInvalidObject = featureDataConverter
            .convertFeatureClass(sourceFeatureClassName, null, null,
                    targetFeatureClassName, targetGeometryDef,
                    targetFields[0], "", 1000, 0);

    // Check for errors.
    IInvalidObjectInfo invalidObjectInfo = null;
    enumInvalidObject.reset();
    List<Integer> invalidObjects = new ArrayList<Integer>();
    while ((invalidObjectInfo = enumInvalidObject.next()) != null)
    {
        invalidObjects.add(invalidObjectInfo.getInvalidObjectID());
    }

    IFeatureLayer targetLayer = new FeatureLayer();
    targetLayer.setFeatureClassByRef(((Workspace)targetWorkspace).openFeatureClass(targetDatasetName.getName()));
    targetLayer.setName(targetDatasetName.getName());

    return targetLayer;
}

gets automation exception when trying to convert the data featureDataConverter .convertFeatureClass(sourceFeatureClassName, null, null, targetFeatureClassName, targetGeometryDef, targetFields[0], "", 1000, 0);

Thanks for helping me out.

share|improve this question
What do you mean by group layer? Is it a feature layer inside a group layer, or are you shooting for the function to copy all feature layers inside a group layer to shapefiles? – Stefan Oct 7 '11 at 11:50
Can you add some more details, including the product and version you are using, to avoid the question being closed, please? – PolyGeo Jan 8 at 20:45

closed as not a real question by PolyGeo, Simon, Devdatta Tengshe, whuber Jan 9 at 13:53

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

Browse other questions tagged or ask your own question.