ArcGIS Engine開發之旅04---ARCGIS接口詳細說明


ArcGIS接口詳細說明... 1

1.      IField接口(esriGeoDatabase)... 2

2.      IFieldEdit接口(esriGeoDatabase)... 2

3.      IFields接口(esriGeoDatabase)... 2

4. IRow接口(esriGeoDatabase)... 3

5. ITable接口(esriGeoDatabase)... 3

6. IArea接口(esriGeometry)... 4

7. IEnvelope接口(esriGeometry)... 4

8. IPoint接口(esriGeometry)... 5

9. IPointArray接口(esriGeometry)... 5

10. IPointCollection接口(esriGeometry)... 6

11. IPolyline接口(esriGeometry)... 6

12. IGeometry接口(esriGeometry)... 6

13. IFeature接口(esriGeoDatabase)... 7

14. IFeatureLayer接口(esriCarto)... 8

15. IFeatureClass接口(esriGeoDatabase)... 8

16. IFeatureCursor接口(esriGeoDatabase)... 9

17. ISpatialFilter接口(esriGeoDatabase)... 9

18. IQueryFilter接口(esriGeoDatabase)... 11

19. IFeatureSelection接口(esriCarto)... 11

20. IMap接口(esriCarto). 11

21. IPropertySet接口(esriSystem). 12

22. IFeatureWorkspace接口(esriGeoDatabase)... 12

23. IWorkspaceEdit接口(esriGeoDatabase)... 12

24. IWorkspaceFactory接口(esriGeoDatabase)... 13

25. ITopologicalOperator接口(esriGeometry)... 13

 

  1. 1.  IField接口(esriGeoDatabase)

IField接口的第一個屬性AliasName(只讀,獲得字段的別名)

IField接口的第二個方法CheckValue(Value)(方法,對於指定的屬性字段,基於字段類型判斷參數值是否有效,有效,則返回True,否則返回False)

例子代碼: 

IFeatureClass pFC_SCP_PT;

editPT = new FieldClass();

editPT.Precision_2 = 8;

editPT.Scale_2 = 3;

editPT.Name_2 = "ELEV1";

editPT.Type_2 = esriFieldType.esriFieldTypeDouble;

IField接口的其他屬性均為只讀屬性,常用有Name(只讀,獲得字段的名稱)

  1. 2.  IFieldEdit接口(esriGeoDatabase)

所有該接口的屬性均為可讀可寫,經常用與對新建字段的設置,因為字段一旦被設置,其基本屬性就不能被更改,所以就需要該接口類型的變量去轉換,方法為:

IFeatureClass pFC_SCP_PT; 

IFieldEdit editPT = new FieldClass(); 

pFC_SCP_PT.AddField((IField)editPT); 

如果在vb中去編寫代碼,則賦值和獲取均為同一屬性,而在C#中,為了區分設置和獲取,屬性均有兩個,類似於Name和Name_2,這樣就可以區分了,普遍用設置的帶有_2的那個屬性。

IFieldEdit接口的第一個屬性Name (讀寫,設置或者獲取該變量類型變量字段的名稱)

IFieldEdit接口的第二個屬性Precision(讀寫,設置或者獲取該變量類型變量字段的長度)

IFieldEdit接口的第三個屬性Scale(讀寫,設置或者獲取該變量類型變量字段的精度)

IFieldEdit接口的第四個屬性Type(讀寫,設置或者獲取該變量類型變量字段的類型)

 

  1. 3.  IFields接口(esriGeoDatabase)

IFields接口的第一個屬性Field(Index)(只讀,以用於獲取具體的字段,返回類型為IField)

IFields接口的第二個屬性FieldCount(只讀,以用於獲取屬性的數量)

利用上面兩個接口並用索引去依次循環獲得每一列的屬性pField(Ifield接口)

IFields接口的第三個方法FindField(Name)(方法,輸入想要查找的屬性域字段的名稱,如果有,則返回該屬性域字段在此Fields的索引,沒有則返回-1)

IFields接口的第四個方法FindFieldByAliasName(Name)(方法,與第三個方法類似,此時輸入的為該列屬性字段的別名,此方法不經常用)

 

4. IRow接口(esriGeoDatabase)

IRow接口的第一個方法Delete(方法,刪除該行)

IRow接口的第二個屬性Fields(只讀,獲取該Feature要素的字段集合,返回值為IFields類型)此方法類似於IFeature接口的Fields屬性

IRow 接口的第三個方法Store(方法,保存該行。)此方法類似於IFeature接口的Store方法

IRow接口的第四個屬性Table(只讀,獲取該行所在的表格,返回值為ITable類型)

IRow接口的第五個屬性Value(Index) (讀寫,獲取該行在參數索引的字段的值,注意,索引Index是從0開始的。)

object.Value(Index ) = [ value ]

IRow接口的第六個屬性HasOID(只讀,判斷指出該行是否有OID)

IRow接口的第七個屬性OID(只讀,獲取該行的OID值)

 

5. ITable接口(esriGeoDatabase)

ITable是把要素類當成一個表格來看,每一列對應一個字段(Field),每一行對應一個要素(Feature),所以對要素類(IFeatureClass)接口的操作均可以類似的在Itable接口中找到。

兩個接口可以進行如下強制轉化:

 

IFeatureClass pFC;

ITable pTable;

pTable =(ITable)pFC;

 

ITable接口的第一個方法AddField(Field)(方法,增加一個屬性字段到這個表,其中傳入的參數為一個IField接口的變量,此變量可以由其他表獲得並賦值給要操作的表,可用IFeilds接口的Field屬性來獲得)

ITable接口的第二個方法GetRow(OID) (方法,通過OID來從表格數據庫中獲取一行,返回一個IRow接口的變量)此方法類似於IFeatureClass接口的GetFeature方法

 

ITable接口的第三個方法GetRows(oids, Recycling) (方法,得到一個游標ICursor,通過一個oids的OID數組參數和一個Recycling的布爾類型的參數,一般為True)此方法類似於IFeatureClass接口的GetFeatures方法

 

ITable接口的第四個方法RowCount(QueryFilter) (方法,得到滿足查詢過濾器條件的行數。此方法IFeatureClass接口沒有,所以是一個很好的有條件查詢要素數量的一個方法)

 

6. IArea接口(esriGeometry)

IArea接口的第一個屬性Area(只讀,返回一個double類型的數值,為此Area的面積)

IArea接口的第二個屬性Centroid(只讀,返回一個IPoint類型的變量,為此Area的重心)

IArea接口的第三個屬性LablePoint(只讀,返回一個IPoint類型的變量,為此Area的標簽的位置,一般都在此Area的內部)

IArea接口的第四個方法QueryCentroid (Center ) (方法,Center參數為一個IPoint類型的變量,通過調用此方法將重心點賦值給參數Center)

