internal static string LocateCBfile()
        {
            IGxDialog GxD = new GxDialog();

            GxD.AllowMultiSelect = false;
            GxD.ButtonCaption    = "Add";
            GxD.Title            = "Select the Colorbrewer File";
            GxD.RememberLocation = true;

            IGxObjectFilter textFileFilter = new GxFilterTextFiles();

            GxD.ObjectFilter = textFileFilter;

            IEnumGxObject enumObj;

            if (GxD.DoModalOpen(ArcMap.Application.hWnd, out enumObj) == false)
            {
                System.Windows.Forms.MessageBox.Show("Operation Failed");
                return("Operation Failed: Please Try Again");
            }
            IGxObject gxObj = enumObj.Next();

            filepath = gxObj.FullName;
            System.Windows.Forms.MessageBox.Show("File Path: " + filepath);
            return(filepath);
        }
        protected override void OnClick()
        {
             IMxDocument pmxdoc = (IMxDocument)ArcMap.Application.Document;
             IMap pmap = pmxdoc.FocusMap;
             IGxDialog pGxDialog = new GxDialog();
             pGxDialog.Title = "Browse Data";
             //pGxDialog.set_StartingLocation("C:\\Temp");
             pGxDialog.set_StartingLocation("GIS Servers");
             IEnumGxObject pEnumGx;
             if (!pGxDialog.DoModalOpen(0, out pEnumGx))
                 return; // Exit if user press Cancel
             IGxObject pgxobject = pEnumGx.Next();
             IGxAGSObject gxAGSObject = pgxobject as IGxAGSObject;
             IAGSServerObjectName agsServerObjectName = gxAGSObject.AGSServerObjectName;
             IAGSServerConnectionName agsServerConnectionName = agsServerObjectName.AGSServerConnectionName;
             IPropertySet propertySet = agsServerConnectionName.ConnectionProperties;
             //create a new ArcGIS Server connection factory
             IAGSServerConnectionFactory2 agsServerConnectionFactory2 = (IAGSServerConnectionFactory2)new AGSServerConnectionFactory();
             IAGSServerConnection agsServerConnection = agsServerConnectionFactory2.Open(propertySet, 0);
             //get an enum of all server object names from the server (GIS services, i.e.)
             IAGSEnumServerObjectName soNames = agsServerConnection.ServerObjectNames;
             IAGSServerObjectName3 soName = (IAGSServerObjectName3)soNames.Next();
             ILayerFactory msLayerFactory = new MapServerLayerFactory();
             IEnumLayer enumLyrs = msLayerFactory.Create(soName);
             IMapServerLayer mapServerLayer = (IMapServerLayer)enumLyrs.Next();
             pmap.AddLayer((ILayer)mapServerLayer);

             ArcMap.Application.CurrentTool = null;
        }
Ejemplo n.º 3
0
        private void button5_Click(object sender, EventArgs e)
        {
            IGxDialog gxd = new GxDialog();

            gxd.AllowMultiSelect = false;
            gxd.ButtonCaption    = "Add";
            gxd.Title            = "Add a GDB";
            gxd.RememberLocation = true;

            IGxObjectFilter filter1 = new GxFilterFileGeodatabases();

            gxd.ObjectFilter = filter1;

            IEnumGxObject enumObj;

            if (gxd.DoModalOpen(ArcMap.Application.hWnd, out enumObj) == false) // show dialog
            {
                return;                                                         // return if clicking on cancel
            }
            IGxObject gxObj   = enumObj.Next();
            int       len1    = gxObj.FullName.Length;
            int       len2    = gxObj.Name.Length;
            string    shpPath = gxObj.FullName.Substring(0);

            IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;

            textBox5.Text = shpPath;
            output        = shpPath;
        }
