Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 拷贝构造函数。
 /// </summary>
 /// <param name="datasetGridInfo">栅格数据集对象。</param>
 /// <exception cref="ArgumentNullException">当栅格数据集信息对象为 Null 时抛出异常。</exception>
 public DatasetGridInfo(DatasetGridInfo datasetGridInfo)
     : base(datasetGridInfo)
 {
     if (datasetGridInfo == null) throw new ArgumentNullException("datasetGridInfo", Resources.ArgumentIsNotNull);
     this.BlockSize = datasetGridInfo.BlockSize;
     this.Height = datasetGridInfo.Height;
     this.MaxValue = datasetGridInfo.MaxValue;
     this.MinValue = datasetGridInfo.MinValue;
     this.NoValue = datasetGridInfo.NoValue;
     this.PixelFormat = datasetGridInfo.PixelFormat;
     this.Width = datasetGridInfo.Width;
 }
Exemplo n.º 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);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> datasetInfoValues = serializer.Deserialize<Dictionary<string, object>>(reader);
            if (datasetInfoValues == null) return null;
            DatasetInfo datasetInfo = null;
            if (datasetInfoValues.ContainsKey("recordCount"))
            {
                datasetInfo = new DatasetVectorInfo();
                DatasetVectorInfo datasetVectorInfo = datasetInfo as DatasetVectorInfo;
                int recordCount = 0;
                if (datasetInfoValues.ContainsKey("recordCount") && datasetInfoValues["recordCount"] != null)
                {
                    recordCount = int.Parse(datasetInfoValues["recordCount"].ToString());
                }
                datasetVectorInfo.RecordCount = recordCount;
                bool isFileCache = false;
                if (datasetInfoValues.ContainsKey("isFileCache") && datasetInfoValues["isFileCache"] != null)
                {
                    isFileCache = bool.Parse(datasetInfoValues["isFileCache"].ToString());
                }
                datasetVectorInfo.IsFileCache = isFileCache;
                Charset charset = Charset.ANSI;
                if (datasetInfoValues.ContainsKey("charset") && datasetInfoValues["charset"] != null)
                {
                    charset = (Charset)Enum.Parse(typeof(Charset), datasetInfoValues["charset"].ToString(), false);
                }
                datasetVectorInfo.Charset = charset;
            }
            else if (datasetInfoValues.ContainsKey("isMultiBand"))
            {
                datasetInfo = new DatasetImageInfo();
                DatasetImageInfo datasetImageInfo = datasetInfo as DatasetImageInfo;
                int blockSize = 0;
                if (datasetInfoValues.ContainsKey("blockSize") && datasetInfoValues["blockSize"] != null)
                {
                    blockSize = int.Parse(datasetInfoValues["blockSize"].ToString());
                }
                datasetImageInfo.BlockSize = blockSize;
                int height = 0;
                if (datasetInfoValues.ContainsKey("height") && datasetInfoValues["height"] != null)
                {
                    height = int.Parse(datasetInfoValues["height"].ToString());
                }
                datasetImageInfo.Height = height;
                bool isMultiBand = false;
                if (datasetInfoValues.ContainsKey("isMultiBand") && datasetInfoValues["isMultiBand"] != null)
                {
                    isMultiBand = bool.Parse(datasetInfoValues["isMultiBand"].ToString());
                }
                datasetImageInfo.IsMultiBand = isMultiBand;

                datasetImageInfo.Palette = datasetInfoValues.ContainsKey("palette") && datasetInfoValues["palette"] != null ?
                    JsonConvert.DeserializeObject<Color[]>(datasetInfoValues["palette"].ToString()) : null;
                PixelFormat pixelFormat = PixelFormat.SINGLE;
                if (datasetInfoValues.ContainsKey("pixelFormat") && datasetInfoValues["pixelFormat"] != null)
                {
                    pixelFormat = (PixelFormat)Enum.Parse(typeof(PixelFormat), datasetInfoValues["pixelFormat"].ToString(), false);
                }
                datasetImageInfo.PixelFormat = pixelFormat;
                int width = 0;
                if (datasetInfoValues.ContainsKey("width") && datasetInfoValues["width"] != null)
                {
                    width = int.Parse(datasetInfoValues["width"].ToString());
                }
                datasetImageInfo.Width = width;
            }
            else if (datasetInfoValues.ContainsKey("noValue"))
            {
                datasetInfo = new DatasetGridInfo();
                DatasetGridInfo datasetGridInfo = datasetInfo as DatasetGridInfo;
                int blockSize = 0;
                if (datasetInfoValues.ContainsKey("blockSize") && datasetInfoValues["blockSize"] != null)
                {
                    blockSize = int.Parse(datasetInfoValues["blockSize"].ToString());
                }
                datasetGridInfo.BlockSize = blockSize;
                int height = 0;
                if (datasetInfoValues.ContainsKey("height") && datasetInfoValues["height"] != null)
                {
                    height = int.Parse(datasetInfoValues["height"].ToString());
                }
                datasetGridInfo.Height = height;
                double maxValue = 0.0;
                if (datasetInfoValues.ContainsKey("maxValue") && datasetInfoValues["maxValue"] != null)
                {
                    maxValue = double.Parse(datasetInfoValues["maxValue"].ToString());
                }
                datasetGridInfo.MaxValue = maxValue;
                double minValue = 0.0;
                if (datasetInfoValues.ContainsKey("minValue") && datasetInfoValues["minValue"] != null)
                {
                    maxValue = double.Parse(datasetInfoValues["minValue"].ToString());
                }
                datasetGridInfo.MinValue = minValue;
                double noValue = 0.0;
                if (datasetInfoValues.ContainsKey("noValue") && datasetInfoValues["noValue"] != null)
                {
                    noValue = double.Parse(datasetInfoValues["noValue"].ToString());
                }
                datasetGridInfo.NoValue = noValue;
                PixelFormat pixelFormat = PixelFormat.SINGLE;
                if (datasetInfoValues.ContainsKey("pixelFormat") && datasetInfoValues["pixelFormat"] != null)
                {
                    pixelFormat = (PixelFormat)Enum.Parse(typeof(PixelFormat), datasetInfoValues["pixelFormat"].ToString(), false);
                }
                datasetGridInfo.PixelFormat = pixelFormat;
                int width = 0;
                if (datasetInfoValues.ContainsKey("width") && datasetInfoValues["width"] != null)
                {
                    width = int.Parse(datasetInfoValues["width"].ToString());
                }
                datasetGridInfo.Width = width;
            }
            else
            {
                datasetInfo = new DatasetInfo();
            }
            datasetInfo.Bounds = datasetInfoValues.ContainsKey("bounds") && datasetInfoValues["bounds"] != null ?
                JsonConvert.DeserializeObject<Rectangle2D>(datasetInfoValues["bounds"].ToString()) : null;
            datasetInfo.DataSourceName = datasetInfoValues.ContainsKey("dataSourceName") && datasetInfoValues["dataSourceName"] != null ? datasetInfoValues["dataSourceName"].ToString() : "";
            datasetInfo.Description = datasetInfoValues.ContainsKey("description") && datasetInfoValues["description"] != null ? datasetInfoValues["description"].ToString() : "";
            EncodeType encodeType = EncodeType.NONE;
            if (datasetInfoValues.ContainsKey("encodeType") && datasetInfoValues["encodeType"] != null)
            {
                encodeType = (EncodeType)Enum.Parse(typeof(EncodeType), datasetInfoValues["encodeType"].ToString(), false);
            }
            datasetInfo.EncodeType = encodeType;
            bool isReadOnly = true;
            if (datasetInfoValues.ContainsKey("isReadOnly") && datasetInfoValues["isReadOnly"] != null)
            {
                isReadOnly = bool.Parse(datasetInfoValues["isReadOnly"].ToString());
            }
            datasetInfo.IsReadOnly = isReadOnly;
            datasetInfo.Name = datasetInfoValues.ContainsKey("name") && datasetInfoValues["name"] != null ? datasetInfoValues["name"].ToString() : "";
            datasetInfo.PrjCoordSys = datasetInfoValues.ContainsKey("prjCoordSys") && datasetInfoValues["prjCoordSys"] != null ?
                JsonConvert.DeserializeObject<PrjCoordSys>(datasetInfoValues["prjCoordSys"].ToString()) : null;
            datasetInfo.TableName = datasetInfoValues.ContainsKey("tableName") && datasetInfoValues["tableName"] != null ?
                datasetInfoValues["tableName"].ToString() : "";
            DatasetType type = DatasetType.UNDEFINED;
            if (datasetInfoValues.ContainsKey("type") && datasetInfoValues["type"] != null)
            {
                type = (DatasetType)Enum.Parse(typeof(DatasetType), datasetInfoValues["type"].ToString(), false);
            }
            datasetInfo.Type = type;

            return datasetInfo;
        }