IArea接口的第五個方法QueryLablePoint (LablePoint ) (方法,LablePoint參數為設置IPoint類型的變量,通過調用此方法將標簽點賦值給參數LablePoint)

 

7. IEnvelope接口(esriGeometry)

IEnvelope接口的第一個方法CenterAt(pPoint) (方法,將這個矩形的邊框移動到參數pPoint的位置,但是其他屬性不變,如它的Width和Height)

IEnvelope接口的長寬屬性Height和Width屬性(讀寫,可以通過該屬性獲取或設置該邊框的長和寬)

IEnvelope接口的4個頂點屬性UpperLeft、UpperRight、LowerLeft和LowerRight(讀寫,返回IPoint類型的四個頂點,比直接獲得最值坐標更加方便嚴謹)

IEnvelope接口的最值坐標屬性XMax、XMin、YMax和YMin(讀寫,可以通過該屬性獲取或設置該邊框的四個頂點的坐標)

IEnvelope接口的第五個方法Union (inEnvelope ) (方法,將參數輸入的幾何邊框和調用該方法的幾何邊框求並集,並將結果賦值給第一個邊框,即調用此方法的object)

例子代碼:

IEnvelope接口的第六個方法Union (inEnvelope ) (方法,返回與輸入參數相交的區域的幾何邊框,並將結果賦值給第一個邊框,即調用此方法的object)

IEnvelope接口的第七個方法PutCoords (XMin, YMin,XMax,YMax) (方法,將新建的一個邊框的4個極坐標設置為輸入的參數)

IEnvelope接口的第八個方法QueryCoords (XMin, YMin,XMax,YMax)(方法,將已有的一個邊框的4個極坐標輸出到參數當中以備后用)

IEnvelope接口的第九個方法Expand (dx, dy, asRatio) (方法,按照輸入的dx與dy參數來放大或者縮小當前的邊框,用與對ArcMap窗體的中心放大或縮小,或者點擊屏幕獲得點擊點的坐標,並將中心點設置成點擊點,並進行一定比例的放大或者縮小)

例子代碼:

一般情況設置為True,來控制倍數的放大

IEnvelope接口的第十個方法Offset (X, Y)(方法,將已有的一個邊框的按照輸入參數的大小來進行水平豎直的移動)

 

8. IPoint接口(esriGeometry)

IPoint接口的第一個方法PutCoords(X,Y)(方法,設置該點的坐標)或者直接調用可以讀寫的屬性X和Y,將坐標賦值給X和Y

例子代碼:

Dim pPoint AsIPoint

Set pPoint = NewPoint

pPoint.PutCoords100,100

IPoint接口的第二個方法QueryCoords(X,Y)(方法,得到該點的坐標)

例子代碼:

Dim pPoint asIPoint

Dim dX asDouble,dYasDouble

pPoint.QueryCoordsdX,dY

IPoint接口的第三個方法ConstrainAngle (constraintAngle, anchor, allowOpposite ) (方法,如果第三個參數allowOpposite為True,則將第二個參數anchor這個點作為一個原點,然后以第一個參數 constraintAngle為與x軸的角度,做一條直線,再將調用此參數的點向該直線做垂線並交於一個新點,並將調用此方法的點移動到該點)

IPoint接口的第四個方法ConstrainDistance(constraintRadius, anchor ) (方法,以第二個參數anchor這個點為圓心,然后以第一個參數constraintRadius為半徑做一個圓,將調用此參數的點移動到該點與圓心做線段交於該圓的交點上)

 

9. IPointArray接口(esriGeometry)

IPointArray接口的第一個方法Add(p) (方法,向該類型的數組變量添加Point)

IPointArray接口的第二個屬性Count (只讀,獲得該數組變量中Point的個數,返回Long類型變量)

IPointArray接口的第三個屬性Element(Index)(只讀,獲得該數組變量中位於參數Index索引位置的點Point,返回一個Point類型的變量)

IPointArray接口的第四個方法Insert (Index, p ) (方法,向索引位置Index插入一個點Point)

IPointArray接口的第五個方法Remove (Index )  (方法,移除索引位置Index的點Point)

IPointArray接口的第六個方法RemoveAll (方法,移除所有在此數組中的點)

 

10. IPointCollection接口(esriGeometry)

IPointCollection接口的第一個方法AddPoint(inPoint [,before] [,after]) (方法,向該類型的點集變量添加Point,第一個參數為添加的Point,第二個第三個參數為可選擇的參數,默認添加進點集的末尾)

IPointCollection接口的第二個屬性Point(i) (只讀,獲得該點集變量中第i個位置的Point,返回IPoint類型變量,i從0計算開始)

IPointCollection接口的第三個屬性PointCount (只讀,獲得該點集變量中點的個數,返回Long類型變量,切記,如果一個PointCollection變量是由閉合的Geometry轉換而來的話,那么點的個數比節點數多一個,因為是閉合的,所以首位節點是同一個點)

 

11. IPolyline接口(esriGeometry)

IPolyline接口的第一個屬性FromPoint與ToPoint(讀寫,設置或者讀取該點的起始點和終止點,返回都是IPoint類型的變量)

IPolyline接口的第二個方法QueryFromPoint (from )(方法,返回IPoint類型的變量到參數from)

IPolyline接口的第三個方法QueryToPoint (to ) (方法,返回IPoint類型的變量到參數to)

 

IPolyline接口的第四個方法Generalize (maxAllowableOffset ) (方法,用道格拉斯普克發來簡化polyline)

IPolyline接口的第五個方法Weed (maxAllowableOffsetFactor ) (方法,和方法Generalize類似,均為簡化polyline的方法,不同的是參數。)

 

12. IGeometry接口(esriGeometry)

IGeometry接口的第一個屬性Dimension(只讀,返回一個類型為esriGeometryDimension的該圖形的幾何維度)

1    esriGeometryNoDimension

2    esriGeometry0Dimension

3    esriGeometry1Dimension

4    esriGeometry2Dimension

5    esriGeometry25Dimension

6    esriGeometry3Dimension

IGeometry接口的第二個屬性Extent(只讀,返回一個類型為IEnvelope的該圖形的幾何范圍的最大邊框)

IGeometry接口的第三個屬性GeometryType(只讀,返回一個類型為esriGeometryType的該圖形的幾何類型)

esriGeometryNull       = 0

esriGeometryPoint      = 1

esriGeometryMultipoint   = 2

esriGeometryPolyline    = 3

esriGeometryPolygon     = 4

esriGeometryEnvelope    = 5

esriGeometryPath      = 6

esriGeometryAny       = 7

esriGeometryMultiPatch   = 9

esriGeometryRing      = 11

esriGeometryLine      = 13

esriGeometryCircularArc  = 14

esriGeometryBezier3Curve  = 15

esriGeometryEllipticArc  = 16

