ESRI.ArcGIS.AnalysisTools 및 ESRI.ArcGIS.Geoprocessor

ESRI를 사용합니다.ArcGIS.AnalysisTools의 도구(예를 들어 테슨 다각형의 구축 등)는 다음 코드를 사용합니다.
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            ESRI.ArcGIS.AnalysisTools.CreateThiessenPolygons CTP = new CreateThiessenPolygons(@"D:\AEtestyao\Data\school.shp", 
                                         "D:\AEtestyao\Data\CTP.shp");
            CTP.fields_to_copy = "ONLY_FID";           
            gp.Execute(CTP, null);
처음에는 줄곧 결과를 얻지 못하다가 인터넷에 접속하여 오랫동안 조사한 후에 마침내 해결되었다.일반적으로 도구가 등록되지 않은 경우(the tool is not licensed)
해결 방안은 다음과 같이 메인 창의 초기화 함수에 코드를 추가합니다.
public Mainform()
        {
#region 초기화 라이센스
            IAoInitialize m_AoInitialize = new AoInitializeClass();
            esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
            
            licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
//기본적으로 첫 번째는 유효하고 그 다음은 무효입니다. 이 레벨이 가장 높고 절대 다수의 기능을 사용할 수 있습니다.
           //licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);최저 수준
            #endregion
            InitializeComponent();  
        }
키 코드는 Initialize Component()에 올바르게 배치해야 합니다.
원인 설명: 시스템을 구축할 때 axLicense Control은 기본적으로 esriLicense ProductCodeEngine을 사용하는데 이 등급이 가장 낮아서 ESRI를 초래한다.ArcGIS.AnalysisTools의 많은 기능을 사용할 수 없기 때문에 다시 설정해야 합니다.주의:axLicense Control에서 속성 설정을 오른쪽 단추로 누르면 설정이 적용되지 않기 때문에 코드만 추가할 수 있습니다.
ArcGIS Engine에서 GP를 호출하는 두 가지 방법
//      
 using ESRI.ArcGIS.esriSystem;
 using ESRI.ArcGIS.Geoprocessor;
 
//  button click  
 private void button1_Click(object sender, EventArgs e)
 {
 //  Geoprocessor
 Geoprocessor gp = new Geoprocessor();
 //    
 ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
 intersect.in_features = @"F:\foshan\Data\wuqutu_b.shp;F:\foshan\Data\world30.shp";
 intersect.out_feature_class = @"E:\intersect.shp";
 intersect.join_attributes = "ONLY_FID";
 //  Intersect  
 RunTool(gp, intersect, null);
 }
 
private void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC)
 {
 // Set the overwrite output option to true
 geoprocessor.OverwriteOutput = true;
 
try
 {
 geoprocessor.Execute(process, null);
 ReturnMessages(geoprocessor);
 
}
 catch (Exception err)
 {
 Console.WriteLine(err.Message);
 ReturnMessages(geoprocessor);
 }
 }
 
// Function for returning the tool messages.
 private void ReturnMessages(Geoprocessor gp)
 {
 string ms = "";
 if (gp.MessageCount > 0)
 {
 for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
 {
 ms += gp.GetMessage(Count);
 }
 }
 
//1-  GeoProcessor  
 Geoprocessor gp = new Geoprocessor();
 object sev = null;
 //2-    
 gp.OverwriteOutput = true;
 //3-          
 gp.AddToolbox(@"F:\lib_test\AirportsAndGolf.tbx");
 //4-      
 IVariantArray parameters = new VarArrayClass();
 parameters.Add(@"F:\lib_test\        .xls\Sheet1$");
 parameters.Add("`YEAR` = 2009");
 parameters.Add("W20111");
 parameters.Add(@"F:\lib_test\temp.gdb\tempwww");
 
//5-    
 gp.Execute("ModelAnalysis", parameters, null);

ESRI 공식 도움말의 예:
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.AnalysisTools;

public void SampleBufferTool()
{

  // Initialize the geoprocessor. 
  Geoprocessor GP = new Geoprocessor();

  ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new
    ESRI.ArcGIS.AnalysisTools.Buffer();

  bufferTool.in_features = @"D:\St_Johns\data.mdb\roads_Buffer";
  bufferTool.out_feature_class = @"D:\St_Johns\data.mdb\roads";
  bufferTool.buffer_distance_or_field = "distance";

  GP.Execute(bufferTool, null);

}
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.esriSystem;

public void SampleCalculateBestPathTool()
{

  // Initialize the geoprocessor.
  Geoprocessor GP = new Geoprocessor();

  // Add the BestPath toolbox.
  GP.AddToolbox(@"C:\SanDiego\BestPath.tbx");

  // Generate the array of parameters.
  IVariantArray parameters = new VarArrayClass();
  parameters.Add(@"C:\SanDiego\source.shp");
  parameters.Add(@"C:\SanDiego\destination.shp");
  parameters.Add(@"C:\SanDiego\bestpath.shp");

  // Execute the model tool by name.
  GP.Execute("CalculateBestPath", parameters, null);

좋은 웹페이지 즐겨찾기