本文整理汇总了C#中QueryFilter.AddField方法的典型用法代码示例。如果您正苦于以下问题:C# QueryFilter.AddField方法的具体用法?C# QueryFilter.AddField怎么用?C# QueryFilter.AddField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryFilter
的用法示例。
在下文中一共展示了QueryFilter.AddField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnClick
protected override void OnClick()
{
//
// TODO: Sample code showing how to access button host
//
ArcMap.Application.CurrentTool = null;
IMap map = ArcMap.Document.ActivatedView.FocusMap;
//Check to make sure the map contains a layer
if (map.LayerCount < 1)
{
MessageBox.Show("Must have a layer in your map...");
return;
}
//Get the selected layer
ILayer selectedLayer = ArcMap.Document.SelectedLayer;
//Checl that there is a selected layer in the table of contents
if (selectedLayer == null)
{
MessageBox.Show("You must have a layer highlighted in the table of contents.");
return;
}
//Check that the selected layer is a featuer layer
if (!(selectedLayer is IFeatureLayer))
{
MessageBox.Show("The highlighted layer in the TOC must be a feature layer.");
return;
}
IFeatureLayer featureLayer = selectedLayer as IFeatureLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
//Check that the features shape is a line
if (featureClass.ShapeType != esriGeometryType.esriGeometryPolyline)
{
MessageBox.Show("The highlighted layer in the TOC must be a polyline.");
return;
}
//Check that features are selected in the table of contents
IFeatureSelection featureSelection = featureLayer as IFeatureSelection;
if (featureSelection.SelectionSet.Count < 1)
{
MessageBox.Show("The highlighted layer in the TOC must have some features selected.");
return;
}
ISelectionSet2 selectionSet = featureSelection.SelectionSet as ISelectionSet2;
int streetFieldIndex = featureClass.FindField(sStreetFldName);
//Check that the street name exists in the table.
if (streetFieldIndex < 0)
{
MessageBox.Show(sStreetFldName + " was not found in highlighted layer.");
return;
}
int crossA = featureClass.FindField(sCrossAFldName);
//Check that the cross from field was found in the table
if (crossA < 1)
{
MessageBox.Show(sCrossAFldName + " was not found in highlighted layer.");
return;
}
//Check that the cross to field was found in the table
int crossB = featureClass.FindField(sCrossBFldName);
if (crossB < 1)
{
MessageBox.Show(sCrossBFldName + " was not found in highlighted layer.");
return;
}
//Find the editor
UID id = new UID();
id.Value = "esriEditor.Editor";
IApplication application = ArcMap.Application;
IEditor3 editorExtension = application.FindExtensionByCLSID(id) as IEditor3;
//Make sure that an active edit session is happening
if (!(editorExtension.EditState == esriEditState.esriStateEditing))
{
MessageBox.Show("Must be in an edit session");
return;
}
//Update the status bar
application.StatusBar.Message[0] = "Populating Cross Streets...";
editorExtension.StartOperation();
IQueryFilter queryFilter = new QueryFilter();
queryFilter.AddField(sCrossAFldName);
queryFilter.AddField(sCrossBFldName);
ICursor featureCursor;
selectionSet.Update(null, false, out featureCursor);
IFeature feature = featureCursor.NextRow() as IFeature;
string total = selectionSet.Count.ToString();
int count = 0;
//Iterate through the features until all of the selected ones have been tested
do
{
count++;
application.StatusBar.Message[0] = "Populating cross streets... " + count.ToString() + " of " + total;
string street = feature.Value[streetFieldIndex] as string;
//.........这里部分代码省略.........
示例2: OnClick
protected override void OnClick()
{
try
{
if (_wkspHelper.CurrentWorkspace == null)
{
MessageBox.Show("You must select and open a telecom workspace before running this tool");
return;
}
DialogResult res = MessageBox.Show(null, "This test may run for a considerable time (15+ minutes) and may make modifications to the database to resolve issues. \n\nConsider taking a backup before doing this. \n\nDo you wish to proceed?", "DB Integrity Check", MessageBoxButtons.OKCancel);
if (res != DialogResult.OK)
return;
IFeatureClass cableFc = _wkspHelper.FindFeatureClass(ConfigUtil.FiberCableFtClassName);
if (cableFc == null) { return; }
IFeatureWorkspace fworkspace =_wkspHelper.CurrentWorkspace;
if (fworkspace == null) { return; }
// --------------------------------------------
// Check the integrity of the cable feature class
// --------------------------------------------
IRelationshipClass fiberCableToFiberRc = fworkspace.OpenRelationshipClass(ConfigUtil.FiberCableToFiberRelClassName);
IRelationshipClass fiberCableToBufferRc = fworkspace.OpenRelationshipClass(ConfigUtil.FiberCableToBufferRelClassName);
IFeature feature;
bool badCable = false;
bool badBuffers = false;
bool badFibers = false;
bool conversionRequired = false;
IWorkspaceEdit2 edit = fworkspace as IWorkspaceEdit2;
ITransactions transaction = edit as ITransactions;
edit.StartEditing(true);
edit.StartEditOperation();
IQueryFilter qf = new QueryFilter();
qf.AddField(ConfigUtil.NumberOfBuffersFieldName);
qf.AddField(ConfigUtil.NumberOfFibersFieldName);
qf.AddField(ConfigUtil.IpidFieldName);
using (ComReleaser comReleaser = new ComReleaser())
{
IFeatureCursor fCursor = (IFeatureCursor)cableFc.Update(qf, false);
ICursor pCursor = fCursor as ICursor;
comReleaser.ManageLifetime(fCursor);
int buffersFieldIdx = cableFc.FindField(ConfigUtil.NumberOfBuffersFieldName);
int fibersFieldIdx = cableFc.FindField(ConfigUtil.NumberOfFibersFieldName);
int ipidFieldIdx = cableFc.FindField(ConfigUtil.IpidFieldName);
int count = 0;
while ((feature = fCursor.NextFeature()) != null)
{
// Cables should have non null field values
if (feature.get_Value(ipidFieldIdx) == DBNull.Value)
{
badCable = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL IPID value");
continue;
}
if (feature.get_Value(buffersFieldIdx) == DBNull.Value)
{
badBuffers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL buffer field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}
if (feature.get_Value(fibersFieldIdx) == DBNull.Value)
{
badFibers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL fiber field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}
int bufferCount = (int)feature.get_Value(buffersFieldIdx);
int fiberCount = (int)feature.get_Value(fibersFieldIdx);
// Cables should have non zero values
if (bufferCount == 0)
{
badBuffers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 buffer field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}
if (fiberCount == 0)
{
badFibers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 strand field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}
// Cables should have relationships
int rcBufferCount = fiberCableToBufferRc.GetObjectsRelatedToObject(feature).Count;
if (rcBufferCount == 0)
{
badBuffers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 related buffers", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}
int rcFiberCount = fiberCableToFiberRc.GetObjectsRelatedToObject(feature).Count;
//.........这里部分代码省略.........