esriGeometryBag       = 17

esriGeometryTriangleStrip = 18

esriGeometryTriangleFan  = 19

esriGeometryRay       = 20

esriGeometrySphere     = 21

 

13. IFeature接口(esriGeoDatabase)

IFeature接口的第一個屬性Class(只讀)

IFeature接口的第二個方法Delete(方法,刪除該行。因為一個Feature在表格中對應的就是一行數據,刪除該行就能相應的刪除這個Feature)

IFeature接口的第三個屬性Extent(只讀,獲取該Feature要素在地圖上的一個矩形范圍,返回值為IEnvelope類型)

IFeature接口的第四個屬性FeatureType(只讀,獲取該Feature要素的要素類型,返回值為枚舉類型的esriFeatureType)

IFeature接口的第五個屬性Fields(只讀,獲取該Feature要素的字段集合,返回值為IFields類型)

IFeature接口的第六個屬性Shape(讀寫,獲取該Feature要素的圖形,返回值為IGeometry類型,或者各種實體化的類型,如IPolyline)

IFeature接口的第七個屬性ShapeCopy(只讀,克隆該Feature要素的幾何圖形,返回值為IGeometry類型)

IFeature 接口的第八個方法Store(方法,保存該行。)

此屬性可用於對Feature要素的幾何圖形進行操作,步驟如下:

用IFeature.ShapeCopy方法獲取一個已經存在的Geometry,或者新建一個Geometry

對Geometry進行操作

通過IFeature.Shape屬性將Geometry寫入

通過IFeature.Store方法保存該Feature要素

IFeature接口的第九個屬性Value(讀寫,利用字段的索引進行對該要素該字段的值的讀寫)

注意,索引Index是從0開始的。

object.Value(Index ) = [ value ]

IFeature 接口的第十個屬性Table(只讀,將該行要素轉換成ITable格式的數據,即可對一張表進行數據操作,具體方法查看ITable接口)

 

14. IFeatureLayer接口(esriCarto)

IFeatureLayer接口的第一個屬性FeatureClass(讀寫,設置或者讀取此layer的要素類)

IFeatureLayer接口的第二個屬性MaximumScale(讀寫,設置或者讀取此layer顯示的最大比例尺)

IFeatureLayer接口的第三個屬性MinimumScale(讀寫,設置或者讀取此layer顯示的最小比例尺)

IFeatureLayer接口的第四個方法Search (queryFilter, recycling ) (方法,創建一個游標去查詢相應設置的過濾器的查詢)

IFeatureLayer接口的第五個屬性Visible(讀寫,設置或者讀取此layer的可見性)

IFeatureLayer接口的第六個屬性AreaOfInterest(只讀,讀取此layer的最大范圍,回返一個IEnvelope接口的變量)

 

15. IFeatureClass接口(esriGeoDatabase)

IFeatureClass  用於訪問控制要素類行為和屬性的成員

IFeatureClass接口是獲取和設置要素類屬性的主要接口。例如,使用IFeatureClass接口獲取要素類類型、獲取滿足查詢條件的要素數目或在要素類中創建新要素。

IFeatureClass接口繼承了IObjectClass接口。

成員

AddField      向這個類中添加一個字段

AddIndex        向這個類中添加一個索引

AliasName       這個類的別名

AreaField       幾何區域字段

CLSID         與這個對象類實例相關的組件類的GUID

CreateFeature        創建一個新要素,系統自動分配一個ID,沒有屬性值

DeleteField      從對象類中刪除字段

DeleteIndex       從對象類中刪除索引

EXTCLSID          與這個要素類的擴展類相關的組件類的GUID

Extension       這個對象類的擴展

ExtensionProperties  這個對象類的擴展屬性

FeatureClassID    要素類的唯一標識符

FeatureCount         指定查詢獲得的要素數目

FeatureDataset    包含要素類的要素數據集

FeatureType       要素類中的要素類型

Fields          要素類的字段集合

FindField      指定名稱的字段索引

GetFeature      根據對象ID獲得要素

GetFeatures       由一系列ID獲得Rows的指針

HasOID             指出要素類是否是否有一個要素表示字段(OID)

Indexes            要素類的索引集合

Insert          返回一個可以插入新要素的指針

LengthField      圖形長度字段

ObjectClassID    對象類的唯一標識符

OIDFieldName     與OID相關的字段名稱

RelationshipClasses  該類參與的關系類

Search            根據指定的查詢返回要素的指針

Select          根據查詢返回包含對象ID的選擇集合

ShapeFieldName    默認Shape字段的名稱

ShapeType       要素類中默認Shape的類型

Update            按照查詢返回一個更新要素的指針

繼承的接口

IObjectClass       獲得對象類的信息

IClass           獲得類的信息和管理類

實現IFeatureClass的類

FeatureClass       FeatureClass對象

NAClass(NetworkAnalyst)   網絡分析中將要素輸入,以及產生輸出要素

NetCDFFeatureClass(DataSourceNetCDF)內存中呈現的NetCDF要素類

RasterCatalog     Geodatabase表中的柵格數據集合

RelQueryTable       用於連接有相同數據的兩個數據集

RouteEventSource(Location)Route event source對象

TemporalFeatureClass(TrackingAnalyst) 控制時態要素類的設置

XYEventSource     XY event source對象

