ArcGIS Engine开发Geodatabase代码(四)——Join

时间:2013-4-25    作者:悬浮的青春    分类:


/****>在我们使用过程中,经常使用Join进行连接,以下代码就是来实现join功能


<p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line- style=" font-family:arial;font-size:14px;line-height:26px;"="">

  • ArcGIS Engine9.3/9.3.1
  • VS2008
  • 关于版本的接口差别参考:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Type_changes_between_9_3_and_10/000100000408000000/




    在我们使用过程中,经常使用Join进行连接,以下代码就是来实现join功能


    1. using System;  
    2. using System.Runtime.InteropServices;  
    3. using ESRI.ArcGIS.ADF;  
    4. using ESRI.ArcGIS.esriSystem;  
    5. using ESRI.ArcGIS.Geodatabase;  
    6. using ESRI.ArcGIS.Geometry;  
    7.   
    8. namespace JoinDemo  
    9. {  
    10.     public class JoinDemo  
    11.     {  
    12.         public static void Main(string[] args)  
    13.         {  
    14.             #region Licensing  
    15.             // Set up the licencing. NOTE: This sample assumes that you are using ArcInfo Desktop.  
    16.             // You will need to adjust this code if using ArcEngine or ArcEditor.  
    17.             IAoInitialize aoInitialize = new AoInitializeClass();  
    18.             esriLicenseStatus licenseStatus = aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo);  
    19.             if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)  
    20.             {  
    21.                 Console.WriteLine("Unable to check-out an ArcInfo license, error code is {0}", licenseStatus);  
    22.                 return;  
    23.             }  
    24.             #endregion  
    25.   
    26.             // Open the File Geodatabase and the Parcels feature class.  
    27.             Type fgdbFactoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");  
    28.             IWorkspaceFactory fgdbWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(fgdbFactoryType);  
    29.             IWorkspace fgdbWorkspace = fgdbWorkspaceFactory.OpenFromFile(@"..\..\..\Data\JoinDemo.gdb", 0);  
    30.             IFeatureWorkspace fgdbFeatureWorkspace = (IFeatureWorkspace)fgdbWorkspace;  
    31.             IFeatureClass featureClass = fgdbFeatureWorkspace.OpenFeatureClass("Parcels");  
    32.               
    33.             // Open the Shapefile workspace and the Owners DBF file.  
    34.             Type shpFactoryType = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");  
    35.             IWorkspaceFactory shpWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(shpFactoryType);  
    36.             IWorkspace shpWorkspace = shpWorkspaceFactory.OpenFromFile(@"..\..\..\Data", 0);  
    37.             IFeatureWorkspace shpFeatureWorkspace = (IFeatureWorkspace)shpWorkspace;  
    38.             IObjectClass objectClass = (IObjectClass)shpFeatureWorkspace.OpenTable("Owners");  
    39.   
    40.             // Create a memory relationship class between the two datasets.  
    41.             IMemoryRelationshipClassFactory memRelClassFactory = new MemoryRelationshipClassFactoryClass();  
    42.             IRelationshipClass relationshipClass = memRelClassFactory.Open("ParcelsOwners",  
    43.                 featureClass, "PROPERTY_I", objectClass, "PROPERTY_I""Is Owned By""Owns",  
    44.                 esriRelCardinality.esriRelCardinalityOneToOne);  
    45.   
    46.             // Create a RelQueryTable using the memory relationship class.  
    47.             IRelQueryTableFactory relQueryTableFactory = new RelQueryTableFactoryClass();  
    48.             ITable relQueryTable = (ITable)relQueryTableFactory.Open(relationshipClass,  
    49.                 truenullnull""truefalse);  
    50.   
    51.             // Create a query filter that finds the names of the owners of large parcels.  
    52.             IQueryFilter queryFilter = new QueryFilterClass  
    53.             {  
    54.                 SubFields = "Parcels.PROPERTY_I, Owners.OWNER_NAME",  
    55.                 WhereClause = "Parcels.SHAPE_AREA > 300000"  
    56.             };  
    57.   
    58.             // Find the indexes of the Property ID and Owner Name fields.  
    59.             int propertyIdIndex = relQueryTable.FindField("Parcels.PROPERTY_I");  
    60.             int ownerNameIndex = relQueryTable.FindField("Owners.OWNER_NAME");  
    61.   
    62.             // Execute a query, displaying the names&nb


    标签: arcgis二次开发 arcgis Geodatabase

    WRITTEN BY

    avatar