Пример #1
0
        private void CreateDataset_Click(object sender, RoutedEventArgs e)
        {
            Workspace workspace           = null;
            DatasourceConnectionInfo info = null;

            try
            {
                Toolkit.SetDtNameAsTableName(true);

                var datasetName = "test222";

                workspace = new Workspace();
                info      = new DatasourceConnectionInfo();
                Datasource datasource = GetDbDatasource(workspace, info);
                Datasets   datasets   = datasource.Datasets;
                if (!datasets.IsAvailableDatasetName(datasetName))
                {
                    datasets.Delete(datasetName);
                }
                DatasetVectorInfo vectorInfo = new DatasetVectorInfo();
                vectorInfo.Name = datasetName;
                vectorInfo.Type = DatasetType.Point;
                var result = datasets.Create(vectorInfo);
                if (result != null)
                {
                    MessageBox.Show("添加数据集成功");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (info != null)
                {
                    info.Dispose();
                }
                if (workspace != null)
                {
                    workspace.Dispose();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 创建数据集
        /// Create the dataset
        /// </summary>
        public Boolean CreateDataset(Datasource datasource, DatasetType datasetType, String datasetName)
        {
            Boolean result = false;

            if (datasource == null)
            {
                return(result);
            }

            // 首先要判断输入的名字是否可用
            // Judge that whether the input name is usable or not
            if (!datasource.Datasets.IsAvailableDatasetName(datasetName))
            {
                MessageBox.Show($"名称为{datasetName}的数据集已存在");
                return(result);
            }

            Datasets          datasets   = datasource.Datasets;
            DatasetVectorInfo vectorInfo = new DatasetVectorInfo();

            vectorInfo.Name = datasetName;

            try
            {
                // Point等为Vector类型,类型是一样的,可以统一处理
                // Data such as Point,Line,etc can be operated as the same method as they are all vector type
                switch (datasetType)
                {
                case DatasetType.Point:
                case DatasetType.Line:
                case DatasetType.CAD:
                case DatasetType.Region:
                case DatasetType.Text:
                case DatasetType.Tabular:
                {
                    vectorInfo.Type = datasetType;
                    if (datasets.Create(vectorInfo) != null)
                    {
                        result = true;
                    }
                }
                break;

                case DatasetType.Grid:
                {
                    DatasetGridInfo datasetGridInfo = new DatasetGridInfo();
                    datasetGridInfo.Name        = datasetName;
                    datasetGridInfo.Height      = 200;
                    datasetGridInfo.Width       = 200;
                    datasetGridInfo.NoValue     = 1.0;
                    datasetGridInfo.PixelFormat = SuperMap.Data.PixelFormat.Single;
                    datasetGridInfo.EncodeType  = EncodeType.LZW;

                    if (datasets.Create(datasetGridInfo) != null)
                    {
                        result = true;
                    }
                }
                break;

                case DatasetType.Image:
                {
                    DatasetImageInfo datasetImageInfo = new DatasetImageInfo();
                    datasetImageInfo.Name            = datasetName;
                    datasetImageInfo.BlockSizeOption = BlockSizeOption.BS_128;
                    datasetImageInfo.Height          = 200;
                    datasetImageInfo.Width           = 200;
                    //datasetImageInfo.Palette = Colors.MakeRandom(10);
                    datasetImageInfo.EncodeType = EncodeType.None;

                    if (datasets.Create(datasetImageInfo) != null)
                    {
                        result = true;
                    }
                }
                break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(result);
        }
Пример #3
0
        public Boolean CreateDataset(DatasetType datasetType, String datasetName)
        {
            Boolean result = false;

            if (m_datasource == null)
            {
                return(result);
            }

            // 首先要判断输入的名字是否可用
            if (!m_datasource.Datasets.IsAvailableDatasetName(datasetName))
            {
                MessageBox.Show("该名字已经存在或不合法");
                return(result);
            }

            Datasets          datasets   = m_datasource.Datasets;
            DatasetVectorInfo vectorInfo = new DatasetVectorInfo();

            vectorInfo.Name = datasetName;

            try
            {
                // Point等为Vector类型,类型是一样的,可以统一处理
                switch (datasetType)
                {
                case DatasetType.Point:
                case DatasetType.Line:
                case DatasetType.CAD:
                case DatasetType.Region:
                case DatasetType.Text:
                case DatasetType.Tabular:
                {
                    vectorInfo.Type = datasetType;
                    if (datasets.Create(vectorInfo) != null)
                    {
                        result = true;
                    }
                }
                break;

                case DatasetType.Grid:
                {
                    DatasetGridInfo datasetGridInfo = new DatasetGridInfo();
                    datasetGridInfo.Name        = datasetName;
                    datasetGridInfo.BlockSize   = 125;
                    datasetGridInfo.Height      = 200;
                    datasetGridInfo.Width       = 200;
                    datasetGridInfo.NoValue     = 1.0;
                    datasetGridInfo.PixelFormat = PixelFormat.Single;
                    datasetGridInfo.EncodeType  = EncodeType.LZW;

                    if (datasets.Create(datasetGridInfo) != null)
                    {
                        result = true;
                    }
                }
                break;

                case DatasetType.Image:
                {
                    DatasetImageInfo datasetImageInfo = new DatasetImageInfo();
                    datasetImageInfo.Name       = datasetName;
                    datasetImageInfo.Height     = 200;
                    datasetImageInfo.Width      = 200;
                    datasetImageInfo.Palette    = Colors.MakeRandom(10);
                    datasetImageInfo.EncodeType = EncodeType.None;

                    if (datasets.Create(datasetImageInfo) != null)
                    {
                        result = true;
                    }
                }
                break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(result);
        }