[C#]

//e.g., nameOfFeatureClass=”states”;

//on ArcSDE use ISqlSyntax::QualifyTableName的完全限定表名。

public IFeatureClass getIFeatureClass(IWorkspace workspace,string nameOfFeatureClass)

{

       //cast for the feature workspace from the workspace

       IFeatureWorkspace featureWorkspace=(IFeatureWorkspace)workspace;

       //open the featureclass

       return featureWorkspace.OpenFeatureClass(nameOfFeatureClass);

}

 

幾個常用的成員

15.1、IFeatureClass.AddField 方法

[C#]

 public void AddField(IField Field)

 

IFeatureClass.AddField(Field) 方法,增加一個屬性字段到這個要素類,其中傳入的參數為一個IField接口的變量,此變量可以由其他要素類獲得並賦值給要操作的要素類,可用IFeilds接口的Field屬性來獲得。

 

返回的錯誤

-2147220649-FDO_E_TABLE_DUPLICATE_COLUMN

表中已存在指定名稱的字段。

-2147220961-FDO_E_NO_SCHEMA_LICENSE

無權修改要素類的結構。使用ArcView的license,向參與集合網絡、拓撲和混合關系類(feature-linked annotation)的要素類添加字段能引發這個錯誤。

 

15.2、IFeatureClass.DeleteField 方法

 [C#] 

 public void DeleteField(IField Field);

 

IFeatureClass.DeleteField(Field) 方法,刪除一個屬性字段,其中傳入的參數為一個IField接口的變量。

 

返回的錯誤

-2147219878-FDO_E_FIELD_CANNOT_DELETE_WEIGHT_FIELD

不能刪除geometric network中與權重相關的字段。

-2147219877-FDO_E_FIEID_CANNOT_DELETE_REQUIRED_FIELD

不能刪除所要求的字段。如果字段設為required,可以使用IFieldEdit::Required屬性移除required狀態,然后就可以刪除field了。

-2147220961-FDO_E_NO_SCHEMA_LICENSE

無權修改要素類的結構。使用ArcView的license,向參與集合網絡、拓撲和混合關系類(feature-linked annotation)的要素類添加字段能引發這個錯誤。

-2147215862-FDO_E_SE_DBMS_DOES_NOT_SUPPORT

不能從DB2中刪除字段。

DeleteField從從表、對象類或要素類中刪除指定字段。Geodatabase需要的和不能刪除的字段包括:OBJECTID字段、SHAPE和shape依賴的字段例如SHAPE_Length、網絡要素類激活的AncillaryRole和Weight字段、亞字段-如果要刪除一個subtype字段,必須以subtype字段刪除。

[C#]

//e.g.,fieldName=”MyField”

Public void IClass_DeletField(IFeatureClass featureClass,string fieldname)

{

       //The following sample code demonstrates one methodology for deleting

       //a field using DeleteFields

       IFields fields=featureClass.Fields;

       IField field=fields.get_Field(fields.FindField(fieldname));

//IFeatureClass interface inherits from IClass

       featureClass.DeleteField(field);

}

 

15.3、IFeatureClass.CreateFeature 方法

 [C#]

 public IFeature CreateFeature();

CreateFeature在要素類中創建一個新要素。這個要素僅分配一個唯一的對象ID(OID),沒有其他屬性值。使用IFeature::Store方法將這個要素存儲到database中。當工作在版本要素類上時,CreateFeature應當在edit時期調用。調用IWorkspaceEdit::StartEditing可以開始edit session。對Topology或Geometric Network要素的編輯要在edit階段進行,並且要包含edit operation。

調用CreateFeature之后,並不自動設置默認的子類型,也不初始化默認值。如果要素沒有子類型,調用IRowSubtypes::InitDefaultValues來初始化默認值。可以調用IRowSubtypes::SubtypeCode來設置要素的要素的子類型。

在要素類上調用CreateFeature方法(通過IFeatureClass接口)同調用CreateRow方法(通過ITable接口)的效果相同,不過IFeatureClass的方法返回一個row對象昂的IFeature接口。

創建一個新要素的步驟是:

1) 創建要素

2) 為要素創建幾何圖形。

3) 在要素中存儲幾何圖形。

4) 存儲要素。

 

15.4、IFeatureClass.CreateFeatureBuffer 方法

[C#]

 public IFeatureBuffer CreateFeatureBuffer();

CreateFeatureBuffer方法創建一個feature緩沖區,並返回IFeatureBuffer類型的變量,然后再對這個變量進行操作。結合insert cursor可以使用這個方法在要素類中創建新要素。調用IFeatureClass的CreateFeatureBuffer方法和調用ITable中的CreateRowBuffer的作用相同,只是IFeatureClass的方法返回一個row buffer的IFeatureClass指針。

 

 

 

15.5、IFeatureClass.FeatureCount 方法

 [C#]

 public int FeatureCount(IQueryFilter QueryFilter);

FeatureCount返回滿足某些屬性或IQueryFilter指定的空間查詢的要素的數量。如果沒有指定IQueryFilter,返回要素類中所有要素的數量。

 

15.6、IFeatureClass.FeatureDataset 屬性

這個只讀屬性返回包含該要素類的數據集的IFeatureDataset接口。如果要素類是一個獨立的要素類(無dataset),那么這個動能將會返回一個null值。一個coverage要素類返回指向自身的IFeatureDataset接口。Shapefiles返回一個null指針。

 

15.7、IFeatureClass.GetFeature 方法

 [C#]

 public IFeature GetFeature(int ID)

通過給定的對象ID(OID)返回要素的IFeature接口。適用於通過OID尋找提頂要素。使用cursor可以遍歷要素類中所有要素。

調用要素類的GetFeature方法(使用IFeatureClass接口)同調用GetRow方法(使用要素類的ITable接口)的效果相同,只是IFeatureClass返回IFeature接口。

[C#]//e.g, nameOfField=”City_Name”

public void IFeatureClass_GetFeature(IFeatureClass featureClass,string nameOfField)

{

       //get the index of the field we are interested in

       int fieldIndexValue=featureClass.FindField(nameOfField);

       //get feature with OID 11,because it is known to exist

       //This method is typically used to get a feature by know OID

       //If you wish to loop through a series of features,use a Cursor.

       IFeature feature=featureClass.GetFeature(1);

       Console.WriteLine("The {0} field conains a value of{1}",nameOfField,feature.get_Value(fieldIndexValue));

}

15.8、IFeatureClass.GetFeatures 方法

 [C#]

 public IFeatureCursor GetFeatures(object fids,bool Recycling);

GetFeatures返回包含要素類所有要素OID的IFeatureCursor。這個方法可以用來遍歷已知OID的要素集。

調用IFeatureClass的GetFeatures方法和調用ITable的GetRows方法效果相同,只是返回IFeatureCursor接口。

[C#]

//e.g,nameOfField=”Symbol”

public void IFeatureClass_GetFeatures(IFeatureClass featureClass,string nameOfField)

{

       //get the index of the field we are interested in

       int fieldIndexValue=featureClass.FindField(nameOfField);

      

       System.Collections.Generic.List<int> constructoidList=new System.Collections.Generic.List<int>();

       constructoidList.Add(1);

       constructoidList.Add(2);

       constructoidList.Add(3);

       constructoidList.Add(4);

       constructoidList.Add(10);

       int[] oidList=constructoidList.ToArray();

       IFeatureCursor featureCursor=featureClass.GetFeatures(oidList,false);

       IFeature feature=featureCursor.NextFeature();

       //loop through the returned features and get the value for the field

       while(feature!=null)

       {

              //do something with each feature(ie update geometry or attribute)

              Console.WriteLine("The {0} field contains a value of {1}",nameOfField,feature.get_Value(fieldIndexValue));

              feature=featureCursor.NextFeature();

       }

}

15.9、IFeatureClass.Search 方法

[C#]

 public IFeatureCursor Search(IQueryFilter filter, bool Recycling);

Search返回滿足條件的IFeatureCursor。如果IQueryFilter沒有給定值,feature cursor返回要素類的所有要素。再用IfeatureCursor的NextFeature的方法依次得到每一個Feature。

Recycling參數控制row的allocation行為。每次調用簡單要素對象時,Recycling cursors可以rehydrate該對象,並可以最優化只讀訪問,例如在繪圖時。多次調用cursor的NextFeature,維持recycling cursor返回的引用並不合法。不能修改要素對象返回的recycling cursor。使用Non-recycling cursor每次返回一個單獨的要素。non-recycling返回的要素可以修改、存儲各種行為。Geodatabase保證在編輯階段non-recycling要素的唯一語義。如果搜索的要素已經被應用程序引用,將返回一個要素的地址。

Search方法返回的non-recycling要素指針並不用來更新cursor中的要素。Update方法返回的feature cursor可以用來更新要素。

[C#]

//下面的例子使用屬性查詢和空間查詢獲得要素的子集。

//在要素類中,遍歷所有要素,並計算它們的的總面積。

public void IFeatureClass_Search(IFeatureClass featureClass)

{

       //在這個函數中將使用空間過濾器,並結合屬性查詢進行搜索。

       //在搜索中不必執行兩種過濾類型,可以單獨使用每一種。

      

       //創建一個envelope在空間上限制搜索。

       //(注意:只有高級geometries、envelopes和geometrybags可以使用)

       ESRI.ArcGIS.Geometry.IEnvelope envelope=new ESRI.ArcGIS.Geometry.EnvelopeClass();

       envelope.PutCoords(508786,681196,513033,684341);

      

       //創建一個空間查詢

       ISpatialFilter spatialFilter=new SpatialFilterClass();

      

       //指定一個查詢的的幾何圖形

       spatialFilter.Geometry=(ESRI.ArcGIS.Geometry.IGeometry)envelope;

      

       //確定在要素類上查詢的幾何字段

       string shpFld=featureClass.ShapeFieldName;

       spatialFilter.GeometryFiled=shpFld;

      

       //指定要使用的空間操作

       spatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelIntersects;

      

       //創建where表達式,這里只要要素

       //在envelope中有一個子類型"COM"

       spatialFilter.WhereClause="subtype='COM'";

      

       //將spatial filter賦給IQueryFilter接口

       IQueryFilter queryFilter=new QueryFilterClass();

       queryFilter=(IQueryFilter)spatialFilter;

      

       //在要素類上進行搜索,使用cursor保存結果

       IFeatureCursor featureCursor=featureClass.Search(queryFilter,false);

      

       //第一個返回的要素

       IFeature feature=featureCursor.NextFeature();

      

       //獲得“Area”字段

       IFields fields=featCursor.Fields;

       int areaIndex=fields.FindField("Area");

      

       //保存總面積的變量

       double searchedArea=0;

      

       //遍歷所有要素計算總面積

       while(feature!=null)

       {

         searchedArea=searcheArea+(double)feature.get_Value(areaIndex);

         feature=featureCursor.NextFeature();

       }

       Console.WriteLine("The total area of searched features is {0}",searchedArea);

       System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);

}

15.10、IFeatureClass.Select 方法

[C#]

 public ISelectionSet Select(IQueryFilter QueryFilter, esriSelectionType selType, esriSelectionOption selOption, IWorkspace selectionContainer);

Select返回一個滿足條件的ISelectionSet。如果IQueryFilter中無值,將選擇要素類的所有要素。調用IFeatureClass的Select方法同調用ITable中的相應方法效果相同。調用Select時,selectionContainer不需要參數。實參應為Null(C#,VB.Net)或者Nothing(VB6)。(注意:提供workspace類型的selectionContainer只讀參數將會失敗,因為Select會將選擇的結果寫入workspace。

IFeatureClass Select Example

 [C#]

public void IFeatureClass_Select_Example(IFeatureClass featureClass)

{

       //創建查詢過濾器並附予一個where從句

       IQueryFilter queryFilter=new QueryFilterClass();

       queryFilter.WhereClause="Shape_Area>77000";

       //使用query過濾器選擇要素

       //調用Select時不需要selectionContainer參數。在C#和VB.Net中賦給其Null值

       ISelectionSet selectionSet=featureClass.Select(queryFilter,esriSelectionType.esriSelectionTypeIDSet,esriSelectionOption.esriSelectionOptionNormal,null);

       //計算選擇的要素數目

       Console.WriteLine("{0}features where selected from{1} with where clause {2}",selectionSet.Count,featureClass.AliasName,queryFilter.WhereClause);

}

16. IFeatureCursor接口(esriGeoDatabase)

 

IFeatureCursor接口用於遍歷從FeatureLayer等搜索出來的結果,可用來訪問要素類中的一系列要素。雖然它並沒有繼承ICursor接口,但它的操作方法同ICursor一樣,這樣在處理features時,不像rows那樣,可以不使用QI。

成員

DetleteFeature,

Fields,

FindField,

Flush,

InsertFeature,

NextFeature,

UpdateFeature.

16.1、IFeatureCursor.NextFeature方法

 [C#]

 public IFeature NextFeature();

IFeatureCursor.NextFeature方法,將游標向前跳到下一個位置,並且返回該位置的Feature.

當你使用cursor獲取非geodatabase的要素時,返回的空間參考為指定的類型。

不能確保要素的幾何圖形仍然在該空間參考中。例如,若使用非recycling cursor,你獲得的要素可以與其他人共享,任何人在任何時間都能改變其空間參考。如果想恢復或獲得指定的空間參考,開發者要測試要素的空間參考或幾何圖形。

 

16.2、IFeatureCursor.UpdateFeature方法

    [C#]

 public void UpdateFeature(IFeature Object);

IFeatureCursor.UpdateFeature(Feature) 方法,對當前游標位置的Feature進行更新)

[C#]

public void IFeatureCursor_UpdaterFeature_Example(IFeatureClass featureClass)

{

 IQeryFilter queryFilter=new QueryFilterClass();

 queryFilter.WhereClause="ZONING='U'";

 IFeatureCursor updateCursor=featureClass.Update(queryFilter,false);

 int fieldIndex=featureClass.FindField("ZONING");

 IFeature feature=updateCursor.NextFeature();

 While(feature!=null)

 {

  m++;

  feature.set_Value(fieldIndex,"C");

  updateCursor.UpdateFeature(feature);

  feature=updateCursor.NextFeature();

 }

 System.Runtime.InteropServices.Marshal.ReleaseComObject(updateCursor);

 

16.3、IFeatureCursor.InsertFeature方法

用參數傳進來的屬性值插入一個新的要素到數據庫中,返回該插入新的Feature的ID值,其中參數類型為IFeatureBuffer。

 

17. ISpatialFilter接口(esriGeoDatabase)3sNews.Net——最具影響力的中國地理空間信息門戶網站 M"@/L;~D&c,i&c

用於返回和修改filter使用的空間關系(空間拓撲查找的功能,即:在圖形上通過某一范圍查找空間制定要素)。是一個包含空間和屬性限制的QueryFilter。因此可以使用SpatialFilter來限制從要素類中獲得的要素集。ISpatialFilter繼承IQueryFilter接口,因此可以指定一個whereclause、返回的colunms或者指定輸出圖形的空間參考。使用spatial filter執行空間查詢,常將其作為IFeatureClass::Search、IFeatureClass::Select或feature layers上相似方法的參數。

17.1、ISpatialFilter.Geometry屬性

Geometry是源圖形,根據與其的關系執行空間選擇。

17.2、ISpatialFilter. GeometryField屬性

GeometryField是圖形字段名,將其中的圖形與源圖形比較。

17.3、ISpatialFilter. SpatialRel屬性

SpatialRel屬性將一個esriSpatialRelEnum傳入來指定空間關系。

 

ISpatialFilter Example

[C#]

NOTE:要用到ISpatialFilter的三個方法Geometry,GeometryField和SpatialRel。

public void ISpatialFilter_(IFeatureClass featureClass)

{

   //Create a point to use for the search;

   ESRI.ArcGIS.Geometry.IPoint point=new ESRI.ArcGIS.Geometry.PointClass();

   point.PutCoords(-117.946,35.823);

    

   //Getting a reference;

   ISpatialFilter spatialFilter=new SpatialFilterClass();

   //Setting the Geometry,GeometryField and SpatialRel parameters;

   

   spatialFilter.Geometry=point;

   spatialFilter.GeometryField=featureClass.ShapeFieldName;

   spatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelIntersects;

   //Execute the spatiafilter;

   IFeatureCursor featureCursor=featureClass.Search(spatialFilter,false);

}

 

18. IQueryFilter接口(esriGeoDatabase)3sNews.Net——最具影響力的中國地理空間信息門戶網站 M"@/L;~D&c,i&c

IQueryFilter接口的第一個屬性WhereClause(讀寫,為過濾器設置條件語句)

各種不同的數據,設置條件查詢語句的語法是不相同的,如一個shp文件在設置字段的時候要加“””雙引號,而在SDE數據連接中,則什么都不加;在gdb文件的語句中,符號是“*”,而在SDE或者shp文件查詢中則是“%”

IQueryFilter接口的第二個屬性SubFields(讀寫,為過濾器設置提供賽選的字段,用逗號來分隔每一個逗號,如果不設置該屬性,則當做所有字段均為查找字段)

 

19. IFeatureSelection接口(esriCarto)

IFeatureSelection接口的第一個方法SelectFeatures (Filter, Method, justOne ) (方法,根據指定的標准過濾器filter和方法,選擇要素,第一個參數為QueryFilter類型的變量,第二個參數為esriSelectionResultEnum類型的變量,第三個參數為布爾型變量,通常為false)

 

20. IMap接口(esriCarto)

IMap接口的第一個屬性Layers (uid, recursive ) (只讀,第二個參數為True的時候,該屬性獲取第一個參數uid指定的Layers,賦值給一個IEnumLayer的變量)

IMap接口的第二個屬性LayerCount(只讀,返回該map里面Layer的個數)

IMap接口的第三個屬性Layer(Index) (只讀,返回指定索引index位置的Layer)

IMap接口的第四個方法AddLayer(Layer) (方法,向該map添加一個Layer)

IMap接口的第五個方法AddLayers(Layers, autoArrange) (方法,添加一個EnumLayer變量的layers到該map,第一個參數為IEnumLayer類型,第二個參數為bool型變量)

IMap接口的第六個方法ClearLayers(方法,將所有的layer從map中移除)

IMap接口的第七個方法ClearSelection(方法,將該map中選擇的要素清空)

IMap接口的第八個屬性SelectionCount(只讀,返回該map被選中要素的個數)

IMap接口的第九個方法SelectFeature(Layer,Feature) (方法,從一個Layer中選擇一個Feature)

IMap接口的第十個屬性MapScale(讀寫,獲取或者設置當前map的地圖比例尺,double類型)

IMap接口的第十一個方法MoveLayer(Layer,toIndex) (方法,把一個Layer從當前的位置移動到指定的索引位置)

 

IMap接口的第十二個方法SelectByShape(Shape, env, justOne) (方法,從Layer中依靠一個圖形的范圍shape和一個選擇的環境env來選擇要素,而在所有圖層中只從IFeatureLayer的圖層中進行選擇)

 

21. IPropertySet接口(esriSystem)

IPropertySet接口的第一個方法SetProperties (names, values ) (方法,設置屬性)

IPropertySet接口的第二個方法SetProperty (name, value ) (方法,設置屬性)

 

22. IFeatureWorkspace接口(esriGeoDatabase)

IFeatureWorkspace接口用於訪問和管理地理數據庫中的要素的重要成分 -- 數據集,如Tables,ObjectClasses,FeatureClasses,FeatureDatasets,和RelationshipClasses。所有的Open方法(例如OpenTable)都要以dataset的名稱作為輸入。在企業數據庫上工作時,就需要使用完全限定名(例如,”database.owner.tablename”或”owner.tablename”)。

處理地理數據庫時(personal,file或ArcSDE),workspace將運行一個實例datasets的對象表。不同的opendatasets的方法返回一個對其的引用。

IFeatureWorkspace是用workspace創建和打開對象、對象類的主接口。

成員:

CreateFeatureClass,

CreateFeatureDataset,

CreateQueryDef,

CreateRelationshipClass,

CreateTable,

OpenFeatureClass,

OpenFeatureDataset,

OpenFeatureQuery,

OpenRelationshipClass,

OPenRelationshipQuery,

OpenTable。

 

常用的成員:

22.1、IFeatureWorkspace.CreateFeatureClass方法

 [C#] 

public IFeatureClass CreateFeatureClass(string Name,IFields Fields,UID CLSID,UID EXTCLSID,esriFeatureType FeatureType,string ShapeFieldName,string ConfigKeyword);

CreateFeatureClass方法可以用來創建獨立的要素類。除了CreateTable所需的參數外,還要指定FeatureType參數(如esriFTsimple,esriFTComplexEdgeFeature和其他)和shapeFieldName。ShapeFieldName表示要素類幾何圖形字段的名稱。在調用CreateFeatureClass之前,設置好GeometryDef對象的空間參考以及空間索引。

在Geodatabase wokspace中創建FeatureClass要包含一些必須的字段。從你要創建的對象類型的類描述中可以獲得所需字段(IObjectClassDescription的RequiredFields字段)。

CLSID參數用來指定實例化對象的GUID。如果未傳入參數,地理數據庫將使用與esriGeoDatabase.Feature有關的CLSID。多數例子中該法可行。如果要素類有自定義的Feature而不是esriGeoDatabase.Feature,這時或以后調用要素類的IClassSchemaEdit接口傳入GUID。

EXTCLSID可選參數指定實例化FeatureClassExtension對象的GUID。該對象至少要支持IClassExtension接口。使用configurationKeyword參數可以控制RDBMS中的表的物理布局—例如,在Oracle數據庫中,configuration keyword控制表創建的空間、初始化、next extents和其他屬性。ArcSDE的configurationKeyword由ArcSDE data adimistrator設置。

在9.2地理數據庫之前的workspace中,GeometryDef引用一個低精度的空間參考。9.1和之前的版本只支持低精度的空間參考,9.2要求高精度的空間參考。使用IControlPrecision2::IsHighRecision來管理空間參考的精度。使用IGeodatabaseRelease接口釋放geodatabase。

注意:不支持下列表和要素名稱前綴:”gdb_”,”sde_”,”delta_”

 

22.2、IFeatureWorkspace.OpenFeatureClass方法

[C#] 

public IFeatureClass OpenFeatureClass(string Name);

使用完全限定名可以打開workspace中任何已存在的要素類。地理數據庫中的每一個要素類都有唯一的完全限定名,使用OpenFeatureClass可以直接打開要素類。

使用IDatabaseConnectionInfo接口確定User和Database。ISQLSyntax::QualifyTableName可以用來確定要素類的完全限定名。使用IWorkspace2接口的NameExists來確定geodatabase中的要素類是否有適當的名稱。

打開參與topology或geometric network的要素類將在內存中打開所有參與的要素類。

OpenFeatureClass名稱參數的一些例子。

Coverage要素類

building:polygon

Oracle 要素類(如果已經連接到要素類,則不需要owner前綴。

gdb.Buildings

SQLServer要素類

fdo_data.gdb.Buildings

Informix要素類

Bladetest2:gdb.Buildings

VPF要素類

Ks032193:veg:vgfarea(library:coverage:feature class)

VPF數據的library名稱區分大小寫,並且要和LAT中存儲的一致(Library Attribute Table)

與Topology有關的4個表格:T_#_DirtyAreas,T_#_PolyErrors,T_#_LineErrors和T_#_PointErrors可以直接編輯。由於這個原因他們不能打開,打開時返回一個地理數據庫的錯誤。

 

23. IWorkspaceEdit接口(esriGeoDatabase)

 

在實際問題中,如果有多次操作需要更改Feature的時候,切記要將操作對象重新賦值,不然在pWorkspaceEdit.StopEditing(true)的時候會出現錯誤,報錯代碼為-2147467259。

(詳細代碼可見WindowsApplication6的代碼,其中詳細操作了對字段的編輯過程,其中涉及到很多對字段Field的方法 Add(Field),Delete(Field),get_value(object value),set_value(intindex, object value)等等操作,其中還涉及到Feature經過ICursor類選取與經過FeatureClass類的方法GetFeature選取的區別)

 

24. IWorkspaceFactory接口(esriGeoDatabase)

IWorkspaceFactory接口提供創建和打開workspace的成員以及訪問workspace factory信息的成員。

當需要創建一個新的workspace,連接已存在的workspace和尋找有關workspace的信息時使用IWorkspaceFactory接口。

成員

24.1、IWorkspaceFactory.ContainsWorkspace方法

 [C#] 

 public bool ContainsWorkspace(sring parentDirectory,IFileNames filenames);

瀏覽文件系統查詢查找workspace時,ContainsWorkspace非常有用。它提供一個parent directory和待檢查的文件名稱列表。如果parent directory表示這個factory的一個workspace或parent directory包含一個workspace或一個workspace的connection文件時,返回true。

[C#]

//e.g.,nameOFFile="canada.mdb"//Personal Geodatabase

//nameOFFile="canada.gdb"//File Geodatabase

public Boolean IWorkspaceFactory_ContainsWorkspace_Example(string nameOfFile)

{

       //use with AccessWorkspaceFactory

       IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();

       //for FileGDB use ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();

       ESRI.ArcGIS.esrSystem.IFileNames fileNames=new ESRI.ArcGIS.esriSystem.FileNamesClass();

       fileNames.Add(nameOfFile);

       return workspaceFactory.ContainsWorkspace("E:\\data\\english\\canada\\",fileNames);

}

24.2、IWorkspaceFactory.Create方法

 [C#] 

 public IWorkspaceName Create(string parentDirectory,string Name,IPropertySet ConnectionProperties,int hWnd);

Workspace factory由多種類型,Create會產生不同的結果。ArcSDE類型,將會產生一個新的connection文件(.sde)。ArcInfo workspace factory類型,創建一個INFO的亞文件夾。ConnectionProperties參數是個可選項,指定任何額外的所需連接屬性,例如創建遠程數據庫workspace時的connection文件所需的server,instance,user和password。如果沒有指定連接屬性,這個方法將會返回一個對話框提醒用戶需要屬性。

[C#]

public void IWorkspaceFactory_Create_Example_Access()

{

       //create a new Access workspace factory

       IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();

       //Create a workspacename with the workspace factory

       IWorkspaceName workspaceName=workspaceFactory.Create("C:\\temp\\","MyNewpGDB.mdb",null,0);

       //Cast for IName

       ESRI.ArcGIS.esriSystem.IName name=(ESRI.ArcGIS.esriSystem.IName)workspaceName;

       //Open a reference to the access workspace through the name object

       IWorkspace pGDB_workspace=(IWorkspace)name.Open();

      

       Console.WriteLine("Current path of the{0} is {1}",pGDB_workspace.Type,pGDB_workspace.PathName);

public void IWorkspaceFactory_Create_Example_FileGDB()

{

       //create a new FileGDB workspace factory

       IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();

       //Create a workspacename with the workspace factory

       IWorkspaceName workspaceName=workspaceFactory.Create("C:\\temp\\","MyNewFileGDB.gdb",null,0);

       //Cast for IName

       ESRI.ArcGIS.esriSystem.IName name=(ESRI.ArcGIS.esriSystem.IName)workspaceName;

       //Open a reference to the FileGDB workspace through the name object

       IWorkspace fileGDB_workspace=(IWorkspace)name.Open();

      

       Console.WriteLine("Current pathe of the {0} is {1}",fileGDB_workspace.Type,fileGDB_workspace.PathName);

public void IWorkspaceFactory_Create_Example_ArcSDE()

{

       ESRI.ArcGIS.esriSystem.IPropertySet propertySet=new ESRI.ArcGIS.esriSystem.PropertySetClass();

       propertySet.SetProperty("Server","testserver");

       propertySet.SetProperty("Instance","5151");

       propertySet.SetPropert("Database","sde");

       propertySet.SetProperty("pasword","go");

       propertySet.SetProperty("version","sde.DEFAULT");

      

       //Create a workspacename with the workspace factory

       IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();

       //Create a workspacename with the workspace factory

       IWorkspaceName workspaceName=workspaceFactory.Create("C:\\temp\\","MyNewArcSDE_Connection.sde",propertySet,0);

       //Cast for IName

       ESRI.ArcGIS.esriSystem.IName name=(ESRI.ArcGIS.esriSystem.IName)workspaceName;

       //Open a reference to the sde workspace through the name object

       IWorkspace sde_workspace=(IWorkspace)name.Open();

       //the path returned in this case weill be for the sde connection

       Console.WriteLine("Current path of the {0} is {1}",sde_workspace.Type,sde_workspace.PathName);

}

24.3、IWorkspaceFactory.GetWorkspaceName方法

 [C#]

public IWorkspaceName GetWorkspaceName(string parentDirectory,IFileNames filenames);

Example

[C#]

public void IWorkspaceFactory_GetWorkspaceName_Example()

{

       ESRI.ArcGIS.esriSystem.IFileNames fileNames=new ESRI.ArcGIS.esriSystem.FileNamesClass();

       fileNames.Add("shapefile");

       fileNames.Add("access\\canada\\cananda.mdb");

       fileNames.Add("access\\big.mdb");

      

       IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();

       IWorkspaceName workspaceName=workspaceFactory.GetWorkspaceName("E:\\data\\english",fileNames);

      

       Console.WriteLine(workspaceName.PathName);

      

       fileNames.Reset();

      

       string fn=fileNames.Next();

       while(fn!=null)

       {

              Console.WriteLine(fn);

              fn=fileNames.Next();

       }

      

       ESRI.ArcGIS.esriSystem.IName name=(ESRI.ArcGIS.esriSystem.IName)workspaceName;

       IWorkspace workspace=(IWorkspace)name.Open();

}

24.4、IWorkspaceFactory.Open方法

 [C#]

public IWorkspace Open(IPropertySet ConnectionProperties,int hWnd);

Example

[C#]

Public IWorkspace IWorkspaceFactory_Open_Example(String server,String instance,String user,String password,String database,String version)

{

       ESRI.ArcGIS.esriSystem.IPropertySet propertySet=new ESRI.ArcGIS.esriSystem.PropertySetClass();

       propertySet.SetProperty(“SERVER”,server);

       propertySet.SetProperty(“INSTANCE”,instance);

       propertySet.SetProperty(“DATABASE”,database);

       propertySet.SetProperty(“USER”,user);

       propertySet.SetProperty(“PASSWORD”,password);

       propertySet.SetProperty(“VERSION”,version);

IWorkspaceFactory worspaceFactory=new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();

Return workspaceFactory.Open(propertySet,0);

}

24.5、IWorkspaceFactory.OpenFromFile方法

 [C#]

 public IWorkspace OpenFromFile(string fileName,int hWnd);

OpenFromFile采用表示FileSystemWorkspace或LocalDatabaseWorkspace,或是RemoteDatabaseWorkspace的connection文件的參數,並返回一個指定workspace的接口。這些方法的客戶然后就可以打開和訪問workspace中的數據集。調用這些方法時,如果屬性不足,將提供一個連接對話框提示需要其他屬性。

hWnd引數是父窗體或應用程序窗體,確保connection對話框有正確的父窗體。

Example

[C#]

//e.g.,nameOfFile="E:\\data\\english\\access\\canada\\canada.mdb"

public IWorkspace IWorkspaceFactory_OpenFromFile_Example_Access(string nameOfFile)

{

       IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();

       return workspaceFactory.OpenFromFile(nameOfFile,0);

//e.g.,nameOfFile="E:\\data\\english\\FileGDB\\canada\\canada.gdb"

public IWorspace IWorkspaceFactory_OpenFromFile_Example_FileGDB(string nameOfFile)

{

       IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();

       return workspaceFactory.OpenFromFile(nameOfFile,0);

//e.g.,nameOfFile="D:\\data\\redarrow.sde"

public IWorkspace IWorkspaceFactory_OpenFromFile_Example_ArcSDE(string nameOfFile)

{

       IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();

       return workspaceFactory.OpenFromFile(nameOfFile,0);

//The connection string for a shapefile should be the full path

//to the shapfile's folder(e.g.,"C:\\temp")

//Note:location cannot be relative path ".\\temp" it must be an explicit pathname

public IWorkspace IWorkspaceFactory_OpenFromFile_Example_Shapefile(string nameOfFile)

{

       IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();

       return workspaceFactory.OpenFromFile(nameOfFile,0);

}

WorkspaceFactory負責管理workspace,允許用戶通過一系列connection properties連接workspace。一個workspace表示包含一個或多個數據集的數據庫。Dataset包括tables,feature classes和relationship classes。一個workspaceFactory是可以單獨創建的。一個WorkspaceFactory包括應用程序引用的當前連接的活動的workspaces。使用PropertySet指定Connection屬性,並且可以存到connection文件中。WorkspaceFactory也支持瀏覽和管理file system Workspaces,以及管理remot database workspaces。

 

25. ITopologicalOperator接口(esriGeometry)

可以將一個Polygon類型的數據或者Polyline的數據賦值給該接口的變量,如:

   Set pUnionedPolylines =NewPolyline Set pTopOp = pUnionedPolylines

 ITopologicalOperator接口的第一個方法ConstructUnion(geometries ) (方法,合並圖形的工具,輸入的參數是一個IEnumGeometry類型的參數,此方法效率甚高)

ITopologicalOperator接口的第二個方法Cut(cutter, leftGeom, rightGeom) (方法,剪切圖形,第一個參數為剪切的線要素,為IPloyline類型,第二個第三個參數均為剪切后的圖形,為輸出參數)

ITopologicalOperator接口的第三個方法Boundary(方法,獲取一個圖形的邊框,一個Polygon的boundary是一個Polyline類型的要素,一個Polyline的boundary是一個nultipoint類型的要素,一個Point的boundary是為空的)

ITopologicalOperator接口的第四個方法Buffer(distance) (方法,創造一個Polygon的要素來顯示緩沖區域,參數為緩沖距離)

 

ITopologicalOperator接口的第五個方法Clip (clipperEnvelope ) (方法,輸入一個IEnvelope類型的變量,來獲取被這個邊框剪切的要素,並將切割后的變量返回給調用方法的變量)

ITopologicalOperator接口的第六個方法QueryClipped (clipperEnvelope, clippedGeometry ) (方法,與Clip類似,但是第二個參數為剪切后返回輸出的參數,本身不會改變)

ITopologicalOperator接口的第七個方法ConvexHull(方法,構造一個Geometry,大部分為Polygon類型的幾何要素,該要素為調用此方法的ITopologicalOperator類型的變量最小的外邊框)

ITopologicalOperator接口的第八個方法SymmetricDifference (other ) (方法,並集減去交集的部分,調用次方法的變量為第一個參數,other為第二個參數,最后返回變量到一個Geometry類型的變量,該變量的范圍均在兩個參數范圍內,但不在兩個參數相交的部分)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM