版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
GIS应用开发DevelopingGISApplicationswithArcObjectsusingC#.NET
空间数据管理(6学时)本章内容:GeoDatabase对象模型概述Workspace及相关对象Dataset对象表、对象类和要素类ROW,Object和Feature对象关系与关系类7.1GeoDatabase对象模型概述不同类型的空间数据:Geodatabase:Personal/Filegeodatabase、ArcSDEgeodatabaseArcInfocoveragesShapefileCADTIN…………在AO(AE)中,各种类型的空间数据都采用统一的对象模型—
Geodatabase数据模型进行操作。RasterDatasetGeodatabase模型的主要对象如下:Workspace(工作空间):代表一个Geodatabase或一个ArcInfocoverage工作空间或一个文件夹(内有地理数据文件)。Dataset(数据集):是任何数据的集合,可以是Table(表)、要素类等。GeoDataSet:是一个包含了地理数据的数据集。FeatureDataset(要素数据集):由要素类、几何网络和拓扑等组成。Table:是数据库中的一个二维表,它由Row(行)组成,其列属性由字段集设置;Row是表中的一条记录,一个表中的记录的字段集是相同的。ObjectClass(对象类):是Table的扩展,它是一种具有面向对象特性的表,用于存储非空间数据;Object代表了一个具有属性和行为的实体(entity)对象,而不是简单的Row,具有OID。FeatureClass(要素类):是一种可以存储空间数据的对象类,它是对象类的扩展,其定义中包含几何字段;Feature(要素)是要素类中的一条记录,它是一个有几何字段的对象。RelationshipClass(关系类):定义两个不同的要素类或对象类之间的关联关系;Relationship代表关系类中对象之间、要素之间或对象要素之间的联系,它可以控制这些对象之间的行为。AttributedRelationshipClass(属性关系类):是一种用于存储关系的表;AttributedRelationship为属性关系类中的数据。7.2Workspace及相关对象在Geodatabase数据模型中,一个工作空间对应于一个geodatabase或一个ArcInfo
coverage工作空间或一个文件夹(内有地理数据文件)。工作空间是空间数据集与非空间数据集的容器。由esriWorkspaceType枚举类型指定的Workspace有三种类型:esriFileSystemWorkspace:基于文件类型的Shapefiles和ArcInfo的工作空间esriLocalDatabaseWorkspace:Personal/FilegeodatabaseesriRemoteDatabaseWorkspace:ArcSDEgeodatabase其它workspace类型包括:RasterWorkspace:包含格网和影像数据的工作空间;TinWorkspace:包含TINs的工作空间;CADWorkspace:包含CAD数据的工作空间;VPFWorkspace:包含VPF数据的工作空间。7.2.1
工作空间工厂(WorkspaceFactory)要操作各种类型的空间数据,首先要获得空间数据所在的工作空间。Workspace(工作空间)是一个普通类(Class),这意味着用户不能直接新建它。为了获得一个工作空间,需要使用WorkspaceFactory对象来创建或打开一个Workspace。WorkspaceFactory是Geodatabase的入口。它是一个抽象类,派生了很多的子类,例如SdeWorkspaceFactory,
AccessWorkspaceFactory,ShapefileWorkspaceFactory
,
FileGDBWorkspaceFactory等。不同类型的空间数据需要不同的工作空间工厂对象来打开对应的工作空间。不同类型的空间数据需要不同的工作空间工厂对象来打开对应的工作空间。
ClassesthatimplementIWorkspaceFactoryClassesAccessWorkspaceFactory(esriDataSourcesGDB)AMSWorkspaceFactory(esriTrackingAnalyst)ArcInfoWorkspaceFactory(esriDataSourcesFile)CadWorkspaceFactory(esriDataSourcesFile)ExcelWorkspaceFactory(esriDataSourcesOleDB)FileGDBWorkspaceFactory(esriDataSourcesGDB)GeoRSSWorkspaceFactory(esriDataSourcesFile)IMSWorkspaceFactory(esriGISClient)InMemoryWorkspaceFactory(esriDataSourcesGDB)NetCDFWorkspaceFactory(esriDataSourcesNetCDF)OLEDBWorkspaceFactory(esriDataSourcesOleDB)PCCoverageWorkspaceFactory(esriDataSourcesFile)PlugInWorkspaceFactoryRasterWorkspaceFactory(esriDataSourcesRaster)SDCWorkspaceFactory(esriDataSourcesFile)SdeWorkspaceFactory(esriDataSourcesGDB)ShapefileWorkspaceFactory(esriDataSourcesFile)SqlWorkspaceFactory(esriDataSourcesGDB)StreetMapWorkspaceFactory(esriDataSourcesFile)TextFileWorkspaceFactory(esriDataSourcesOleDB)TinWorkspaceFactory(esriDataSourcesFile)ToolboxWorkspaceFactory(esriGeoprocessing)VpfWorkspaceFactory(esriDataSourcesFile)IWorkspaceFactory接口定义了所有工作空间工厂对象的一般属性和方法,用户可以通过它管理不同类型的工作空间,所有的工作空间对象都可以通过这个接口产生。IWorkspaceFactory
使用IWorkspaceFactory.Create方法可以用于新建一个工作空间名称对象。publicIWorkspaceNameCreate(
stringparentDirectory,
stringName,
IPropertySetConnectionProperties,
inthWnd
);IWorkspaceFactory.Open方法和IWorkspaceFactory.OpenFromFile方法可以用于打开一个已经存在的工作空间。publicIWorkspaceOpen(IPropertySetConnectionProperties,inthWnd);publicIWorkspaceOpenFromFile(stringfileName,inthWnd);IWorkspaceFactory.WorkspaceType属性可以返回工作空间的类型。HowtocreatenewgeodatabasesCreatingapersonalgeodatabaseworkspacestoredinAccessprivatevoidCreateAccessWorkspace(){IWorkspaceFactorypAccessWorkspaceFactory=newAccessWorkspaceFactoryClass();IWorkspaceName
pWorkspaceName=pAccessWorkspaceFactory.Create(@"d:\temp","test.mdb",null,0);ESRI.ArcGIS.esriSystem.INamename=(IName)pWorkspaceName;IWorkspacepGDB_Wor=(IWorkspace
)name.Open(); }publicIWorkspaceNameCreate(
stringparentDirectory,
stringName,
IPropertySetConnectionProperties,
inthWnd);Creatingafilegeodatabaseworkspace//Createafilegeodatabaseworkspacefactory.IWorkspaceFactoryworkspaceFactory=newFileGDBWorkspaceFactoryClass();//Createanewfilegeodatabase.IWorkspaceNameworkspaceName=workspaceFactory.Create("C:\\temp\\","MyFGDB.gdb",null,0);INamename=(IName)workspaceName;//Openareferencetothefilegeodatabaseworkspacethroughthenameobject.IWorkspacefGDB_Wor=(IWorkspace)name.Open();publicstaticIWorkspaceCreateFileGdbWorkspace(Stringpath)
{TypefactoryType=Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
IWorkspaceFactoryworkspaceFactory=(IWorkspaceFactory)Activator.CreateInstance(factoryType);
IWorkspaceNameworkspaceName=workspaceFactory.Create
(path,"Sample.gdb",null,0);
INamename=(IName)workspaceName;
IWorkspaceworkspace=(IWorkspace)name.Open();returnworkspace;
}publicIWorkspaceNameCreate(
stringparentDirectory,
stringName,
IPropertySet
ConnectionProperties,
inthWnd);Creatingaconnectionfile(.sde)toanEnterpriseArcSDEworkspacepublicIWorkspaceNameopen_ArcSDE_Workspace
(stringserver,stringinstance,stringuser,stringpassword,stringdatabase,stringversion){IPropertySetpropertySet=newPropertySetClass();propertySet.SetProperty("SERVER",server);propertySet.SetProperty("INSTANCE",instance);propertySet.SetProperty("DATABASE",database);propertySet.SetProperty("USER",user);propertySet.SetProperty("PASSWORD",password);propertySet.SetProperty("VERSION",version);
IWorkspaceFactory2workspaceFactory=(IWorkspaceFactory2)newSdeWorkspaceFactoryClass();returnworkspaceFactory.Create("d:\\temp\\","myconnection.sde",propertySet,0);}publicIWorkspaceNameCreate(
stringparentDirectory,
stringName,
IPropertySetConnectionProperties,
inthWnd);CreatingageodatabaseinapersonalorworkgroupArcSDEworkspace//Createadataservermanagerobject.IDataServerManagerdataserverManager=newDataServerManagerClass();//Settheservernameandconnecttotheserver.dataserverManager.ServerName="tivo\\sqlexpress";dataserverManager.Connect();//Openoneofthegeodatabasesinthedatabaseserver.IDataServerManagerAdmindataservermanagerAdmin=(IDataServerManagerAdmin)dataserverManager;IWorkspaceNameworkspaceName=dataservermanagerAdmin.CreateWorkspaceName("sewer","VERSION","dbo.Default");INamename=(IName)workspaceName;IWorkspaceGDB_wor=(IWorkspace)name.Open();Howtoconnecttoageodatabase有3种不同的方法打开工作空间:IWorkspaceFactory.Open
publicIWorkspace
Open(IPropertySetConnectionProperties,inthWnd);IWorkspaceFactory.OpenFromFile
publicIWorkspace
OpenFromFile(string
fileName,inthWnd);IWorkspaceFactory2.OpenFromStringpublicIWorkspace
OpenFromString(
string
connectStr,
inthWnd);Theconnectstringisacollectionofnamevaluepairsseparatedbyasemicolon(;).thepathnameofafileordirectorythatrepresentseitheraFileSystemWorkspaceorLocalDatabaseWorkspace,oraconnectionfiletoaRemoteDatabaseworkspaceThehWndargumentistheparentwindoworapplication'swindow.ThehWndwillguaranteethattheconnectiondialog,ifpresentedtoyoubecauseofinsufficientproperties,hasthecorrectparent.(1)打开PersonalGeoDatabae数据库//Forexample,database="C:\\myData\\mypGDB.mdb".
publicIWorkspaceopen_pGDB_Workspace(stringdatabase)
{IPropertySetpropertySet=newPropertySetClass();propertySet.SetProperty("DATABASE",database);
IWorkspaceFactoryworkspaceFactory=newAccessWorkspaceFactoryClass();returnworkspaceFactory.Open(propertySet,0);}publicIWorkspace
Open(IPropertySet
ConnectionProperties,
inthWnd);//Forexample,fileName="C:\\myData\\mypGDB.mdb".publicIWorkspaceopenFromFilepGDBWorkspace(stringfileName){IWorkspaceFactoryworkspaceFactory=newAccessWorkspaceFactoryClass();returnworkspaceFactory.OpenFromFile(fileName,0);}publicIWorkspaceOpenFromFile(stringfileName,
inthWnd);//Forexample,connectionString="DATABASE=C:\\myData\\mypGDB.mdb".publicIWorkspaceopenFromStringpGDBWorkspace(stringconnectionString){IWorkspaceFactory2workspaceFactory=(IWorkspaceFactory2)newAccessWorkspaceFactoryClass();returnworkspaceFactory.OpenFromString(connectionString,0);}publicIWorkspaceOpenFromString(stringconnectStr,
inthWnd);"SERVER=myServer;DATABASE=sde;INSTANCE=5151;USER=Editor;PASSWORD=Editor;VERSION=SDE.DEFAULT"(2)Connectingtoafilegeodatabaseworkspace//Forexample,database="C:\\myData\\myfGDB.gdb".publicIWorkspaceopen_fGDB_Workspace(stringdatabase){IPropertySetpropertySet=newPropertySetClass();propertySet.SetProperty("DATABASE",database);IWorkspaceFactoryworkspaceFactory=newFileGDBWorkspaceFactoryClass();returnworkspaceFactory.Open(propertySet,0);}publicIWorkspaceOpen(IPropertySet
ConnectionProperties,
inthWnd);//Forexample,fileName="C:\\myData\\myfGDB.gdb".publicIWorkspaceopenFromFile_fGDB_Workspace(StringfileName){IWorkspaceFactoryworkspaceFactory=newFileGDBWorkspaceFactoryClass();returnworkspaceFactory.OpenFromFile(fileName,0);}publicIWorkspaceOpenFromFile(stringfileName,
inthWnd);//Forexample,connectionString="DATABASE=C:\\myData\\myfGDB.gdb".publicIWorkspaceopenFromString_fGDB_Workspace(stringconnectionString){
IWorkspaceFactory2workspaceFactory=(IWorkspaceFactory2)newFileGDBWorkspaceFactoryClass();returnworkspaceFactory.OpenFromString(connectionString,0);}
publicIWorkspaceOpenFromString(stringconnectStr,
inthWnd);"SERVER=myServer;DATABASE=sde;INSTANCE=5151;USER=Editor;PASSWORD=Editor;VERSION=SDE.DEFAULT"(3)ConnectingtoanenterpriseArcSDEgeodatabaseworkspacepublicIWorkspaceopen_ArcSDE_Workspace(stringserver,stringinstance,stringuser,stringpassword,stringdatabase,stringversion)
{IPropertySetpropertySet=newPropertySetClass();propertySet.SetProperty("SERVER",server);propertySet.SetProperty("INSTANCE",instance);propertySet.SetProperty("DATABASE",database);propertySet.SetProperty("USER",user);propertySet.SetProperty("PASSWORD",password);propertySet.SetProperty("VERSION",version);
IWorkspaceFactoryworkspaceFactory=newSdeWorkspaceFactoryClass();returnworkspaceFactory.Open(propertySet,0);}(4)打开Shapefile工作空间publicIWorkspaceOpenShapfileWorkspace
(stringLocation){
IWorkspaceFactorywsf=newShapefileWorkspaceFactoryClass();
IWorkspacews=wsf.OpenFromFile(Location,0); returnws;}7.2.2
工作空间(Workspace)Workspace实现的主要接口如下表所示.InterfacesDescriptionIDatasetContainer3Providesaccesstoaddingdatasetstothedatasetcontainer.IFeatureWorkspaceProvidesaccesstomembersthatcreateandopenvarioustypesofdatasetsandotherworkspacelevelobjects.IFeatureWorkspaceSchemaEditProvidesaccesstoalteringtheinstanceCLSIDandtheclassextensionCLSID.ITopologyWorkspaceProvidesaccesstomembersthataccessthetopologiesinaworkspace.ITransactionsProvidesaccesstomembersthatcontrolTransactionmanagement.ITransactionsOptionsProvidesaccesstomembersthatcontrolTransactionoptions.IWorkspace2Providesaccesstomembersthathaveinformationabouttheworkspace.IWorkspaceConfigurationProvidesaccesstoconfigurationkeywords.IWorkspaceDomainsProvidesaccesstomembersthatreturninformationaboutdomainsandallowsyoutoaddordeletedomains.IWorkspaceDomains2Providesaccesstomembersthatallowyoutoalteradomain.IWorkspaceEditProvidesaccesstomembersthatcontrolWorkspaceEditing.IWorkspaceReplicaDatasetsProvidesaccesstomembersthatreturnalistofreplicadatasets.IWorkspaceReplicasProvidesaccesstomembersthatreturnobjectscontaininginformationaboutreplicas.IWorkspaceReplicasAdmin3Providesaccesstomembersthatmodifyinformationaboutareplica.IWorkspace接口IWorkspace接口定义了一个工作空间最普通的属性和方法。
ConnectionProperties返回工作空间的连接属性集对象;Datasets属性可以按照数据集(Dataset)的类型而返回一个数据集枚举对象;Type和WorkspaceFactory属性则可以分别返回工作空间的类型和工作空间工厂的种类。publicIEnumDataset
get_Datasets(esriDatasetType
DatasetType);该方法按照数据集(Dataset)的类型返回一个数据集枚举对象;当数据集类型为esriDTAny,该方法将返回工作空间中的所有数据集。注意:该方法只返回工作空间中顶层的数据集;假如一个工作空间中有一个独立的要素类和另一个位于要素数据集中的要素类,使用该方法时,数据集类型参数为esriDTFeatureClass,那么仅返回那个独立的要素类,位于要素数据集中的要素类不会返回。esriDatasetTypeConstantsConstantValueDescriptionesriDTAny1AnyDataset.esriDTContainer2AnyContainerDataset.esriDTGeo3AnyGeoDataset.esriDTFeatureDataset4FeatureDataset.esriDTFeatureClass5FeatureClass.esriDTPlanarGraph6PlanarGraph.esriDTGeometricNetwork7GeometricNetwork.esriDTTopology8Topology.esriDTText9TextDataset.esriDTTable10TableDataset.esriDTRelationshipClass11RelationshipClass.esriDTRasterDataset12RasterDataset.esriDTRasterBand13RasterBand.esriDTTin14TinDataset.esriDTCadDrawing15CadDrawingDataset.ConstantValueDescriptionesriDTRasterCatalog16RasterCatalog.esriDTToolbox17Toolbox.esriDTTool18Tool.esriDTNetworkDataset19NetworkDataset.esriDTTerrain20Terraindataset.esriDTRepresentationClass21FeatureClassRepresentation.esriDTCadastralFabric22CadastralFabric.esriDTSchematicDataset23SchematicDataset.esriDTLocator24AddressLocator.esriDTMap26Map.esriDTLayer27Layer.esriDTStyle28Style.esriDTMosaicDataset29MosaicDataset.esriDTLasDataset30LasDataset.//拷贝数据库模式:包括属性域、要素数据集、要素类(包括要素数据集中的要素类和独立的要素类)、表
privatevoidCreateSchema(){CopyDomains(sourceWorkspace,targetWorkspace);
IEnumDatasetsourceFeatureDatasets=sourceWorkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);CreateFeatureDatasetsAndFeatureClasses(sourceFeatureDatasets);
IEnumDatasetfeatureClasses=sourceWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass);CreateFeatureClassesInWorkspace(featureClasses);
IEnumDatasettables=sourceWorkspace.get_Datasets(esriDatasetType.esriDTTable);CreateTablesInWorkspace(tables);}IFeatureWorkspace接口主要用于管理基于要素的数据集,如表(Table)、对象类(ObjectClass)、要素类(FeatureClass)、要素数据集(FeatureDataset)和关系类(RelationshipClass)等。privatevoidmnuAddFeatureClassToMap_Click(objectsender,System.EventArgse){
IWorkspaceFactorywsf=newShapefileWorkspaceFactoryClass();
IFeatureWorkspacepFeatWorkspace=wsf.OpenFromFile(@"D:\ArcTutor\usa",0)asIFeatureWorkspace;
IFeatureClasspFeatClass=pFeatWorkspace.OpenFeatureClass("counties");
IFeatureLayerpFeatLyr=newFeatureLayerClass(); pFeatLyr.FeatureClass=pFeatClass; pFeatLyr.Name=pFeatClass.AliasName;
IMappMap=axMapControl1.Map; pMap.AddLayer(pFeatLyr);}7.2.3PropertySetPropertyset对象是一个专门用于设置属性的对象,它是一种name-value对的集合。属性名必须是字符串,属性值可以是字符串、数值或日期,也可以是一个对象。属性值支持通过名字来查找属性的方法。IWorkspaceFactory.Open方法要求用Propertyset(属性集合)来设置打开一个Workspace。如打开一个SDE数据库的时候,进行如下配置:IPropertySetpPropertyset=newPropertySetClass();pPropertyset.SetProperty("Server","data");//服务器pPropertyset.SetProperty("Instance","esrisde");//SDE实例pPropertyset.SetProperty("user","sde");//SDE数据库的用户名pPropertyset.SetProperty("password","sde");//SDE数据库的密码pPropertyset.SetProperty("version","sde.DEFAULT");//'默认版本7.2.4名称对象名称(Name)对象标识并且定义了Geodatabase对象(如数据集或者工作空间)或地图对象(如图层)。尽管名称对象只是它代表的对象的一个“代理”,但它支持程序员使用实例化的特定对象的Open方法。下面是一个使用Open方法实例化的例子:
INamepName=pFeatureClassNameasIName;
IFeatureClasspFeatureClass=pName.Open()asIFeatureClass;名称对象的子类众多,如TableName、FeatureClassName、ObjectClassName等。7.3Dataset对象所有放在工作空间(Workspace)中的对象都是一种数据集(Dataset)对象。Dataset对象分为两大类一种是Table,可以简单看成是一张二维表,它是由一条条记录组成的,是保存记录Row的容器;一种是GeoDataset,地理数据集,如要素数据集、栅格数据集。IDataset接口定义的属性、方法如右图所示:7.3.1GeoDataset类GeoDataset(地理数据集)是一个抽象类,它代表了拥有空间属性的数据集。GeoDataset的例子包括要素数据集FeatureDataset、要素类FeatureClass、TIN和栅格数据集RasterDataset等。非GeoDataset的数据集包括Table、对象类ObjectClass和关系类RelationshipClass等。IGeoDataset接口定义了GeoDataset对象的空间信息,包括空间参考和范围属性。通过IGeoDataset.SpatialRefrence可以获得一个GeoDataset对象的空间参考,IGeoDataset.Extent则可以获得要素集的范围。IGeoDatasetSchemaEdit接口可以让程序员去改变一个GeoDataset的空间参考,IGeoDatasetSchemaEdit.AlterSpatialRefrence方法重新设置与数据集关联的空间参考。这个方法多使用于给一个空间参考为Unknown的地理数据集设置空间参考。IGeoDatasetSchemaEdit.CanAlterSpatialReferenceIndicatesifthespatialreferenceofthedatasetcanbealtered.改变一个图层的空间参考privatevoidAlterSpatialReferrenc(
IMappMap,IFeatureLayerfeaturelayer)
{IActiveViewpActiveView=pMapasIActiveView;
IFeatureClasspFeatureClass=featurelayer.FeatureClass;
IGeoDatasetpGeoDataset=pFeatureClassasIGeoDataset;
IGeoDatasetSchemaEditpGeoDatasetEdit=pGeoDatasetasIGeoDatasetSchemaEdit;
????????????????if(pGeoDatasetEdit.CanAlterSpatialReference==true)
{ISpatialReferenceFactory2pSpatRefFact=newSpatialReferenceEnvironmentClass();
IGeographicCoordinateSystempGeoSys=pSpatRefFact.CreateGeographicCoordinateSystem(4214);//esriSRGeoCSType.esriSRGeoCS_Beijing1954pGeoDatasetEdit.AlterSpatialReference(pGeoSys);
}pActiveView.Refresh();
}7.3.2FeatureDataset对象要素数据集对象是具有相同空间参考的要素类的容器。使用要素数据集的情况十分广泛,例如几何网络、拓扑关系必须建立在一个要素数据集中。在工作空间中对一个要素类进行编程的时候,需要注意这个要素类放在什么地方,是直接放在工作空间中(这种要素类被称为standalonefeatureclass),还是放在一个要素数据集中。当使用IWorkspace.Datasets属性来遍历一个工作空间内的数据集时,返回的只是直接放在工作空间的数据集,而保存在一个要素数据集中的要素类则不会被遍历。使用IFeatureWorkspace.OpenFeatureClass打开工作空间中的任何一个要素类,无论它是直接存放在工作空间还是存放在工作空间中的一个要素数据集中。IFeatureDataset这个接口是从IDataset接口继承而来的。使用IFeatureDataset.CreateFeatureClass方法可以用来在要素数据集中创建一个新的要素类。这个方法和IFeatureWorkspace.CreateFeaureClass的方法类似。新建要素类的空间参考是通过它的几何字段来设置的。
IEnumDatasetsourceFeatureDatasets=sourceWorkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);privatevoidCreateFeatureDatasetsAndFeatureClasses(IEnumDatasetsourceFeatureDatasets){if(sourceWorkspace==null||targetWorkspace==null)return;
ISpatialReferencespatialRference;sourceFeatureDatasets.Reset();
IDatasetdataset=sourceFeatureDatasets.Next();while(dataset!=null){IGeoDatasetgeoDataset=datasetasIGeoDataset;spatialRference=geoDataset.SpatialReference;
IFeatureDatasetsourceFeatureDataset=datasetasIFeatureDataset;
IFeatureWorkspacefeatureWorkspace=targetWorkspaceasIFeatureWorkspace;if((IWorkspace2)targetWorkspace).get_NameExists
(esriDatasetType.esriDTFeatureDataset,((IDataset)sourceFeatureDataset).Name))dataset=sourceFeatureDatasets.Next();IFeatureDatasettargetFeatureDataset=featureWorkspace.CreateFeatureDataset(dataset.Name,spatialRference);CreateFeatureClassesInDataset
(sourceFeatureDataset,targetFeatureDataset);dataset=sourceFeatureDatasets.Next();}}publicbool
get_NameExists(
esriDatasetTypeType,
stringName
);//创建要素数据集中的要素类、拓扑关系publicvoidCreateFeatureClassesInDataset(IFeatureDatasetsourceFeatureDataset,IFeatureDatasettargetFeatureDataset){if(sourceFeatureDataset==null||targetFeatureDataset==null)return;
IEnumDatasetdatasets=sourceFeatureDataset.Subsets;
IDatasetsourceDataset=datasets.Next();while(sourceDataset!=null){switch(sourceDataset.Type){case
esriDatasetType.esriDTFeatureClass:
if(((IWorkspace2)targetWorkspace).get_NameExists
(esriDatasetType.esriDTFeatureClass,sourceDataset.Name))break;
IFeatureClasssourceFeatureClass=sourceDatasetasIFeatureClass;
CreateFeatureClassInThisDataset(sourceFeatureClass,targetFeatureDataset);break;case
esriDatasetType.esriDTNetworkDataset:
INetworkDatasetsourceNetworkDataset=sourceDatasetasINetworkDataset;
CreateNetworkDataset(sourceFeatureDataset,targetFeatureDataset);break;case
esriDatasetType.esriDTRelationshipClass:
CreateRelationshipClassSchema(sourceFeatureDataset,targetFeatureDataset);break;case
esriDatasetType.esriDTTopology:
CreateTopology(sourceFeatureDataset,targetFeatureDataset);break;default:break;}sourceDataset=datasets.Next();}
}IFeatureClassContainerIFeatureClassContainer接口用于管理要素数据集中的要素类。该接口的ClassByName和Class(index)等属性都可以用来获取数据集中的特定的要素类。IFeatureClassContainer.ClassCount和Classes属性分别可以获得要素数据集中的要素类的数目和得到一个要素类的枚举对象。IFeatureClassContainer.ClassByID属性可以让程序员通过对象类的ID值返回一个特定的对象类。publicvoidCreateFeatureClassesInDataset(
IFeatureDataset
sourceFeatureDataset,IFeatureDatasettargetFeatureDataset){IFeatureClassContainersourceFeatureClassContainer=sourceFeatureDatasetasIFeatureClassContainer;
for(inti=0;i<sourceFeatureClassContainer.ClassCount;i++)
{
IFeatureClasssourceFeatureClass=sourceFeatureClassContainer.get_Class(i);CreateFeatureClassInThisDataset(sourceFeatureClass,targetFeatureDataset);
}
}IRelationshipClassContainer接口要素数据集中还可以存储关系类对象,可以通过这个接口来添加、新建和获得要素数据集中的关系类对象。IRelationshipClassContainer.CreateRelationshipClass方法可以让程序员在要素数据集中新建一个关系类。publicIRelationshipClass
CreateRelationshipClass(string
relClassName,
IObjectClass
OriginClass,
IObjectClass
DestinationClass,
string
forwardLabel,
string
backwardLabel,
esriRelCardinality
Cardinality,
esriRelNotification
Notification,
bool
IsComposite,
bool
IsAttributed,
IFields
relAttrFields,
string
OriginPrimaryKey,
string
destPrimaryKey,
string
OriginForeignKey,
string
destForeignKey);privatevoidCreateRelationshipClassSchema
(IFeatureDataset
sourceFeatureDataset,IFeatureDatasettargetFeatureDataset){
IRelationshipClassContainerfromRelClsContainer=sourceFeatureDatasetasIRelationshipClassContainer;
IRelationshipClassContainertoRelClsContainer=targetFeatureDatasetasIRelationshipClassContainer;
IFeatureWorkspacetargetFeatureWorkspace=targetWorkspaceasIFeatureWorkspace;
IEnumRelationshipClassfromRelClasses=fromRelClsContainer.RelationshipClasses;
fromRelClasses.Reset();
IRelationshipClassfromRelClass=fromRelClasses.Next();while(fromRelClass!=null){
stringfromRelClsName=(fromRelClassasIDataset).Name;
esriRelCardinalityfromRelCardinality=fromRelClass.Cardinality;
stringfromFwdPathLabel=fromRelClass.ForwardPathLabel;
stringfromBwdPathLabel=fromRelClass.BackwardPathLabel;
IObjectClassfromOriginCls=fromRelClass.OriginClass;
stringfromOriginPK=fromRelClass.OriginPrimaryKey;
stringfromOriginFK=fromRelClass.OriginForeignKey;
IObjectClassfromDesCls=fromRelClass.DestinationClass;
stringfromDesPK=fromRelClass.DestinationPrimaryKey;
stringfromDesFK=fromRelClass.DestinationForeignKey;
boolfromIsAttributed=fromRelClass.IsAttributed;
boolfromIsComposite=fromRelClass.IsComposite;
esriRelNotificationfromRelNotif=fromRelClass.Notification;
IObjectClasstoOriginCls=null;if(fromOriginClsisIFeatureClass)toOriginCls=targetFeatureWorkspace.OpenFeatureClass(((IDataset)fromOriginCls).Name);elseif(fromOriginClsisITable)toOriginCls=targetFeatureWorkspace.OpenTable(((IDataset)fromOriginCls).Name)asIObjectClass;
IObjectClasstoDesCls=null;if(fromDesClsisIFeatureClass)toDesCls=targetFeatureWorkspace.OpenFeatureClass(((IDataset)fromDesCls).Name);elseif(fromOriginClsisITable)toDesCls=targetFeatureWorkspace.OpenTable(((IDataset)fromDesCls).Name)asIObjectClass;toRelClsContainer.CreateRelationshipClass(fromRelClsName,toOriginCls,toDesCls,fromFwdPathLabel,fromBwdPathLabel,fromRelCardinality,fromRelNotif,fromIsComposite,fromIsAttributed,null,fromOriginPK,"",fromOriginFK,"");fromRelClass=fromRelClasses.Next();}}ITopologyContainer2
–拓扑关系publicITopology
CreateTopology(string
Name,
double
ClusterTolerance,
int
maxGeneratedErrorCount,
string
ConfigurationKeyword
);ITopologypublicvoidAddClass(IClass
classToAdd,
doubleWeight,
intXYRank,
intZRank,
boolEventNotificationOnValidate);//拷贝拓扑关系
privatevoidCreateTopology(IFeatureDatasetsourceFeatureDataset,IFeatureDatasettargetFeatureDataset){
IFeatureWorkspaceManage2sourceWsManage=sourceWorkspaceasIFeatureWorkspaceManage2;
IFeatureWorkspacetargetFeatureWorkspace=targetWorkspaceasIFeatureWorkspace;
ITopologyContainertoTopoContainer=(ITopologyContainer)targetFeatureDataset;
ITopologyContainerfromTopoContainer=(ITopologyContainer)sourceFeatureDataset;
inttopoCount=fromTopoContainer.TopologyCount;
ITopologyfromTopology;ITopologytoTopology;for(inti=0;i<topoCount;i++){fromTopology=fromTopoContainer.get_Topology(i);
stringtopologyName=(fromTopologyasIDataset).Name;toTopology=toTopoContainer.CreateTopology(topologyName,toTopoContainer.DefaultClusterTolerance,-1,"");
ITopologyPropertiesfromTopoProps=fromTopologyasITopologyProperties;
IEnumFeatureClassfromTopoClasses=fromTopoProps.Classes;IFeatureClassfromFeatureClass=fromTopoClasses.Next();while(fromFeatureClass!=null){ITopologyClassfromTopoClass=fromFeatureClassasITopologyClass;
IFeatureClasstoFeatureClass=targetFeatureWorkspace.OpenFeatureClass(((IDat
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024版常州土地使用权转让合同(住宅用地)
- 2024年度橱柜定制与环保要求合同
- 2024年度影视制作合同标的及制作周期
- 2024年度在建度假村房产买卖协议
- 2024版智能仓库管理系统定制与实施合同
- 二零二四年份室内植物租赁合同
- 2024年度股权转让合同条款与转让条件
- 2024年度大庆房屋买卖合同解析
- 2024年度融资租赁合同with标的:飞机租赁
- 2024年度网络安全审查与合规评估合同
- 2024入团积极分子入团考试题库(含答案)
- 2024收购稻草合同范本
- 对外投资合作国别(地区)指南 -巴林-20240529-00467
- 2024年小学科学新教材培训心得8篇
- QBT 2739-2005 洗涤用品常用试验方法 滴定分析 (容量分析)用试验溶液的制备
- 粪污处理产业发展政策与法规
- 五十六个民族之乌孜别克族介绍
- 流体力学-刘鹤年-章节课后答案
- 售后服务方案及运维方案
- 教科版小学科学四上《3.4弹簧测力计》课件
- 超声介入诊断技术指南操作规范
评论
0/150
提交评论