如何修改rasterworkspace
1个回答
展开全部
在这里提醒大家注意,读取处理SDE上的栅格数据的时候一定要注意,其workspace是扩展的工作空间,即:RasterWorSpaceEx。
不能使用RasterWorSpace,转换的时候会失败。
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;
namespace RadioAnalysisGIS.DataToSDE
{
/// <summary>
/// 连接类型
/// </summary>
public enum ConnectWorkSpaceType
{
FeatureClassWorkSpace=0,
RasterWorkSpace=1
};
public abstract class ConnectWorkSpaceDef
{
protected ConnectWorkSpaceType CurrentWorkSpaceType = ConnectWorkSpaceType.FeatureClassWorkSpace;
public ConnectWorkSpaceDef() { }
public ConnectWorkSpaceType GetWorkSpaceType()
{
return CurrentWorkSpaceType;
}
}
public class SDEConnectPara //SDE的连接参数
{
public string Server;
public string Instance;
public string User;
public string Password;
public string Database;
public string Version;
public SDEConnectPara()
{
Version = "SDE.DEFAULT";
}
}
#region 定义连接参数
public class ConnectFeatureWorkSpaceDef : ConnectWorkSpaceDef
{
public readonly SDEConnectPara ConnectPara;
public ConnectFeatureWorkSpaceDef(SDEConnectPara Connparas)
{
CurrentWorkSpaceType = ConnectWorkSpaceType.FeatureClassWorkSpace;
ConnectPara = Connparas;
}
}
public class ConnectRasterWorkSpaceDef : ConnectWorkSpaceDef
{
public readonly SDEConnectPara ConnectPara;
public ConnectRasterWorkSpaceDef(SDEConnectPara Connparas)
{
CurrentWorkSpaceType = ConnectWorkSpaceType.RasterWorkSpace;
ConnectPara = Connparas;
}
}
#endregion
#region 获取工作空间
/// <summary>
/// 连接到SDE feature数据工作空间
/// </summary>
public class ConnectFeatureWorkSpaceGet
{
private ConnectFeatureWorkSpaceDef pDef;
public ConnectFeatureWorkSpaceGet(ConnectFeatureWorkSpaceDef ConnDef)
{
pDef = ConnDef;
}
public IFeatureWorkspace GetSDEWorkspace()
//依据pDef得到SDE的工作空间
{
IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
IFeatureWorkspace pWorkspace;
SDEConnectPara para = pDef.ConnectPara;
IPropertySet pPropSet = new PropertySetClass();
pPropSet.SetProperty("SERVER", para.Server);
pPropSet.SetProperty("INSTANCE", para.Instance);
pPropSet.SetProperty("USER", para.User);
pPropSet.SetProperty("PASSWORD", para.Password);
pPropSet.SetProperty("VERSION", para.Version);//可选,缺省为SDE.DEFAULT版本
pPropSet.SetProperty("Database", para.Database);
try
{
pWorkspace = pWorkspaceFactory.Open(pPropSet, 0) as IFeatureWorkspace;
}
catch (Exception ex)
{
return null;
}
return pWorkspace;
}
}
/// <summary>
/// 连接到SDE栅格数据工作空间
/// </summary>
public class ConnectRasterWorkSpaceGet
{
private ConnectRasterWorkSpaceDef pDef;
public ConnectRasterWorkSpaceGet(ConnectRasterWorkSpaceDef ConnDef)
{
pDef = ConnDef;
}
public IRasterWorkspaceEx GetSDEWorkspace()
//依据pDef得到SDE的工作空间
{
IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
IRasterWorkspaceEx pWorkspace;
SDEConnectPara para = pDef.ConnectPara;
IPropertySet pPropSet = new PropertySetClass();
pPropSet.SetProperty("SERVER", para.Server);
pPropSet.SetProperty("INSTANCE", para.Instance);
pPropSet.SetProperty("USER", para.User);
pPropSet.SetProperty("PASSWORD", para.Password);
pPropSet.SetProperty("VERSION", para.Version);//可选,缺省为SDE.DEFAULT版本
pPropSet.SetProperty("Database", para.Database);
try
{
pWorkspace = pWorkspaceFactory.Open(pPropSet, 0) as IRasterWorkspaceEx;
}
catch (Exception ex)
{
return null;
}
return pWorkspace;
}
}
#endregion
#region 连接参数设置
public class SDEConnectParas
{
#region SDE连接参数
string Server = "gisserver";
string Instance = "5152/tcp";
string User = "sde";
string Pass = "sde";
string Database = "sde";
string Version = "SDE.DEFAULT";
#endregion
public void GetSDEParameters(out string server, out string instance, out string user, out string password, out string database, out string version)
{
server = Server;
instance = Instance;
user = User;
password = Pass;
database = Database;
version = Version;
}//得到SDE连接参数
public bool ReadFromFile()
//从连接参数txt文件读取属性库和SDE的连接关键参数,以及站点关键表和关键SDE要素
{
string lpszPathName = FilePath.GetApplicationDir();
lpszPathName = lpszPathName + "//sdeconn.txt";
StreamReader reader = null;
try
{
reader = new StreamReader(lpszPathName);
string line = reader.ReadLine();
line = reader.ReadLine();
string[] SubStrings = line.Split(':');
Server = SubStrings[1];
line = reader.ReadLine();
SubStrings = line.Split(':');
Instance = SubStrings[1];
line = reader.ReadLine();
SubStrings = line.Split(':');
User = SubStrings[1];
line = reader.ReadLine();
SubStrings = line.Split(':');
Pass = SubStrings[1];
line = reader.ReadLine();
SubStrings = line.Split(':');
Database = SubStrings[1];
line = reader.ReadLine();
SubStrings = line.Split(':');
Version = SubStrings[1];
}
catch (IOException e)
{
Console.WriteLine(e.Message);
return false;
}
catch
{
return false;
}
finally
{
if (reader != null) reader.Close();
}
return true;
}
public void WhiteToLogFile()
//写入连接参数txt文件-----属性库和SDE的连接关键参数,以及站点关键表和关键SDE要素
{
string lpszPathName = FilePath.GetCurrentDir();
lpszPathName = lpszPathName + "//sdeconn.txt";
StreamWriter writer = File.CreateText(lpszPathName);
writer.Write("SDE配置参数");
writer.Write(writer.NewLine);
writer.Write("1、服务器:" + Server);
writer.Write(writer.NewLine);
writer.Write("2、SDE端口:" + Instance);
writer.Write(writer.NewLine);
writer.Write("3、用户:" + User);
writer.Write(writer.NewLine);
writer.Write("4、密码:" + Pass);
writer.Write(writer.NewLine);
writer.Write("5、数据库:" + Database);
writer.Write(writer.NewLine);
writer.Write("6、版本:" + Version);
writer.Write(writer.NewLine);
writer.Write(@"///////////////////////////////////////////");
writer.Write(writer.NewLine);
writer.Close();
}
}
#endregion
}
以上代码在SDE for Sql2005上测试通过。AE为9.3。
不能使用RasterWorSpace,转换的时候会失败。
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;
namespace RadioAnalysisGIS.DataToSDE
{
/// <summary>
/// 连接类型
/// </summary>
public enum ConnectWorkSpaceType
{
FeatureClassWorkSpace=0,
RasterWorkSpace=1
};
public abstract class ConnectWorkSpaceDef
{
protected ConnectWorkSpaceType CurrentWorkSpaceType = ConnectWorkSpaceType.FeatureClassWorkSpace;
public ConnectWorkSpaceDef() { }
public ConnectWorkSpaceType GetWorkSpaceType()
{
return CurrentWorkSpaceType;
}
}
public class SDEConnectPara //SDE的连接参数
{
public string Server;
public string Instance;
public string User;
public string Password;
public string Database;
public string Version;
public SDEConnectPara()
{
Version = "SDE.DEFAULT";
}
}
#region 定义连接参数
public class ConnectFeatureWorkSpaceDef : ConnectWorkSpaceDef
{
public readonly SDEConnectPara ConnectPara;
public ConnectFeatureWorkSpaceDef(SDEConnectPara Connparas)
{
CurrentWorkSpaceType = ConnectWorkSpaceType.FeatureClassWorkSpace;
ConnectPara = Connparas;
}
}
public class ConnectRasterWorkSpaceDef : ConnectWorkSpaceDef
{
public readonly SDEConnectPara ConnectPara;
public ConnectRasterWorkSpaceDef(SDEConnectPara Connparas)
{
CurrentWorkSpaceType = ConnectWorkSpaceType.RasterWorkSpace;
ConnectPara = Connparas;
}
}
#endregion
#region 获取工作空间
/// <summary>
/// 连接到SDE feature数据工作空间
/// </summary>
public class ConnectFeatureWorkSpaceGet
{
private ConnectFeatureWorkSpaceDef pDef;
public ConnectFeatureWorkSpaceGet(ConnectFeatureWorkSpaceDef ConnDef)
{
pDef = ConnDef;
}
public IFeatureWorkspace GetSDEWorkspace()
//依据pDef得到SDE的工作空间
{
IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
IFeatureWorkspace pWorkspace;
SDEConnectPara para = pDef.ConnectPara;
IPropertySet pPropSet = new PropertySetClass();
pPropSet.SetProperty("SERVER", para.Server);
pPropSet.SetProperty("INSTANCE", para.Instance);
pPropSet.SetProperty("USER", para.User);
pPropSet.SetProperty("PASSWORD", para.Password);
pPropSet.SetProperty("VERSION", para.Version);//可选,缺省为SDE.DEFAULT版本
pPropSet.SetProperty("Database", para.Database);
try
{
pWorkspace = pWorkspaceFactory.Open(pPropSet, 0) as IFeatureWorkspace;
}
catch (Exception ex)
{
return null;
}
return pWorkspace;
}
}
/// <summary>
/// 连接到SDE栅格数据工作空间
/// </summary>
public class ConnectRasterWorkSpaceGet
{
private ConnectRasterWorkSpaceDef pDef;
public ConnectRasterWorkSpaceGet(ConnectRasterWorkSpaceDef ConnDef)
{
pDef = ConnDef;
}
public IRasterWorkspaceEx GetSDEWorkspace()
//依据pDef得到SDE的工作空间
{
IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
IRasterWorkspaceEx pWorkspace;
SDEConnectPara para = pDef.ConnectPara;
IPropertySet pPropSet = new PropertySetClass();
pPropSet.SetProperty("SERVER", para.Server);
pPropSet.SetProperty("INSTANCE", para.Instance);
pPropSet.SetProperty("USER", para.User);
pPropSet.SetProperty("PASSWORD", para.Password);
pPropSet.SetProperty("VERSION", para.Version);//可选,缺省为SDE.DEFAULT版本
pPropSet.SetProperty("Database", para.Database);
try
{
pWorkspace = pWorkspaceFactory.Open(pPropSet, 0) as IRasterWorkspaceEx;
}
catch (Exception ex)
{
return null;
}
return pWorkspace;
}
}
#endregion
#region 连接参数设置
public class SDEConnectParas
{
#region SDE连接参数
string Server = "gisserver";
string Instance = "5152/tcp";
string User = "sde";
string Pass = "sde";
string Database = "sde";
string Version = "SDE.DEFAULT";
#endregion
public void GetSDEParameters(out string server, out string instance, out string user, out string password, out string database, out string version)
{
server = Server;
instance = Instance;
user = User;
password = Pass;
database = Database;
version = Version;
}//得到SDE连接参数
public bool ReadFromFile()
//从连接参数txt文件读取属性库和SDE的连接关键参数,以及站点关键表和关键SDE要素
{
string lpszPathName = FilePath.GetApplicationDir();
lpszPathName = lpszPathName + "//sdeconn.txt";
StreamReader reader = null;
try
{
reader = new StreamReader(lpszPathName);
string line = reader.ReadLine();
line = reader.ReadLine();
string[] SubStrings = line.Split(':');
Server = SubStrings[1];
line = reader.ReadLine();
SubStrings = line.Split(':');
Instance = SubStrings[1];
line = reader.ReadLine();
SubStrings = line.Split(':');
User = SubStrings[1];
line = reader.ReadLine();
SubStrings = line.Split(':');
Pass = SubStrings[1];
line = reader.ReadLine();
SubStrings = line.Split(':');
Database = SubStrings[1];
line = reader.ReadLine();
SubStrings = line.Split(':');
Version = SubStrings[1];
}
catch (IOException e)
{
Console.WriteLine(e.Message);
return false;
}
catch
{
return false;
}
finally
{
if (reader != null) reader.Close();
}
return true;
}
public void WhiteToLogFile()
//写入连接参数txt文件-----属性库和SDE的连接关键参数,以及站点关键表和关键SDE要素
{
string lpszPathName = FilePath.GetCurrentDir();
lpszPathName = lpszPathName + "//sdeconn.txt";
StreamWriter writer = File.CreateText(lpszPathName);
writer.Write("SDE配置参数");
writer.Write(writer.NewLine);
writer.Write("1、服务器:" + Server);
writer.Write(writer.NewLine);
writer.Write("2、SDE端口:" + Instance);
writer.Write(writer.NewLine);
writer.Write("3、用户:" + User);
writer.Write(writer.NewLine);
writer.Write("4、密码:" + Pass);
writer.Write(writer.NewLine);
writer.Write("5、数据库:" + Database);
writer.Write(writer.NewLine);
writer.Write("6、版本:" + Version);
writer.Write(writer.NewLine);
writer.Write(@"///////////////////////////////////////////");
writer.Write(writer.NewLine);
writer.Close();
}
}
#endregion
}
以上代码在SDE for Sql2005上测试通过。AE为9.3。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
名片
2024-10-28 广告
2024-10-28 广告
Altair HyperWorks是一套功能强大的集成化CAE(计算机辅助工程)软件平台,由Altair公司开发。它涵盖了结构分析、流体动力学、优化、多体动力学、电磁场仿真等多个领域,提供了丰富的仿真工具和优化算法。HyperWorks以其...
点击进入详情页
本回答由名片提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询