示例#1
0
        /// <summary>
        /// Deletes the dataset.
        /// </summary>
        /// <param name="targetWorkspace">The target workspace.</param>
        /// <param name="sTargetName">Name of the s target.</param>
        /// <param name="type">The type.</param>
        public static void DeleteDataset(IWorkspace targetWorkspace, string sTargetName, esriDatasetType type = esriDatasetType.esriDTFeatureClass)
        {
            IDatasetName datasetName = null;

            switch (type)
            {
            case esriDatasetType.esriDTFeatureDataset:
                datasetName = new FeatureDatasetNameClass();
                break;

            case esriDatasetType.esriDTFeatureClass:
                datasetName = new FeatureClassNameClass();
                break;

            default:
                if (type == esriDatasetType.esriDTTable)
                {
                    datasetName = new TableNameClass();
                }
                break;
            }
            if (datasetName != null)
            {
                datasetName.Name          = sTargetName;
                datasetName.WorkspaceName = ((targetWorkspace as IDataset).FullName as IWorkspaceName);
                EngineAPI.DeleteDataset(targetWorkspace, datasetName);
            }
        }
示例#2
0
        /// <summary>
        /// 打开dbf表
        /// </summary>
        /// <param name="pathName"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public ITable OpenDBFTable(string pathName, string tableName)
        {
            // Create the workspace name object.
            IWorkspaceName workspaceName = new WorkspaceNameClass();

            workspaceName.PathName = pathName;
            if (pathName.Contains(".gdb"))
            {
                workspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory";
            }
            else
            {
                workspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.shapefileworkspacefactory";
            }
            // Create the table name object.
            IDatasetName dataSetName = new TableNameClass();

            dataSetName.Name          = tableName;
            dataSetName.WorkspaceName = workspaceName;
            // Open the table.
            IName  name  = (IName)dataSetName;
            ITable table = (ITable)name.Open();

            return(table);
        }
        /// <summary>
        ///     Overlays two event tables to create an output event table that represents the union or intersection of the input.
        /// </summary>
        /// <param name="gp">The route event geoprocessor.</param>
        /// <param name="type">The type of overlay to be performed.</param>
        /// <param name="output">
        ///     Parameter consisting of the route location fields and the type of events in the overlay event
        ///     table.
        /// </param>
        /// <param name="outputTableName">The table to be created.</param>
        /// <param name="outputWorkspace">The workspace that will contain the table that has been created.</param>
        /// <param name="trackCancel">Allows the operation be be cancelled.</param>
        /// <returns>Returns a <see cref="ITable" /> representing the table that has been created.</returns>
        private static ITable OverlayImpl(IRouteMeasureEventGeoprocessor2 gp, OverlayType type, IRouteEventProperties2 output, string outputTableName, IWorkspace outputWorkspace, ITrackCancel trackCancel)
        {
            var outputName = new TableNameClass();

            outputName.WorkspaceName = (IWorkspaceName)((IDataset)outputWorkspace).FullName;
            outputName.Name          = outputTableName;

            outputWorkspace.Delete(outputName);

            if (type == OverlayType.Union)
            {
                return(gp.Union2(output, true, outputName, trackCancel, ""));
            }

            return(gp.Intersect2(output, true, outputName, trackCancel, ""));
        }
        /// <summary>
        ///     Events will be aggregated where the to-measure of one event matches the from-measure of the next event. This option
        ///     is applicable only for line events.
        /// </summary>
        /// <param name="table">The table whose rows will be aggregated.</param>
        /// <param name="source">Parameter consisting of the route location fields and the type of events in the input event table.</param>
        /// <param name="outputWorkspace"></param>
        /// <param name="outputTableName">The table to be created.</param>
        /// <param name="output">
        ///     Parameter consisting of the route location fields and the type of events in the concatenate event
        ///     table.
        /// </param>
        /// <param name="trackCancel">The object that allows for monitoring the progress.</param>
        /// <param name="concatenateFields">The field(s)used to aggregate rows.</param>
        /// <returns>Returns a <see cref="ITable" /> representing the table that has been created.</returns>
        public static ITable Concatenate(this ITable table, IRouteEventProperties2 source, IWorkspace outputWorkspace, string outputTableName, IRouteEventProperties2 output, ITrackCancel trackCancel, params string[] concatenateFields)
        {
            var outputName = new TableNameClass();

            outputName.WorkspaceName = (IWorkspaceName)((IDataset)outputWorkspace).FullName;
            outputName.Name          = outputTableName;

            outputWorkspace.Delete(outputName);

            IRouteMeasureEventGeoprocessor2 gp = new RouteMeasureGeoprocessorClass();

            gp.InputEventProperties     = source;
            gp.InputTable               = table;
            gp.KeepZeroLengthLineEvents = false;

            return(gp.Concatenate2(output, concatenateFields, outputName, trackCancel, ""));
        }
        public static ITable LoadTable(string tblpath,string tblname)
        {
            ITable tbl = null;

            // Create workspace name object.
            IWorkspaceName wsName = new WorkspaceNameClass();
            wsName.PathName = tblpath;
            wsName.WorkspaceFactoryProgID = "esriDataSourcesFile.shapefileworkspacefactory";
            // Create dataset name object.
            IDatasetName dsetName = new TableNameClass();
            dsetName.Name = tblname;
            dsetName.WorkspaceName = wsName;
            // Open the table
            IName name = dsetName as IName;
            tbl = name.Open() as ITable;

            return tbl;
        }
