//创建工作空间(超图)
        public void CreateWorkspace(string wpsPath, string sources, string symbol)
        {
            // 创建工作空间,弹出 “关于”对话框
            SuperMap.Data.Workspace workspace = new SuperMap.Data.Workspace();
            WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo();
            workspaceConnectionInfo.Type = WorkspaceType.SMWU;

            workspaceConnectionInfo.Name = "MapResult";
            workspaceConnectionInfo.Password = "******";
            String file = wpsPath;
            workspaceConnectionInfo.Server = file;

            if (workspace.Create(workspaceConnectionInfo))
            {
                //MessageBox.Show("创建工作空间成功");
                workspace.Caption = "MapResult";
                workspace.Save();
                DirectoryInfo di = new DirectoryInfo(symbol);
                foreach (FileInfo fill in di.GetFiles("*.bru"))
                {
                    File.Copy(fill.FullName, sources + "//" + fill.Name, true);
                    SymbolFillLibrary sf = workspace.Resources.FillLibrary;
                    sf.FromFile(sources + "//" + fill.Name);
                    workspace.Save();
                }
                foreach (FileInfo point in di.GetFiles("*.sym"))
                {
                    File.Copy(point.FullName, sources + "//" + point.Name, true);

                    SymbolMarkerLibrary sf = workspace.Resources.MarkerLibrary;
                    sf.FromFile(sources + "//" + point.Name);
                    workspace.Save();
                } foreach (FileInfo Line in di.GetFiles("*.lsl"))
                {
                    File.Copy(Line.FullName, sources + "//" + Line.Name, true);

                    SymbolLineLibrary sf = workspace.Resources.LineLibrary;
                    sf.FromFile(sources + "//" + Line.Name);
                    workspace.Save();
                }
                di = new DirectoryInfo(sources);
                FileInfo[] fl = di.GetFiles("*.udb");
                for (int s = 0; s < fl.Length; s++)
                {
                    DatasourceConnectionInfo ds = new DatasourceConnectionInfo();
                    ds.Alias = fl[s].Name.Substring(0, fl[s].Name.Length - 4);
                    ds.Password = "******";
                    ds.Server = sources + "\\" + fl[s].ToString();
                    //ds.Password = "******";
                    Datasource datasource = workspace.Datasources.Open(ds);
                    if (ds.Alias.Substring(0, 4) == "ymgc")
                    {
                        ProjectConverTest(@"G:\移动风险监测\参考坐标\CGCS_2000.xml", datasource);
                        System.Threading.Thread.Sleep(100);
                    }
                    //= "ymgc1";
                    if (datasource == null)
                    {
                        MessageBox.Show("打开数据源失败");
                    }
                    else
                    {
                        //MessageBox.Show(fl[s].Name+"数据源打开成功!");
                    }
                    workspace.Save();

                }
                workspace.Close();
                workspace.Dispose();
                workspaceConnectionInfo.Dispose();
            }

        }
        public void CreateWorkspace(string wpsPath, string sources, string symbol)
        {
            // 创建工作空间,弹出 “关于”对话框
            Msg("正在创建工作空间···");
            SuperMap.Data.Workspace workspace = new SuperMap.Data.Workspace();
            WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo();
            workspaceConnectionInfo.Type = WorkspaceType.SMWU;

            workspaceConnectionInfo.Name = "MapResult";
            workspaceConnectionInfo.Password = set.passWod;
            String file = wpsPath;
            workspaceConnectionInfo.Server = file;

            if (workspace.Create(workspaceConnectionInfo))
            {
                //MessageBox.Show("创建工作空间成功");
                workspace.Caption = "MapResult";
                workspace.Save();
                Msg("工作空间创建成功:" + workspace.Caption);
                //System.Threading.Thread.Sleep(500);
                Msg("正在导入符号库···");
                DirectoryInfo di = new DirectoryInfo(symbol);
                foreach (FileInfo fill in di.GetFiles("*.bru"))
                {
                    File.Copy(fill.FullName, sources + "//" + fill.Name, true);
                    SymbolFillLibrary sf = workspace.Resources.FillLibrary;
                    sf.FromFile(sources + "//" + fill.Name);
                    workspace.Save();
                }
                foreach (FileInfo point in di.GetFiles("*.sym"))
                {
                    File.Copy(point.FullName, sources + "//" + point.Name, true);

                    SymbolMarkerLibrary sf = workspace.Resources.MarkerLibrary;
                    sf.FromFile(sources + "//" + point.Name);
                    workspace.Save();
                } foreach (FileInfo Line in di.GetFiles("*.lsl"))
                {
                    File.Copy(Line.FullName, sources + "//" + Line.Name, true);

                    SymbolLineLibrary sf = workspace.Resources.LineLibrary;
                    sf.FromFile(sources + "//" + Line.Name);
                    workspace.Save();
                }
                Msg("符号库导入成功");

                System.Threading.Thread.Sleep(500);

                di = new DirectoryInfo(sources);
                FileInfo[] fl = di.GetFiles("*.udb");
                for (int s = 0; s < fl.Length; s++)
                {

                    DatasourceConnectionInfo ds = new DatasourceConnectionInfo();
                    ds.Alias = fl[s].Name.Substring(0, fl[s].Name.Length - 4);
                    Msg( "添加数据源:" + ds.Alias);
                    
                    ds.Server = sources + "\\" + fl[s].ToString();
                    ds.Password = set.passWod;
                    
                    Datasource datasource = workspace.Datasources.Open(ds);
                    if (datasource == null)
                    {
                        MessageBox.Show("打开数据源失败");
                    }
                    else
                    {
                        //MessageBox.Show(fl[s].Name+"数据源打开成功!");
                    }
                    workspace.Save();

                }
                workspace.Close();
                workspace.Dispose();
                workspaceConnectionInfo.Dispose();
            }

        }
        public string TransFile(byte[] fileBt, double width, string fileName, bool ifCreate)
        {
            // 0长度文件返回 0
            string rst = "0";

            if (fileBt.Length == 0)
            {
                return(rst);
            }
            string filePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["CSVPath"].ToString());   //存储文件路径

            //创建系统日期文件夹,避免同一文件夹下文件太多问题,避免同一地图应文档重名
            filePath = filePath + DateTime.Now.ToString("yyyyMMdd") + "\\";

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            FileStream fstream;

            //是否创建新文件
            if (ifCreate)
            {
                fstream = new FileStream(filePath + fileName, FileMode.Create);
            }
            else
            {
                fstream = new FileStream(filePath + fileName, FileMode.Append);
            }
            try
            {
                fstream.Write(fileBt, 0, fileBt.Length);   //二进制转换成文件
                //上传成功返回 1
                fstream.Close();
            }
            catch (Exception ex)
            {
                //上传失败返回 1
                rst = "error";
            }
            finally
            {
                fstream.Close();
            }
            //读取坐标文件转换面积
            //设置为实际值
            string imgPath = filePath + fileName;
            //坐标点导入处理
            StreamReader objReader = new StreamReader(imgPath);
            string       sLine     = "";
            ArrayList    LineList  = new ArrayList();

            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null && !sLine.Equals(""))
                {
                    LineList.Add(sLine);
                }
            }
            objReader.Close();
            bool   isrewrite  = true;
            string sourcePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["sourcePath"].ToString());   //存储文件路径
            string targetPath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["targetPath"].ToString());   //存储文件路径            String targetPath = str + "\\tempFolder\\temp_gkfqd.shp";
            string temp       = GenerateRandomCode(10);

            targetPath = targetPath + DateTime.Now.ToString("yyyyMMdd") + "\\";

            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }
            targetPath = targetPath + temp + "\\";
            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }
            System.IO.File.Copy(sourcePath + "testG.smwu", targetPath + "testG.smwu", isrewrite);
            System.IO.File.Copy(sourcePath + "test.udd", targetPath + "test.udd", isrewrite);
            System.IO.File.Copy(sourcePath + "test.udb", targetPath + "test.udb", isrewrite);
            this.fileWorkspace = new SuperMap.Data.Workspace();
            string workSpaceFilePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["BinPath"].ToString());   //存储文件路径

            try
            {
                //打开工作空间及地图文件类型
                WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(targetPath + "testG.smwu");
                fileWorkspace.Open(conInfo);
                fileDatasource      = fileWorkspace.Datasources["test"];
                sourceDatasetVector = fileDatasource.Datasets["dataT"] as DatasetVector;
                Recordset recordset = (sourceDatasetVector as DatasetVector).GetRecordset(false, CursorType.Dynamic);
                // 获得记录集对应的批量更新对象
                Recordset.BatchEditor editor = recordset.Batch;
                // 开始批量添加,将 example 数据集每条记录对应的几何对象添加到数据集中
                editor.Begin();
                //删除所有记录
                recordset.DeleteAll();
                Point2Ds points = new Point2Ds();
                for (int i = 1; i < LineList.Count - 1; i++)
                {
                    string[] fieldInfoListZ = LineList[i].ToString().Split(',');
                    Point2D  point2D        = new Point2D();
                    point2D.X = double.Parse(fieldInfoListZ[0].ToString());
                    point2D.Y = double.Parse(fieldInfoListZ[1].ToString());
                    points.Add(point2D);
                }
                GeoLine geolineE = new GeoLine();
                geolineE.AddPart(points);
                recordset.AddNew(geolineE);
                editor.Update();
                //调用创建矢量数据集缓冲区方法
                //设置缓冲区分析参数
                BufferAnalystParameter bufferAnalystParam = new BufferAnalystParameter();

                //FLAT:平头缓冲。ROUND:圆头缓冲。
                bufferAnalystParam.EndType = BufferEndType.Flat;
                //左侧缓冲距离,单位:米。
                bufferAnalystParam.LeftDistance = width / 2;
                //右侧缓冲距离,单位:米。
                bufferAnalystParam.RightDistance = width / 2;
                String bufferName = "bufferRegionDt";
                bufferName      = fileDatasource.Datasets.GetAvailableDatasetName(bufferName);
                m_bufferDataset = fileDatasource.Datasets.Create(new DatasetVectorInfo(bufferName, DatasetType.Region));
                //设置投影信息 不设置 报投影不一致错误
                m_bufferDataset.Datasource.Datasets["bufferRegionDt"].PrjCoordSys = (fileDatasource.Datasets["dataT"] as DatasetVector).PrjCoordSys;
                Boolean   isTrue     = SuperMap.Analyst.SpatialAnalyst.BufferAnalyst.CreateBuffer(recordset, m_bufferDataset, bufferAnalystParam, false, true);
                Recordset recordsetS = m_bufferDataset.Query("SmID=1", CursorType.Static);
                pfm = double.Parse(recordsetS.GetFieldValue("SMAREA").ToString());
                mu  = pfm * 0.0015;
                double gongqing = 0.0666667 * mu;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            rst = String.Format("{0:F2}", mu);
            fileWorkspace.Close();
            return(rst);
        }
