![](/kaifa.jpg)
金山游侠官网-微软杀毒软件官方下载
![如何打开mdb文件](/uploads/image/0275.jpg)
2023年3月30日发(作者:asp文件怎么打开)
persongeodatabase(mdb格式)导⼊到SDE的数据库中
//将上传的mdb⽂件保存⾄sde数据库中
protectedvoidbtnSaveToSDE_Click(objectsender,EventArgse)
{
//获取服务器上下⽂
IServerContextserverContext=GetServerContext();
//打开mdb⽂件所在的⼯作空间
paceFactorywf=
Object("WorkspaceFactory")asIWorkspaceFactory;
stringfileName=@"F:";
IFeatureWorkspacepFeatureWorkspaceMDB=omFile(fileName,0)asIFeatureWorkspace;
IWorkspacepWorkspaceMDB=pFeatureWorkspaceMDBasIWorkspace;
//打开sde空间数据库的⼯作空间
IFeatureWorkspacepFeatureWorkspaceSDE=OpenWorkspace(serverContext);
IWorkspacepWorkspaceSDE=pFeatureWorkspaceSDEasIWorkspace;
#region//获得mdb所有的要素数据集并进⾏转换复制
IEnumDatasetpEnumDataset=_Datasets(FeatureDataset);
IDatasetpDataset=();
//遍历mdb中每⼀个数据集
stringnameOfSourceFeatureDataset=null;//源数据集名称
stringnameOfTargetFeatureDataset=null;//⽬标数据集名称
while(pDataset!=null)
{
nameOfSourceFeatureDataset=;
nameOfTargetFeatureDataset=nameOfSourceFeatureDataset+"_SDE";
ConvertMDBFeatureDatasetToSDE(serverContext,pWorkspaceMDB,pWorkspaceSDE,
nameOfSourceFeatureDataset,nameOfTargetFeatureDataset);
pDataset=();
}
#endregion
#region//获得mdb中所有的独⽴要素类并进⾏转换复制
IEnumDatasetenumDataset=_Datasets(FeatureClass)asIEnumDataset;
IDatasetdataset=();
//遍历mdb的每⼀个独⽴要素类
stringnameOfSourceFeatureClass=null;//源要素类名称
stringnameOfTargetFeatureClass=null;//⽬标要素类名称
while(dataset!=null)
{
if(==FeatureClass)
{
IFeatureClasspFeatureClass=datasetasIFeatureClass;
nameOfSourceFeatureClass=ame;
nameOfTargetFeatureClass=nameOfSourceFeatureClass+"_SDE";
ConvertMDBFeatureClassToSDE(serverContext,pWorkspaceMDB,pWorkspaceSDE,nameOfSourceFeatureClass,
nameOfTargetFeatureClass);
dataset=();
}
else
{
return;
}
}
#endregion
//释放服务器上下⽂
eContext();
}
//获得服务器上下⽂
publicIServerContextGetServerContext()
{
#region通过IGISServerConnection来创建服务器上下⽂
IGISServerConnectiongisServerConnection=newGISServerConnection();
t("服务器名");
IServerObjectManager4serverObjectManager=(IServerObjectManager4)ObjectManager;
IServerContextserverContext=ServerContext("","");
#endregion
returnserverContext;
}
//打开sde数据库
publicIFeatureWorkspaceOpenWorkspace(IServerContextserverContext)
{
//sde数据库连接属性设置
IPropertySetpProperty=Object("tySet")asIPropertySet;
perty("Server","fms");//服务器名称或者IP
perty("Instance","esri_sde");//
perty("Database","sde数据库名");//sde数据库名称
perty("user","⽤户名");//⽤户名称
perty("password","密码");//⽤户密码
perty("version","T");//连接版本
//创建IWorkspaceFactory对象
paceFactory2wf=
Object("kspaceFactory")asIWorkspaceFactory2;
//打开IFeatureWorkspace对象
IFeatureWorkspacefws=(pProperty,0)asIFeatureWorkspace;
returnfws;
}
//将mdb中的要素数据集转换到sde数据库中
publicvoidConvertMDBFeatureDatasetToSDE(IServerContextserverContext,IWorkspacesourceWorkspace,IWorkspace
targetWorkspace,stringnameOfSourceFeatureDataset,stringnameOfTargetFeatureDataset)
{
if(sourceWorkspace==null||targetWorkspace==null)
{
return;
}
//创建源⼯作空间名
IDatasetsourceWorkspaceDataset=(IDataset)sourceWorkspace;
IWorkspaceNamesourceWorkspaceName=(IWorkspaceName)me;
//创建源数据集名
IFeatureDatasetNamesourceFeatureDatasetName=
Object("eDatasetName")asIFeatureDatasetName;
IDatasetNamesourceDatasetName=(IDatasetName)sourceFeatureDatasetName;
aceName=sourceWorkspaceName;
=nameOfSourceFeatureDataset;
//创建⽬标⼯作空间名
IDatasettargetWorkspaceDataset=(IDataset)targetWorkspace;
IWorkspaceNametargetWorkspaceName=(IWorkspaceName)me;
//创建⽬标数据集名
IFeatureDatasetNametargetFeatureDatasetName=
Object("eDatasetName")asIFeatureDatasetName;
IDatasetNametargetDatasetName=(IDatasetName)targetFeatureDatasetName;
aceName=targetWorkspaceName;
=nameOfTargetFeatureDataset;
//转换(复制)源数据集到⽬标数据集
IFeatureDataConverterfeatureDataConverter=Object("eDataConverter")
asIFeatureDataConverter;
tFeatureDataset(sourceFeatureDatasetName,targetFeatureDatasetName,null,"",1000,
0);
}
//将mdb中要素类转换复制到sde数据库中
publicvoidConvertMDBFeatureClassToSDE(IServerContextserverContext,IWorkspacesourceWorkspace,IWorkspace
targetWorkspace,stringnameOfSourceFeatureClass,stringnameOfTargetFeatureClass)
{
//创建源⼯作空间名称
IDatasetsourceWorkspaceDataset=(IDataset)sourceWorkspace;
IWorkspaceNamesourceWorkspaceName=(IWorkspaceName)me;
//创建源数据集名称
IFeatureClassNamesourceFeatureClassName=Object("eClassName")as
IFeatureClassName;
IDatasetNamesourceDatasetName=(IDatasetName)sourceFeatureClassName;
aceName=sourceWorkspaceName;
=nameOfSourceFeatureClass;
//创建⽬标⼯作空间名称
IDatasettargetWorkspaceDataset=(IDataset)targetWorkspace;
IWorkspaceNametargetWorkspaceName=(IWorkspaceName)me;
//创建⽬标数据集名称
IFeatureClassNametargetFeatureClassName=Object("eClassName")as
IFeatureClassName;
IDatasetNametargetDatasetName=(IDatasetName)targetFeatureClassName;
aceName=targetWorkspaceName;
=nameOfTargetFeatureClass;
//打开输⼊的要素类以得到字段定义
ourceName=()sourceFeatureClassName;
IFeatureClasssourceFeatureClass=(IFeatureClass)();//打开源要素类
//验证字段名称,因为你正在不同类型的⼯作空间之间进⾏数据转换
IFieldCheckerfieldChecker=Object("hecker")asIFieldChecker;
IFieldssourceFeatureClassFields=;
IFieldstargetFeatureClassFields;
IEnumFieldErrorenumFieldError;
//最重要的设置输⼊和验证⼯作空间
orkspace=sourceWorkspace;
teWorkspace=targetWorkspace;
te(sourceFeatureClassFields,outenumFieldError,outtargetFeatureClassFields);
//遍历所有输出字段找到⼏何字段
IFieldgeometryField;
for(inti=0;i
{
if(_Field(i).Type==eldTypeGeometry)
{
geometryField=_Field(i);
//得到⼏何字段的⼏何定义
IGeometryDefgeometryDef=ryDef;
//赋予⼏何定义⼀个空间索引格⽹数⽬和格⽹⼤⼩值
IGeometryDefEdittargetFCGeoDefEdit=(IGeometryDefEdit)geometryDef;
unt_2=1;
_GridSize(0,0);
//允许ArcGIS为数据加载确定⼀个有效的格⽹⼤⼩
lReference_2=lReference;
//转换要素类中所有的要素
IQueryFilterqueryFilter=Object("ilter")asIQueryFilter;;
lause="";
//加载要素类
IFeatureDataConverterfctofc=Object("eDataConverter")as
IFeatureDataConverter;
IEnumInvalidObjectenumErrors=tFeatureClass(sourceFeatureClassName,queryFilter,null,
targetFeatureClassName,geometryDef,targetFeatureClassFields,"",1000,0);
break;
}
}
}
更多推荐
如何打开mdb文件
发布评论