示例#6
0
        /// <summary>
        /// 打开dbf表
        /// </summary>
        /// <param name="pathName"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        private ITable OpenDBFTable(string pathName, string tableName)
        {
            // Create the workspace name object.
            IWorkspaceName workspaceName = new WorkspaceNameClass();

            workspaceName.PathName = pathName;
            workspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.shapefileworkspacefactory";
            // Create the table name object.
            IDatasetName dataSetName = new TableNameClass();

            dataSetName.Name          = tableName;
            dataSetName.WorkspaceName = workspaceName;
            // Open the table.
            IName  name  = (IName)dataSetName;
            ITable table = (ITable)name.Open();

            return(table);
        }
示例#7
0
        private IName method_0()
        {
            if (this.string_0.Length == 0)
            {
                return(null);
            }
            IWorkspaceName name2 = new WorkspaceNameClass
            {
                WorkspaceFactoryProgID = "esriDataSourcesOleDB.TextFileWorkspaceFactory",
                PathName = System.IO.Path.GetDirectoryName(this.string_0)
            };
            IDatasetName name3 = new TableNameClass
            {
                Name          = System.IO.Path.GetFileName(this.string_0),
                WorkspaceName = name2
            };

            return(name3 as IName);
        }
示例#8
0
        private void ExportTable2DBF(ITable ptable, string strPath, string strFilename)
        {
            IDataset     pDataset     = ptable as IDataset;
            IDatasetName pDatasetName = pDataset.FullName as IDatasetName;



            IWorkspaceFactory pWF             = new ShapefileWorkspaceFactory();
            IWorkspace        pWorkspace      = pWF.OpenFromFile(strPath, 0);
            IDataset          pDatasetOUT     = pWorkspace as IDataset;
            IWorkspaceName    pWorkspaceName  = pDatasetOUT.FullName as IWorkspaceName;
            IDatasetName      pOUTDatasetName = new TableNameClass();

            pOUTDatasetName.Name          = strFilename;
            pOUTDatasetName.WorkspaceName = pWorkspaceName;

            IExportOperation pExpOp = new ExportOperationClass();

            pExpOp.ExportTable(pDatasetName, null, null, pOUTDatasetName, 0);
        }
示例#9
0
 private IDatasetName method_3(IDatasetName idatasetName_0, string string_0)
 {
     try
     {
         new GxCadDataset();
         IDatasetName   name  = new TableNameClass();
         IWorkspaceName name2 = new WorkspaceNameClass
         {
             WorkspaceFactoryProgID = "esriDataSourcesFile.CadWorkspaceFactory",
             PathName = idatasetName_0.WorkspaceName.PathName
         };
         name.Name          = idatasetName_0.Name + ":" + string_0;
         name.WorkspaceName = name2;
         return(name);
     }
     catch (Exception exception)
     {
         Logger.Current.Error("", exception, "");
     }
     return(null);
 }
