Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have built a webservice which is to realize one of the functions in ArcTools named FeatureclassToCoverage. My code is as below:
public string FeatureClassToCoverage(string string_inFeatures, string string_outCoverage) //List<string string_inFeatures>
   {
       IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
       IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(string_inFeatures), 0);//<big>THE PROBLEM LINE</big>
       IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
       IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(string_inFeatures));

       String outDict = System.IO.Path.GetDirectoryName(string_inFeatures);
       String outCoverage = outDict + "\\" + string_outCoverage;

       ESRI.ArcGIS.ConversionTools.FeatureclassToCoverage featureClassToCoverage = new FeatureclassToCoverage(pFeatureClass, outCoverage);

       ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new Geoprocessor();
       ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult results = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(featureClassToCoverage, null);

       string returnString = outCoverage;
       if (results.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
       {
           returnString = "Changing Failed!";
       }
       return returnString;
   }


When I test the service, the problem shows as the title. It points to the 'IWorkSpace' line.
Who can help me with it? Thank you!
Posted

I have solved it by myself.
I just add code to it as follows:
public string FeatureClassToCoverage(string string_inFeatures, string string_outCoverage) //List<string string_inFeatures>
{
    <big>ESRI.ArcGIS.esriSystem.IAoInitialize ao = new ESRI.ArcGIS.esriSystem.AoInitialize();
 ao.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcInfo);</big> 

    IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
    IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(string_inFeatures), 0);
    IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
    IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(string_inFeatures));

    String outDict = System.IO.Path.GetDirectoryName(string_inFeatures);
    String outCoverage = outDict + "\\" + string_outCoverage;

    ESRI.ArcGIS.ConversionTools.FeatureclassToCoverage featureClassToCoverage = new FeatureclassToCoverage(pFeatureClass, outCoverage);

    ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new Geoprocessor();
    ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult results = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(featureClassToCoverage, null);

    string returnString = outCoverage;
    if (results.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
    {
        returnString = "Changing Failed!";
    }
    return returnString;
}
 
Share this answer
 
Hello,

I don't know what string_inFeatures contains but anyway if it is a file name then the problem is that System.IO.Path.GetDirectoryName(string_inFeatures) returns a directory name not a file path.

you need to pass a file path.

Look here for details.
 
Share this answer
 
Comments
Scarlettlee 25-Nov-10 7:08am    
I am sure that my file path is right, and my problem is solved by myself.
Thank you very much, anyway:)
Maybe we can communicate more about programming, do you have a MSN or else?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900