Exemple #4
0
        public string TransFile(byte[] fileBt, string fileName, bool ifCreate)
        {
            // 0长度文件返回 0
            string rst = "0";

            if (fileBt.Length == 0)
            {
                return(rst);
            }
            string filePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["CSVPath"].ToString());   //存储文件路径

            //创建系统日期文件夹,避免同一文件夹下文件太多问题,避免同一地图应文档重名
            // filePath = filePath + DateTime.Now.ToString("yyyyMMdd") + "\\";
            if (!Directory.Exists(filePath))
            {
                // Create the directory it does not exist.
                Directory.CreateDirectory(filePath);
            }
            FileStream fstream;

            //是否创建新文件
            if (ifCreate)
            {
                fstream = new FileStream(filePath + fileName, FileMode.Create);
            }
            else
            {
                fstream = new FileStream(filePath + fileName, FileMode.Append);
            }
            try
            {
                fstream.Write(fileBt, 0, fileBt.Length);   //二进制转换成文件
                //上传成功返回 1
                fstream.Close();
            }
            catch (Exception ex)
            {
                //上传失败返回 1
                rst = "error";
            }
            finally
            {
                fstream.Close();
            }
            //读取坐标文件转换面积
            string imgPath = "d:/zuobiao.txt";
            //坐标点导入处理
            StreamReader objReader = new StreamReader(imgPath);
            string       sLine     = "";
            ArrayList    LineList  = new ArrayList();

            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null && !sLine.Equals(""))
                {
                    LineList.Add(sLine);
                }
            }
            objReader.Close();
            this.fileWorkspace = new SuperMap.Data.Workspace();
            try
            {
                //打开工作空间及地图文件类型
                WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(@"d:\testG.smwu");
                fileWorkspace.Open(conInfo);
                fileDatasource      = fileWorkspace.Datasources["test"];
                sourceDatasetVector = fileDatasource.Datasets["dataT"] as DatasetVector;
                //Recordset recordset = new Recordset();
                Recordset recordset = (sourceDatasetVector as DatasetVector).GetRecordset(false, CursorType.Dynamic);
                // 获得记录集对应的批量更新对象
                Recordset.BatchEditor editor = recordset.Batch;
                // 开始批量添加,将 example 数据集每条记录对应的几何对象添加到数据集中
                editor.Begin();
                //删除所有记录
                recordset.DeleteAll();
                Point2Ds points = new Point2Ds();
                for (int i = 1; i < LineList.Count - 1; i++)
                {
                    string[] fieldInfoListZ = LineList[i].ToString().Split(',');
                    Point2D  point2D        = new Point2D();
                    point2D.X = double.Parse(fieldInfoListZ[0].ToString());
                    point2D.Y = double.Parse(fieldInfoListZ[1].ToString());
                    points.Add(point2D);
                }
                GeoLine geolineE = new GeoLine();
                geolineE.AddPart(points);
                recordset.AddNew(geolineE);
                editor.Update();
                //调用创建矢量数据集缓冲区方法
                //设置缓冲区分析参数
                BufferAnalystParameter bufferAnalystParam = new BufferAnalystParameter();
                bufferAnalystParam.EndType       = BufferEndType.Flat;
                bufferAnalystParam.LeftDistance  = 50;
                bufferAnalystParam.RightDistance = 50;
                String bufferName = "bufferRegionDt";
                bufferName      = fileDatasource.Datasets.GetAvailableDatasetName(bufferName);
                m_bufferDataset = fileDatasource.Datasets.Create(new DatasetVectorInfo(bufferName, DatasetType.Region));
                Boolean   isTrue          = SuperMap.Analyst.SpatialAnalyst.BufferAnalyst.CreateBuffer(recordset, m_bufferDataset, bufferAnalystParam, false, true);
                Recordset formatRecordset = m_bufferDataset.GetRecordset(false, CursorType.Dynamic);
                GeoRegion geometrySearch  = (GeoRegion)formatRecordset.GetGeometry();
                pfm = geometrySearch.Area;
                mu  = pfm * 0.0015;
                double gongqing = 0.0666667 * mu;
                // 释放记录集
                //  recordset.Dispose();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            rst = pfm.ToString();
            fileWorkspace.Close();
            return(rst);
        }