示例#10
0
        internal static IName RicavaDatasetName(IDataset datasetInput, IWorkspaceName workspaceName)
        {
            IDatasetName datasetName = null;

            switch (datasetInput.Type)
            {
            case esriDatasetType.esriDTFeatureDataset:
                IFeatureDatasetName InFeatureDatasetName = new FeatureDatasetNameClass();
                datasetName = (IDatasetName)InFeatureDatasetName;
                break;

            case esriDatasetType.esriDTFeatureClass:
                IFeatureClassName InFeatureClassName = new FeatureClassNameClass();
                datasetName = (IDatasetName)InFeatureClassName;
                break;

            case esriDatasetType.esriDTTable:
                ITableName InTableName = new TableNameClass();
                datasetName = (IDatasetName)InTableName;
                break;

            case esriDatasetType.esriDTGeometricNetwork:
                IGeometricNetworkName InGeometricNetworkName = new GeometricNetworkNameClass();
                datasetName = (IDatasetName)InGeometricNetworkName;
                break;

            default:
                return(null);
            }

            // Set the name and workspace name of the new name object.
            datasetName.Name          = datasetInput.Name;
            datasetName.WorkspaceName = workspaceName;
            // Cast the object to the IName interface and return it.
            IName name = (IName)datasetName;

            return(name);
        }
示例#11
0
        /// <summary>
        /// Exports a dbf file to a designated place from a layer
        /// </summary>
        /// <param name="sOutputLocation">The location to create the dbf</param>
        /// <param name="pFLayer">the Featue layer from which to export the data</param>
        /// <returns>string - the name of the exported dbf (without the extension)</returns>
        /// <notes>
        ///     Modified from Kirk Kuykendall's code from this post
        ///         http://forums.esri.com/Thread.asp?c=93&f=993&t=210767&mc=12#msgid652601
        /// </notes>
        /// <changelog>
        ///         comments created.
        ///
        /// </changelog>
        public string createDBF(string sOutputLocation, IFeatureLayer pFLayer)
        {
            if (pFLayer == null)
            {
                MessageBox.Show("Feature layer was not found");
                return("");
            }

            try
            {
                ITable       pTable  = (ITable)pFLayer.FeatureClass;
                IDataset     pDs     = (IDataset)pTable;
                IDatasetName pDsName = (IDatasetName)pDs.FullName;

                IWorkspaceFactory pWkSpFact = new ShapefileWorkspaceFactoryClass();
                IWorkspace        pWkSp     = pWkSpFact.OpenFromFile(sOutputLocation, 0);
                IDataset          pWkSpDs   = (IDataset)pWkSp;

                IWorkspaceName pWkSpName  = (IWorkspaceName)pWkSpDs.FullName;
                IDatasetName   pOutDsName = new TableNameClass();
                pOutDsName.Name = pDs.Name + "_" + DateTime.UtcNow.DayOfYear + DateTime.UtcNow.Hour + DateTime.UtcNow.Minute + DateTime.UtcNow.Second;
                //pOutDsName.Name = pDs.Name;
                pOutDsName.WorkspaceName = pWkSpName;

                IExportOperation pExpOp = new ExportOperationClass();
                pExpOp.ExportTable(pDsName, null, null, pOutDsName, 0);

                return(pOutDsName.Name);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Errors occurred: \r\n\r\n" + ex.Message);
                return(null);
            }
            finally
            {
            }
        }
