Example #1
0
        //创建工作空间(超图)
        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();
            }

        }
Example #2
0
 //
 /// <summary>
 /// 模板应用
 /// </summary>
 /// <param name="xml">模板文件字符</param>
 /// <param name="wksPath">工作空间路径</param>
 /// <param name="name">地图名称</param>
 public void ModelApplication(String xml, string wksPath, string name)
 {
     //初始化工作空间
     SuperMap.Data.Workspace sWorkspace1 = new SuperMap.Data.Workspace();
     WorkspaceConnectionInfo info = new WorkspaceConnectionInfo(wksPath);//@"G:\数据转换\测试数据\Test1\test.smwu");
     info.Password ="******";
     sWorkspace1.Open(info);
     SuperMap.Data.Maps maps = sWorkspace1.Maps;
     maps.Add(name, xml);
     sWorkspace1.Save();
     sWorkspace1.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();
            }

        }
Example #4
0
        public void ProjectConver(string wpsPath, string prjRef, string name)
        {
            try
            {
                SuperMap.Data.Workspace wps = new SuperMap.Data.Workspace();
                WorkspaceConnectionInfo info = new WorkspaceConnectionInfo(wpsPath);
                wps.Open(info);
                Datasource dc = wps.Datasources["ymgc3"];

                //Dataset dset = wps.Datasources["ymgc1"].Datasets[name];// dsets["time1"];

                //dset.Datasource.Datasets.Delete("time2");
                //Dataset dst = dset.Datasource.CopyDataset(dset, "time2", dset.EncodeType);
                PrjCoordSys prj = new PrjCoordSys();
                prj.FromFile(prjRef, PrjFileType.SuperMap);

                for (int i = 1; i <= dc.Datasets.Count; i++)
                {
                    name = "time" + i.ToString();
                    try
                    {
                        Dataset dset = dc.Datasets[name];
                        //bool ok = CoordSysTranslator.Convert(dset, prj, new CoordSysTransParameter(), CoordSysTransMethod.GeocentricTranslation);
                        dset = CoordSysTranslator.Convert(dset, prj, dset.Datasource, name + "_", new CoordSysTransParameter(), CoordSysTransMethod.GeocentricTranslation);
                        dset.Datasource.Datasets.Delete(name);
                        dset.Datasource.CopyDataset(dset, name, dset.EncodeType);
                        dset.Datasource.Datasets.Delete(name + "_");
                        wps.Save();
                    }
                    catch
                    {
                        continue;
                    }

                }
                wps.Dispose();
                MessageBox.Show("OVER");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        public void ModelApplication(String xml, string wksPath, string name)
        {
            //初始化工作空间
            try
            {
                SuperMap.Data.Workspace sWorkspace1 = new SuperMap.Data.Workspace();
                WorkspaceConnectionInfo info = new WorkspaceConnectionInfo(wksPath);//@"G:\数据转换\测试数据\Test1\test.smwu");
                info.Password = set.passWod;
                sWorkspace1.Open(info);
                SuperMap.Data.Maps maps = sWorkspace1.Maps;
                maps.Add(name, xml);//,WorkspaceVersion.UGC60
                
                //sWorkspace1.Maps.SetMapXML(name, xml);
                
                sWorkspace1.Save();

                sWorkspace1.Dispose();
            }
            catch (Exception ex)
            {
                Msg(ex.Message);
            }

        }