Exemplo n.º 1
0
        private void method_13(IMap imap_0)
        {
            int          num;
            IDataset     featureClass;
            IWorkspace   workspace;
            IEnumReplica replicas;

            this.iarray_0 = new ArrayClass();
            new PropertySetClass();
            IFeatureLayer layer = null;

            for (num = 0; num < imap_0.LayerCount; num++)
            {
                ILayer layer2 = imap_0.get_Layer(num);
                if (layer2 is IGroupLayer)
                {
                    this.method_12(this.iarray_0, layer2 as ICompositeLayer);
                }
                else if (layer2 is IFeatureLayer)
                {
                    layer        = layer2 as IFeatureLayer;
                    featureClass = layer.FeatureClass as IDataset;
                    if ((featureClass != null) && !(featureClass is ICoverageFeatureClass))
                    {
                        workspace = featureClass.Workspace;
                        if (workspace is IWorkspaceReplicas)
                        {
                            replicas = (workspace as IWorkspaceReplicas).Replicas;
                            replicas.Reset();
                            if (replicas.Next() != null)
                            {
                                (this.method_14(this.iarray_0, workspace).EnumName as IEnumNameEdit).Add(
                                    featureClass.FullName);
                            }
                        }
                    }
                }
            }
            IStandaloneTableCollection tables = imap_0 as IStandaloneTableCollection;

            for (num = 0; num < tables.StandaloneTableCount; num++)
            {
                ITable table = tables.get_StandaloneTable(num) as ITable;
                if (table is IDataset)
                {
                    featureClass = table as IDataset;
                    workspace    = featureClass.Workspace;
                    if (workspace is IWorkspaceReplicas)
                    {
                        replicas = (workspace as IWorkspaceReplicas).Replicas;
                        replicas.Reset();
                        if (replicas.Next() != null)
                        {
                            (this.method_14(this.iarray_0, workspace).EnumName as IEnumNameEdit).Add(
                                featureClass.FullName);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override IMap CreateMap()
        {
            if (_Map != null)
            {
                return(_Map);
            }

            _Map = new MapClass();

            foreach (var o in base.GetTestClasses())
            {
                IFeatureLayer layer = new FeatureLayerClass();
                layer.FeatureClass = o;
                layer.Name         = o.AliasName;

                _Map.AddLayer(layer);
            }

            var table = base.GetTestTable();
            IStandaloneTable standaloneTable = new StandaloneTableClass();

            standaloneTable.Table = table;
            standaloneTable.Name  = ((IDataset)table).Name;

            IStandaloneTableCollection collection = (IStandaloneTableCollection)_Map;

            collection.AddStandaloneTable(standaloneTable);

            return(_Map);
        }
Exemplo n.º 3
0
        private void method_13(IMap imap_0)
        {
            int              num;
            IDataset         featureClass;
            IWorkspace       workspace;
            IVersionedObject obj2;

            this.iarray_0 = new ArrayClass();
            new PropertySetClass();
            IFeatureLayer layer = null;

            for (num = 0; num < imap_0.LayerCount; num++)
            {
                ILayer layer2 = imap_0.get_Layer(num);
                if (layer2 is IGroupLayer)
                {
                    this.method_12(this.iarray_0, layer2 as ICompositeLayer);
                }
                else if (layer2 is IFeatureLayer)
                {
                    layer        = layer2 as IFeatureLayer;
                    featureClass = layer.FeatureClass as IDataset;
                    if ((featureClass != null) && !(featureClass is ICoverageFeatureClass))
                    {
                        workspace = featureClass.Workspace;
                        if ((workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) &&
                            (workspace is IWorkspaceEdit))
                        {
                            obj2 = layer.FeatureClass as IVersionedObject;
                            if (obj2.IsRegisteredAsVersioned)
                            {
                                (this.method_14(this.iarray_0, workspace).EnumName as IEnumNameEdit).Add(
                                    featureClass.FullName);
                            }
                        }
                    }
                }
            }
            IStandaloneTableCollection tables = imap_0 as IStandaloneTableCollection;

            for (num = 0; num < tables.StandaloneTableCount; num++)
            {
                ITable table = tables.get_StandaloneTable(num) as ITable;
                if (table is IDataset)
                {
                    featureClass = table as IDataset;
                    workspace    = featureClass.Workspace;
                    if ((workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) &&
                        (workspace is IWorkspaceEdit))
                    {
                        obj2 = table as IVersionedObject;
                        if (obj2.IsRegisteredAsVersioned)
                        {
                            (this.method_14(this.iarray_0, workspace).EnumName as IEnumNameEdit).Add(
                                featureClass.FullName);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 public void fillDictionary()
 {
     FeatureDictionary        = new Dictionary <string, IFeatureClass>();
     TableDictionary          = new Dictionary <string, ITable>();
     FunctionRasterDictionary = new Dictionary <string, IFunctionRasterDataset>();
     if (TheMap != null)
     {
         for (int i = 0; i < TheMap.LayerCount; i++)
         {
             try
             {
                 ILayer lyr = TheMap.Layer[i];
                 if (lyr is FeatureLayer)
                 {
                     IFeatureLayer ftrLyr = (IFeatureLayer)lyr;
                     FeatureDictionary[lyr.Name] = ftrLyr.FeatureClass;
                 }
                 else if (lyr is RasterLayer)
                 {
                     IRasterLayer rsLyr = (IRasterLayer)lyr;
                     FunctionRasterDictionary[lyr.Name] = RasterUtility.createIdentityRaster(((IRaster2)rsLyr.Raster).RasterDataset);
                 }
                 else if (lyr is MosaicLayer)
                 {
                     IMosaicLayer  msLyr  = (IMosaicLayer)lyr;
                     IFeatureLayer ftrLyr = msLyr.BoundaryLayer;
                     FeatureDictionary[ftrLyr.Name] = ftrLyr.FeatureClass;
                     ftrLyr = msLyr.FootprintLayer;
                     FeatureDictionary[ftrLyr.Name]     = ftrLyr.FeatureClass;
                     FunctionRasterDictionary[lyr.Name] = (IFunctionRasterDataset)msLyr.MosaicDataset;
                 }
             }
             catch
             {
             }
         }
         IStandaloneTableCollection tblCol = (IStandaloneTableCollection)TheMap;
         for (int i = 0; i < tblCol.StandaloneTableCount; i++)
         {
             try
             {
                 IStandaloneTable StTbl = tblCol.StandaloneTable[i];
                 TableDictionary[StTbl.Name] = StTbl.Table;
             }
             catch
             {
             }
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        ///     Adds the table as a standalone table to the map.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="table">The table.</param>
        /// <returns>Returns a <see cref="IStandaloneTable" /> representing the table that was added to the map.</returns>
        public static IStandaloneTable AddTable(this IMap source, ITable table)
        {
            var standalone = new StandaloneTableClass
            {
                Table = table,
                Name  = ((IDataset)table).Name
            };

            IStandaloneTableCollection collection = (IStandaloneTableCollection)source;

            collection.AddStandaloneTable(standalone);

            return(standalone);
        }
Exemplo n.º 6
0
 private void populateComboBox()
 {
     if (mp != null)
     {
         IEnumLayer mLyr = mp.Layers;
         ILayer     lyr  = mLyr.Next();
         while (lyr != null)
         {
             string lyrNm = lyr.Name;
             if (lyr is FeatureLayer)
             {
                 IFeatureLayer ftrLyr = (IFeatureLayer)lyr;
                 ITable        tbl    = (ITable)ftrLyr.FeatureClass;
                 if (!tblDic.ContainsKey(lyrNm))
                 {
                     tblDic.Add(lyrNm, tbl);
                     cmbTable.Items.Add(lyrNm);
                 }
                 else
                 {
                     tblDic[lyrNm] = tbl;
                 }
             }
             lyr = mLyr.Next();
         }
         IStandaloneTableCollection tblCol = (IStandaloneTableCollection)mp;
         for (int i = 0; i < tblCol.StandaloneTableCount; i++)
         {
             IStandaloneTable StTbl = tblCol.StandaloneTable[i];
             string           lyrNm = StTbl.Name;
             ITable           tbl   = StTbl.Table;
             if (!tblDic.ContainsKey(lyrNm))
             {
                 tblDic.Add(lyrNm, tbl);
                 cmbTable.Items.Add(lyrNm);
             }
             else
             {
                 tblDic[lyrNm] = tbl;
             }
         }
         foreach (string s in Enum.GetNames(typeof(rasterUtil.localType)))
         {
             if (s != "POWER")
             {
                 cmbStats.Items.Add(s);
             }
         }
     }
 }
Exemplo n.º 7
0
 private void method_4(IStandaloneTableCollection istandaloneTableCollection_0,
                       IFeatureWorkspace ifeatureWorkspace_0, IFeatureWorkspace ifeatureWorkspace_1,
                       ICollectionTableVersionChanges icollectionTableVersionChanges_0)
 {
     try
     {
         IDisplayTable table = null;
         for (int i = 0; i < istandaloneTableCollection_0.StandaloneTableCount; i++)
         {
             IStandaloneTable table2 = istandaloneTableCollection_0.get_StandaloneTable(i);
             if (table2 is IDisplayTable)
             {
                 table = table2 as IDisplayTable;
                 if (this.method_3(table.DisplayTable as IDataset, ifeatureWorkspace_0, ifeatureWorkspace_1,
                                   icollectionTableVersionChanges_0))
                 {
                     this.method_2(table2 as IDisplayRelationshipClass, table.DisplayTable as IRelQueryTable);
                 }
             }
             IDataset dataset = table2.Table as IDataset;
             if (dataset != null)
             {
                 this.method_3(dataset, ifeatureWorkspace_0, ifeatureWorkspace_1,
                               icollectionTableVersionChanges_0);
                 if (dataset.Workspace == ifeatureWorkspace_0)
                 {
                     ITable newTable = this.method_1(ifeatureWorkspace_1, dataset);
                     if (newTable != null)
                     {
                         table2.Table = newTable;
                         icollectionTableVersionChanges_0.Add(dataset as ITable, newTable);
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
     }
 }
Exemplo n.º 8
0
        private void AddTable(string strPath, string strFileName)
        {
            try
            {
                IWorkspaceFactory pFact      = new ShapefileWorkspaceFactory();
                IWorkspace        pWorkspace = pFact.OpenFromFile(strPath, 0);
                IFeatureWorkspace pFeatws    = pWorkspace as IFeatureWorkspace;
                ITable            ptable     = pFeatws.OpenTable(strFileName);

                IMxDocument pmxdoc = ArcMap.Document as IMxDocument;
                IMap        pmap   = pmxdoc.FocusMap;

                IStandaloneTable pStTab = new StandaloneTableClass();
                pStTab.Table = ptable;
                IStandaloneTableCollection pStTabColl = pmap as IStandaloneTableCollection;
                pStTabColl.AddStandaloneTable(pStTab);
                pmxdoc.UpdateContents();

                ITableWindow2 ptableWindow = new TableWindowClass();
                ptableWindow.Application     = ArcMap.Application;
                ptableWindow.StandaloneTable = pStTab;

                ptableWindow.Show(true);

                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFact);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pWorkspace);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatws);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ptable);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pStTab);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pStTabColl);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ptableWindow);

                GC.Collect();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 9
0
        private void PopulateInputDataComboBox(IMapControl3 mapControl, IDataLayer dataLayer)
        {
            esriGeometryType targetGeoType = GetDataLayerGeometryType(dataLayer);

            IEnumLayer    sourceLayers       = null;
            ILayer        sourceLayer        = null;
            IDisplayTable sourceDisplayTable = null;
            UID           searchInterfaceUID = new UID();

            if (targetGeoType != esriGeometryType.esriGeometryNull)
            {
                // Only include layers that are of type IFeatureLayer
                searchInterfaceUID.Value = typeof(IFeatureLayer).GUID.ToString("B");
                sourceLayers             = mapControl.Map.get_Layers(searchInterfaceUID, true);

                // iterate over all of the feature layers
                sourceLayer = sourceLayers.Next();
                while (sourceLayer != null)
                {
                    // Verify that the layer is a feature layer and a display table
                    IFeatureLayer sourceFeatureLayer = sourceLayer as IFeatureLayer;
                    sourceDisplayTable = sourceLayer as IDisplayTable;
                    if ((sourceFeatureLayer != null) && (sourceDisplayTable != null))
                    {
                        // Make sure that the geometry of the feature layer matches the geometry
                        //   of the class into which we are loading
                        IFeatureClass    sourceFeatureClass = sourceFeatureLayer.FeatureClass;
                        esriGeometryType sourceGeoType      = sourceFeatureClass.ShapeType;
                        if ((sourceGeoType == targetGeoType) ||
                            (targetGeoType == esriGeometryType.esriGeometryPoint && sourceGeoType == esriGeometryType.esriGeometryMultipoint))
                        {
                            // Add the layer name to the combobox and the layer to the list
                            cboInputData.Items.Add(sourceLayer.Name);
                            m_listDisplayTable.Add(sourceDisplayTable);
                        }
                    }

                    sourceLayer = sourceLayers.Next();
                }
            }
            // The layer being loaded into has no geometry type
            else
            {
                // Find all of the standalone table that are not part of an NALayer
                IStandaloneTableCollection sourceStandaloneTables = mapControl.Map as IStandaloneTableCollection;
                IStandaloneTable           sourceStandaloneTable  = null;
                sourceDisplayTable = null;

                int count = 0;
                if (sourceStandaloneTables != null)
                {
                    count = sourceStandaloneTables.StandaloneTableCount;
                }

                for (int i = 0; i < count; ++i)
                {
                    sourceStandaloneTable = sourceStandaloneTables.get_StandaloneTable(i);
                    sourceDisplayTable    = sourceStandaloneTable as IDisplayTable;

                    if ((sourceStandaloneTable != null) && (sourceDisplayTable != null))
                    {
                        // Add the table name to the combobox and the layer to the list
                        cboInputData.Items.Add(sourceStandaloneTable.Name);
                        m_listDisplayTable.Add(sourceDisplayTable);
                    }
                }

                // Find all of the standalone tables that are part of an NALayer
                searchInterfaceUID.Value = typeof(INALayer).GUID.ToString("B");
                sourceLayers             = mapControl.Map.get_Layers(searchInterfaceUID, true);

                sourceLayer = sourceLayers.Next();
                while (sourceLayer != null)
                {
                    INALayer sourceNALayer = sourceLayer as INALayer;
                    if (sourceNALayer != null)
                    {
                        sourceStandaloneTables = sourceNALayer as IStandaloneTableCollection;
                        sourceStandaloneTable  = null;
                        sourceDisplayTable     = null;

                        count = 0;
                        if (sourceStandaloneTables != null)
                        {
                            count = sourceStandaloneTables.StandaloneTableCount;
                        }

                        for (int i = 0; i < count; ++i)
                        {
                            sourceStandaloneTable = sourceStandaloneTables.get_StandaloneTable(i);
                            sourceDisplayTable    = sourceStandaloneTable as IDisplayTable;

                            if ((sourceStandaloneTable != null) && (sourceDisplayTable != null))
                            {
                                // Add the table name to the combobox and the layer to the list
                                cboInputData.Items.Add(sourceStandaloneTable.Name);
                                m_listDisplayTable.Add(sourceDisplayTable);
                            }
                        }
                    }

                    sourceLayer = sourceLayers.Next();
                }
            }
        }
Exemplo n.º 10
0
        public static void AddDataset(IBasicMap pMap, IDataset pDataset, string dsName)
        {
            IFeatureLayer fDOGraphicsLayerClass;
            IFeatureClass j;
            IFeatureLayer featureLayerClass;

            if (dsName == null)
            {
                dsName = "";
            }
            switch (pDataset.Type)
            {
            case esriDatasetType.esriDTFeatureDataset:
            {
                IEnumDataset subsets = pDataset.Subsets;
                subsets.Reset();
                for (IDataset i = subsets.Next(); i != null; i = subsets.Next())
                {
                    MapHelper.AddDataset(pMap, i, dsName);
                }
                return;
            }

            case esriDatasetType.esriDTFeatureClass:
            {
                IFeatureClass idataset0 = (IFeatureClass)pDataset;
                if (idataset0.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    fDOGraphicsLayerClass = new FDOGraphicsLayerClass();
                    try
                    {
                        fDOGraphicsLayerClass.FeatureClass = idataset0;
                        fDOGraphicsLayerClass.Name         = string.Concat(dsName, idataset0.AliasName);
                        pMap.AddLayer(fDOGraphicsLayerClass);
                        return;
                    }
                    catch (Exception exception)
                    {
                        exception.ToString();
                        return;
                    }
                }
                else if (idataset0.FeatureType != esriFeatureType.esriFTDimension)
                {
                    fDOGraphicsLayerClass = new FeatureLayerClass()
                    {
                        FeatureClass = idataset0,
                        Name         = string.Concat(dsName, idataset0.AliasName)
                    };
                    pMap.AddLayer(fDOGraphicsLayerClass);
                    return;
                }
                else
                {
                    fDOGraphicsLayerClass = new DimensionLayerClass()
                    {
                        FeatureClass = idataset0,
                        Name         = string.Concat(dsName, idataset0.AliasName)
                    };
                    pMap.AddLayer(fDOGraphicsLayerClass);
                    return;
                }
                break;
            }

            case esriDatasetType.esriDTPlanarGraph:
            case esriDatasetType.esriDTText:
            case esriDatasetType.esriDTRelationshipClass:
            {
                return;
            }

            case esriDatasetType.esriDTGeometricNetwork:
            {
                IGeometricNetwork geometricNetwork = pDataset as IGeometricNetwork;
                if (geometricNetwork == null)
                {
                    return;
                }
                IEnumFeatureClass classesByType =
                    geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleJunction];
                classesByType.Reset();
                for (j = classesByType.Next(); j != null; j = classesByType.Next())
                {
                    featureLayerClass = new FeatureLayerClass()
                    {
                        FeatureClass = j,
                        Name         = string.Concat(dsName, (j as IDataset).Name)
                    };
                    pMap.AddLayer(featureLayerClass);
                }
                classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexJunction];
                classesByType.Reset();
                for (j = classesByType.Next(); j != null; j = classesByType.Next())
                {
                    featureLayerClass = new FeatureLayerClass()
                    {
                        FeatureClass = j,
                        Name         = string.Concat(dsName, (j as IDataset).Name)
                    };
                    pMap.AddLayer(featureLayerClass);
                }
                classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleEdge];
                classesByType.Reset();
                for (j = classesByType.Next(); j != null; j = classesByType.Next())
                {
                    featureLayerClass = new FeatureLayerClass()
                    {
                        FeatureClass = j,
                        Name         = string.Concat(dsName, (j as IDataset).Name)
                    };
                    pMap.AddLayer(featureLayerClass);
                }
                classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexEdge];
                classesByType.Reset();
                for (j = classesByType.Next(); j != null; j = classesByType.Next())
                {
                    featureLayerClass = new FeatureLayerClass()
                    {
                        FeatureClass = j,
                        Name         = string.Concat(dsName, (j as IDataset).Name)
                    };
                    pMap.AddLayer(featureLayerClass);
                }
                return;
            }

            case esriDatasetType.esriDTTopology:
            {
                ITopologyLayer topologyLayerClass = new TopologyLayerClass()
                {
                    Topology = pDataset as ITopology
                };
                (topologyLayerClass as ILayer).Name = string.Concat(dsName, pDataset.Name);
                pMap.AddLayer(topologyLayerClass as ILayer);
                return;
            }

            case esriDatasetType.esriDTTable:
            {
                try
                {
                    IRasterCatalogTable rasterCatalogTableClass = new RasterCatalogTable()
                    {
                        Table = (ITable)pDataset
                    };
                    rasterCatalogTableClass.Update();
                    IRasterCatalogLayer rasterCatalogLayerClass = new RasterCatalogLayerClass();
                    rasterCatalogLayerClass.Create(rasterCatalogTableClass);
                    rasterCatalogLayerClass.Name = string.Concat(dsName, pDataset.BrowseName);
                    pMap.AddLayer(rasterCatalogLayerClass);
                    return;
                }
                catch
                {
                    try
                    {
                        IStandaloneTableCollection ibasicMap0 = pMap as IStandaloneTableCollection;
                        IPropertySet connectionProperties     = pDataset.Workspace.ConnectionProperties;
                        bool         flag = false;
                        int          num  = 0;
                        while (true)
                        {
                            if (num < ibasicMap0.StandaloneTableCount)
                            {
                                ITable table = ibasicMap0.StandaloneTable[num].Table;
                                if (
                                    !connectionProperties.IsEqual((table as IDataset).Workspace.ConnectionProperties) ||
                                    !((table as IDataset).Name == pDataset.Name))
                                {
                                    num++;
                                }
                                else
                                {
                                    flag = true;
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (!flag)
                        {
                            ibasicMap0.AddStandaloneTable(new StandaloneTableClass()
                                {
                                    Table = pDataset as ITable
                                });
                        }
                    }
                    catch (Exception exception1)
                    {
                        Logger.Current.Write(exception1.Message, LogLevel.Error, null);
                    }
                    return;
                }
                break;
            }

            case esriDatasetType.esriDTRasterDataset:
            case esriDatasetType.esriDTRasterBand:
            {
                IRasterLayer rasterLayerClass = new RasterLayerClass();
                rasterLayerClass.CreateFromDataset((IRasterDataset)pDataset);
                rasterLayerClass.Name = string.Concat(dsName, pDataset.Name);
                pMap.AddLayer(rasterLayerClass);
                return;
            }

            case esriDatasetType.esriDTTin:
            {
                ITinLayer tinLayerClass = new TinLayerClass()
                {
                    Dataset = (ITin)pDataset,
                    Name    = string.Concat(dsName, pDataset.Name)
                };
                pMap.AddLayer(tinLayerClass);
                return;
            }

            case esriDatasetType.esriDTCadDrawing:
            {
                ICadLayer cadLayerClass = new CadLayerClass()
                {
                    CadDrawingDataset = pDataset as ICadDrawingDataset,
                    Name = pDataset.Name
                };
                pMap.AddLayer(cadLayerClass);
                return;
            }

            default:
            {
                return;
            }
            }
        }
Exemplo n.º 11
0
        public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv)
        {
            // Initialize variables
            m_okClicked        = false;
            m_listDisplayTable = new System.Collections.ArrayList();

            // Get the NALayer and NAContext
            INALayer   naLayer   = naEnv.NAWindow.ActiveAnalysis;
            INAContext naContext = naLayer.Context;

            //Get the active category
            IEngineNAWindowCategory2 activeCategory = naEnv.NAWindow.ActiveCategory as IEngineNAWindowCategory2;

            if (activeCategory == null)
            {
                return(false);
            }

            INAClass   naClass    = activeCategory.NAClass;
            IDataset   naDataset  = naClass as IDataset;
            IDataLayer pDataLayer = activeCategory.DataLayer;

            ILayer           pLayer           = pDataLayer as ILayer;
            IFeatureLayer    pFeatureLayer    = pDataLayer as IFeatureLayer;
            IStandaloneTable pStandaloneTable = pDataLayer as IStandaloneTable;

            esriGeometryType targetGeoType = esriGeometryType.esriGeometryNull;

            String dataLayerName = "";

            if (pFeatureLayer != null)
            {
                if (pLayer.Valid)
                {
                    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                    if (pFeatureClass != null)
                    {
                        targetGeoType = pFeatureClass.ShapeType;
                        dataLayerName = pLayer.Name;
                    }
                }
            }
            else if (pStandaloneTable != null)
            {
                dataLayerName = pStandaloneTable.Name;
            }

            if (dataLayerName.Length == 0)
            {
                return(false);
            }

            this.Text = "Load Items into " + dataLayerName;

            // Loop through all the sourcedisplayTables having targetGeoType to the combo box and the
            // list of displayTables

            IEnumLayer    sourceLayers       = null;
            ILayer        sourceLayer        = null;
            IDisplayTable sourceDisplayTable = null;
            UID           searchInterfaceUID = new UID();

            if (targetGeoType != esriGeometryType.esriGeometryNull)
            {
                searchInterfaceUID.Value = typeof(IFeatureLayer).GUID.ToString("B");
                sourceLayers             = mapControl.Map.get_Layers(searchInterfaceUID, true);

                sourceLayer = sourceLayers.Next();
                while (sourceLayer != null)
                {
                    IFeatureLayer sourceFeatureLayer = sourceLayer as IFeatureLayer;
                    sourceDisplayTable = sourceLayer as IDisplayTable;

                    if ((sourceFeatureLayer != null) && (sourceDisplayTable != null))
                    {
                        IFeatureClass    sourceFeatureClass = sourceFeatureLayer.FeatureClass;
                        esriGeometryType sourceGeoType      = sourceFeatureClass.ShapeType;
                        if ((sourceGeoType == targetGeoType) ||
                            (targetGeoType == esriGeometryType.esriGeometryPoint && sourceGeoType == esriGeometryType.esriGeometryMultipoint))
                        {
                            // Add the layer name to the combobox and the layer to the list
                            cboInputData.Items.Add(sourceLayer.Name);
                            m_listDisplayTable.Add(sourceDisplayTable);
                        }
                    }

                    sourceLayer = sourceLayers.Next();
                }
            }
            else //if (targetGeoType == esriGeometryType.esriGeometryNull)
            {
                IStandaloneTableCollection sourceStandaloneTables = mapControl.Map as IStandaloneTableCollection;
                IStandaloneTable           sourceStandaloneTable  = null;
                sourceDisplayTable = null;

                int count = 0;
                if (sourceStandaloneTables != null)
                {
                    count = sourceStandaloneTables.StandaloneTableCount;
                }

                for (int i = 0; i < count; ++i)
                {
                    sourceStandaloneTable = sourceStandaloneTables.get_StandaloneTable(i);
                    sourceDisplayTable    = sourceStandaloneTable as IDisplayTable;

                    if ((sourceStandaloneTable != null) && (sourceDisplayTable != null))
                    {
                        // Add the table name to the combobox and the layer to the list
                        cboInputData.Items.Add(sourceStandaloneTable.Name);
                        m_listDisplayTable.Add(sourceDisplayTable);
                    }
                }

                searchInterfaceUID.Value = typeof(INALayer).GUID.ToString("B");
                sourceLayers             = mapControl.Map.get_Layers(searchInterfaceUID, true);

                sourceLayer = sourceLayers.Next();
                while (sourceLayer != null)
                {
                    INALayer sourceNALayer = sourceLayer as INALayer;
                    if (sourceNALayer != null)
                    {
                        sourceStandaloneTables = sourceNALayer as IStandaloneTableCollection;
                        sourceStandaloneTable  = null;
                        sourceDisplayTable     = null;

                        count = 0;
                        if (sourceStandaloneTables != null)
                        {
                            count = sourceStandaloneTables.StandaloneTableCount;
                        }

                        for (int i = 0; i < count; ++i)
                        {
                            sourceStandaloneTable = sourceStandaloneTables.get_StandaloneTable(i);
                            sourceDisplayTable    = sourceStandaloneTable as IDisplayTable;

                            if ((sourceStandaloneTable != null) && (sourceDisplayTable != null))
                            {
                                // Add the table name to the combobox and the layer to the list
                                cboInputData.Items.Add(sourceStandaloneTable.Name);
                                m_listDisplayTable.Add(sourceDisplayTable);
                            }
                        }
                    }

                    sourceLayer = sourceLayers.Next();
                }
            }

            //Select the first display table from the list
            if (cboInputData.Items.Count > 0)
            {
                cboInputData.SelectedIndex = 0;
            }

            // Show the window
            this.ShowDialog();

            // If we selected a layer and clicked OK, load the locations
            if (m_okClicked && (cboInputData.SelectedIndex >= 0))
            {
                // Get a cursor on the source display table (either though the selection set or table)
                // Use IDisplayTable because it accounts for joins, querydefs, etc.
                // IDisplayTable is implemented by FeatureLayers and StandaloneTables.
                //
                IDisplayTable displayTable = m_listDisplayTable[cboInputData.SelectedIndex] as IDisplayTable;
                ICursor       cursor;
                if (chkUseSelection.Checked)
                {
                    ISelectionSet selSet;
                    selSet = displayTable.DisplaySelectionSet;
                    selSet.Search(null, false, out cursor);
                }
                else
                {
                    cursor = displayTable.SearchDisplayTable(null, false);
                }

                // Setup NAClassLoader and Load Locations
                INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2;
                naClassLoader.Initialize(naContext, naDataset.Name, cursor);

                // Avoid loading network locations onto non-traversable portions of elements
                INALocator3 locator = naContext.Locator as INALocator3;
                locator.ExcludeRestrictedElements = true;
                locator.CacheRestrictedElements(naContext);

                int rowsIn      = 0;
                int rowsLocated = 0;
                naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);

                return(true);
            }

            return(false);
        }
Exemplo n.º 12
0
        public void ExportSelectedRecordsToExcel()
        {
            ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null;
            ESRI.ArcGIS.esriSystem.IStepProgressor       stepProgressor        = null;
            ESRI.ArcGIS.Framework.IProgressDialog2       progressDialog        = null;
            IMxDocument mxdoc = null;
            IMap        map   = null;
            IStandaloneTableCollection standTabColl = null;
            IStandaloneTable           standTable   = null;
            ITableSelection            tableSel     = null;
            IEnumFeature      enumFeat  = null;
            IFeature          feat      = null;
            IFeatureSelection featSel   = null;
            ITable            openTable = null;
            object            missing   = null;
            //object fileName = null;
            object newTemplate = null;
            object docType     = null;
            object isVisible   = null;


            UID geoFeatureLayerID = null;

            IEnumLayer    enumLayer = null;
            IFeatureLayer featlayer = null;

            try
            {
                mxdoc = (IMxDocument)_app.Document;
                map   = mxdoc.FocusMap;

                long standTableCnt;
                int  i = 0;
                bool selectionInTable = false;


                missing = System.Reflection.Missing.Value;
                // fileName = "normal.dot";
                newTemplate = false;
                docType     = 0;
                isVisible   = true;

                //Get enumeration of feature layers
                geoFeatureLayerID       = new UIDClass();
                geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
                enumLayer = map.get_Layers(geoFeatureLayerID, true);

                enumLayer.Reset();

                standTabColl  = (IStandaloneTableCollection)map;
                standTableCnt = standTabColl.StandaloneTableCount;

                enumFeat = (IEnumFeature)map.FeatureSelection;
                enumFeat.Reset();
                feat = enumFeat.Next();



                if (standTableCnt > 0)
                {
                    for (int j = 0; j < standTableCnt; j++)
                    {
                        standTable = standTabColl.get_StandaloneTable(j);
                        if (standTable.Valid)
                        {
                            openTable = (ITable)standTable;
                            tableSel  = (ITableSelection)openTable;
                            if (tableSel.SelectionSet.Count > 0)
                            {
                                selectionInTable = true;
                                break;
                            }
                        }
                    }
                }

                if ((selectionInTable == false) && (feat == null))
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("DataToolsMess_1") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("DataToolsMess_2"), messageBoxHeader);
                    return;
                }
                // Create a CancelTracker
                ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();

                // Set the properties of the Step Progressor
                System.Int32 int32_hWnd = _app.hWnd;

                progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();
                stepProgressor        = progressDialogFactory.Create(trackCancel, int32_hWnd);



                stepProgressor.MinRange  = 0;
                stepProgressor.MaxRange  = mxdoc.FocusMap.SelectionCount;
                stepProgressor.StepValue = 1;
                stepProgressor.Message   = A4LGSharedFunctions.Localizer.GetString("ExportXL");
                // Create the ProgressDialog. This automatically displays the dialog
                progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast

                // Set the properties of the ProgressDialog
                progressDialog.CancelEnabled = true;
                progressDialog.Description   = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + "1" + A4LGSharedFunctions.Localizer.GetString("Of") + mxdoc.FocusMap.SelectionCount.ToString() + ".";
                progressDialog.Title         = A4LGSharedFunctions.Localizer.GetString("ExportXL");
                progressDialog.Animation     = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe;
                progressDialog.ShowDialog();

                if ((feat != null) && (selectionInTable == true))
                {
                    ExcelApp = new Excel.ApplicationClass();


                    //Delete default worksheets
                    ExcelApp.DisplayAlerts = false;
                    objBook = ExcelApp.Workbooks.Add(missing);
                    //objBook = ExcelApp.Workbooks.get_Item(1);
                    for (int m = objBook.Sheets.Count; m > 1; m--)
                    {
                        objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(m);
                        objSheet.Delete();
                    }

                    featlayer = (IFeatureLayer)enumLayer.Next();
                    while (featlayer != null)
                    {
                        if ((featlayer.Valid) && (featlayer.Selectable))
                        {
                            featSel = (IFeatureSelection)featlayer;
                            if (featSel.SelectionSet.Count > 0)
                            {
                                if (ExportLayer(objBook, mxdoc, featlayer, ref progressDialog, ref stepProgressor, ref trackCancel) == false)
                                {
                                    return;
                                }
                            }
                        }
                        featlayer = (IFeatureLayer)enumLayer.Next();
                    }

                    for (i = 0; i < standTableCnt; i++)
                    {
                        standTable = standTabColl.get_StandaloneTable(i);
                        if (standTable.Valid)
                        {
                            openTable = (ITable)standTable;
                            tableSel  = (ITableSelection)openTable;
                            if (tableSel.SelectionSet.Count > 0)
                            {
                                if (ExportTable(objBook, mxdoc, standTable, ref progressDialog, ref stepProgressor, ref trackCancel) == false)
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
                else if ((feat != null) && (selectionInTable == false))
                {
                    ExcelApp = new Excel.ApplicationClass();

                    //Delete default worksheets
                    ExcelApp.DisplayAlerts = false;
                    objBook = ExcelApp.Workbooks.Add(missing);
                    //objBook = ExcelApp.Workbooks.get_Item(1);
                    for (int m = objBook.Sheets.Count; m > 1; m--)
                    {
                        objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(m);
                        objSheet.Delete();
                    }


                    ILayer pTLay = enumLayer.Next();
                    while (pTLay != null)
                    {
                        if (pTLay is IFeatureLayer)
                        {
                            featlayer = (IFeatureLayer)pTLay;
                            if ((featlayer.Valid))
                            {
                                featSel = (IFeatureSelection)featlayer;
                                if (featSel.SelectionSet.Count > 0)
                                {
                                    if (ExportLayer(objBook, mxdoc, featlayer, ref progressDialog, ref stepProgressor, ref trackCancel) == false)
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        pTLay = enumLayer.Next();
                    }
                    pTLay = null;
                }
                else if ((feat == null) && (selectionInTable == true))
                {
                    ExcelApp = new Excel.ApplicationClass();

                    //Delete default worksheets
                    ExcelApp.DisplayAlerts = false;
                    objBook = ExcelApp.Workbooks.Add(missing);
                    //objBook = ExcelApp.Workbooks.get_Item(1);
                    for (int m = objBook.Sheets.Count; m > 1; m--)
                    {
                        objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(m);
                        objSheet.Delete();
                    }
                    for (i = 0; i < standTableCnt; i++)
                    {
                        standTable = standTabColl.get_StandaloneTable(i);
                        if (standTable.Valid)
                        {
                            openTable = (ITable)standTable;
                            tableSel  = (ITableSelection)openTable;
                            if (tableSel.SelectionSet.Count > 0)
                            {
                                if (ExportTable(objBook, mxdoc, standTable, ref progressDialog, ref stepProgressor, ref trackCancel) == false)
                                {
                                    return;
                                }
                            }
                        }
                    }
                }


                if (objBook.Sheets.Count > 1)
                {
                    objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(1);
                    objSheet.Delete();
                }
                //objSheet = (Excel.Worksheet)objBook.Sheets["Sheet2"];
                //objSheet.Delete();
                //objSheet = (Excel.Worksheet)objBook.Sheets["Sheet3"];
                //objSheet.Delete();
                ExcelApp.DisplayAlerts = true;

                //Make the first sheet active
                objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(1) as Excel.Worksheet;
                (objSheet as Microsoft.Office.Interop.Excel._Worksheet).Activate();

                //Make Excel visible
                ExcelApp.Visible = true;
                return;
            }
            catch (Exception ex)
            {
                if (ExcelApp != null)
                {
                    ExcelApp = null;
                }

                //ExcelApp.Visible = true;
                MessageBox.Show("ExportSelectedRecordsToExcel\n" + ex.Message, ex.Source);
                return;
            }
            finally
            {
                if (progressDialog != null)
                {
                    progressDialog.HideDialog();
                }

                progressDialogFactory = null;
                stepProgressor        = null;
                progressDialog        = null;
                mxdoc        = null;
                map          = null;
                standTabColl = null;
                standTable   = null;
                tableSel     = null;
                enumFeat     = null;
                feat         = null;
                featSel      = null;
                openTable    = null;
                missing      = null;
                //fileName = null;
                newTemplate = null;
                docType     = null;
                isVisible   = null;


                geoFeatureLayerID = null;

                enumLayer = null;
                featlayer = null;
            }
        }
Exemplo n.º 13
0
        public void LoadData(IList ilist_0)
        {
            IEnumDataset      subsets;
            IDataset          j;
            string            str;
            IFeatureClass     dataset;
            IFeatureLayer     cadFeatureLayerClass;
            ITopologyLayer    topologyLayerClass;
            IEnumFeatureClass classes;
            IFeatureClass     m;
            IFeatureClass     n;
            IFeatureLayer     featureLayerClass;
            List <object>     objs = new List <object>();

            foreach (object ilist0 in ilist_0)
            {
                if (ilist0 is IGxDataset)
                {
                    if ((ilist0 as IGxDataset).Type != esriDatasetType.esriDTFeatureDataset)
                    {
                        objs.Add(ilist0);
                    }
                    else
                    {
                        IEnumGxObject children = (ilist0 as IGxObjectContainer).Children;
                        children.Reset();
                        for (IGxObject i = children.Next(); i != null; i = children.Next())
                        {
                            objs.Add(i);
                        }
                    }
                }
                else if (!(ilist0 is IDataset))
                {
                    objs.Add(ilist0);
                }
                else
                {
                    if ((ilist0 as IDataset).Type != esriDatasetType.esriDTFeatureDataset)
                    {
                        continue;
                    }
                    subsets = (ilist0 as IDataset).Subsets;
                    subsets.Reset();
                    for (j = subsets.Next(); j != null; j = subsets.Next())
                    {
                        objs.Add(j);
                    }
                }
            }
            ProcessAssist processAssist = new ProcessAssist();

            processAssist.InitProgress();
            processAssist.SetMaxValue(objs.Count);
            processAssist.SetMessage("正在加载数据,请稍候...");
            processAssist.Start();
            try
            {
                ILayer layer = null;
                IMap   map   = this.GetMap();
                this.list_0 = new List <ILayer>();
                List <string> strs      = new List <string>();
                IEnvelope     envelope  = null;
                IDataset      item      = null;
                IGxDataset    gxDataset = null;
                for (int k = 0; k < objs.Count; k++)
                {
                    string name = "";
                    if (objs[k] is IGxObject)
                    {
                        name = (objs[k] as IGxObject).Name;
                    }
                    else if (objs[k] is IDataset)
                    {
                        name = (objs[k] as IDataset).Name;
                    }
                    bool flag = true;
                    str = string.Format("加载图层[{0}],第{1}/{2}个", name, k + 1, objs.Count);
                    processAssist.Increment(1);
                    processAssist.SetMessage(str);
                    if (objs[k] is IGxLayer)
                    {
                        layer = (objs[k] as IGxLayer).Layer;
                        if (layer is IGeoDataset && !SpatialReferenctOperator.ValideFeatureClass(layer as IGeoDataset))
                        {
                            strs.Add(layer.Name);
                            flag = false;
                        }
                        this.AddLayer(map, layer, ref envelope, flag);
                    }
                    else if (!(objs[k] is IGxAGSObject))
                    {
                        if (objs[k] is IGxDataset)
                        {
                            gxDataset = objs[k] as IGxDataset;
                            item      = gxDataset.Dataset;
                        }
                        else if (ilist_0[k] is IDataset)
                        {
                            item = objs[k] as IDataset;
                        }
                        if (item != null)
                        {
                            if (item is IGeoDataset)
                            {
                                flag = SpatialReferenctOperator.ValideFeatureClass(item as IGeoDataset);
                            }
                            if (item.Type == esriDatasetType.esriDTFeatureClass)
                            {
                                dataset = (IFeatureClass)item;
                                if ((gxDataset as IGxObject).Category.IndexOf("CAD") != -1)
                                {
                                    if (dataset.FeatureType != esriFeatureType.esriFTCoverageAnnotation)
                                    {
                                        cadFeatureLayerClass = new CadFeatureLayerClass();
                                    }
                                    else
                                    {
                                        cadFeatureLayerClass = new CadAnnotationLayerClass();
                                    }
                                    cadFeatureLayerClass.FeatureClass = dataset;
                                    cadFeatureLayerClass.Name         = dataset.AliasName;
                                }
                                else if (dataset.FeatureType == esriFeatureType.esriFTAnnotation)
                                {
                                    cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                else if (dataset.FeatureType != esriFeatureType.esriFTDimension)
                                {
                                    cadFeatureLayerClass = new FeatureLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                else
                                {
                                    cadFeatureLayerClass = new DimensionLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                if (!flag)
                                {
                                    strs.Add(cadFeatureLayerClass.Name);
                                }
                                this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                            }
                            else if (item.Type == esriDatasetType.esriDTCadDrawing)
                            {
                                if ((gxDataset as IGxObject).Category != "CAD绘图")
                                {
                                    IEnumGxObject enumGxObject = (gxDataset as IGxObjectContainer).Children;
                                    enumGxObject.Reset();
                                    for (IGxDataset l = enumGxObject.Next() as IGxDataset; l != null; l = enumGxObject.Next() as IGxDataset)
                                    {
                                        dataset = l.Dataset as IFeatureClass;
                                        if (dataset != null)
                                        {
                                            if (dataset.FeatureType != esriFeatureType.esriFTAnnotation)
                                            {
                                                cadFeatureLayerClass = new CadFeatureLayerClass()
                                                {
                                                    FeatureClass = dataset,
                                                    Name         = dataset.AliasName
                                                };
                                            }
                                            else
                                            {
                                                cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                                {
                                                    FeatureClass = dataset,
                                                    Name         = dataset.AliasName
                                                };
                                            }
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag1 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag1;
                                                if (!flag1)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                    }
                                }
                                else
                                {
                                    ICadLayer cadLayerClass = new CadLayerClass()
                                    {
                                        CadDrawingDataset = gxDataset.Dataset as ICadDrawingDataset,
                                        Name = gxDataset.Dataset.Name
                                    };
                                    if (!flag)
                                    {
                                        strs.Add(cadLayerClass.Name);
                                    }
                                    this.AddLayer(map, cadLayerClass, ref envelope, flag);
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTFeatureDataset)
                            {
                                subsets = item.Subsets;
                                subsets.Reset();
                                for (j = subsets.Next(); j != null; j = subsets.Next())
                                {
                                    if (j.Type == esriDatasetType.esriDTFeatureClass)
                                    {
                                        dataset = j as IFeatureClass;
                                        if (dataset.FeatureType != esriFeatureType.esriFTAnnotation)
                                        {
                                            cadFeatureLayerClass = new FeatureLayerClass()
                                            {
                                                FeatureClass = dataset,
                                                Name         = dataset.AliasName
                                            };
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag2 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag2;
                                                if (!flag2)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                        else
                                        {
                                            cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                            {
                                                FeatureClass = dataset,
                                                Name         = dataset.AliasName
                                            };
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag3 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag3;
                                                if (!flag3)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                    }
                                    else if (j.Type == esriDatasetType.esriDTTopology)
                                    {
                                        topologyLayerClass = new TopologyLayerClass()
                                        {
                                            Topology = j as ITopology
                                        };
                                        (topologyLayerClass as ILayer).Name = j.Name;
                                        this.AddLayer(map, topologyLayerClass as ILayer, ref envelope, true);
                                    }
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTTopology)
                            {
                                if (MessageBox.Show(string.Concat("是否将参加拓扑-", item.Name, "-的所有要素添加到地图中"), "添加拓扑层", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                                {
                                    classes = (item as IFeatureClassContainer).Classes;
                                    classes.Reset();
                                    for (m = classes.Next(); m != null; m = classes.Next())
                                    {
                                        cadFeatureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = m,
                                            Name         = m.AliasName
                                        };
                                        flag = true;
                                        if (cadFeatureLayerClass is IGeoDataset)
                                        {
                                            bool flag4 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                            flag = flag4;
                                            if (!flag4)
                                            {
                                                strs.Add(cadFeatureLayerClass.Name);
                                            }
                                        }
                                        this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                    }
                                }
                                topologyLayerClass = new TopologyLayerClass()
                                {
                                    Topology = item as ITopology
                                };
                                (topologyLayerClass as ILayer).Name = item.Name;
                                this.AddLayer(map, topologyLayerClass as ILayer, ref envelope, true);
                            }
                            else if (item.Type == esriDatasetType.esriDTTin)
                            {
                                ITinLayer tinLayerClass = new TinLayerClass()
                                {
                                    Dataset = (ITin)item,
                                    Name    = item.Name
                                };
                                flag = true;
                                if (tinLayerClass is IGeoDataset)
                                {
                                    bool flag5 = SpatialReferenctOperator.ValideFeatureClass(tinLayerClass as IGeoDataset);
                                    flag = flag5;
                                    if (!flag5)
                                    {
                                        strs.Add(tinLayerClass.Name);
                                    }
                                }
                                this.AddLayer(map, tinLayerClass, ref envelope, flag);
                            }
                            else if (item.Type == esriDatasetType.esriDTRasterCatalog)
                            {
                                IGdbRasterCatalogLayer gdbRasterCatalogLayerClass = null;
                                gdbRasterCatalogLayerClass = new GdbRasterCatalogLayerClass();
                                if (gdbRasterCatalogLayerClass.Setup((ITable)(item as IRasterCatalog)))
                                {
                                    bool flag6 = SpatialReferenctOperator.ValideFeatureClass(gdbRasterCatalogLayerClass as IGeoDataset);
                                    flag = flag6;
                                    if (!flag6)
                                    {
                                        strs.Add((gdbRasterCatalogLayerClass as ILayer).Name);
                                    }
                                    this.AddLayer(map, gdbRasterCatalogLayerClass as ILayer, ref envelope, flag);
                                }
                            }
                            else if (!(item.Type == esriDatasetType.esriDTRasterDataset ? false : item.Type != esriDatasetType.esriDTRasterBand))
                            {
                                bool flag7 = true;
                                if (!((IRasterPyramid)item).Present)
                                {
                                    if (this.m_pApp.PyramidPromptType == PyramidPromptType.AlwaysBuildNoPrompt)
                                    {
                                        ((IRasterPyramid)item).Create();
                                    }
                                    else if (this.m_pApp.PyramidPromptType == PyramidPromptType.AlwaysPrompt)
                                    {
                                        DialogResult dialogResult = BuildPyramidSet.Show();
                                        if (dialogResult == DialogResult.Yes)
                                        {
                                            ((IRasterPyramid)item).Create();
                                        }
                                        else if (dialogResult == DialogResult.Cancel)
                                        {
                                            flag7 = false;
                                        }
                                    }
                                }
                                if (flag7)
                                {
                                    IRasterLayer rasterLayerClass = new RasterLayerClass()
                                    {
                                        Cached = true
                                    };
                                    rasterLayerClass.CreateFromDataset((IRasterDataset)item);
                                    rasterLayerClass.Name = item.Name;
                                    bool flag8 = SpatialReferenctOperator.ValideFeatureClass(rasterLayerClass as IGeoDataset);
                                    flag = flag8;
                                    if (!flag8)
                                    {
                                        strs.Add(rasterLayerClass.Name);
                                    }
                                    this.AddLayer(map, rasterLayerClass, ref envelope, flag);
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTTable)
                            {
                                try
                                {
                                    IStandaloneTableCollection standaloneTableCollection = this.GetMap() as IStandaloneTableCollection;
                                    IPropertySet connectionProperties = item.Workspace.ConnectionProperties;
                                    bool         flag9 = false;
                                    int          num   = 0;
                                    while (true)
                                    {
                                        if (num < standaloneTableCollection.StandaloneTableCount)
                                        {
                                            ITable table = standaloneTableCollection.StandaloneTable[num].Table;
                                            if (!connectionProperties.IsEqual((table as IDataset).Workspace.ConnectionProperties) || !((table as IDataset).Name == item.Name))
                                            {
                                                num++;
                                            }
                                            else
                                            {
                                                flag9 = true;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    if (!flag9)
                                    {
                                        standaloneTableCollection.AddStandaloneTable(new StandaloneTableClass()
                                        {
                                            Table = item as ITable
                                        });
                                    }
                                }
                                catch (Exception exception)
                                {
                                    CErrorLog.writeErrorLog(this, exception, "");
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTGeometricNetwork)
                            {
                                IGeometricNetwork geometricNetwork = item as IGeometricNetwork;
                                if (geometricNetwork != null)
                                {
                                    IEnumFeatureClass classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleJunction];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexJunction];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleEdge];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexEdge];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTNetworkDataset)
                            {
                                INetworkLayer networkLayerClass = new NetworkLayerClass()
                                {
                                    NetworkDataset = item as INetworkDataset
                                };
                                this.AddLayer(map, networkLayerClass as ILayer, ref envelope, true);
                                if (MessageBox.Show(string.Concat("是否将参加网络要素集-", item.Name, "-的所有要素添加到地图中"), "添加拓扑层", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                                {
                                    classes = (item as IFeatureClassContainer).Classes;
                                    classes.Reset();
                                    for (m = classes.Next(); m != null; m = classes.Next())
                                    {
                                        cadFeatureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = m,
                                            Name         = m.AliasName
                                        };
                                        this.AddLayer(map, cadFeatureLayerClass, ref envelope, true);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        IMapServerLayer mapServerLayerClass = new MapServerLayerClass();
                        mapServerLayerClass.ServerConnect((objs[k] as IGxAGSObject).AGSServerObjectName, (objs[k] as IGxAGSObject).DefaultMapName);
                        this.AddLayer(map, mapServerLayerClass as ILayer, ref envelope, false);
                    }
                }
                processAssist.End();
                bool layerCount = this.GetMap().LayerCount > 0;
                if (strs.Count > 0)
                {
                    MessageBox.Show("警告:数据范围不一致。\r\n 一个或多个添加的图层范围与关联的空间坐标系范围不一致。请检查数据问题。存在问题图层信息请查看错误日志!", "管理平台", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (string str1 in strs)
                    {
                        if (stringBuilder.Length > 0)
                        {
                            stringBuilder.Append(",");
                        }
                        stringBuilder.Append(str1);
                    }
                    CErrorLog.writeErrorLog(stringBuilder, null, "图层范围不一致!");
                }
                foreach (ILayer list0 in this.list_0)
                {
                    list0.Visible = true;
                }
                if (layerCount && envelope != null)
                {
                    IMap map1 = this.GetMap();
                    ISpatialReference spatialReference = map1.SpatialReference;
                    if ((spatialReference is IUnknownCoordinateSystem || envelope.SpatialReference is IUnknownCoordinateSystem || envelope.SpatialReference == null ? false : spatialReference != null))
                    {
                        envelope.Project(spatialReference);
                    }
                    (map1 as IActiveView).Extent = envelope;
                    (map1 as IActiveView).Refresh();
                }
                if (this.m_pApp != null)
                {
                    this.m_pApp.MapDocumentChanged();
                }
                else if (ApplicationRef.Application != null)
                {
                    ApplicationRef.Application.MapDocumentChanged();
                }
            }
            catch (Exception exception1)
            {
                str = exception1.ToString();
            }
            if (this.onLoadCompleteHand_0 != null)
            {
                this.onLoadCompleteHand_0();
            }
        }
Exemplo n.º 14
0
        public void LoadData(IList ilist_0)
        {
            try
            {
                List <ILayer> list = new List <ILayer>();
                for (int i = 0; i < ilist_0.Count; i++)
                {
                    if (ilist_0[i] is IGxLayer)
                    {
                        list.Add((ilist_0[i] as IGxLayer).Layer);
                    }
                    else
                    {
                        IGxDataset gxDataset = ilist_0[i] as IGxDataset;
                        if (gxDataset != null)
                        {
                            IDataset dataset = gxDataset.Dataset;
                            if (dataset != null)
                            {
                                if (dataset.Type == esriDatasetType.esriDTFeatureClass)
                                {
                                    IFeatureClass featureClass = (IFeatureClass)dataset;
                                    IFeatureLayer featureLayer;
                                    if ((gxDataset as IGxObject).Category.IndexOf("CAD") != -1)
                                    {
                                        if (featureClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
                                        {
                                            featureLayer = new CadAnnotationLayer() as IFeatureLayer;
                                        }
                                        else
                                        {
                                            featureLayer = new CadFeatureLayer() as IFeatureLayer;
                                        }
                                        featureLayer.FeatureClass = featureClass;
                                        featureLayer.Name         = featureClass.AliasName;
                                    }
                                    else if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                                    {
                                        featureLayer = new FDOGraphicsLayer() as IFeatureLayer;
                                        featureLayer.FeatureClass = featureClass;
                                        featureLayer.Name         = featureClass.AliasName;
                                    }
                                    else if (featureClass.FeatureType == esriFeatureType.esriFTDimension)
                                    {
                                        featureLayer = new DimensionLayer() as IFeatureLayer;
                                        featureLayer.FeatureClass = featureClass;
                                        featureLayer.Name         = featureClass.AliasName;
                                    }
                                    else
                                    {
                                        featureLayer = new FeatureLayer();
                                        featureLayer.FeatureClass = featureClass;
                                        featureLayer.Name         = featureClass.AliasName;
                                    }
                                    list.Add(featureLayer);
                                }
                                else if (dataset.Type == esriDatasetType.esriDTCadDrawing)
                                {
                                    if ((gxDataset as IGxObject).Category == "CAD绘图")
                                    {
                                        ICadLayer item = new CadLayer() as ICadLayer;
                                        item.CadDrawingDataset = gxDataset.Dataset as ICadDrawingDataset;
                                        item.Name = gxDataset.Dataset.Name;
                                        list.Add(item);
                                    }
                                    else
                                    {
                                        IEnumGxObject children = (gxDataset as IGxObjectContainer).Children;
                                        children.Reset();
                                        for (IGxDataset gxDataset2 = children.Next() as IGxDataset; gxDataset2 != null; gxDataset2 = (children.Next() as IGxDataset))
                                        {
                                            IFeatureClass featureClass = gxDataset2.Dataset as IFeatureClass;
                                            if (featureClass != null)
                                            {
                                                IFeatureLayer featureLayer;
                                                if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                                                {
                                                    featureLayer = new FDOGraphicsLayer() as IFeatureLayer;
                                                    featureLayer.FeatureClass = featureClass;
                                                    featureLayer.Name         = featureClass.AliasName;
                                                }
                                                else
                                                {
                                                    featureLayer = new CadFeatureLayer() as IFeatureLayer;
                                                    featureLayer.FeatureClass = featureClass;
                                                    featureLayer.Name         = featureClass.AliasName;
                                                }
                                                list.Add(featureLayer);
                                            }
                                        }
                                    }
                                }
                                else if (dataset.Type == esriDatasetType.esriDTFeatureDataset)
                                {
                                    IEnumDataset subsets = dataset.Subsets;
                                    subsets.Reset();
                                    for (IDataset dataset2 = subsets.Next(); dataset2 != null; dataset2 = subsets.Next())
                                    {
                                        if (dataset2.Type == esriDatasetType.esriDTFeatureClass)
                                        {
                                            IFeatureClass featureClass = dataset2 as IFeatureClass;
                                            if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                                            {
                                                IFeatureLayer item = new FDOGraphicsLayer() as IFeatureLayer;
                                                item.FeatureClass = featureClass;
                                                item.Name         = featureClass.AliasName;
                                                list.Add(item);
                                            }
                                            else
                                            {
                                                list.Add(new FeatureLayer
                                                {
                                                    FeatureClass = featureClass,
                                                    Name         = featureClass.AliasName
                                                });
                                            }
                                        }
                                        else if (dataset2.Type == esriDatasetType.esriDTTopology)
                                        {
                                            ITopologyLayer topologyLayer = new TopologyLayer() as ITopologyLayer;
                                            topologyLayer.Topology         = (dataset2 as ITopology);
                                            (topologyLayer as ILayer).Name = dataset2.Name;
                                            list.Add(topologyLayer as ILayer);
                                        }
                                    }
                                }
                                else if (dataset.Type == esriDatasetType.esriDTTopology)
                                {
                                    if (System.Windows.Forms.MessageBox.Show("是否将参加拓扑-" + dataset.Name + "-的所有要素添加到地图中", "添加拓扑层", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Asterisk) == System.Windows.Forms.DialogResult.Yes)
                                    {
                                        IEnumFeatureClass classes = (dataset as IFeatureClassContainer).Classes;
                                        classes.Reset();
                                        for (IFeatureClass featureClass2 = classes.Next(); featureClass2 != null; featureClass2 = classes.Next())
                                        {
                                            list.Add(new FeatureLayer
                                            {
                                                FeatureClass = featureClass2,
                                                Name         = featureClass2.AliasName
                                            });
                                        }
                                    }
                                    ITopologyLayer topologyLayer = new TopologyLayer() as ITopologyLayer;
                                    topologyLayer.Topology         = (dataset as ITopology);
                                    (topologyLayer as ILayer).Name = dataset.Name;
                                    list.Add(topologyLayer as ILayer);
                                }
                                else if (dataset.Type == esriDatasetType.esriDTTin)
                                {
                                    list.Add(new TinLayer
                                    {
                                        Dataset = (ITin)dataset,
                                        Name    = dataset.Name
                                    });
                                }
                                else if (dataset.Type == esriDatasetType.esriDTRasterDataset || dataset.Type == esriDatasetType.esriDTRasterBand)
                                {
                                    bool flag = true;
                                    if (!((IRasterPyramid)dataset).Present)
                                    {
                                        if (ApplicationRef.PyramidPromptType == PyramidPromptType.AlwaysBuildNoPrompt)
                                        {
                                            ((IRasterPyramid)dataset).Create();
                                        }
                                        else if (ApplicationRef.PyramidPromptType == PyramidPromptType.AlwaysPrompt)
                                        {
                                            System.Windows.Forms.DialogResult dialogResult = BuildPyramidSet.Show();
                                            if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                                            {
                                                ((IRasterPyramid)dataset).Create();
                                            }
                                            else if (dialogResult == System.Windows.Forms.DialogResult.Cancel)
                                            {
                                                flag = false;
                                            }
                                        }
                                    }
                                    if (flag)
                                    {
                                        IRasterLayer rasterLayer = new RasterLayer
                                        {
                                            Cached = true
                                        };
                                        rasterLayer.CreateFromDataset((IRasterDataset)dataset);
                                        rasterLayer.Name = dataset.Name;
                                        list.Add(rasterLayer);
                                    }
                                }
                                else
                                {
                                    if (dataset.Type == esriDatasetType.esriDTTable)
                                    {
                                        try
                                        {
                                            IRasterCatalogTable rasterCatalogTable = new RasterCatalogTable();
                                            rasterCatalogTable.Table = (ITable)dataset;
                                            rasterCatalogTable.Update();
                                            IRasterCatalogLayer rasterCatalogLayer = new RasterCatalogLayer() as IRasterCatalogLayer;
                                            rasterCatalogLayer.Create(rasterCatalogTable);
                                            rasterCatalogLayer.Name = dataset.BrowseName;
                                            list.Add(rasterCatalogLayer);
                                            goto IL_8B0;
                                        }
                                        catch (Exception ex)
                                        {
                                            try
                                            {
                                                IStandaloneTableCollection standaloneTableCollection = this.method_0() as IStandaloneTableCollection;
                                                IPropertySet connectionProperties = dataset.Workspace.ConnectionProperties;
                                                bool         flag2 = false;
                                                for (int j = 0; j < standaloneTableCollection.StandaloneTableCount; j++)
                                                {
                                                    ITable table = standaloneTableCollection.get_StandaloneTable(j).Table;
                                                    if (
                                                        connectionProperties.IsEqual(
                                                            (table as IDataset).Workspace.ConnectionProperties) &&
                                                        (table as IDataset).Name == dataset.Name)
                                                    {
                                                        flag2 = true;
                                                    }
                                                    else
                                                    {
                                                        standaloneTableCollection.AddStandaloneTable(new StandaloneTable
                                                        {
                                                            Table = dataset as ITable
                                                        });
                                                    }
                                                }
                                            }
                                            catch (Exception exception_)
                                            {
                                                CErrorLog.writeErrorLog(this, exception_, "");
                                            }

                                            goto IL_8B0;
                                        }
                                    }
                                    if (dataset.Type == esriDatasetType.esriDTGeometricNetwork)
                                    {
                                        IGeometricNetwork geometricNetwork = dataset as IGeometricNetwork;
                                        if (geometricNetwork != null)
                                        {
                                            IEnumFeatureClass enumFeatureClass = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleJunction);
                                            enumFeatureClass.Reset();
                                            for (IFeatureClass featureClass3 = enumFeatureClass.Next(); featureClass3 != null; featureClass3 = enumFeatureClass.Next())
                                            {
                                                list.Add(new FeatureLayer
                                                {
                                                    FeatureClass = featureClass3,
                                                    Name         = (featureClass3 as IDataset).Name
                                                });
                                            }
                                            enumFeatureClass = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexJunction);
                                            enumFeatureClass.Reset();
                                            for (IFeatureClass featureClass3 = enumFeatureClass.Next(); featureClass3 != null; featureClass3 = enumFeatureClass.Next())
                                            {
                                                list.Add(new FeatureLayer
                                                {
                                                    FeatureClass = featureClass3,
                                                    Name         = (featureClass3 as IDataset).Name
                                                });
                                            }
                                            enumFeatureClass = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge);
                                            enumFeatureClass.Reset();
                                            for (IFeatureClass featureClass3 = enumFeatureClass.Next(); featureClass3 != null; featureClass3 = enumFeatureClass.Next())
                                            {
                                                list.Add(new FeatureLayer
                                                {
                                                    FeatureClass = featureClass3,
                                                    Name         = (featureClass3 as IDataset).Name
                                                });
                                            }
                                            enumFeatureClass = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge);
                                            enumFeatureClass.Reset();
                                            for (IFeatureClass featureClass3 = enumFeatureClass.Next(); featureClass3 != null; featureClass3 = enumFeatureClass.Next())
                                            {
                                                list.Add(new FeatureLayer
                                                {
                                                    FeatureClass = featureClass3,
                                                    Name         = (featureClass3 as IDataset).Name
                                                });
                                            }
                                        }
                                    }
                                    else if (dataset.Type == esriDatasetType.esriDTNetworkDataset)
                                    {
                                        INetworkDataset networkDataset = dataset as INetworkDataset;
                                        INetworkLayer   item           = new NetworkLayer() as INetworkLayer;
                                        item.NetworkDataset = networkDataset;

                                        list.Add(item as ILayer);
                                        if (System.Windows.Forms.MessageBox.Show("是否将参加网络要素集-" + dataset.Name + "-的所有要素添加到地图中", "添加拓扑层", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Asterisk) == System.Windows.Forms.DialogResult.Yes)
                                        {
                                            IEnumFeatureClass classes = (dataset as IFeatureClassContainer).Classes;
                                            classes.Reset();
                                            for (IFeatureClass featureClass2 = classes.Next(); featureClass2 != null; featureClass2 = classes.Next())
                                            {
                                                list.Add(new FeatureLayer
                                                {
                                                    FeatureClass = featureClass2,
                                                    Name         = featureClass2.AliasName
                                                });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    IL_8B0 :;
                }
                int    num   = list.Count;
                ILayer layer = null;
                for (int i = num - 1; i >= 0; i--)
                {
                    layer = list[i];
                    if (layer is IRasterCatalogLayer)
                    {
                        this.method_0().AddLayer(layer);
                        (this.method_0() as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, layer, null);
                        list.RemoveAt(i);
                        num--;
                    }
                }
                for (int i = num - 1; i >= 0; i--)
                {
                    layer = list[i];
                    if (layer is IRasterLayer)
                    {
                        this.method_0().AddLayer(layer);
                        (this.method_0() as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, layer, null);
                        list.RemoveAt(i);
                        num--;
                    }
                }
                for (int i = num - 1; i >= 0; i--)
                {
                    layer = list[i];
                    if (layer is ITinLayer)
                    {
                        this.method_0().AddLayer(layer);
                        (this.method_0() as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, layer, null);
                        list.RemoveAt(i);
                        num--;
                    }
                }
                for (int i = num - 1; i >= 0; i--)
                {
                    layer = list[i];
                    if (layer is ICadLayer)
                    {
                        this.method_0().AddLayer(layer);
                        (this.method_0() as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, layer, null);
                        list.RemoveAt(i);
                        num--;
                    }
                }
                for (int i = num - 1; i >= 0; i--)
                {
                    layer = list[i];
                    if (layer is IFeatureLayer)
                    {
                        IFeatureLayer featureLayer = layer as IFeatureLayer;
                        IFeatureClass featureClass = featureLayer.FeatureClass;
                        if (featureClass.ShapeType == esriGeometryType.esriGeometryPolygon || featureClass.ShapeType == esriGeometryType.esriGeometryEnvelope)
                        {
                            this.method_0().AddLayer(layer);
                            (this.method_0() as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, layer, null);
                            list.RemoveAt(i);
                            num--;
                        }
                    }
                }
                for (int i = num - 1; i >= 0; i--)
                {
                    layer = list[i];
                    if (layer is IFeatureLayer)
                    {
                        IFeatureLayer featureLayer = layer as IFeatureLayer;
                        IFeatureClass featureClass = featureLayer.FeatureClass;
                        if (featureClass.ShapeType == esriGeometryType.esriGeometryLine || featureClass.ShapeType == esriGeometryType.esriGeometryBezier3Curve || featureClass.ShapeType == esriGeometryType.esriGeometryCircularArc || featureClass.ShapeType == esriGeometryType.esriGeometryEllipticArc || featureClass.ShapeType == esriGeometryType.esriGeometryPath || featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                        {
                            try
                            {
                                this.method_0().AddLayer(layer);
                                goto IL_B56;
                            }
                            catch
                            {
                                goto IL_B56;
                            }
                            goto IL_B4D;
IL_B56:
                            (this.method_0() as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, layer, null);
                            list.RemoveAt(i);
                            num--;
                        }
                    }
                    IL_B4D :;
                }
                for (int i = num - 1; i >= 0; i--)
                {
                    layer = list[i];
                    if (layer is IFeatureLayer)
                    {
                        IFeatureLayer featureLayer = layer as IFeatureLayer;
                        IFeatureClass featureClass = featureLayer.FeatureClass;
                        if (featureClass.ShapeType == esriGeometryType.esriGeometryMultipoint || featureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                        {
                            this.method_0().AddLayer(layer);
                            (this.method_0() as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, layer, null);
                            list.RemoveAt(i);
                            num--;
                        }
                    }
                }
                for (int i = num - 1; i >= 0; i--)
                {
                    layer = list[i];
                    this.method_0().AddLayer(layer);
                    (this.method_0() as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, layer, null);
                    list.RemoveAt(i);
                    num--;
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
        public void RunManualRules()
        {
            ICursor cursor = null; IFeatureCursor fCursor = null;
            bool    ran = false;

            try
            {
                //Get list of editable layers
                IEditor     editor  = _editor;
                IEditLayers eLayers = (IEditLayers)editor;
                long        lastOID = -1;
                string      lastLay = "";

                if (_editor.EditState != esriEditState.esriStateEditing)
                {
                    return;
                }

                IMap        map        = editor.Map;
                IActiveView activeView = map as IActiveView;


                IStandaloneTable stTable;

                ITableSelection tableSel;

                IStandaloneTableCollection stTableColl = (IStandaloneTableCollection)map;

                long rowCount    = stTableColl.StandaloneTableCount;
                long rowSelCount = 0;
                for (int i = 0; i < stTableColl.StandaloneTableCount; i++)
                {
                    stTable  = stTableColl.get_StandaloneTable(i);
                    tableSel = (ITableSelection)stTable;
                    if (tableSel.SelectionSet != null)
                    {
                        rowSelCount = rowSelCount + tableSel.SelectionSet.Count;
                    }
                }
                long featCount  = map.SelectionCount;
                int  totalCount = (Convert.ToInt32(rowSelCount) + Convert.ToInt32(featCount));


                if (totalCount >= 1)
                {
                    editor.StartOperation();

                    if (MessageBox.Show("Are you sure you wish to apply attribute assistant manual rules for the selected " + totalCount + " rows and features?",
                                        "Confirm", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        ran = true;


                        //bool test = false;

                        //Get list of feature layers
                        UID geoFeatureLayerID = new UIDClass();
                        geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
                        IEnumLayer        enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true);
                        IFeatureLayer     fLayer;
                        IFeatureSelection fSel;
                        ILayer            layer;
                        // Step through each geofeature layer in the map
                        enumLayer.Reset();
                        // Create an edit operation enabling undo/redo
                        try
                        {
                            while ((layer = enumLayer.Next()) != null)
                            {
                                // Verify that this is a valid, visible layer and that this layer is editable
                                fLayer = (IFeatureLayer)layer;
                                if (fLayer.Valid && eLayers.IsEditable(fLayer))//fLayer.Visible &&
                                {
                                    // Verify that this layer has selected features
                                    IFeatureClass fc = fLayer.FeatureClass;
                                    fSel = (IFeatureSelection)fLayer;

                                    if ((fc != null) && (fSel.SelectionSet.Count > 0))
                                    {
                                        // test = true;

                                        fSel.SelectionSet.Search(null, false, out cursor);
                                        fCursor = cursor as IFeatureCursor;
                                        IFeature feat;
                                        while ((feat = (IFeature)fCursor.NextFeature()) != null)
                                        {
                                            lastLay = fLayer.Name;


                                            lastOID = feat.OID;
                                            IObject pObj = feat as IObject;

                                            AAState.FeatureManual(pObj);
                                            feat.Store();
                                        }
                                        if (feat != null)
                                        {
                                            Marshal.ReleaseComObject(feat);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            editor.AbortOperation();
                            ran = false;
                            MessageBox.Show("RunManualRules\n" + ex.Message + " \n" + lastLay + ": " + lastOID, ex.Source);
                            return;
                        }
                        finally
                        {
                            //try
                            //{
                            //    // Stop the edit operation
                            //    editor.StopOperation("Run Manual Rules - Features");
                            //}
                            //catch (Exception ex)
                            //{ }
                        }



                        try
                        {
                            for (int i = 0; i < stTableColl.StandaloneTableCount; i++)
                            {
                                stTable  = stTableColl.get_StandaloneTable(i);
                                tableSel = (ITableSelection)stTable;
                                if (tableSel.SelectionSet != null)
                                {
                                    if (tableSel.SelectionSet.Count > 0)
                                    {
                                        tableSel.SelectionSet.Search(null, false, out cursor);
                                        IRow pRow;
                                        while ((pRow = (IRow)cursor.NextRow()) != null)
                                        {
                                            lastOID = pRow.OID;
                                            lastLay = stTable.Name;
                                            IObject pObj = pRow as IObject;
                                            AAState.FeatureManual(pObj);
                                            pRow.Store();
                                        }
                                        if (pRow != null)
                                        {
                                            Marshal.ReleaseComObject(pRow);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            editor.AbortOperation();
                            MessageBox.Show("RunManualRules\n" + ex.Message + " \n" + lastLay + ": " + lastOID, ex.Source);
                            ran = false;

                            return;
                        }
                        finally
                        {
                            //try
                            //{
                            //     Stop the edit operation
                            //    editor.StopOperation("Run Manual Rules - Features");
                            //}
                            //catch (Exception ex)
                            //{ }
                        }
                        try
                        {
                            editor.StopOperation("Run Manual Rules - Features");
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please select some features or rows to run this process.");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " \n" + "RunManualRules", ex.Source);
                ran = false;

                return;
            }
            finally
            {
                if (ran)
                {
                    MessageBox.Show("Process has completed successfully");
                }

                if (cursor != null)
                {
                    Marshal.ReleaseComObject(cursor);
                }
                if (fCursor != null)
                {
                    Marshal.ReleaseComObject(fCursor);
                }
            }
        }
Exemplo n.º 16
0
        private void OpenDataset()
        {
            if (null == m_hookHelper || null == m_workspace)
            {
                return;
            }

            if (string.Empty == (string)lstFeatureClasses.SelectedItem)
            {
                return;
            }

            bool refreshActiveView = false;

            foreach (string dataset in lstFeatureClasses.SelectedItems)
            {
                //get the selected item from the listbox
                //string dataset = (string)lstFeatureClasses.SelectedItem;

                //cast the workspace into a feature workspace
                IFeatureWorkspace featureWorkspace = m_workspace as IFeatureWorkspace;
                if (null == featureWorkspace)
                {
                    return;
                }

                //get a featureclass (or standalone table) from the workspace
                ITable table = featureWorkspace.OpenTable(dataset) as ITable;

                if (table == null)
                {
                    System.Windows.Forms.MessageBox.Show("Failed to open " + dataset);
                    return;
                }

                // figure out if it is a table or featureclass

                IFeatureClass featureClass = table as IFeatureClass;

                if (featureClass == null)
                {
                    // add as table

                    IStandaloneTableCollection tableCollection = m_hookHelper.FocusMap as IStandaloneTableCollection;
                    IStandaloneTable           standaloneTable = new StandaloneTableClass();
                    standaloneTable.Name  = ((IDataset)table).Name;
                    standaloneTable.Table = table;
                    tableCollection.AddStandaloneTable(standaloneTable);

                    refreshActiveView = true;
                }
                else
                {
                    // add as feature class

                    IFeatureLayer featureLayer = new FeatureLayerClass();
                    featureLayer.Name         = featureClass.AliasName;
                    featureLayer.FeatureClass = featureClass;
                    m_hookHelper.FocusMap.AddLayer((ILayer)featureLayer);
                }
            }

            if (refreshActiveView)
            {
                m_hookHelper.ActiveView.ContentsChanged();
            }
        }
        private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool useRepresentation) // bool hasTopologyStuff, bool hasStationFunction,
        {
            // Get references to the map for adding layers and tables
            IMxDocument MxDoc   = (IMxDocument)ArcMap.Document;
            IMap        thisMap = MxDoc.FocusMap;
            IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap;

            // Create a group layer
            IGroupLayer GeoMapGroupLayer = new GroupLayerClass();

            GeoMapGroupLayer.Name = "Geologic Map";

            // Create a group layer
            IGroupLayer StationGroupLayer = new GroupLayerClass();

            StationGroupLayer.Name = "Observation Data";

            //if (hasTopologyStuff == true)
            {
                #region "GeologicMapTopology"
                ITopology      geoMapTopo   = commonFunctions.OpenTopology(ValidNcgmpDatabase, "GeologicMapTopology");
                ITopologyLayer geoMapTopoTL = new TopologyLayerClass();
                geoMapTopoTL.Topology = geoMapTopo;

                ILayer geoMapTopoL = (ILayer)geoMapTopoTL;
                geoMapTopoL.Name    = "Geologic Map Topology";
                geoMapTopoL.Visible = false;

                // Minimizing the legend info in the Table of Contents is not trivial
                ILegendInfo  geoMapTopoLegendInfo  = (ILegendInfo)geoMapTopoL;
                ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup         = geoMapTopoLegendInfo.get_LegendGroup(1);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup         = geoMapTopoLegendInfo.get_LegendGroup(2);
                geoMapTopoLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(geoMapTopoL);

                #endregion
            }
            {
                #region "OrientationPoints"
                IFeatureClass orientationPointsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationPoints");
                IFeatureLayer orientationPointsFL = new FeatureLayerClass();
                orientationPointsFL.FeatureClass = orientationPointsFC;

                orientationPointsFL.Name         = "Orientation Points";
                orientationPointsFL.DisplayField = "Type";

                if (useRepresentation == true)
                {
                    // Set the layer renderer to use representations
                    IGeoFeatureLayer orientationPointsGeoFL = (IGeoFeatureLayer)orientationPointsFL;

                    IRepresentationRenderer orientationPointsRepRend = new RepresentationRendererClass();
                    orientationPointsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "OrientationPoints_Rep");

                    orientationPointsGeoFL.Renderer = (IFeatureRenderer)orientationPointsRepRend;

                    commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, orientationPointsFL as ILayer, "OrientationPoints");
                }

                ILegendInfo  orientationPointsLegendInfo  = (ILegendInfo)orientationPointsFL;
                ILegendGroup orientationPointsLegendGroup = orientationPointsLegendInfo.get_LegendGroup(0);
                orientationPointsLegendGroup.Visible = false;

                StationGroupLayer.Add(orientationPointsFL);

                #endregion

                #region "ObservationData"
                string[] arr = new string[4]; // Initialize
                arr[0] = "Stations";          // Element 1
                arr[1] = "GenericPoints";     // Element 2
                arr[2] = "GenericSamples";    // Element 3
                arr[3] = "GeochronPoints";    // Element 4

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name    = s;
                        FL.Visible = false;

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        StationGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }

            //add station group layer to map document
            GeoMapGroupLayer.Add(StationGroupLayer);

            {
                #region "LinesWithoutRepresentations"
                string[] arr = new string[2]; // Initialize
                arr[0] = "CartographicLines"; // Element 1
                arr[1] = "IsoValueLines";     // Element 2

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name    = s;
                        FL.Visible = false;

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "LinesWithRepresentations"
                string[] arr = new string[2]; // Initialize
                arr[0] = "GeologicLines";     // Element 1
                arr[1] = "ContactsAndFaults"; // Element 2

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;

                        if (useRepresentation == true)
                        {
                            // Set the layer renderer to use representations
                            IGeoFeatureLayer GeoFL = (IGeoFeatureLayer)FL;

                            IRepresentationRenderer RepRend = new RepresentationRendererClass();
                            RepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, s + "_Rep");

                            GeoFL.Renderer = (IFeatureRenderer)RepRend;

                            commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, FL as ILayer, s);
                        }

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "Polygons"
                string[] arr = new string[3]; // Initialize
                arr[0] = "DataSourcePolys";   // Element 1
                arr[1] = "MapUnitPolys";      // Element 2
                arr[2] = "OtherPolys";        // Element 3

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "Tables"
                string[] arr = new string[7];     // Initialize
                arr[0] = "DataSources";           // Element 1
                arr[1] = "DescriptionOfMapUnits"; // Element 2
                arr[2] = "ExtendedAttributes";    // Element 3
                arr[3] = "GeologicEvents";        // Element 4
                arr[4] = "Glossary";              // Element 5
                arr[5] = "Notes";                 // Element 6
                arr[6] = "StandardLithology";     // Element 7
                foreach (string s in arr)
                {
                    try
                    {
                        ITable           Table      = commonFunctions.OpenTable(ValidNcgmpDatabase, s);
                        IStandaloneTable Standalone = new StandaloneTableClass();
                        Standalone.Table = Table;

                        Standalone.Name = s;

                        thisMapTables.AddStandaloneTable(Standalone);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }

            // Add the Geologic Map Group Layer to the map
            GeoMapGroupLayer.Expanded = true;
            thisMap.AddLayer(GeoMapGroupLayer);

            // Adjust the MapUnitPolys Renderer
            commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase);

            // Adjust the MapUnitPolys Feature Templates
            commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase);
        }
Exemplo n.º 18
0
 private void method_1()
 {
     if (this.itable_0 != null)
     {
         int     num;
         IFields fields = this.itable_0.Fields;
         if (fields != null)
         {
             for (num = 0; num < fields.FieldCount; num++)
             {
                 IField field = fields.get_Field(num);
                 switch (field.Type)
                 {
                 case esriFieldType.esriFieldTypeDouble:
                 case esriFieldType.esriFieldTypeInteger:
                 case esriFieldType.esriFieldTypeOID:
                 case esriFieldType.esriFieldTypeSingle:
                 case esriFieldType.esriFieldTypeSmallInteger:
                 case esriFieldType.esriFieldTypeString:
                     this.cboJoiningField.Properties.Items.Add(field.Name);
                     break;
                 }
             }
         }
         if (this.cboJoiningField.Properties.Items.Count > 0)
         {
             this.cboJoiningField.SelectedIndex = 0;
         }
         if (this.ibasicMap_0 != null)
         {
             ITable attributeTable;
             ILayer layer = null;
             for (num = 0; num < this.ibasicMap_0.LayerCount; num++)
             {
                 layer = this.ibasicMap_0.get_Layer(num);
                 if (layer != this.itable_0)
                 {
                     if (layer is IAttributeTable)
                     {
                         attributeTable = (layer as IAttributeTable).AttributeTable;
                         if (!JoiningRelatingHelper.TableIsJoinLayer(this.itable_0, attributeTable))
                         {
                             this.cboJoiningTable.Properties.Items.Add(new ObjectWrap(layer));
                         }
                     }
                     else if (layer is IGroupLayer)
                     {
                         this.method_0(layer as ICompositeLayer);
                     }
                 }
             }
             IStandaloneTableCollection tables = this.ibasicMap_0 as IStandaloneTableCollection;
             for (num = 0; num < tables.StandaloneTableCount; num++)
             {
                 attributeTable = tables.get_StandaloneTable(num) as ITable;
                 if (!JoiningRelatingHelper.TableIsJoinLayer(this.itable_0, attributeTable))
                 {
                     this.cboJoiningTable.Properties.Items.Add(new ObjectWrap(attributeTable));
                 }
             }
             if (this.cboJoiningTable.Properties.Items.Count > 0)
             {
                 this.cboJoiningTable.SelectedIndex = 0;
             }
         }
     }
 }
Exemplo n.º 19
0
        public static void AddDataset(IBasicMap ibasicMap_0, IDataset idataset_0, string string_0)
        {
            if (string_0 == null)
            {
                string_0 = "";
            }
            switch (idataset_0.Type)
            {
            case esriDatasetType.esriDTFeatureDataset:
            {
                IEnumDataset subsets = idataset_0.Subsets;
                subsets.Reset();
                for (IDataset dataset2 = subsets.Next(); dataset2 != null; dataset2 = subsets.Next())
                {
                    AddDataset(ibasicMap_0, dataset2, string_0);
                }
                break;
            }

            case esriDatasetType.esriDTFeatureClass:
            {
                IFeatureLayer layer;
                IFeatureClass class2 = (IFeatureClass)idataset_0;
                if (class2.FeatureType != esriFeatureType.esriFTAnnotation)
                {
                    if (class2.FeatureType == esriFeatureType.esriFTDimension)
                    {
                        IFeatureLayer dimensionLayer = new DimensionLayer() as IFeatureLayer;
                        dimensionLayer.FeatureClass = class2;
                        dimensionLayer.Name         = string_0 + class2.AliasName;
                        layer = dimensionLayer as IFeatureLayer;
                        ibasicMap_0.AddLayer(layer);
                    }
                    else
                    {
                        layer = new FeatureLayer
                        {
                            FeatureClass = class2,
                            Name         = string_0 + class2.AliasName
                        };
                        ibasicMap_0.AddLayer(layer);
                    }
                    break;
                }
                layer = new FDOGraphicsLayer() as IFeatureLayer;
                try
                {
                    layer.FeatureClass = class2;
                    layer.Name         = string_0 + class2.AliasName;
                    ibasicMap_0.AddLayer(layer);
                }
                catch (Exception exception)
                {
                    exception.ToString();
                }
                break;
            }

            case esriDatasetType.esriDTGeometricNetwork:
            {
                IGeometricNetwork network = idataset_0 as IGeometricNetwork;
                if (network != null)
                {
                    IFeatureLayer     layer7;
                    IEnumFeatureClass class3 = network.get_ClassesByType(esriFeatureType.esriFTSimpleJunction);
                    class3.Reset();
                    IFeatureClass class4 = class3.Next();
                    while (class4 != null)
                    {
                        layer7 = new FeatureLayer
                        {
                            FeatureClass = class4,
                            Name         = string_0 + (class4 as IDataset).Name
                        };
                        ibasicMap_0.AddLayer(layer7);
                        class4 = class3.Next();
                    }
                    class3 = network.get_ClassesByType(esriFeatureType.esriFTComplexJunction);
                    class3.Reset();
                    for (class4 = class3.Next(); class4 != null; class4 = class3.Next())
                    {
                        layer7 = new FeatureLayer
                        {
                            FeatureClass = class4,
                            Name         = string_0 + (class4 as IDataset).Name
                        };
                        ibasicMap_0.AddLayer(layer7);
                    }
                    class3 = network.get_ClassesByType(esriFeatureType.esriFTSimpleEdge);
                    class3.Reset();
                    for (class4 = class3.Next(); class4 != null; class4 = class3.Next())
                    {
                        layer7 = new FeatureLayer
                        {
                            FeatureClass = class4,
                            Name         = string_0 + (class4 as IDataset).Name
                        };
                        ibasicMap_0.AddLayer(layer7);
                    }
                    class3 = network.get_ClassesByType(esriFeatureType.esriFTComplexEdge);
                    class3.Reset();
                    for (class4 = class3.Next(); class4 != null; class4 = class3.Next())
                    {
                        layer7 = new FeatureLayer
                        {
                            FeatureClass = class4,
                            Name         = string_0 + (class4 as IDataset).Name
                        };
                        ibasicMap_0.AddLayer(layer7);
                    }
                }
                break;
            }

            case esriDatasetType.esriDTTopology:
            {
                ITopologyLayer layer = new TopologyLayer() as ITopologyLayer;
                layer.Topology = idataset_0 as ITopology;
                ITopologyLayer layer3 = layer as ITopologyLayer;
                (layer3 as ILayer).Name = string_0 + idataset_0.Name;
                ibasicMap_0.AddLayer(layer3 as ILayer);
                break;
            }

            case esriDatasetType.esriDTTable:
                try
                {
                    IRasterCatalogTable pCatalog = new RasterCatalogTable
                    {
                        Table = (ITable)idataset_0
                    };
                    pCatalog.Update();
                    IRasterCatalogLayer pLayer = new RasterCatalogLayer() as IRasterCatalogLayer;
                    pLayer.Create(pCatalog);
                    pLayer.Name = string_0 + idataset_0.BrowseName;
                    ibasicMap_0.AddLayer(pLayer);
                }
                catch
                {
                    try
                    {
                        IStandaloneTableCollection tables = ibasicMap_0 as IStandaloneTableCollection;
                        IPropertySet connectionProperties = idataset_0.Workspace.ConnectionProperties;
                        bool         flag = false;
                        for (int i = 0; i < tables.StandaloneTableCount; i++)
                        {
                            ITable table = tables.get_StandaloneTable(i).Table;
                            if (connectionProperties.IsEqual((table as IDataset).Workspace.ConnectionProperties) &&
                                ((table as IDataset).Name == idataset_0.Name))
                            {
                                goto Label_03E1;
                            }
                        }
                        goto Label_03E4;
Label_03E1:
                        flag = true;
Label_03E4:
                        if (!flag)
                        {
                            IStandaloneTable table3 = new StandaloneTable
                            {
                                Table = idataset_0 as ITable
                            };
                            tables.AddStandaloneTable(table3);
                        }
                    }
                    catch (Exception exception2)
                    {
                        CErrorLog.writeErrorLog(null, exception2, "");
                    }
                }
                break;

            case esriDatasetType.esriDTRasterDataset:
            case esriDatasetType.esriDTRasterBand:
            {
                IRasterLayer layer5 = new RasterLayer();
                layer5.CreateFromDataset((IRasterDataset)idataset_0);
                layer5.Name = string_0 + idataset_0.Name;
                ibasicMap_0.AddLayer(layer5);
                break;
            }

            case esriDatasetType.esriDTTin:
            {
                ITinLayer layer4 = new TinLayer
                {
                    Dataset = (ITin)idataset_0,
                    Name    = string_0 + idataset_0.Name
                };
                ibasicMap_0.AddLayer(layer4);
                break;
            }

            case esriDatasetType.esriDTCadDrawing:
            {
                ICadLayer layer2 = new CadLayer() as ICadLayer;
                layer2.CadDrawingDataset = idataset_0 as ICadDrawingDataset;
                layer2.Name = idataset_0.Name;
                ibasicMap_0.AddLayer(layer2);
                break;
            }
            }
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            // Check and assign arguments
            String  mxdFolder         = ""; // @"C:\TEMP\testconns\";
            String  newMxdStringToAdd = "DC";
            Boolean verbose           = false;

            if (args == null || args.Length == 0)
            {
                mxdFolder = Directory.GetCurrentDirectory().ToString();
            }
            else if (args.Length == 1)
            {
                if ((args[0] == "?") || (args[0] == "--help"))
                {
                    Console.WriteLine("Usage: MXDconnection_converter.exe [{Current Directory | <PathToMxdDirectory>}] [{DC | <newMxdStringToAdd>}] [VERBOSE] [{? | --help}]");
                    return;
                }
                else
                {
                    mxdFolder = args[0];
                }
            }
            else if (args.Length == 2)
            {
                mxdFolder         = args[0];
                newMxdStringToAdd = args[1];
            }
            else if (args.Length == 3)
            {
                mxdFolder         = args[0];
                newMxdStringToAdd = args[1];
                if (args[2].ToLower() == "true")
                {
                    verbose = true;
                }
            }

            // ESRI License Initializer generated code.
            // Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB },
                                                         new esriLicenseExtensionCode[] { });

            // Put all the mxd files in the specified folder into a list
            String[] arrMxdFiles = Directory.GetFiles(mxdFolder, "*.mxd");

            Console.WriteLine("============================================");
            Console.WriteLine(" MXDconnection_converter");
            Console.WriteLine("     Checking MXD's at: {0}", mxdFolder);
            Console.WriteLine("============================================");

            int m = 1;

            // Run operation for all mxd's in the list
            foreach (String mxdFile in arrMxdFiles)
            {
                try
                {
                    // Open the map document
                    IMapDocument mpdoc   = new MapDocument();
                    String       mxdName = "";
                    mxdName = Path.GetFileNameWithoutExtension(mxdFile);

                    // Check if mxd file already has the supplied extension. If it does skip, since we believe it has already been converted.
                    // Very basic check, does NOT consider different languages/cultures
                    if (mxdName.EndsWith(String.Format("_{0}", newMxdStringToAdd)))
                    {
                        if (verbose)
                        {
                            Console.WriteLine(" Skipping {0}.mxd...", mxdName);
                            Console.WriteLine("============================================");
                        }

                        continue;
                    }

                    Console.WriteLine(" Converting {0}.mxd...", mxdName);

                    mpdoc.Open(String.Format(@"{0}", mxdFile));

                    // Get the first data frame; would need to interrogate all data frames in production
                    IMap map = mpdoc.get_Map(0);

                    // Walk the layer collection (this should work for stand alone rasters too).
                    for (int i = 0; i < map.LayerCount; i++)
                    {
                        ILayer l = map.get_Layer(i);

                        // Other layer types may be required in production (e.g. IRaster, etc.)
                        if (verbose)
                        {
                            Console.WriteLine("----------------");
                            Console.WriteLine(" Layer: {0}", l.Name);
                        }
                        // Update the dataLayer info
                        ITable table = (ITable)l;
                        UpdateDatalayerInfo(table, verbose);
                    }

                    // Walk the stand alone table collection
                    IStandaloneTableCollection saTableColl = (IStandaloneTableCollection)map;
                    for (int i = 0; i < saTableColl.StandaloneTableCount; i++)
                    {
                        IStandaloneTable t = saTableColl.get_StandaloneTable(i);

                        // Other layer types may be required in production (e.g. IRaster, etc.)
                        if (verbose)
                        {
                            Console.WriteLine("----------------");
                            Console.WriteLine(" Stand Alone Table: {0}", t.Name);
                        }

                        // Update the dataLayer info
                        UpdateDatalayerInfo((ITable)t, verbose);
                    }

                    // Save as a new mxd
                    String newMxdFile = String.Format(@"{0}\{1}_{2}.{3}", mxdFolder, mxdName, newMxdStringToAdd, "mxd");
                    mpdoc.SaveAs(newMxdFile);

                    String newMxdName = Path.GetFileNameWithoutExtension(newMxdFile);
                    if (verbose)
                    {
                        Console.WriteLine(" Saved {0}.mxd.", newMxdName);
                        Console.WriteLine("============================================");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                m++;
            } // End foreach MXD

            Console.WriteLine(" Done.");
            Console.WriteLine("============================================");

            m_AOLicenseInitializer.ShutdownApplication();
        } // Main