示例#12
0
        private bool method_0(string string_1, string string_2, bool bool_0)
        {
            IGxObject      obj2 = null;
            IDatasetName   name;
            IWorkspaceName name2;

            switch (string_2.ToLower())
            {
            case ".bmp":
            case ".png":
            case ".jpg":
            case ".tif":
            case ".img":
            case ".sid":
                obj2  = new GxRasterDataset();
                name  = new RasterDatasetNameClass();
                name2 = new WorkspaceNameClass
                {
                    WorkspaceFactoryProgID = "esriDataSourcesFile.RasterWorkspaceFactory",
                    PathName = Path.GetDirectoryName(string_1)
                };
                name.Name          = Path.GetFileName(string_1);
                name.WorkspaceName = name2;
                (obj2 as IGxDataset).DatasetName = name;
                obj2.Attach(this.igxObject_0, this.igxCatalog_0);
                if (bool_0)
                {
                    this.igxCatalog_0.ObjectAdded(obj2);
                }
                return(true);

            case ".mdb":
                obj2  = new GxDatabase();
                name2 = new WorkspaceNameClass
                {
                    WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory",
                    PathName = string_1
                };
                (obj2 as IGxDatabase).WorkspaceName = name2;
                obj2.Attach(this.igxObject_0, this.igxCatalog_0);
                if (bool_0)
                {
                    this.igxCatalog_0.ObjectAdded(obj2);
                }
                return(true);

            case ".shp":
                obj2  = new GxShapefileDataset();
                name  = new FeatureClassNameClass();
                name2 = new WorkspaceNameClass
                {
                    WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory",
                    PathName = Path.GetDirectoryName(string_1)
                };
                name.Name          = Path.GetFileName(string_1);
                name.WorkspaceName = name2;
                (obj2 as IGxDataset).DatasetName = name;
                obj2.Attach(this.igxObject_0, this.igxCatalog_0);
                if (bool_0)
                {
                    this.igxCatalog_0.ObjectAdded(obj2);
                }
                return(true);

            case ".dbf":
                if (
                    !File.Exists(Path.Combine(Path.GetDirectoryName(string_1),
                                              Path.GetFileNameWithoutExtension(string_1) + ".shp")))
                {
                    obj2  = new GxDataset();
                    name  = new TableNameClass();
                    name2 = new WorkspaceNameClass
                    {
                        WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory",
                        PathName = Path.GetDirectoryName(string_1)
                    };
                    name.Name          = Path.GetFileName(string_1);
                    name.WorkspaceName = name2;
                    (obj2 as IGxDataset).DatasetName = name;
                    obj2.Attach(this.igxObject_0, this.igxCatalog_0);
                    if (bool_0)
                    {
                        this.igxCatalog_0.ObjectAdded(obj2);
                    }
                    return(true);
                }
                return(false);

            case ".sde":
                obj2  = new GxDatabase();
                name2 = new WorkspaceNameClass
                {
                    WorkspaceFactoryProgID = "esriDataSourcesGDB.SdeWorkspaceFactory",
                    PathName = string_1
                };
                (obj2 as IGxDatabase).WorkspaceName = name2;
                obj2.Attach(this.igxObject_0, this.igxCatalog_0);
                if (bool_0)
                {
                    this.igxCatalog_0.ObjectAdded(obj2);
                }
                return(true);

            case ".lyr":
                obj2 = new GxLayer();
                (obj2 as IGxFile).Path = string_1;
                obj2.Attach(this.igxObject_0, this.igxCatalog_0);
                if (bool_0)
                {
                    this.igxCatalog_0.ObjectAdded(obj2);
                }
                return(true);

            case ".dwg":
            case ".dxf":
                obj2  = new GxCadDataset();
                name  = new CadDrawingNameClass();
                name2 = new WorkspaceNameClass
                {
                    WorkspaceFactoryProgID = "esriDataSourcesFile.CadWorkspaceFactory",
                    PathName = Path.GetDirectoryName(string_1)
                };
                name.Name          = Path.GetFileName(string_1);
                name.WorkspaceName = name2;
                (obj2 as IGxDataset).DatasetName = name;
                obj2.Attach(this.igxObject_0, this.igxCatalog_0);
                if (bool_0)
                {
                    this.igxCatalog_0.ObjectAdded(obj2);
                }
                return(true);

            case ".doc":
            case ".xls":
                obj2 = new GxOfficeFile();
                (obj2 as IGxFile).Path = string_1;
                obj2.Attach(this.igxObject_0, this.igxCatalog_0);
                if (bool_0)
                {
                    this.igxCatalog_0.ObjectAdded(obj2);
                }
                return(true);
            }
            return(false);
        }