Ejemplo n.º 4
0
        protected override void OnClick()
        {
            IMxDocument pmxdoc    = (IMxDocument)ArcMap.Application.Document;
            IMap        pmap      = pmxdoc.FocusMap;
            IGxDialog   pGxDialog = new GxDialog();

            pGxDialog.Title = "Browse Data";
            //pGxDialog.set_StartingLocation("C:\\Temp");
            pGxDialog.set_StartingLocation("GIS Servers");
            IEnumGxObject pEnumGx;

            if (!pGxDialog.DoModalOpen(0, out pEnumGx))
            {
                return;  // Exit if user press Cancel
            }
            IGxObject                pgxobject               = pEnumGx.Next();
            IGxAGSObject             gxAGSObject             = pgxobject as IGxAGSObject;
            IAGSServerObjectName     agsServerObjectName     = gxAGSObject.AGSServerObjectName;
            IAGSServerConnectionName agsServerConnectionName = agsServerObjectName.AGSServerConnectionName;
            IPropertySet             propertySet             = agsServerConnectionName.ConnectionProperties;
            //create a new ArcGIS Server connection factory
            IAGSServerConnectionFactory2 agsServerConnectionFactory2 = (IAGSServerConnectionFactory2) new AGSServerConnectionFactory();
            IAGSServerConnection         agsServerConnection         = agsServerConnectionFactory2.Open(propertySet, 0);
            //get an enum of all server object names from the server (GIS services, i.e.)
            IAGSEnumServerObjectName soNames        = agsServerConnection.ServerObjectNames;
            IAGSServerObjectName3    soName         = (IAGSServerObjectName3)soNames.Next();
            ILayerFactory            msLayerFactory = new MapServerLayerFactory();
            IEnumLayer      enumLyrs       = msLayerFactory.Create(soName);
            IMapServerLayer mapServerLayer = (IMapServerLayer)enumLyrs.Next();

            pmap.AddLayer((ILayer)mapServerLayer);

            ArcMap.Application.CurrentTool = null;
        }
Ejemplo n.º 5
0
        private void button4_Click(object sender, EventArgs e)
        {
            IGxDialog gxd = new GxDialog();

            gxd.AllowMultiSelect = false;
            gxd.ButtonCaption    = "Add";
            gxd.Title            = "Add a shapefile";
            gxd.RememberLocation = true;

            IGxObjectFilter           filter1 = new GxFilterFileGeodatabases();
            IGxObjectFilter           filter2 = new GxFilterTables();
            IGxObjectFilterCollection filters = gxd as IGxObjectFilterCollection;

            filters.AddFilter(filter1, true);
            filters.AddFilter(filter2, false);

            IEnumGxObject enumObj;

            if (gxd.DoModalOpen(ArcMap.Application.hWnd, out enumObj) == false) // show dialog
            {
                return;                                                         // return if clicking on cancel
            }
            IGxObject gxObj    = enumObj.Next();
            int       len1     = gxObj.FullName.Length;
            int       len2     = gxObj.Name.Length;
            string    shpPath  = gxObj.FullName.Substring(0, len1 - len2);
            string    shpPath2 = gxObj.FullName.Substring(0);

            IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;

            textBox4.Text = shpPath2;
            population    = shpPath2;
        }
Ejemplo n.º 6
0
        private void openFileDialogue(object sender, EventArgs e)
        {
            this.btIdentifyCurveAreas.Enabled = false;

            IGxDialog igxDialog = new GxDialog();

            igxDialog.AllowMultiSelect = false;
            igxDialog.ObjectFilter     = new ESRI.ArcGIS.Catalog.GxFilterPolylineFeatureClasses();

            ESRI.ArcGIS.Catalog.IEnumGxObject selection;
            igxDialog.DoModalOpen(this.Handle.ToInt32(), out selection);

            ESRI.ArcGIS.Catalog.IGxObject nextObj = selection.Next();

            this.rIDField.Items.Clear();

            if (nextObj == null)
            {
                this.txtInput.Clear();
                this.txtOutput.Clear();
                this.run = null;
            }
            else
            {
                this.run            = new ClassLib.Run(nextObj.FullName, this.AngleVariation.Value, isDissolved: cbDisslv.Checked);
                this.txtInput.Text  = this.run.inputPath;
                this.txtOutput.Text = this.run.outputPath;

                if (!run.isFeetOrMeters)
                {
                    MessageBox.Show("The input coordinate system must be in meters or feet");

                    return;
                }

                this.btIdentifyCurveAreas.Enabled = true;

                this.cbFeet.Checked = this.run.isFeet;

                this.rIDField.Items.Clear();

                this.rIDField.Items.AddRange(run.fieldNames.ToArray());

                if (this.rIDField.Items.Count > 0)
                {
                    this.rIDField.SelectedIndex = 0;
                }
            }
        }
