版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
GIS應(yīng)用開發(fā)DevelopingGISApplicationswithArcObjectsusingC#.NET
空間數(shù)據(jù)管理(6學(xué)時(shí))本章內(nèi)容:GeoDatabase對(duì)象模型概述Workspace及相關(guān)對(duì)象Dataset對(duì)象表、對(duì)象類和要素類ROW,Object和Feature對(duì)象關(guān)系與關(guān)系類7.1GeoDatabase對(duì)象模型概述不同類型的空間數(shù)據(jù):Geodatabase:Personal/Filegeodatabase、ArcSDEgeodatabaseArcInfocoveragesShapefileCADTIN…………在AO(AE)中,各種類型的空間數(shù)據(jù)都采用統(tǒng)一的對(duì)象模型—
Geodatabase數(shù)據(jù)模型進(jìn)行操作。RasterDatasetGeodatabase模型的主要對(duì)象如下:Workspace(工作空間):代表一個(gè)Geodatabase或一個(gè)ArcInfocoverage工作空間或一個(gè)文件夾(內(nèi)有地理數(shù)據(jù)文件)。Dataset(數(shù)據(jù)集):是任何數(shù)據(jù)的集合,可以是Table(表)、要素類等。GeoDataSet:是一個(gè)包含了地理數(shù)據(jù)的數(shù)據(jù)集。FeatureDataset(要素?cái)?shù)據(jù)集):由要素類、幾何網(wǎng)絡(luò)和拓?fù)涞冉M成。Table:是數(shù)據(jù)庫(kù)中的一個(gè)二維表,它由Row(行)組成,其列屬性由字段集設(shè)置;Row是表中的一條記錄,一個(gè)表中的記錄的字段集是相同的。ObjectClass(對(duì)象類):是Table的擴(kuò)展,它是一種具有面向?qū)ο筇匦缘谋?,用于存?chǔ)非空間數(shù)據(jù);Object代表了一個(gè)具有屬性和行為的實(shí)體(entity)對(duì)象,而不是簡(jiǎn)單的Row,具有OID。FeatureClass(要素類):是一種可以存儲(chǔ)空間數(shù)據(jù)的對(duì)象類,它是對(duì)象類的擴(kuò)展,其定義中包含幾何字段;Feature(要素)是要素類中的一條記錄,它是一個(gè)有幾何字段的對(duì)象。RelationshipClass(關(guān)系類):定義兩個(gè)不同的要素類或?qū)ο箢愔g的關(guān)聯(lián)關(guān)系;Relationship代表關(guān)系類中對(duì)象之間、要素之間或?qū)ο笠刂g的聯(lián)系,它可以控制這些對(duì)象之間的行為。AttributedRelationshipClass(屬性關(guān)系類):是一種用于存儲(chǔ)關(guān)系的表;AttributedRelationship為屬性關(guān)系類中的數(shù)據(jù)。7.2Workspace及相關(guān)對(duì)象在Geodatabase數(shù)據(jù)模型中,一個(gè)工作空間對(duì)應(yīng)于一個(gè)geodatabase或一個(gè)ArcInfo
coverage工作空間或一個(gè)文件夾(內(nèi)有地理數(shù)據(jù)文件)。工作空間是空間數(shù)據(jù)集與非空間數(shù)據(jù)集的容器。由esriWorkspaceType枚舉類型指定的Workspace有三種類型:esriFileSystemWorkspace:基于文件類型的Shapefiles和ArcInfo的工作空間esriLocalDatabaseWorkspace:Personal/FilegeodatabaseesriRemoteDatabaseWorkspace:ArcSDEgeodatabase其它workspace類型包括:RasterWorkspace:包含格網(wǎng)和影像數(shù)據(jù)的工作空間;TinWorkspace:包含TINs的工作空間;CADWorkspace:包含CAD數(shù)據(jù)的工作空間;VPFWorkspace:包含VPF數(shù)據(jù)的工作空間。7.2.1
工作空間工廠(WorkspaceFactory)要操作各種類型的空間數(shù)據(jù),首先要獲得空間數(shù)據(jù)所在的工作空間。Workspace(工作空間)是一個(gè)普通類(Class),這意味著用戶不能直接新建它。為了獲得一個(gè)工作空間,需要使用WorkspaceFactory對(duì)象來創(chuàng)建或打開一個(gè)Workspace。WorkspaceFactory是Geodatabase的入口。它是一個(gè)抽象類,派生了很多的子類,例如SdeWorkspaceFactory,
AccessWorkspaceFactory,ShapefileWorkspaceFactory
,
FileGDBWorkspaceFactory等。不同類型的空間數(shù)據(jù)需要不同的工作空間工廠對(duì)象來打開對(duì)應(yīng)的工作空間。不同類型的空間數(shù)據(jù)需要不同的工作空間工廠對(duì)象來打開對(duì)應(yīng)的工作空間。
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接口定義了所有工作空間工廠對(duì)象的一般屬性和方法,用戶可以通過它管理不同類型的工作空間,所有的工作空間對(duì)象都可以通過這個(gè)接口產(chǎn)生。IWorkspaceFactory
使用IWorkspaceFactory.Create方法可以用于新建一個(gè)工作空間名稱對(duì)象。publicIWorkspaceNameCreate(
stringparentDirectory,
stringName,
IPropertySetConnectionProperties,
inthWnd
);IWorkspaceFactory.Open方法和IWorkspaceFactory.OpenFromFile方法可以用于打開一個(gè)已經(jīng)存在的工作空間。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數(shù)據(jù)庫(kù)//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實(shí)現(xiàn)的主要接口如下表所示.InterfacesDescriptionIDatasetContainer3Providesaccesstoaddingdatasetstothedatasetcontainer.IFeatureWorkspaceProvidesaccesstomembersthatcreateandopenvarioustypesofdatasetsandotherworkspacelevelobjects.IFeatureWorkspaceSchemaEditProvidesaccesstoalteringtheinstanceCLSIDandtheclassextensionCLSID.ITopologyWorkspaceProvidesaccesstomembersthataccessthetopologiesinaworkspace.ITransactionsProvidesaccesstomembersthatcontrolTransactionmanagement.ITransactionsOptionsProvidesaccesstomembersthatcontrolTransactionoptions.IWorkspace2Providesaccesstomembersthathaveinformationabouttheworkspace.IWorkspaceConfigurationProvidesaccesstoconfigurationkeywords.IWorkspaceDomainsProvidesaccesstomembersthatreturninformationaboutdomainsandallowsyoutoaddordeletedomains.IWorkspaceDomains2Providesaccesstomembersthatallowyoutoalteradomain.IWorkspaceEditProvidesaccesstomembersthatcontrolWorkspaceEditing.IWorkspaceReplicaDatasetsProvidesaccesstomembersthatreturnalistofreplicadatasets.IWorkspaceReplicasProvidesaccesstomembersthatreturnobjectscontaininginformationaboutreplicas.IWorkspaceReplicasAdmin3Providesaccesstomembersthatmodifyinformationaboutareplica.IWorkspace接口IWorkspace接口定義了一個(gè)工作空間最普通的屬性和方法。
ConnectionProperties返回工作空間的連接屬性集對(duì)象;Datasets屬性可以按照數(shù)據(jù)集(Dataset)的類型而返回一個(gè)數(shù)據(jù)集枚舉對(duì)象;Type和WorkspaceFactory屬性則可以分別返回工作空間的類型和工作空間工廠的種類。publicIEnumDataset
get_Datasets(esriDatasetType
DatasetType);該方法按照數(shù)據(jù)集(Dataset)的類型返回一個(gè)數(shù)據(jù)集枚舉對(duì)象;當(dāng)數(shù)據(jù)集類型為esriDTAny,該方法將返回工作空間中的所有數(shù)據(jù)集。注意:該方法只返回工作空間中頂層的數(shù)據(jù)集;假如一個(gè)工作空間中有一個(gè)獨(dú)立的要素類和另一個(gè)位于要素?cái)?shù)據(jù)集中的要素類,使用該方法時(shí),數(shù)據(jù)集類型參數(shù)為esriDTFeatureClass,那么僅返回那個(gè)獨(dú)立的要素類,位于要素?cái)?shù)據(jù)集中的要素類不會(huì)返回。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.//拷貝數(shù)據(jù)庫(kù)模式:包括屬性域、要素?cái)?shù)據(jù)集、要素類(包括要素?cái)?shù)據(jù)集中的要素類和獨(dú)立的要素類)、表
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接口主要用于管理基于要素的數(shù)據(jù)集,如表(Table)、對(duì)象類(ObjectClass)、要素類(FeatureClass)、要素?cái)?shù)據(jù)集(FeatureDataset)和關(guān)系類(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對(duì)象是一個(gè)專門用于設(shè)置屬性的對(duì)象,它是一種name-value對(duì)的集合。屬性名必須是字符串,屬性值可以是字符串、數(shù)值或日期,也可以是一個(gè)對(duì)象。屬性值支持通過名字來查找屬性的方法。IWorkspaceFactory.Open方法要求用Propertyset(屬性集合)來設(shè)置打開一個(gè)Workspace。如打開一個(gè)SDE數(shù)據(jù)庫(kù)的時(shí)候,進(jìn)行如下配置:IPropertySetpPropertyset=newPropertySetClass();pPropertyset.SetProperty("Server","data");//服務(wù)器pPropertyset.SetProperty("Instance","esrisde");//SDE實(shí)例pPropertyset.SetProperty("user","sde");//SDE數(shù)據(jù)庫(kù)的用戶名pPropertyset.SetProperty("password","sde");//SDE數(shù)據(jù)庫(kù)的密碼pPropertyset.SetProperty("version","sde.DEFAULT");//'默認(rèn)版本7.2.4名稱對(duì)象名稱(Name)對(duì)象標(biāo)識(shí)并且定義了Geodatabase對(duì)象(如數(shù)據(jù)集或者工作空間)或地圖對(duì)象(如圖層)。盡管名稱對(duì)象只是它代表的對(duì)象的一個(gè)“代理”,但它支持程序員使用實(shí)例化的特定對(duì)象的Open方法。下面是一個(gè)使用Open方法實(shí)例化的例子:
INamepName=pFeatureClassNameasIName;
IFeatureClasspFeatureClass=pName.Open()asIFeatureClass;名稱對(duì)象的子類眾多,如TableName、FeatureClassName、ObjectClassName等。7.3Dataset對(duì)象所有放在工作空間(Workspace)中的對(duì)象都是一種數(shù)據(jù)集(Dataset)對(duì)象。Dataset對(duì)象分為兩大類一種是Table,可以簡(jiǎn)單看成是一張二維表,它是由一條條記錄組成的,是保存記錄Row的容器;一種是GeoDataset,地理數(shù)據(jù)集,如要素?cái)?shù)據(jù)集、柵格數(shù)據(jù)集。IDataset接口定義的屬性、方法如右圖所示:7.3.1GeoDataset類GeoDataset(地理數(shù)據(jù)集)是一個(gè)抽象類,它代表了擁有空間屬性的數(shù)據(jù)集。GeoDataset的例子包括要素?cái)?shù)據(jù)集FeatureDataset、要素類FeatureClass、TIN和柵格數(shù)據(jù)集RasterDataset等。非GeoDataset的數(shù)據(jù)集包括Table、對(duì)象類ObjectClass和關(guān)系類RelationshipClass等。IGeoDataset接口定義了GeoDataset對(duì)象的空間信息,包括空間參考和范圍屬性。通過IGeoDataset.SpatialRefrence可以獲得一個(gè)GeoDataset對(duì)象的空間參考,IGeoDataset.Extent則可以獲得要素集的范圍。IGeoDatasetSchemaEdit接口可以讓程序員去改變一個(gè)GeoDataset的空間參考,IGeoDatasetSchemaEdit.AlterSpatialRefrence方法重新設(shè)置與數(shù)據(jù)集關(guān)聯(lián)的空間參考。這個(gè)方法多使用于給一個(gè)空間參考為Unknown的地理數(shù)據(jù)集設(shè)置空間參考。IGeoDatasetSchemaEdit.CanAlterSpatialReferenceIndicatesifthespatialreferenceofthedatasetcanbealtered.改變一個(gè)圖層的空間參考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對(duì)象要素?cái)?shù)據(jù)集對(duì)象是具有相同空間參考的要素類的容器。使用要素?cái)?shù)據(jù)集的情況十分廣泛,例如幾何網(wǎng)絡(luò)、拓?fù)潢P(guān)系必須建立在一個(gè)要素?cái)?shù)據(jù)集中。在工作空間中對(duì)一個(gè)要素類進(jìn)行編程的時(shí)候,需要注意這個(gè)要素類放在什么地方,是直接放在工作空間中(這種要素類被稱為standalonefeatureclass),還是放在一個(gè)要素?cái)?shù)據(jù)集中。當(dāng)使用IWorkspace.Datasets屬性來遍歷一個(gè)工作空間內(nèi)的數(shù)據(jù)集時(shí),返回的只是直接放在工作空間的數(shù)據(jù)集,而保存在一個(gè)要素?cái)?shù)據(jù)集中的要素類則不會(huì)被遍歷。使用IFeatureWorkspace.OpenFeatureClass打開工作空間中的任何一個(gè)要素類,無論它是直接存放在工作空間還是存放在工作空間中的一個(gè)要素?cái)?shù)據(jù)集中。IFeatureDataset這個(gè)接口是從IDataset接口繼承而來的。使用IFeatureDataset.CreateFeatureClass方法可以用來在要素?cái)?shù)據(jù)集中創(chuàng)建一個(gè)新的要素類。這個(gè)方法和IFeatureWorkspace.CreateFeaureClass的方法類似。新建要素類的空間參考是通過它的幾何字段來設(shè)置的。
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
);//創(chuàng)建要素?cái)?shù)據(jù)集中的要素類、拓?fù)潢P(guān)系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接口用于管理要素?cái)?shù)據(jù)集中的要素類。該接口的ClassByName和Class(index)等屬性都可以用來獲取數(shù)據(jù)集中的特定的要素類。IFeatureClassContainer.ClassCount和Classes屬性分別可以獲得要素?cái)?shù)據(jù)集中的要素類的數(shù)目和得到一個(gè)要素類的枚舉對(duì)象。IFeatureClassContainer.ClassByID屬性可以讓程序員通過對(duì)象類的ID值返回一個(gè)特定的對(duì)象類。publicvoidCreateFeatureClassesInDataset(
IFeatureDataset
sourceFeatureDataset,IFeatureDatasettargetFeatureDataset){IFeatureClassContainersourceFeatureClassContainer=sourceFeatureDatasetasIFeatureClassContainer;
for(inti=0;i<sourceFeatureClassContainer.ClassCount;i++)
{
IFeatureClasssourceFeatureClass=sourceFeatureClassContainer.get_Class(i);CreateFeatureClassInThisDataset(sourceFeatureClass,targetFeatureDataset);
}
}IRelationshipClassContainer接口要素?cái)?shù)據(jù)集中還可以存儲(chǔ)關(guān)系類對(duì)象,可以通過這個(gè)接口來添加、新建和獲得要素?cái)?shù)據(jù)集中的關(guān)系類對(duì)象。IRelationshipClassContainer.CreateRelationshipClass方法可以讓程序員在要素?cái)?shù)據(jù)集中新建一個(gè)關(guān)系類。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
–拓?fù)潢P(guān)系publicITopology
CreateTopology(string
Name,
double
ClusterTolerance,
int
maxGeneratedErrorCount,
string
ConfigurationKeyword
);ITopologypublicvoidAddClass(IClass
classToAdd,
doubleWeight,
intXYRank,
intZRank,
boolEventNotificationOnValidate);//拷貝拓?fù)潢P(guān)系
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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 醫(yī)療美容招投標(biāo)服務(wù)質(zhì)量表
- 2024年羊毛收購(gòu)合同3篇
- 高鐵項(xiàng)目招投標(biāo)文件模板
- 工業(yè)自動(dòng)化系統(tǒng)工程委托施工合同
- 傳媒團(tuán)副總經(jīng)理招聘合同范例
- 旅游景區(qū)宣傳舞蹈演員聘請(qǐng)合同
- 辦公大樓建設(shè)項(xiàng)目合同樣本
- 2025年度鋁合金門窗產(chǎn)品研發(fā)、生產(chǎn)與安裝一體化合同3篇
- 員工心理健康輔導(dǎo)
- 醫(yī)療急救通道建設(shè)打路施工合同
- 滬教牛津版五年級(jí)下冊(cè)英語(yǔ)全冊(cè)課件
- 北京大學(xué)簡(jiǎn)介介紹PPT模板
- 湘藝版 四年級(jí)上冊(cè)音樂教案- 第十課 我心愛的小馬車
- 前置胎盤的手術(shù)配合課件
- 魚骨圖模板1PPT課件
- 中國(guó)動(dòng)畫之經(jīng)典賞析PPT課件
- 浙江省杭州市2021-2022學(xué)年九年級(jí)(上)期末科學(xué)試題【含答案】
- T∕CAMDI 041-2020 增材制造(3D打印)定制式骨科手術(shù)導(dǎo)板
- 實(shí)施農(nóng)村客運(yùn)公交化改造推進(jìn)城鄉(xiāng)客運(yùn)一體化發(fā)展
- 【雙人相聲劇本搞笑校園】有關(guān)2人校園搞笑相聲劇本
- 【圖文】化學(xué)纖維質(zhì)量檢驗(yàn)標(biāo)準(zhǔn)
評(píng)論
0/150
提交評(píng)論