示例#13
0
        public static void CopyPasteGeodatabaseData(IWorkspace sourceWorkspace, IWorkspace targetWorkspace, string objectName, esriDatasetType esriDataType)
        {
            // Validate input

            if ((sourceWorkspace.Type == esriWorkspaceType.esriFileSystemWorkspace) || (targetWorkspace.Type == esriWorkspaceType.esriFileSystemWorkspace))
            {
                return; // Should be a throw
            }
            //create source workspace name

            IDataset sourceWorkspaceDataset = (IDataset)sourceWorkspace;

            IWorkspaceName sourceWorkspaceName = (IWorkspaceName)sourceWorkspaceDataset.FullName;

            //create target workspace name

            IDataset targetWorkspaceDataset = (IDataset)targetWorkspace;

            IWorkspaceName targetWorkspaceName = (IWorkspaceName)targetWorkspaceDataset.FullName;

            //Create Name Object Based on data type

            IDatasetName datasetName;

            switch (esriDataType)
            {
            case esriDatasetType.esriDTFeatureDataset:

                IFeatureDatasetName inFeatureDatasetName = new FeatureDatasetNameClass();

                datasetName          = (IDatasetName)inFeatureDatasetName;
                inFeatureDatasetName = null;
                break;

            case esriDatasetType.esriDTFeatureClass:

                IFeatureClassName inFeatureClassName = new FeatureClassNameClass();

                datasetName        = (IDatasetName)inFeatureClassName;
                inFeatureClassName = null;

                break;

            case esriDatasetType.esriDTTable:

                ITableName inTableName = new TableNameClass();

                datasetName = (IDatasetName)inTableName;
                inTableName = null;

                break;

            case esriDatasetType.esriDTGeometricNetwork:

                IGeometricNetworkName inGeometricNetworkName = new GeometricNetworkNameClass();

                datasetName            = (IDatasetName)inGeometricNetworkName;
                inGeometricNetworkName = null;

                break;

            case esriDatasetType.esriDTRelationshipClass:

                IRelationshipClassName inRelationshipClassName = new RelationshipClassNameClass();

                datasetName             = (IDatasetName)inRelationshipClassName;
                inRelationshipClassName = null;
                break;

            case esriDatasetType.esriDTNetworkDataset:

                INetworkDatasetName inNetworkDatasetName = new NetworkDatasetNameClass();

                datasetName          = (IDatasetName)inNetworkDatasetName;
                inNetworkDatasetName = null;

                break;

            case esriDatasetType.esriDTTopology:

                ITopologyName inTopologyName = new TopologyNameClass();

                datasetName    = (IDatasetName)inTopologyName;
                inTopologyName = null;

                break;

            default:

                return;     // Should be a throw
            }

            // Set the name of the object to be copied

            datasetName.WorkspaceName = (IWorkspaceName)sourceWorkspaceName;

            datasetName.Name = objectName;

            //Setup mapping for copy/paste

            IEnumNameMapping fromNameMapping;

            ESRI.ArcGIS.esriSystem.IEnumNameEdit editFromName;

            ESRI.ArcGIS.esriSystem.IEnumName fromName = new NamesEnumerator();

            editFromName = (ESRI.ArcGIS.esriSystem.IEnumNameEdit)fromName;

            editFromName.Add((ESRI.ArcGIS.esriSystem.IName)datasetName);

            ESRI.ArcGIS.esriSystem.IName toName = (ESRI.ArcGIS.esriSystem.IName)targetWorkspaceName;

            // Generate name mapping


            ESRI.ArcGIS.Geodatabase.IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();

            bool targetWorkspaceExists;

            targetWorkspaceExists = geoDBDataTransfer.GenerateNameMapping(fromName, toName, out fromNameMapping);

            // Copy/Pate the data

            geoDBDataTransfer.Transfer(fromNameMapping, toName);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(geoDBDataTransfer);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(datasetName);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(fromName);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(editFromName);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(fromNameMapping);
            geoDBDataTransfer = null;
            datasetName       = null;
            editFromName      = null;
            fromName          = null;

            sourceWorkspaceDataset = null;
            sourceWorkspaceName    = null;
            targetWorkspaceDataset = null;
            targetWorkspaceName    = null;
            toName          = null;
            fromNameMapping = null;
        }