Ejemplo n.º 7
0
        private void Browse(object o)
        {
            //' allows the user to specify the output shapefile path and name.
            IGxDialog pGxDialog = new GxDialog();
            object    obj       = o;
            IGxObjectFilterCollection FilterCol = (IGxObjectFilterCollection)pGxDialog;

            FilterCol.AddFilter(new GxFilterShapefiles(), true);
            FilterCol.AddFilter(new GxFilterRasterDatasets(), false);



            switch (o.ToString())
            {
            case "OutputBrws":
                if (ShowSaveFileDialog(pGxDialog, out m_Path, out m_Name, out m_GenericName, out m_DatasetType))
                {
                    OutputFilePath        = m_Path;
                    OutputFileName        = m_Name;
                    OutPutFeatureClass    = OutputFilePath + "\\" + OutputFileName;
                    OutputFileNameGeneric = m_GenericName;
                    OutputDatasetType     = m_DatasetType;
                }
                break;

            case "SHPBrws":
                // If Not ShowOpenFileDialog()
                if (ShowOpenFileDialog(pGxDialog, out m_Path, out m_Name, out m_GenericName, out m_DatasetType))
                {
                    IFeatureClass FeatClass;
                    IGeoDataset   GeoDataset;
                    ShapeFilePath = m_Path;
                    ShapeFileName = m_Name;
                    ShpPath       = ShapeFilePath + "/" + ShapeFileName;

                    ShapeFileNameGeneric = m_GenericName;
                    FeatClass            = OpenShapefile(ShapeFilePath, ShapeFileNameGeneric, windowHandle.ToInt32());
                    GeoDataset           = (IGeoDataset)FeatClass;
                    ExtentDataLeft       = GeoDataset.Extent.XMin;
                    ExtentDataRight      = GeoDataset.Extent.XMax;
                    ExtentDataBottom     = GeoDataset.Extent.YMin;
                    ExtentDataTop        = GeoDataset.Extent.YMax;
                    GeoDataset           = null;
                    FeatClass            = null;
                }
                break;
            }
        }
Ejemplo n.º 8
0
        private void button2_Click(object sender, EventArgs e)
        {
            IGxDialog gxd = new GxDialog();

            gxd.AllowMultiSelect = false;
            gxd.ButtonCaption    = "Add";
            gxd.Title            = "Add a shapefile";
            gxd.RememberLocation = true;

            IGxObjectFilter           filter1 = new GxFilterFileGeodatabases();
            IGxObjectFilter           filter2 = new GxFilterShapefiles();
            IGxObjectFilterCollection filters = gxd as IGxObjectFilterCollection;

            filters.AddFilter(filter1, true);
            filters.AddFilter(filter2, false);

            IEnumGxObject enumObj;

            if (gxd.DoModalOpen(ArcMap.Application.hWnd, out enumObj) == false) // show dialog
            {
                return;                                                         // return if clicking on cancel
            }
            IGxObject gxObj    = enumObj.Next();
            int       len1     = gxObj.FullName.Length;
            int       len2     = gxObj.Name.Length;
            string    shpPath  = gxObj.FullName.Substring(0, len1 - len2);
            string    shpPath2 = gxObj.FullName.Substring(0);

            IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;

            IWorkspaceFactory wsf          = new ShapefileWorkspaceFactory();
            IWorkspace        ws           = wsf.OpenFromFile(shpPath, 0);
            IFeatureWorkspace fws          = ws as IFeatureWorkspace;
            IFeatureClass     featureClass = fws.OpenFeatureClass(gxObj.BaseName);
            IFeatureLayer     featureLayer = new FeatureLayer();

            featureLayer.FeatureClass = featureClass;
            ILayer layer = (ILayer)featureLayer;

            layer.Name = gxObj.BaseName;
            mxdoc.AddLayer(layer);
            mxdoc.ActiveView.Refresh();
            mxdoc.UpdateContents();

            textBox2.Text = shpPath2;
            tracts        = shpPath2;
        }
Ejemplo n.º 9
0
        private void gdbloc_btn_Click(object sender, EventArgs e)
        {
            IEnumGxObject   gxEnumGxObject;
            IGxObjectFilter gxObjectFilter = new GxFilterFileGeodatabases();

            IGxDialog gxDialog = new GxDialog {
                AllowMultiSelect = false, Title = "Select Output GDB", ButtonCaption = "Open"
            };

            gxDialog.ObjectFilter = gxObjectFilter;

            if (gxDialog.DoModalOpen(0, out gxEnumGxObject) && gxEnumGxObject != null)
            {
                IGxObject gxObj = gxEnumGxObject.Next();
                gdbToSaveToTxtBox.Text = gxObj.FullName.ToString();
            }
        }
