I want to execute the Visibility Analysis Tool using ArcObjects 10.3. I tested the tool in ArcMap and it works great with the test data I provided, hence it should work as well in ArcObjects code. The only difference is that I don't want to write the output raster to file, I would prefer to have it stored in memory for some immediate pixel analysis.So, please take a look at my code:
private IFeatureClass OpenShapeFile(string shapeFilePath){ string shapeFile = System.IO.Path.GetFileNameWithoutExtension(shapeFilePath); string fileFolder = System.IO.Path.GetDirectoryName(shapeFilePath); IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory(); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(fileFolder, 0); IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(shapeFile); return featureClass;}public bool PerformAnalysis(string inputRaster, string observerLocationShp){ if (InitLicense()) { //var inputRaster = @"C:\Test\kand_lidar_dem_sub_products.dat"; //var observerLocationShp= @"C:\Test\VisTest_ObserverPoint.shp"; //feature class with observer location try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.ResetEnvironments(); gp.OverwriteOutput = true; gp.RegisterGeoProcessorEvents((IGeoProcessorEvents)new GPEvents()); var test2 = new RasterDataset(); test2.OpenFromFile(inputRaster); var testShp = OpenShapeFile(observerLocationShp); var output = new RasterDataset(); output.CreateDefaultRaster(); Viewshed viewshed = new Viewshed(test2, testShp, output); IGeoProcessorResult2 result = gp.Execute(viewshed, null) as IGeoProcessorResult2; IGPMessages msgs = result.GetResultMessages(); var gpInfo = string.Empty; for (int i = 0; i < msgs.Count; i++) { //Console.WriteLine("{0} {1}", msgs.GetMessage(i).Description, msgs.GetMessage(i).Type); gpInfo+=msgs.GetMessage(i).Description+" "+ msgs.GetMessage(i).Type+"\n"; } } catch (COMException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return false;}The code fails on line: IGeoProcessorResult2 result = gp.Execute(viewshed, null) as IGeoProcessorResult2;
The problem is, the GeoProcessor crashes on Execute function giving me the error code -2147467259. I can't see this error code on the list provided by Esri http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/index.html#//000100000312000000.
In the console output I can see "ToolboxChange" message written two times. Since there are no Console.Writeline functions used in my code, I assume that is what GeoProcessor outputs.
أكثر...
private IFeatureClass OpenShapeFile(string shapeFilePath){ string shapeFile = System.IO.Path.GetFileNameWithoutExtension(shapeFilePath); string fileFolder = System.IO.Path.GetDirectoryName(shapeFilePath); IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory(); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(fileFolder, 0); IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(shapeFile); return featureClass;}public bool PerformAnalysis(string inputRaster, string observerLocationShp){ if (InitLicense()) { //var inputRaster = @"C:\Test\kand_lidar_dem_sub_products.dat"; //var observerLocationShp= @"C:\Test\VisTest_ObserverPoint.shp"; //feature class with observer location try { ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); gp.ResetEnvironments(); gp.OverwriteOutput = true; gp.RegisterGeoProcessorEvents((IGeoProcessorEvents)new GPEvents()); var test2 = new RasterDataset(); test2.OpenFromFile(inputRaster); var testShp = OpenShapeFile(observerLocationShp); var output = new RasterDataset(); output.CreateDefaultRaster(); Viewshed viewshed = new Viewshed(test2, testShp, output); IGeoProcessorResult2 result = gp.Execute(viewshed, null) as IGeoProcessorResult2; IGPMessages msgs = result.GetResultMessages(); var gpInfo = string.Empty; for (int i = 0; i < msgs.Count; i++) { //Console.WriteLine("{0} {1}", msgs.GetMessage(i).Description, msgs.GetMessage(i).Type); gpInfo+=msgs.GetMessage(i).Description+" "+ msgs.GetMessage(i).Type+"\n"; } } catch (COMException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return false;}The code fails on line: IGeoProcessorResult2 result = gp.Execute(viewshed, null) as IGeoProcessorResult2;
The problem is, the GeoProcessor crashes on Execute function giving me the error code -2147467259. I can't see this error code on the list provided by Esri http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/index.html#//000100000312000000.
In the console output I can see "ToolboxChange" message written two times. Since there are no Console.Writeline functions used in my code, I assume that is what GeoProcessor outputs.
أكثر...