示例#14
0
 public void Do()
 {
     try
     {
         IDatasetName name;
         this.panel1.Visible = true;
         Dataloaders dataloaders = new Dataloaders();
         (dataloaders.Converter as IFeatureProgress_Event).Step +=
             (new IFeatureProgress_StepEventHandler(this.method_6));
         IQueryFilter filter = null;
         if (this.txtWhere.Text.Length > 0)
         {
             filter = new QueryFilterClass
             {
                 WhereClause = this.txtWhere.Text
             };
         }
         dataloaders.ConvertData(this.iname_0 as IDatasetName, this.iname_1, this.txtOutFeatureClassName.Text,
                                 filter);
         IGxObject obj2 = null;
         this.method_0(this.igxObject_1);
         if (this.iname_1 is IWorkspaceName)
         {
             if ((this.iname_1 as IWorkspaceName).Type == esriWorkspaceType.esriFileSystemWorkspace)
             {
                 obj2 = new GxShapefileDataset();
             }
             else
             {
                 obj2 = new GxDataset();
             }
             if ((this.iname_0 as IDatasetName).Type == esriDatasetType.esriDTFeatureClass)
             {
                 name = new FeatureClassNameClass();
             }
             else
             {
                 name = new TableNameClass();
             }
             name.Name          = this.txtOutFeatureClassName.Text;
             name.WorkspaceName = this.iname_1 as IWorkspaceName;
             (obj2 as IGxDataset).DatasetName = name;
             this.igxObject_1.Refresh();
         }
         else if (this.iname_1 is IDatasetName)
         {
             obj2 = new GxDataset();
             if ((this.iname_0 as IDatasetName).Type == esriDatasetType.esriDTFeatureClass)
             {
                 name = new FeatureClassNameClass();
             }
             else
             {
                 name = new TableNameClass();
             }
             name.Name          = this.txtOutFeatureClassName.Text;
             name.WorkspaceName = (this.iname_1 as IDatasetName).WorkspaceName;
             (obj2 as IGxDataset).DatasetName = name;
             this.igxObject_1.Refresh();
         }
     }
     catch (Exception exception)
     {
         Logger.Current.Error("", exception, "");
     }
 }
        private void ExportTable2DBF(ITable ptable, string strPath, string strFilename)
        {
            IDataset pDataset = ptable as IDataset;
            IDatasetName pDatasetName = pDataset.FullName as IDatasetName;

            IWorkspaceFactory pWF = new ShapefileWorkspaceFactory();
            IWorkspace pWorkspace = pWF.OpenFromFile(strPath, 0);
            IDataset pDatasetOUT = pWorkspace as IDataset;
            IWorkspaceName pWorkspaceName = pDatasetOUT.FullName as IWorkspaceName;
            IDatasetName pOUTDatasetName = new TableNameClass ();
            pOUTDatasetName.Name = strFilename;
            pOUTDatasetName.WorkspaceName = pWorkspaceName;

            IExportOperation pExpOp = new ExportOperationClass();
            pExpOp.ExportTable(pDatasetName, null, null, pOUTDatasetName, 0);
        }
 /// <summary>
 /// performs a simple copy of database object
 /// </summary>
 /// <param name="parentObjClass">the parent object</param>
 /// <param name="outWks">out Workspace</param>
 /// <returns>the new feature object</returns>
 public IObjectClass simpleCopyObj(object parentObjClass, IWorkspace outWks)
 {
     IObjectClass outCls = null;
     IQueryFilter qyf = new QueryFilterClass();
     IFeatureDataConverter2 fdConv2 = new FeatureDataConverterClass();
     IDataset dSet = (IDataset)parentObjClass;
     esriDatasetType pDsetType = dSet.Type;
     string bn = dSet.BrowseName;
     string sbn = bn.Substring(bn.LastIndexOf(".")+1);
     IDatasetName dSetN = (IDatasetName)dSet.FullName;
     IDatasetName dSetN2;
     IWorkspaceName wksN = (IWorkspaceName)((IDataset)outWks).FullName;
     IFields pfs;
     if (pDsetType == esriDatasetType.esriDTTable)
     {
         ITableName tbn = new TableNameClass();
         dSetN2 = (IDatasetName)tbn;
         dSetN2.Name = sbn;
         dSetN2.WorkspaceName = wksN;
         pfs = (IFields)((IClone)((IObjectClass)parentObjClass).Fields).Clone();
         updateDomains(ref pfs, outWks);
         fdConv2.ConvertTable(dSetN,qyf, null, dSetN2, pfs, "",1000, 0);
         outCls = (IObjectClass)((IName)dSetN2).Open();
     }
     else if (pDsetType == esriDatasetType.esriDTFeatureClass)
     {
         IFeatureClass pFtCls = (IFeatureClass)dSet;
         IFeatureClassName fcn = new FeatureClassNameClass();
         IFeatureDatasetName fdn = new FeatureDatasetNameClass();
         IDatasetName dSetN3 = (IDatasetName)fdn;
         dSetN3.WorkspaceName = wksN;
         IFeatureDataset pFtDs = pFtCls.FeatureDataset;
         if (pFtDs == null)
         {
             dSetN3 = null;
             fdn = null;
         }
         else
         {
             string ftDN = pFtCls.FeatureDataset.Name;
             string ftDNs = ftDN.Substring(ftDN.LastIndexOf(".") + 1);
             dSetN3.Name = ftDNs;
         }
         dSetN2 = (IDatasetName)fcn;
         dSetN2.Name = sbn;
         dSetN2.WorkspaceName = wksN;
         IField pSf = pFtCls.Fields.get_Field(pFtCls.FindField(pFtCls.ShapeFieldName));
         pfs = (IFields)((IClone)pFtCls.Fields).Clone();
         updateDomains(ref pfs, outWks);
         fdConv2.ConvertFeatureClass(dSetN, qyf, null, fdn, fcn, (IGeometryDef)((IClone)pSf.GeometryDef).Clone(), pfs, "", 1000, 0);
         outCls = (IObjectClass)((IName)dSetN2).Open();
     }
     else
     {
     }
     return outCls;
 }
