'In this case, we could have set pEnvelope toIActiveView::Extent 'Set pEnvelope = pActiveView.Extent Set pCenterPoint = New Point
pCenterPoint.x= ((pEnvelope.XMax - pEnvelope.XMin) / 2) + pEnvelope.XMin pCenterPoint.y= ((pEnvelope.YMax - pEnvelope.YMin) / 2) + pEnvelope.YMin pEnvelope.width= pEnvelope.width / 2 pEnvelope.height= pEnvelope.height / 2 pEnvelope.CenterAtpCenterPoint pDisplayTransform.VisibleBounds= pEnvelope pActiveView.Refresh End Sub
=============================== 怎样读取一个字段内的所有值: ===============================
IFeatureClass pFC= m_SDEQuery.getFeatureClass(); IFeatureCursor pFeaCur= pFC.Search(null, false); IFeature pFeature= pFeaCur.NextFeature();
int pFieldIndex = pFC.Fields.FindField(this.m_cboQryFld.SelectedItem.Value.ToString()); System.Collections.ArrayListpArr = new System.Collections.ArrayList(); while (pFeature != null) {
string theFieldValue = pFeature.get_Value(pFieldIndex).ToString(); if (!pArr.Contains(theFieldValue)&& (theFieldValue.Trim() != \ {
m_cboQryText.Items.Add(theFieldValue); pArr.Add(theFieldValue); }
pFeature = pFeaCur.NextFeature(); }
=============================== 怎样编辑更改属性字段的值: ===============================
IRow prow = (IRow)bendiFeatureC.GetFeature(1);
MessageBox.Show(prow.Table.Fields.FieldCount.ToString());
ITable ptable = (ITable)bendiFeatureC; IQueryFilter pqfilter= new QueryFilterClass(); pqfilter.WhereClause = \北江路南郊一公里\\'\
IFeatureCursor pfeatcur;
pfeatcur = bendiFeatureC.Search(pqfilter, false);
IFeature pfff = pfeatcur.NextFeature(); while (pfff != null) {
IRowprrr = (IRow)pfff;
prrr.set_Value(prrr.Fields.FindField(\北江路南郊二公里\ pfff = (IFeature)prrr; pfff.Store();
pfff = pfeatcur.NextFeature(); }
===============================
怎样将MapControl中的Map复制到PageLayoutControl中 ===============================
Public Sub CopyAndOverwriteMap()
OnErrorGoToCopyAndOverwriteMap_err
DimpObjectCopyAsIObjectCopy pObjectCopy = New ObjectCopy
DimpToCopyMapAsObject
pToCopyMap = frmMap.AxMapControl1.Map
DimpCopiedMapAsObject
pCopiedMap = pObjectCopy.Copy(pToCopyMap)
DimpToOverwriteMapAsObject
pToOverwriteMap =PrintPageLayout.AxPageLayoutControl1.ActiveView.FocusMap
pObjectCopy.Overwrite(pCopiedMap, pToOverwriteMap) frmMap.AxMapControl1.MousePointer
=ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerArrow frmMain.StatusMessage.Text = \ PrintPageLayout.ShowDialog() ExitSub
CopyAndOverwriteMap_err: MsgBox(Err.Number& \ - \&Err.Description,MsgBoxStyle.Critical,Application.ProductName& \- CopyMap\ ExitSub
End Sub
=============================== 怎样判断是否出于编辑状态: ===============================
If m_pEditor.EditState =esriStateEditingThen m_pEditor.StartOperation
'删除冗余节点
DelSubPoint pMap m_pEditor.StopOperation\ End If
把m_pEditor.StartOperation放在函数里面更好
=============================== 怎样用点创建一个Polygon: ===============================
Dim pPnt0 asIPoint,pPnt1asIPoint,pPnt2asIPoint Set pPnt0 = NewPoint Set pPnt1 = NewPoint Set pPnt2 = NewPoint pPnt0.PutCoordsx1,y1 pPnt1.PutCoordsx2,y2 pPnt2.PutCoordsx3,y3
Dim pPolygon as IPointCollection(注意,这里的polygon是设置为点集的) Set pPolygon =New Polygon pPolygon.AddPointpPnt0 pPolygon.AddPointpPnt1 pPolygon.AddPointpPnt2
pPolygon.AddPoint pPnt0(注意,这里一定要闭合回到pPnt0才能形成一个Polygon)
Set pFeature.Shape = pPolygon pFeature.Store
用这种方法可以创建一个Polyline:
Dim pPolyline asIPointCollection Set pPolyline =New Line pPolyline.AddPointpPnt0 pPolyline.AddPointpPnt1
pPolyline.AddPointpPnt2(这时就是一个polyline,不是闭合的)
还可以用另外一种方法,画一条两点之间的线段:
Dim pLine AsILine
Set pLine = New esriGeometry.Line
pLine.PutCoords pPnt0,pPnt1(第一个为from点,第二个为to点) )
=============================== 怎样运用属性来计算总面积: ===============================
Dim pDoc As IMxDocument Dim pMap As IMap
Dim pFeatureLayer As IFeatureLayer Dim pFeatureClass As IFeatureClass
Set pDoc = m_pApplication.Document Set pMap = pDoc.ActiveView.FocusMap Set pFeatureLayer = pMap.Layer(0)
Set pFeatureClass = pFeatureLayer.FeatureClass
' +++ create the query filter, and give
' +++ it a where clause Dim pQueryFilt As IQueryFilter Dim pFeatureCursor As IFeatureCursor
Set pQueryFilt = New QueryFilter pQueryFilt.WhereClause= \ 'COM'\
Set pFeatureCursor =pFeatureClass.Search(pQueryFilt, False)
' +++ get the area field Dim pFields As IFields Dim pField As IField Dim lAIndex As Long
Set pFields = pFeatureClass.Fields lAIndex = pFields.FindField(\ Set pField = pFields.Field(lAIndex)
' +++ a variable to hold the total area Dim dtotArea As Double dtotArea = 0#
' +++ loop through all of the features and ' +++ calculate the sum of all of the areas Dim pFeature As IFeature
Set pFeature = pFeatureCursor.NextFeature Do
dtotArea = dtotArea + pFeature.Value(lAIndex) Set pFeature = pFeatureCursor.NextFeature Loop Until pFeature Is Nothing
' +++ send the total area to a message box MsgBox dtotArea
=============================== 关于属性域的一些心得 ===============================