Ejemplo n.º 10
0
        public static string BrowseSaveRaster(string formTitle, IntPtr hParentWindowHandle, string sWorkspace = null, string sName = null)
        {
            IGxDialog pGxDialog = new GxDialog();
            IGxObjectFilterCollection pFilterCol = (IGxObjectFilterCollection)pGxDialog;

            pFilterCol.AddFilter(new GxFilterRasterDatasets(), true);
            pGxDialog.RememberLocation = true;
            pGxDialog.AllowMultiSelect = false;
            pGxDialog.Title            = formTitle;
            if (!string.IsNullOrEmpty(sWorkspace))
            {
                pGxDialog.set_StartingLocation(sWorkspace);
            }

            if (sWorkspace is string)
            {
                sWorkspace = string.Empty;
            }

            if (sName is string)
            {
                sName = string.Empty;
            }

            string sResult = string.Empty;

            try
            {
                if (pGxDialog.DoModalSave(hParentWindowHandle.ToInt32()))
                {
                    sWorkspace = pGxDialog.FinalLocation.FullName;
                    sName      = pGxDialog.Name;
                    sResult    = System.IO.Path.Combine(sWorkspace, sName);
                }
            }
            catch (Exception ex)
            {
                ex.Data["Title"]  = formTitle;
                ex.Data["Folder"] = sWorkspace;
                ex.Data["Name"]   = sName;
                throw;
            }

            return(sResult);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 打开指定路径的匹配结果表
        /// </summary>
        /// <returns>返回的表内容</returns>
        public static ITable OpenRelateTable(out string path)
        {
            IGxDialog dlg = new GxDialog();

            IGxObjectFilter pGxFilter = new GxFilterTablesClass();

            dlg.ObjectFilter     = pGxFilter;
            dlg.Title            = "添加关系表";
            dlg.ButtonCaption    = "添加";
            dlg.AllowMultiSelect = false;

            IEnumGxObject pEnumGxObject;

            dlg.DoModalOpen(0, out pEnumGxObject);
            if (pEnumGxObject != null)
            {
                pEnumGxObject.Reset();
                IGxObject gxObj;

                while ((gxObj = pEnumGxObject.Next()) != null)
                {
                    if (gxObj is IGxDataset)
                    {
                        IGxDataset gxDataset = gxObj as IGxDataset;
                        IDataset   pDataset  = gxDataset.Dataset;
                        if (pDataset.Type == esriDatasetType.esriDTTable)
                        {
                            ITable pTable = pDataset as ITable;
                            if (pTable.FindField("源OID") != -1 && pTable.FindField("待更新OID") != -1 &&
                                pTable.FindField("变化标记") != -1)
                            {
                                path = gxObj.FullName;
                                return(pTable);
                            }
                            else
                            {
                                MessageBox.Show("您打开的表格式不正确,请打开匹配关系表!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                }
            }
            path = string.Empty;
            return(null);
        }
Ejemplo n.º 12
0
        private void addFeature()
        {
            // 'make a dialog box object that will show shapefiles only
            IGxDialog       pGxDia = new GxDialog();
            IGxObjectFilter pGxObFil;

            //'the type of filter dictates what type of files can be chosen
            //'in this case it is shapefiles
            pGxObFil            = new GxFilterShapefiles();
            pGxDia.ObjectFilter = pGxObFil;


            //' make a gxEnum object to hold the files that the user selects from the dialog box
            IEnumGxObject gxEnum;

            if (!pGxDia.DoModalOpen(0, out gxEnum))
            {
                return;
            }

            IGxObject gxObj = gxEnum.Next();

            //        'Identify the workspace to access the file from
            //'in this case it will be a shapefile workspace factory since that is the type of file that will be chosen
            IWorkspaceFactory wksFact = new ShapefileWorkspaceFactory();
            IWorkspace        wks     = wksFact.OpenFromFile(gxObj.Parent.FullName, 0);

            //'create a new feature class object from the selected workspace
            //'set it to the name of the shapefile chosen in the dialog
            IFeatureWorkspace featWrk = (IFeatureWorkspace)wks;
            IFeatureClass     fClass  = featWrk.OpenFeatureClass(gxObj.Name);

            //'make a feature layer from teh featureclass object
            IFeatureLayer lyr = new FeatureLayer();

            lyr.FeatureClass = fClass;
            lyr.Name         = gxObj.Name;


            MapWorkspace.currentMap.Model.AddLayer(lyr);
            // imap.AddLayer(lyr);
        }
        protected override void OnClick()
        {
            // set
            m_pApp = (IGxApplication)CustomGxFilter_CS.ArcCatalog.Application;
            IGxCatalog      pCat        = null;
            IGxFileFilter   pFileFilter = null;
            IEnumGxObject   pSelection  = null;
            IGxDialog       pDlg        = null;
            IGxObjectFilter pFilter     = null;

            try
            {
                pDlg        = new GxDialog();
                pCat        = pDlg.InternalCatalog;
                pFileFilter = pCat.FileFilter;
                if (pFileFilter.FindFileType("py") < 0)
                {
                    //enter the third parameter with the location of the icon as needed
                    pFileFilter.AddFileType("PY", "Python file", "");
                }

                pFilter               = new CustomGxFilter_CS.CustomFilter();
                pDlg.ObjectFilter     = pFilter;
                pDlg.Title            = "Please select a .Py file";
                pDlg.AllowMultiSelect = true;
                pDlg.DoModalOpen(0, out pSelection);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
            finally
            {
                pCat        = null;
                pFileFilter = null;
                pSelection  = null;
                pDlg        = null;
                pFilter     = null;
            }
        }
        protected override void OnClick()
        {
            // set
            m_pApp = (IGxApplication)CustomGxFilter_CS.ArcCatalog.Application;
            IGxCatalog pCat = null;
            IGxFileFilter pFileFilter = null;
            IEnumGxObject pSelection = null;
            IGxDialog pDlg = null;
            IGxObjectFilter pFilter = null;
            try
            {
                pDlg = new GxDialog();
                pCat = pDlg.InternalCatalog ;
                pFileFilter = pCat.FileFilter;
                if (pFileFilter.FindFileType("py") < 0)
                {
                    //enter the third parameter with the location of the icon as needed
                    pFileFilter.AddFileType("PY", "Python file", "");
                }

                pFilter = new CustomGxFilter_CS.CustomFilter();
                pDlg.ObjectFilter = pFilter;
                pDlg.Title = "Please select a .Py file";
                pDlg.AllowMultiSelect = true;
                pDlg.DoModalOpen(0, out pSelection);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
            finally
            {
                pCat = null;
                pFileFilter = null;
                pSelection = null;
                pDlg = null;
                pFilter = null;
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 打开源图层
        /// </summary>
        /// <param name="path">路径</param>
        /// <returns></returns>
        public static IFeatureClass OpenSourceLayer(out string path)
        {
            IGxDialog dlg = new GxDialog();

            IGxObjectFilter pGxFilter = new GxFilterFeatureClassesClass();

            dlg.ObjectFilter     = pGxFilter;
            dlg.Title            = "添加源图层";
            dlg.ButtonCaption    = "添加";
            dlg.AllowMultiSelect = false;

            IEnumGxObject pEnumGxObject;

            dlg.DoModalOpen(0, out pEnumGxObject);
            if (pEnumGxObject != null)
            {
                pEnumGxObject.Reset();
                IGxObject gxObj;

                while ((gxObj = pEnumGxObject.Next()) != null)
                {
                    if (gxObj is IGxDataset)
                    {
                        IGxDataset gxDataset = gxObj as IGxDataset;
                        IDataset   pDataset  = gxDataset.Dataset;
                        if (pDataset.Type == esriDatasetType.esriDTFeatureClass)
                        {
                            IFeatureClass pIFeatureClass = pDataset as IFeatureClass;
                            path = gxObj.FullName;
                            return(pIFeatureClass);
                        }
                    }
                }
            }
            path = string.Empty;
            return(null);
        }
Ejemplo n.º 16
0
        //工程设置添加文件
        private void addFile(TextBox tx, string tablename)
        {
            try
            {
                IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();

                IGxDialog dlg = new GxDialog();
                IGxObjectFilterCollection filterCollection = dlg as IGxObjectFilterCollection;
                filterCollection.AddFilter(new GxFilterFeatureClasses(), true);
                IEnumGxObject enumObj;
                dlg.AllowMultiSelect = true;
                dlg.Title            = "添加数据";
                dlg.DoModalOpen(0, out enumObj);
                if (enumObj != null)
                {
                    enumObj.Reset();
                    int       a     = 0;
                    IGxObject gxObj = enumObj.Next();
                    while (gxObj != null)
                    {
                        Console.WriteLine(a++);
                        if (gxObj is IGxDataset)
                        {
                            IGxDataset gxDataset = gxObj as IGxDataset;
                            IDataset   pDataset  = gxDataset.Dataset;
                            switch (pDataset.Type)
                            {
                            case esriDatasetType.esriDTFeatureClass:
                                IFeatureClass pFc = pDataset as IFeatureClass;

                                ISpatialReference pSpatialReference = (pFc as IGeoDataset).SpatialReference;    //空间参考
                                CommonClass       common            = new CommonClass();
                                if (pSpatialReference.Name != common.GetConfigValue("SpatialReferenceName"))
                                {
                                    MessageBox.Show("空间参考错误");
                                    break;
                                }
                                else
                                {
                                    string layerType = "";
                                    if (pDataset.Category.Contains("个人地理数据库") || pDataset.Category.Contains("Personal"))
                                    {
                                        layerType = "Access数据库";
                                    }
                                    else if (pDataset.Category.Contains("文件地理数据库") || pDataset.Category.Contains("File"))
                                    {
                                        layerType = "文件夹数据库";
                                    }

                                    IFields fields = pFc.Fields;
                                    Dictionary <string, List <string> > dicCustom = new Dictionary <string, List <string> >();
                                    Dictionary <string, List <string> > dicSys    = new Dictionary <string, List <string> >();

                                    ConnectDB db = new ConnectDB();
                                    DataTable dt = db.GetDataBySql("select FIELD_NAME,DATA_TYPE,MAXLEN from GISDATA_MATEDATA where REG_NAME  = '" + tablename + "'");
                                    DataRow[] dr = dt.Select(null);

                                    string errorString = "";

                                    for (int i = 0; i < dr.Length; i++)
                                    {
                                        string        FIELD_NAME = dr[i]["FIELD_NAME"].ToString();
                                        string        DATA_TYPE  = dr[i]["DATA_TYPE"].ToString();
                                        string        MAXLEN     = dr[i]["MAXLEN"].ToString();
                                        List <string> list1      = new List <string>();
                                        list1.Add(DATA_TYPE);
                                        list1.Add(MAXLEN);
                                        dicSys.Add(FIELD_NAME, list1);
                                    }

                                    for (int i = 0; i < fields.FieldCount; i++)
                                    {
                                        IField field = fields.get_Field(i);
                                        if (field.Name != pFc.ShapeFieldName && field.Name != pFc.OIDFieldName)
                                        {
                                            List <string> list1 = new List <string>();
                                            list1.Add(field.Type.ToString());
                                            list1.Add(field.Length.ToString());
                                            dicCustom.Add(field.Name.ToString(), list1);
                                            if (dicSys.ContainsKey(field.Name))
                                            {
                                                if (dicSys[field.Name][0] != field.Type.ToString())
                                                {
                                                    errorString += "字段类型错误:" + field.Name + "(" + dicSys[field.Name][0] + ");\r\n";
                                                }
                                                else if (dicSys[field.Name][1] != field.Length.ToString())
                                                {
                                                    errorString += "字段长度错误:" + field.Name + "(" + dicSys[field.Name][0] + ");\r\n";
                                                }
                                            }
                                            else
                                            {
                                                errorString += "多余字段:" + field.Name + ";\r\n";
                                            }
                                        }
                                    }

                                    foreach (KeyValuePair <string, List <string> > itemList in dicSys)
                                    {
                                        if (!dicCustom.ContainsKey(itemList.Key))
                                        {
                                            errorString += "缺少字段:" + itemList.Key + ";\r\n";
                                        }
                                    }

                                    if (errorString != "")
                                    {
                                        FormMessage message = new FormMessage("提示", errorString);
                                        message.ShowDialog();
                                        //MessageBox.Show(errorString);
                                    }
                                    else
                                    {
                                        string path = pDataset.Workspace.PathName.Replace(@"\", @"\\");
                                        Console.WriteLine(path);
                                        Boolean result = db.Update("update GISDATA_REGINFO set PATH= '" + path + "',DBTYPE = '" + layerType + "',TABLENAME = '" + pDataset.Name + "' where REG_NAME = '" + tablename + "'");
                                        common.updateXmlNode(tablename, path, layerType, pDataset.Name);
                                        tx.Text = pDataset.BrowseName;
                                        tx.Name = pDataset.BrowseName;
                                    }
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        else if (gxObj is IGxLayer)
                        {
                            IGxLayer gxLayer = gxObj as IGxLayer;
                            ILayer   pLayer  = gxLayer.Layer;
                            break;
                            //do anything you like
                        }
                        gxObj = enumObj.Next();
                    }
                }
            }
            catch (Exception e)
            {
                LogHelper.WriteLog(typeof(FormMain), e);
            }
        }
Ejemplo n.º 17
0
        //工程设置添加文件
        private void addFile11(TextBox tx, string tablename)
        {
            IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
            string            GdbPath          = Application.StartupPath + "\\GISData.gdb";
            string            MdbPath          = Application.StartupPath + "\\GISData.mdb";
            IWorkspaceFactory pWks             = new AccessWorkspaceFactoryClass();
            IWorkspace        pFwk             = pWks.OpenFromFile(MdbPath, 0) as IWorkspace;

            IGxDialog dlg = new GxDialog();
            IGxObjectFilterCollection filterCollection = dlg as IGxObjectFilterCollection;

            filterCollection.AddFilter(new GxFilterFeatureClasses(), true);
            IEnumGxObject enumObj;

            dlg.AllowMultiSelect = true;
            dlg.Title            = "添加数据";
            dlg.DoModalOpen(0, out enumObj);
            if (enumObj != null)
            {
                enumObj.Reset();
                int       a     = 0;
                IGxObject gxObj = enumObj.Next();
                while (gxObj != null)
                {
                    Console.WriteLine(a++);
                    if (gxObj is IGxDataset)
                    {
                        IGxDataset gxDataset = gxObj as IGxDataset;
                        IDataset   pDataset  = gxDataset.Dataset;
                        switch (pDataset.Type)
                        {
                        case esriDatasetType.esriDTFeatureClass:
                            IFeatureClass pFc = pDataset as IFeatureClass;

                            ISpatialReference pSpatialReference = (pFc as IGeoDataset).SpatialReference;    //空间参考
                            CommonClass       common            = new CommonClass();
                            if (pSpatialReference.Name != common.GetConfigValue("SpatialReferenceName"))
                            {
                                MessageBox.Show("空间参考错误");
                                break;
                            }
                            else
                            {
                                tx.Text = pDataset.BrowseName;
                                tx.Name = pDataset.BrowseName;
                            }
                            break;

                        case esriDatasetType.esriDTFeatureDataset:
                            IFeatureDataset pFeatureDs = pDataset as IFeatureDataset;
                            //do anyting you like
                            break;

                        case esriDatasetType.esriDTRasterDataset:
                            IRasterDataset rasterDs = pDataset as IRasterDataset;
                            //do anyting you like
                            break;

                        case esriDatasetType.esriDTTable:
                            ITable pTable = pDataset as ITable;
                            //do anyting you like
                            break;

                        case esriDatasetType.esriDTTin:
                            ITin pTin = pDataset as ITin;
                            //do anyting you like
                            break;

                        case esriDatasetType.esriDTRasterCatalog:
                            IRasterCatalog pCatalog = pDataset as IRasterCatalog;
                            //do anyting you like
                            break;

                        default:
                            break;
                        }
                    }
                    else if (gxObj is IGxLayer)
                    {
                        IGxLayer gxLayer = gxObj as IGxLayer;
                        ILayer   pLayer  = gxLayer.Layer;
                        break;
                        //do anything you like
                    }
                    gxObj = enumObj.Next();
                }
            }
        }
Ejemplo n.º 18
0
        private void load_button_Click(object sender, EventArgs e)
        {
            IGxDialog gxDialog = new GxDialog();
            gxDialog.AllowMultiSelect = false;
            gxDialog.ObjectFilter = new GxFilterPolylineFeatureClasses();
            gxDialog.Title = "Select your polyline features";
            IEnumGxObject objEnumerator = null;
            gxDialog.DoModalOpen(0, out objEnumerator);
            if (objEnumerator.Next() == null) return;
            objEnumerator.Reset();

            dataViewerMapControl.ActiveView.FocusMap.ClearLayers();

            IGxDataset gxDataset = objEnumerator.Next() as IGxDataset;
            IFeatureWorkspace workspace = gxDataset.Dataset.Workspace.PathName.EndsWith(".sde")
                ? sdeWorkspaceFactory.OpenFromFile(gxDataset.Dataset.Workspace.PathName, 0) as IFeatureWorkspace
                : fileWorkspaceFactory.OpenFromFile(gxDataset.Dataset.Workspace.PathName, 0) as IFeatureWorkspace;

            layer = new FeatureLayerClass();
            layer.FeatureClass = workspace.OpenFeatureClass(gxDataset.DatasetName.Name);
            layer.Name = gxDataset.DatasetName.Name;
            dataViewerMapControl.AddLayer(layer);
            featureClass = layer.FeatureClass;
            populateOIDBox(layer.FeatureClass);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                IMongoDbLoaderDlgVm dbDialog = UIUtils.GetLoaderVM();

                ButtonInfo browseBtn;
                browseBtn.OnClick = () =>
                {
                    string result = UIUtils.BrowseToFile(null, "Connection File to MongoDB (.mongoconn)|*.mongoconn", false);
                    if (String.IsNullOrEmpty(result))
                    {
                        return;
                    }

                    string          connInfoStr = ConnectionUtilities.DecodeConnFile(result);
                    MongoDBConnInfo connInfo    = ConnectionUtilities.ParseConnectionString(connInfoStr);
                    dbDialog.DatabaseText = connInfo.DBName;
                    dbDialog.ServerText   = connInfo.Connection.ToString();
                    dbDialog.File         = result;
                };
                browseBtn.IsEnabled = null;
                dbDialog.SetBrowse(browseBtn);


                IGxObject  ipSelectedItem = null;
                ButtonInfo browseToFC;
                browseToFC.OnClick = () =>
                {
                    IGxDialog ipBrowser = new GxDialog();
                    ipBrowser.ObjectFilter     = (IGxObjectFilter) new GxFilterPointFeatureClasses();
                    ipBrowser.AllowMultiSelect = false;
                    IEnumGxObject ipTempSelected;
                    if (ipBrowser.DoModalOpen(0, out ipTempSelected))
                    {
                        if (null != ipTempSelected)
                        {
                            ipSelectedItem  = ipTempSelected.Next();
                            dbDialog.FCConn = ipSelectedItem.FullName;
                        }
                    }
                };
                browseToFC.IsEnabled = null;
                dbDialog.SetSourceBrowse(browseToFC);

                ButtonInfo okBtn;
                okBtn.OnClick = (() =>
                {
                    if (ipSelectedItem == null)
                    {
                        return;
                    }

                    string connString = dbDialog.File;
                    if (String.IsNullOrEmpty(connString))
                    {
                        return;
                    }

                    dbDialog.Close();

                    IName ipSrcName = ipSelectedItem.InternalObjectName;
                    IFeatureClass ipSrc = (IFeatureClass)ipSrcName.Open();
                    IEnvelope ipExtent = ((IGeoDataset)ipSrc).Extent;

                    MongoDBWorkspacePluginFactory factory = new MongoDBWorkspacePluginFactory();
                    MongoDBWorkspace ws = factory.OpenMongoDBWorkspace(connString);

                    MongoDBDataset target = ws.CreateDataset(ipSelectedItem.BaseName, DataLoadUtilities.GetCreatableFields(ipSrc.Fields), ipExtent);

                    DataLoadUtilities.LoadData(ipSrc, target);
                });
                okBtn.IsEnabled = null;
                dbDialog.SetOk(okBtn);

                ButtonInfo cancelBtn;
                cancelBtn.OnClick = () =>
                {
                    dbDialog.Close();
                };
                cancelBtn.IsEnabled = null;
                dbDialog.SetCancel(cancelBtn);

                UIUtils.DisplayLoaderDialog(dbDialog);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
 private void setWorkspaceToolStripMenuItem_Click(object sender, EventArgs e)
 {
     IGxDialog gxDialog = new GxDialog();
     IGxObjectFilter gxObjectFilter_FGDB = new GxFilterFileGeodatabases();
     IGxObjectFilterCollection gxObjectFilterCollection = (IGxObjectFilterCollection)gxDialog;
     gxObjectFilterCollection.AddFilter(gxObjectFilter_FGDB, false);
     if (gxDialog.DoModalSave(0))
     {
         string workspaceName = gxDialog.FinalLocation.FullName + "/" + gxDialog.Name;
         this.label10.Text = workspaceName;
     }
 }
Ejemplo n.º 21
0
        public static IFeatureClass OpenArcGisFeatureClassFromDialog(int hwnd, string dialogTitle, esriGeometryType possibleInputFeatureClassGeometry)

        {
            IFeatureClass result = null;

            IGxDialog gxDialog = new GxDialog();

            IEnumGxObject gxEnum;



            switch (possibleInputFeatureClassGeometry)

            {
            case esriGeometryType.esriGeometryPoint:

                gxDialog.ObjectFilter = new GxFilterPointFeatureClasses();

                break;

            case esriGeometryType.esriGeometryPolyline:

                gxDialog.ObjectFilter = new GxFilterPolylineFeatureClasses();

                break;

            case esriGeometryType.esriGeometryPolygon:

                gxDialog.ObjectFilter = new GxFilterPolygonFeatureClasses();

                break;

            default:

                gxDialog.ObjectFilter = new GxFilterFeatureClasses();

                break;
            }

            gxDialog.AllowMultiSelect = false;

            gxDialog.Title = dialogTitle;

            if (gxDialog.DoModalOpen(hwnd, out gxEnum) && gxEnum != null)

            {
                IGxObject gxObject = gxEnum.Next();

                if (gxObject is IGxDataset)

                {
                    IGxDataset gxDataset = (IGxDataset)gxObject;

                    if (gxDataset.Dataset is IFeatureClass)
                    {
                        result = (IFeatureClass)gxDataset.Dataset;
                    }
                }
            }

            gxDialog.InternalCatalog.Close();

            Marshal.FinalReleaseComObject(gxDialog);

            return(result);
        }