示例#17
0
        public Hashtable GetDataSummary(string layerName, string summaryFields, string dissolveField, bool selectedOnly = false)
        {
            Hashtable result = new Hashtable();
            ILayer layer = this._getLayerByName(layerName);
            if (layer != null && layer is IFeatureLayer)
            {
                ITable inputTable = (ITable)layer;
                IWorkspaceName wsName =  ((IDataset)(this._tempWorkspace)).FullName as IWorkspaceName;

                /*
                ShapefileWorkspaceFactoryClass tempWSFactory = new ShapefileWorkspaceFactoryClass();
                IWorkspace tempWS = tempWSFactory.OpenFromFile(System.IO.Path.GetTempPath(), 0);
                IWorkspaceName wsName = ((IDataset)(tempWS)).FullName as IWorkspaceName;
                */
                TableNameClass outputName = new TableNameClass();
                outputName.Name = layerName + "_summary_" + DateTime.Now.ToString("MM_dd_yy_H_mm_ss");
                outputName.WorkspaceName = wsName;

                if (inputTable.FindField(dissolveField) > 0)
                {
                    BasicGeoprocessorClass basicGeopro = new BasicGeoprocessorClass();
                    ITable resultTable = basicGeopro.Dissolve(inputTable, selectedOnly, dissolveField, summaryFields, outputName);
                    
                    result.Add("workspace", this._tempWorkspace.PathName);
                    result.Add("table", outputName.Name);

                    // Create a data graph.
                    IDataGraphT dataGraphT = new DataGraphTClass();
                    // Add the graph series.
                    ISeriesProperties seriesProps = dataGraphT.AddSeries("bar:vertical");
                    seriesProps.SourceData = resultTable;

                    seriesProps.SetField(0, resultTable.Fields.get_Field(1).Name);
                    seriesProps.SetField(1, resultTable.Fields.get_Field(2).Name);
                    seriesProps.LabelField = resultTable.Fields.get_Field(1).Name;

                    // Set titles.
                    dataGraphT.GeneralProperties.Title = "Bar Chart";
                    dataGraphT.AxisProperties[1].Title = dissolveField;
                    
                    // Update the data graph.
                    dataGraphT.Update(null);
                    // Export the graph to file (the format depends on the file extension).
                    string tempDir = System.IO.Path.GetTempPath();
                    string outImageFile = System.IO.Path.Combine(tempDir, outputName.Name + ".bmp");

                    if (System.IO.File.Exists(outImageFile))
                    {
                        System.IO.File.Delete(outImageFile);
                    }

                    dataGraphT.ExportToFile(outImageFile);

                    result.Add("graph", outImageFile);

                }
                
                
            }
            return result;
        }
        public ITable exportTable(ITable inputTable, string outPath, IQueryFilter filter)
        {
            // Create a name object for the source workspace and open it.
            IDataset inDset = (IDataset)inputTable;
            IWorkspace sourceWorkspace = (inDset).Workspace;

            // Create a name object for the target (file GDB) workspace and open it.
            string outDbStr = geoUtil.parseDbStr(outPath);
            string outName = System.IO.Path.GetFileName(outPath);
            IWorkspace targetWorkspace = geoUtil.OpenWorkSpace(outDbStr);
            outName = geoUtil.getSafeOutputNameNonRaster(targetWorkspace, outName);

            // Create a name object for the source dataset.
            ITableName sourceTableName = new TableNameClass();
            IDatasetName sourceDatasetName = (IDatasetName)sourceTableName;
            sourceDatasetName.Name = inDset.Name;
            sourceDatasetName.WorkspaceName = (IWorkspaceName)((IDataset)sourceWorkspace).FullName;

            // Create a name object for the target dataset.
            ITableName targetTableName = new TableNameClass();
            IDatasetName targetDatasetName = (IDatasetName)targetTableName;
            targetDatasetName.Name = outName;
            targetDatasetName.WorkspaceName = (IWorkspaceName)((IDataset)targetWorkspace).FullName; ;

            // Open source feature class to get field definitions.
            //IName sourceName = (IName)sourceFeatureClassName;
            ITable sourceTable = inputTable;

            // Create the objects and references necessary for field validation.
            IFieldChecker fieldChecker = new FieldCheckerClass();
            IFields sourceFields = sourceTable.Fields;
            IFields targetFields = null;
            IEnumFieldError enumFieldError = null;

            // Set the required properties for the IFieldChecker interface.
            fieldChecker.InputWorkspace = sourceWorkspace;
            fieldChecker.ValidateWorkspace = targetWorkspace;

            // Validate the fields and check for errors.
            fieldChecker.Validate(sourceFields, out enumFieldError, out targetFields);
            if (enumFieldError != null)
            {
                // Handle the errors in a way appropriate to your application.
                Console.WriteLine("Errors were encountered during field validation.");
            }

            // Create the converter and run the conversion.
            IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();
            IEnumInvalidObject enumInvalidObject = featureDataConverter.ConvertTable(sourceDatasetName, filter, targetDatasetName, targetFields,"",1000,0);

            // Check for errors.
            IInvalidObjectInfo invalidObjectInfo = null;
            enumInvalidObject.Reset();
            while ((invalidObjectInfo = enumInvalidObject.Next()) != null)
            {
                // Handle the errors in a way appropriate to the application.
                Console.WriteLine("Errors occurred for the following feature: {0}", invalidObjectInfo.InvalidObjectID);
            }
            return (Table)((IName)targetTableName).Open();
        }