コード例 #1
0
        /// <summary>
        /// Cleans a featureclass or table according to the selected options.
        /// </summary>
        /// <param name="sSuffix"></param>
        /// <returns></returns>
        public bool CleanLayer(string sSuffix)
        {
            bool bResult = false;

            if (ItemsChecked())
            {
                ITableCollection pTableCollection = (ITableCollection)ArcMap.Document.FocusMap;
                if (m_sLayertype == "FeatureClass")
                {
                    IFeatureLayer pFL = clsStatic.GetFeatureLayer(m_sWorkspace, m_sLayername + "_" + sSuffix);
                    if (pFL != null)
                    {
                        MessageBox.Show("The output featureclass already exists. Choose another output suffix", clsStatic.g_cProjectName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(bResult);
                    }

                    IFeatureLayer pResult = CleanFeatureClass(sSuffix);
                    if (pResult != null)
                    {
                        ArcMap.Document.AddLayer((ILayer)pResult);
                    }
                }
                if (m_sLayertype == "Table")
                {
                    ITable pTable = clsStatic.GetTable(m_sWorkspace, m_sLayername + "_" + sSuffix);
                    if (pTable != null)
                    {
                        MessageBox.Show("The output table already exists. Choose another output suffix.", clsStatic.g_cProjectName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(bResult);
                    }
                    ITable pResultTable = CleanTable(sSuffix);
                    if (pResultTable != null)
                    {
                        pTableCollection.AddTable(pResultTable);
                    }
                }
                bResult = true;
            }
            m_sNewLayername = m_sLayername + "_" + sSuffix;
            return(bResult);
        }
コード例 #2
0
        /// <summary>
        /// adds a layer to the active view
        /// </summary>
        /// <param name="path">full path name</param>
        /// <returns>Ilayer</returns>
        public ILayer addLayer(string path)
        {
            IMap map = (IMap)acView;
            geoDatabaseUtility geoUtil = new geoDatabaseUtility();
            esriDatasetType    dType   = geoUtil.getDataType(path);
            ILayer             lyr     = null;

            switch (dType)
            {
            case esriDatasetType.esriDTFeatureClass:
                IFeatureLayer ftrLayer = new FeatureLayerClass();
                ftrLayer.FeatureClass = geoUtil.getFeatureClass(path);
                lyr      = (ILayer)ftrLayer;
                lyr.Name = ftrLayer.FeatureClass.AliasName;
                map.AddLayer(lyr);
                break;

            case esriDatasetType.esriDTRasterBand:
            case esriDatasetType.esriDTRasterCatalog:
            case esriDatasetType.esriDTRasterDataset:
                IRasterLayer rasterLayer = new RasterLayerClass();
                rasterLayer.CreateFromDataset(geoUtil.getRasterDataset(path));
                rasterLayer.Name = rasterLayer.Name;
                map.AddLayer((ILayer)rasterLayer);
                break;

            case esriDatasetType.esriDTTable:
                ITable           tbl             = geoUtil.getTable(path);
                ITableCollection tableCollection = (ITableCollection)map;
                tableCollection.AddTable(tbl);
                break;

            default:
                break;
            }
            acView.Refresh();
            return(lyr);
        }
コード例 #3
0
        public void CreateNewTable()
        {
            IMxDocument pMxDoc;

            pMxDoc = (IMxDocument)ArcMap.Application.Document;

            IMap pMap;

            pMap = pMxDoc.FocusMap;

            IWorkspaceFactory pWSFactory;

            pWSFactory = new ShapefileWorkspaceFactory();

            IFeatureWorkspace pFWorkspace;

            pFWorkspace = (IFeatureWorkspace)pWSFactory.OpenFromFile("c:/temp", ArcMap.Application.hWnd);

            IFieldsEdit pFieldsEdit;

            pFieldsEdit = (IFieldsEdit) new Fields();

            IFieldEdit pIDField;

            pIDField          = (IFieldEdit) new Field();
            pIDField.Name_2   = "OID";
            pIDField.Type_2   = esriFieldType.esriFieldTypeOID;
            pIDField.Length_2 = 8;

            IFieldEdit pNameField;

            pNameField          = (IFieldEdit) new Field();
            pNameField.Name_2   = "Site_Name";
            pNameField.Type_2   = esriFieldType.esriFieldTypeString;
            pNameField.Length_2 = 20;

            IFieldEdit pReadingField;

            pReadingField          = (IFieldEdit) new Field();
            pReadingField.Name_2   = "Reading";
            pReadingField.Type_2   = esriFieldType.esriFieldTypeInteger;
            pReadingField.Length_2 = 8;

            IFieldEdit pDateField;

            pDateField        = (IFieldEdit) new Field();
            pDateField.Name_2 = "Visit_Date";
            pDateField.Type_2 = esriFieldType.esriFieldTypeDate;

            pFieldsEdit.AddField(pIDField);
            pFieldsEdit.AddField(pNameField);
            pFieldsEdit.AddField(pReadingField);
            pFieldsEdit.AddField(pDateField);

            ITable pTable = default(ITable);

            pTable = pFWorkspace.CreateTable("measurements.dbf", pFieldsEdit, null, null, "");

            ITableCollection pTableCollection = default(ITableCollection);

            pTableCollection = (ITableCollection)pMap;

            pTableCollection.AddTable(pTable);
            pMxDoc.UpdateContents();
        }