2

I am trying to convert a raster dataset into a shapefile using IConversionOp.RasterDataToPolygonFeatureData API.

See the code below:

IConversionOp conversionOp = new RasterConversionOp() as IConversionOp;
IWorkspaceFactory inMemoryWorkSpaceFactory = new InMemoryWorkspaceFactory();
IWorkspaceName inMemoryWorkspaceName = inMemoryWorkSpaceFactory.Create("", "MyWorkspace", null, 0);
IName name = (IName)inMemoryWorkspaceName;
IWorkspace inMemoryWorkspace = (IWorkspace)name.Open();

conversionOp.RasterDataToPolygonFeatureData(rasterDataset as IGeoDataset, 
inMemoryWorkspace, inMemoryWorkspace.PathName, false);

I am using InMemory as RasterDataToPolygonFeatuerData fails when the path argument has spaces and I do have fair chances to have spaces in the output path.

So I tried to create the FeatureClass using InMemory workspace. The FeatureClass gets created successfully and now I need to create the Shapefile on disk.

Can someone help me in creating the Shapefile on a disk from InMemory workspace?

5
  • 3
    Shapefile is a specific file-based format. It is not possible to construct shapefiles as inMemory objects. What you have created is an inMemory feature class, which can be exported through a number of means, among them FeatureClassToFeatureClass.
    – Vince
    Commented Dec 17, 2017 at 16:54
  • 1
    Thanks for correcting, I have updated the question as per your comments. I found the way to convert a featureclass to a featureclass using edndoc.esri.com/arcobjects/9.2/ComponentHelp/esrigeodatabase/…
    – sidd
    Commented Dec 17, 2017 at 18:44
  • Your link is very old, try resources.arcgis.com/en/help/arcobjects-net/componenthelp/… for IFeatureDataConverter2.ConvertFeatureClass.. all you need do is create the required objects for the output. I've not used this interface, I have always created a new shapefile, Search Cursored through the existing data and output to the new shapefile with an Insert Cursor and IFeatureBuffer - works fine for me and is very fast. Just beware that shapefiles have a maximum size which it's very easy to exceed and raise an exception. Commented Dec 21, 2017 at 23:30
  • But if you want a shapefile why not just convert directly to the shapefile? Why are you using an InMemory feature class? Is it because your reference code uses an InMemory feature class and you are unaware of how to change that? It would really only take a few changes.. make your IWorkspaceFactory a ShapefileWorkspaceFactory (from DataSourcesFile) then your workspace is IWorkspaceFactory.Open("an existing folder"). Commented Dec 21, 2017 at 23:32
  • In my case the dataset is produced by the API RasterDataToPolygonFeatureData(....). which gets failed if IWorkSpace argument of the API is from IWorkspaceFactory.Open("an existing folder") and the folder path has spaces in it.
    – sidd
    Commented Dec 23, 2017 at 4:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.