//查找 from vec,参数为空则查找所有 private static ArrayList queryFromRAS(string where) { ArrayList t = new ArrayList(); IName pName = RAS_TABLE as IName; ITable table = pName.Open() as ITable; IQueryFilter query = new QueryFilterClass(); query.WhereClause = where; ISelectionSet selectionSet = table.Select(query, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, null); ICursor cursor; selectionSet.Search(null, false, out cursor); IRow row = cursor.NextRow(); if (selectionSet.Count > 0) { while (row != null) { NameAndType nat = new NameAndType(); nat.name = row.get_Value(1) + ""; nat.type = "rasterDataset"; t.Add(nat); row = cursor.NextRow(); } } return(t); }
private void setDistrictColor(string districtName) { if (m_map.Map.LayerCount < 5) { return; } IFeatureLayer pFeatureLayer = m_map.Map.get_Layer(4) as IFeatureLayer; if (pFeatureLayer == null) { return; } IQueryFilter pFilter; pFilter = new QueryFilterClass(); pFilter.WhereClause = "Name = '" + districtName + "'";//"Name" = '嘉定区' OR "Name" = '杨浦区' IFeatureSelection pFeatureSelection; pFeatureSelection = pFeatureLayer as IFeatureSelection; pFeatureSelection.SelectFeatures(pFilter, esriSelectionResultEnum.esriSelectionResultNew, true); //将选择集添上颜色 IRgbColor pColor; pColor = new RgbColorClass(); pColor.Red = 220; pColor.Green = 112; pColor.Blue = 60; ISelectionSet selectSet = pFeatureSelection.SelectionSet; // pFeatureSelection.SelectionColor = getRGB(220, 60, 60);//pColor //m_map.ClearLayers(); m_map.Refresh(); /* 删除闪烁效果*/ ISelectionSet pFeatSet; pFeatSet = pFeatureSelection.SelectionSet; IFeatureCursor pFeatCursor; ICursor pCursor; pFeatSet.Search(pFilter, true, out pCursor); pFeatCursor = pCursor as IFeatureCursor; IFeature pFeat; pFeat = pFeatCursor.NextFeature(); while (pFeat != null) { if (pFeat != null) { Console.Out.WriteLine(pFeat.Fields); ISimpleFillSymbol pFillsyl2; pFillsyl2 = new SimpleFillSymbolClass(); pFillsyl2.Color = getRGB(220, 60, 60); m_map.FlashShape(pFeat.Shape, 0, 0, pFillsyl2); } pFeat = pFeatCursor.NextFeature(); } setPointColor(listCode[this.districtList.SelectedIndex].ToString()); // */ }
/// <summary> /// Gets the selection set that corresponds to the conflict class. /// </summary> /// <param name="conflictClass">The conflict class.</param> /// <param name="conflictType">Type of the conflict.</param> /// <returns>Returns the <see cref="ISelectionSet" /> representing the set of conflicts.</returns> protected ISelectionSet GetConflictSet(IConflictClass conflictClass, TableConflictType conflictType) { if (conflictClass == null) { throw new ArgumentNullException("conflictClass"); } ISelectionSet set = null; switch (conflictType) { case TableConflictType.DeleteUpdates: set = conflictClass.DeleteUpdates; break; case TableConflictType.UpdateDeletes: set = conflictClass.UpdateDeletes; break; default: set = conflictClass.UpdateUpdates; break; } return(set); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { try { //ILayer player = ClsGlobal.GetSelectedLayer(m_hookHelper); IBasicMap map = null; ILayer layer = null; ClsGlobal.GetSelectedMapAndLayer(m_pTocCtl, ref map, ref layer); if (map == null || layer == null) { return; } IFeatureLayer pFLayer = (IFeatureLayer)layer; IFeatureLayerDefinition pFLDef = (IFeatureLayerDefinition)pFLayer; IFeatureSelection pFSel = (IFeatureSelection)pFLayer; ISelectionSet pSSet = pFSel.SelectionSet; if (pSSet.Count > 0) { IFeatureLayer pSelFL = pFLDef.CreateSelectionLayer(layer.Name + "Selection", true, null, null); map.AddLayer(pSelFL); IActiveView activiView = map as IActiveView; activiView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); m_pTocCtl.Update(); } } catch (Exception ex) { ; } }
private static int[] BuildOidArray(ISelectionSet set, int size) { if (size > set.Count) size = set.Count; if (size < 1) return new int[0]; //int[] oids = new int[size]; var oids = new HashSet<int>(); var rand = new Random(); IEnumIDs ids = set.IDs; while (oids.Count < size) { int oid = ids.Next(); // If we get to the end of the list start over // If we start over, we need to be sure to not add the same item twice. // luckily we are using a Hashset. if (oid == -1) { ids.Reset(); oid = ids.Next(); // I made sure ids has at least one member at the start of this method } // flip a coin - heads it goes in the list, tails it stays out. // this trick coin will land heads just the right percent of the time. if (rand.Next(set.Count) <= size) oids.Add(oid); } return oids.ToArray(); }
private string SerializeSelections(ISelectionSet selectionSet) { StringBuilder builder = new StringBuilder(); SerializeSelections(selectionSet, builder); return(builder.ToString()); }
private IEnvelope GetLayerSelectedFeaturesEnvelope(IFeatureLayer pFeatLyr) { IEnvelope layerEnvelope = null; IFeatureClass pFeatCls = pFeatLyr.FeatureClass; IFeatureSelection selectLayer = pFeatLyr as IFeatureSelection; ISelectionSet selectionSet = selectLayer.SelectionSet; IEnumIDs enumIDs = selectionSet.IDs; IFeature feature; int i = 1; int iD = enumIDs.Next(); while (iD != -1) //-1 is reutned after the last valid ID has been reached { feature = pFeatCls.GetFeature(iD); IEnvelope envelope = feature.ShapeCopy.Envelope; if (i == 1) { layerEnvelope = envelope; } else { layerEnvelope.Union(envelope); } i++; iD = enumIDs.Next(); } return(layerEnvelope); }
protected override ISyntaxVisitorAction Enter( FieldNode node, MatchSelectionsContext context) { IOutputType outputType = context.Types.Peek(); Field field = GetField(context, node, outputType); if (context.Selections.TryGetValue(field.FieldName, out ISelection? selection)) { context.Count++; if (selection.Field.Type.IsCompositeType()) { Debug.Assert( selection.SelectionSet is not null, "A composite type must have a selection set."); foreach (IObjectType possibleType in context.Operation.GetPossibleTypes(selection.SelectionSet !)) { ISelectionSet selectionSet = context.Operation.GetSelectionSet(selection.SelectionSet !, possibleType); return(base.Enter(node, context.Branch(possibleType, selectionSet))); } } } return(Skip); }
public static IGeometry GetSelectGeometry(AxMapControl axMapControl) { for (int i = 0; i < axMapControl.LayerCount; i++) { IFeatureLayer pFeatureLayer = axMapControl.get_Layer(i) as IFeatureLayer; IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection; ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet; ICursor pCursor = null; pSelectionSet.Search(null, false, out pCursor); IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor; IFeature pFeature = pFeatureCursor.NextFeature(); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor); GC.Collect(); GC.WaitForPendingFinalizers(); if (pFeature != null) { return(pFeature.Shape); } } return(null); }
private void AddIdSelection(ISelectionSet set) { if (!set.Selections.OfType <FieldSelection>().Any(x => x.Name == "id")) { set.Selections.Insert(0, new FieldSelection("id", null)); } }
private void SerializeSelections(ISelectionSet selectionSet, StringBuilder builder) { OpenBrace(builder); bool first = true; if (selectionSet.Selections != null) { foreach (var s in selectionSet.Selections) { if (!first) { Separator(builder); } var field = s as FieldSelection; var fragment = s as InlineFragment; if (field != null) { Serialize(field, builder); } else if (fragment != null) { Serialize(fragment, builder); } first = false; } } CloseBrace(builder); }
public override void OnClick() { if (m_MergeLayer != null) { List <int> OIDLst = new List <int>(); IFeatureSelection pFeatSel = m_MergeLayer as IFeatureSelection; ISelectionSet pSelectionSet = pFeatSel.SelectionSet; //如果选择的要素多余一个,则可以开始融合 if (pSelectionSet.Count > 1) { int pOID = -1; IEnumIDs pEnumIDs = pSelectionSet.IDs; pEnumIDs.Reset(); pOID = pEnumIDs.Next(); while (pOID != -1) { OIDLst.Add(pOID); pOID = pEnumIDs.Next(); } frmDataMerge pfrmDataMerge = new frmDataMerge(m_MergeLayer.FeatureClass, OIDLst, m_Hook); pfrmDataMerge.ShowDialog(); } } }
private void FeatureSelectionChanged(IFeatureSelection sender) { if (_dsElement is IFeatureSelection) { ISelectionSet selSet = ((IFeatureSelection)_dsElement).SelectionSet; if (selSet is IIDSelectionSet) { if (_selectedIDs != null) { _selectedIDs.Clear(); } _selectedIDs = ((IIDSelectionSet)selSet).IDs; _selectedIDs.Sort(); } else if (selSet == null) { if (_selectedIDs != null) { _selectedIDs.Clear(); } _selectedIDs = null; } } if (cmbShow.SelectedIndex == 1) { vScrollBar.Value = 0; } markSelected(_maxNewSelectedRows); }
private void PerformSketchToolEnabledChecks() { if (m_editLayer == null) { return; } //Only enable the sketch tool if there is a polyline target layer. if (m_editLayer.TargetLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline) { m_editSketch.GeometryType = esriGeometryType.esriGeometryNull; return; } //check that only one feature in the target layer is currently selected IFeatureSelection featureSelection = m_editLayer.TargetLayer as IFeatureSelection; ISelectionSet selectionSet = featureSelection.SelectionSet; if (selectionSet.Count != 1) { m_editSketch.GeometryType = esriGeometryType.esriGeometryNull; return; } m_editSketch.GeometryType = esriGeometryType.esriGeometryPolyline; }
private FieldSelection AddField(ISelectionSet parent, FieldSelection field, bool updateHead = true) { var existing = field.Alias == null? parent.Selections .OfType <FieldSelection>() .FirstOrDefault(x => x.Name == field.Name && x.Alias == null) : null; if (existing == null) { parent.Selections.Add(field); } else { field = existing; } if (updateHead) { Head = field; FieldStack.Add(field); } return(field); }
/// <summary> /// 获取选择的要素(以cusor形式遍历) /// </summary> /// <param name="pFeatureLayer">预分析要素层</param> /// <returns>选择要素的游标</returns> public IFeatureCursor GetSelectedFeatures(IFeatureLayer pFeatureLayer) { if (pFeatureLayer == null) { //分析图层为空 return(null); } else { IFeatureSelection pFeatSel = null; ISelectionSet pSelectionSet = null; ICursor pCursor = null; pFeatSel = pFeatureLayer as IFeatureSelection; pSelectionSet = pFeatSel.SelectionSet; if (pSelectionSet.Count == 0) { MessageBox.Show("No features are selected in the '" + pFeatureLayer.Name + "' layer"); return(null); } pSelectionSet.Search(null, false, out pCursor); //返回游标 return(pCursor as IFeatureCursor); } }
public Fragment( int fragmentId, IObjectType typeCondition, FragmentSpreadNode fragmentSpread, FragmentDefinitionNode fragmentDefinition, ISelectionSet selectionSet, bool internalFragment, SelectionIncludeCondition?includeCondition) { TypeCondition = typeCondition; SyntaxNode = fragmentDefinition; SelectionSet = selectionSet; Directives = fragmentSpread.Directives; IsInternal = internalFragment; IsConditional = includeCondition is not null; _fragmentId = fragmentId; _includeCondition = includeCondition; InclusionKind = internalFragment ? SelectionInclusionKind.Internal : SelectionInclusionKind.Always; if (IsConditional) { InclusionKind = internalFragment ? SelectionInclusionKind.InternalConditional : SelectionInclusionKind.Conditional; } }
public void SelectByPolygon(int IndexOfLayer, RubberPolygonClass Polygon) { int ConstantNum = 255; IActiveView CurrentView = axMapControl1.ActiveView; IScreenDisplay MyScreenDispaly = CurrentView.ScreenDisplay; MyScreenDispaly.StartDrawing(MyScreenDispaly.hDC, (System.Int16)esriScreenCache.esriNoScreenCache); IRgbColor MYRGBCOLOR = new RgbColorClass(); MYRGBCOLOR.Red = ConstantNum; IColor MyColor = MYRGBCOLOR; ISimpleFillSymbol MySimpleFillPolygon = new SimpleFillSymbolClass(); MySimpleFillPolygon.Color = MyColor; ISymbol MySymbol = MySimpleFillPolygon as ISymbol; IRubberBand MyIRubberBand = Polygon; IGeometry MyGeometry = MyIRubberBand.TrackNew(MyScreenDispaly, MySymbol); MyScreenDispaly.SetSymbol(MySymbol); MyScreenDispaly.DrawPolygon(MyGeometry); MyScreenDispaly.FinishDrawing(); ISpatialFilter MyISpatialFilter = new SpatialFilterClass(); MyISpatialFilter.Geometry = MyGeometry; MyISpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureLayer SelectedLayer = axMapControl1.ActiveView.FocusMap.get_Layer(IndexOfLayer) as IFeatureLayer; IFeatureSelection SelectedFeature = SelectedLayer as IFeatureSelection; SelectedFeature.SelectFeatures(MyISpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false); ISelectionSet MyISelectionSet = SelectedFeature.SelectionSet; axMapControl1.ActiveView.Refresh(); }
IEnumInvalidObject ESRI.ArcGIS.Geodatabase.IFeatureDataConverter2.ConvertFeatureClass( IDatasetName idatasetName_0, IQueryFilter iqueryFilter_0, ISelectionSet iselectionSet_0, IFeatureDatasetName ifeatureDatasetName_0, IFeatureClassName ifeatureClassName_0, IGeometryDef igeometryDef_0, IFields ifields_0, string string_0, int int_0, int int_1) { return(null); }
/// <summary> /// 根据选择的要素判断其所属图层 /// </summary> /// <param name="pMap"></param> /// <returns></returns> public static IFeatureLayer ReturnFeatureSelectedLayer(IMap pMap) { try { IFeatureLayer pFeatureLayer = null; for (int i = 0; i < pMap.LayerCount; i++) { if (pMap.get_Layer(i) is FeatureLayer) { pFeatureLayer = pMap.get_Layer(i) as IFeatureLayer; IFeatureSelection pFeatureSel = pFeatureLayer as IFeatureSelection; ISelectionSet pSelSet = pFeatureSel.SelectionSet; if (pSelSet.Count != 0) { break; } } else { MessageBox.Show("找不到选择的要素!"); return(null); } } return(pFeatureLayer); } catch (Exception ex) { throw ex; } }
/// <summary> /// Subscribes to the pub/sub-system and creates a new <see cref="Subscription"/> /// instance representing that subscriptions. /// </summary> /// <param name="operationContextPool"> /// The operation context pool to rent context pools for execution. /// </param> /// <param name="queryExecutor"> /// The query executor to process event payloads. /// </param> /// <param name="requestContext"> /// The original request context. /// </param> /// <param name="queryPlan"> /// The subscription query plan. /// </param> /// <param name="subscriptionType"> /// The object type that represents the subscription. /// </param> /// <param name="rootSelections"> /// The operation selection set. /// </param> /// <param name="resolveQueryRootValue"> /// A delegate to resolve the subscription instance. /// </param> /// <param name="executionDiagnosticsEvents"> /// The internal diagnostic events to report telemetry. /// </param> /// <returns> /// Returns a new subscription instance. /// </returns> public static async ValueTask <Subscription> SubscribeAsync( ObjectPool <OperationContext> operationContextPool, QueryExecutor queryExecutor, IRequestContext requestContext, QueryPlan queryPlan, ObjectType subscriptionType, ISelectionSet rootSelections, Func <object?> resolveQueryRootValue, IExecutionDiagnosticEvents executionDiagnosticsEvents) { var subscription = new Subscription( operationContextPool, queryExecutor, requestContext, queryPlan, subscriptionType, rootSelections, resolveQueryRootValue, executionDiagnosticsEvents); subscription._subscriptionScope = executionDiagnosticsEvents.ExecuteSubscription(subscription); subscription._sourceStream = await subscription.SubscribeAsync().ConfigureAwait(false); return(subscription); }
public static List <IFeature> GetFeaturesBySelected(IFeatureLayer featureLayer) { List <IFeature> list = new List <IFeature>(); IFeatureSelection pFeatureSelection = featureLayer as IFeatureSelection; if (pFeatureSelection == null) { return(list); } ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet; ICursor pCursor = null; pSelectionSet.Search(null, true, out pCursor); IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor; if (pFeatureCursor == null) { return(list); } IFeature pFeature; while ((pFeature = pFeatureCursor.NextFeature()) != null) { list.Add(pFeature); } Marshal.ReleaseComObject(pFeatureCursor); Marshal.ReleaseComObject(pCursor); return(list); }
private void iQueryByLayerToolStripMenuItem_Click(object sender, EventArgs e) { Stopwatch myWatch = Stopwatch.StartNew(); //从MapControl中获取的点图层 IFeatureLayer pointFeatureLayer = axMapControl1.get_Layer(0) as IFeatureLayer; IFeatureSelection pointFeatureSelection = pointFeatureLayer as IFeatureSelection; //从MapControl中获取的面图层 IFeatureLayer polygonFeatureLayer = axMapControl1.get_Layer(1) as IFeatureLayer; //构建QueryByLayer IQueryByLayer queryByLayer = new QueryByLayerClass(); queryByLayer.FromLayer = pointFeatureLayer; queryByLayer.ByLayer = polygonFeatureLayer; queryByLayer.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectCompletelyWithin; //该参数需要设置 queryByLayer.UseSelectedFeatures = false; ISelectionSet selectionSet = queryByLayer.Select(); pointFeatureSelection.SelectionSet = selectionSet; int count = pointFeatureSelection.SelectionSet.Count; axMapControl1.Refresh(); myWatch.Stop(); string time = myWatch.Elapsed.TotalSeconds.ToString(); MessageBox.Show("The selected point count is " + count.ToString() + "! and " + time + " Seconds"); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add ZoomToSelectedFeatures.OnClick implementation ILayer pLayer = (ILayer)m_mapControl.CustomProperty; IFeatureLayer pFLayer = (IFeatureLayer)pLayer; IFeatureSelection pFSel = (IFeatureSelection)pFLayer; ISelectionSet pSelSet = pFSel.SelectionSet; IEnumGeometry pEnumGeom = new EnumFeatureGeometry(); IEnumGeometryBind pEnumGeomBind = (IEnumGeometryBind)pEnumGeom; pEnumGeomBind.BindGeometrySource(null, pSelSet); IGeometryFactory pGeomFactory = new GeometryEnvironmentClass(); IGeometry pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom); double dblXPer = (pGeom.Envelope.XMax - pGeom.Envelope.XMin) / 10; double dblYPer = (pGeom.Envelope.YMax - pGeom.Envelope.YMin) / 10; IEnvelope pEnvel = new EnvelopeClass(); pEnvel.PutCoords(pGeom.Envelope.XMin - dblXPer, pGeom.Envelope.YMin - dblYPer, pGeom.Envelope.XMax + dblXPer, pGeom.Envelope.YMax + dblYPer); //envelope1.PutCoords(pFLayer1.AreaOfInterest.Envelope.XMin - (pFLayer1.AreaOfInterest.Envelope.XMin * 0.0005), pFLayer1.AreaOfInterest.Envelope.YMin - (pFLayer1.AreaOfInterest.Envelope.YMin * 0.0005), pFLayer1.AreaOfInterest.Envelope.XMax * 1.0005, pFLayer1.AreaOfInterest.Envelope.YMax * 1.0005); m_mapControl.ActiveView.Extent = pEnvel; m_mapControl.ActiveView.Refresh(); }
public Fragment( IObjectType typeCondition, InlineFragmentNode inlineFragment, ISelectionSet selectionSet, bool internalFragment, SelectionIncludeCondition?includeCondition) { TypeCondition = typeCondition; SyntaxNode = inlineFragment; SelectionSet = selectionSet; Directives = inlineFragment.Directives; IsInternal = internalFragment; IsConditional = includeCondition is not null; _includeCondition = includeCondition; InclusionKind = internalFragment ? SelectionInclusionKind.Internal : SelectionInclusionKind.Always; if (IsConditional) { InclusionKind = internalFragment ? SelectionInclusionKind.InternalConditional : SelectionInclusionKind.Conditional; } }
/// <summary> /// To open the editor form, we need to first determine which barrier is /// being edited, then pass that value to the form /// </summary> private void OpenBarrierEditorForm() { // get the barrier layer by using the category name to as the NAClassName INAWindowCategory activeCategory = GetActiveCategory(); string categoryName = activeCategory.NAClass.ClassDefinition.Name; INALayer naLayer = GetActiveAnalysisLayer(); ILayer layer = naLayer.get_LayerByNAClassName(categoryName); // get a selection count and popup a message if more or less than one item is selected IFeatureSelection fSel = layer as IFeatureSelection; ISelectionSet selSet = fSel.SelectionSet; if (selSet.Count != 1) { System.Windows.Forms.MessageBox.Show("Only one barrier in a category can be selected at a time for this command to execute", "Barrier Location Editor Warning"); } else { // get the object IDs of the selected item int id = selSet.IDs.Next(); // Get the barrier feature by using the selected ID IFeatureClass fClass = naLayer.Context.NAClasses.get_ItemByName(categoryName) as IFeatureClass; IFeature barrierFeature = fClass.GetFeature(id); // display the form for editing the barrier EditorForm form = new EditorForm(m_application, naLayer.Context, barrierFeature); form.ShowDialog(); form = null; } }
public async Task <IQueryResult> ExecuteAsync( IOperationContext operationContext, IImmutableDictionary <string, object?> scopedContext) { if (operationContext is null) { throw new ArgumentNullException(nameof(operationContext)); } if (scopedContext is null) { throw new ArgumentNullException(nameof(scopedContext)); } ISelectionSet rootSelections = operationContext.Operation.GetRootSelectionSet(); ResultMap resultMap = rootSelections.EnqueueResolverTasks( operationContext, Path.Root, scopedContext, operationContext.RootValue); await ExecuteTasksAsync(operationContext).ConfigureAwait(false); return(operationContext .TrySetNext() .SetData(resultMap) .BuildResult()); }
/// <summary> /// Helper function to get a polygon object from the selected feature in the /// specified layer. /// </summary> /// <param name="layerName">The polygon layer that contains exactly one selected feature.</param> /// <returns>The polygon object, or null if none could be retrieved.</returns> private IPolygon4 GetPolygonFromSpecifiedLayer(ILayer layerObj) { // Set the AOI of the job, if there is one // Ensure that there's nothing wrong with the AOI feature that is selected, if any IPolygon4 aoiPolygon = null; if (layerObj != null) { ICursor cursor = null; IFeatureLayer featLayer = layerObj as IFeatureLayer; IFeatureSelection featSel = layerObj as IFeatureSelection; ISelectionSet selSet = featSel.SelectionSet as ISelectionSet; if (featLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon) { throw new WmauException(new WmauError(WmauErrorCodes.C_AOI_NOT_POLYGON_ERROR)); } else if (selSet.Count != 1) { throw new WmauException(new WmauError(WmauErrorCodes.C_EXPECTED_ONE_SELECTED_FEATURE_ERROR)); } // If we get this far, we know that there's exactly one selected feature, so we // don't have to loop through the selection set selSet.Search(null, true, out cursor); IFeatureCursor featureCursor = cursor as IFeatureCursor; IFeature aoiCandidate = featureCursor.NextFeature(); // We also know that the feature is a polygon, so just make the cast aoiPolygon = aoiCandidate.Shape as IPolygon4; } return(aoiPolygon); }
private void btncreat_Click(object sender, EventArgs e) { try { ILayer player = null; for (int j = 0; j < pMapControl.Map.LayerCount; j++) { if (cmblayer.SelectedItem.ToString() == pMapControl.Map.Layer[j].Name) { player = pMapControl.Map.Layer[j]; break; } } IFeatureLayer pFLayer = (IFeatureLayer)player; IFeatureLayerDefinition pFLDef = (IFeatureLayerDefinition)pFLayer; IFeatureSelection pFSel = (IFeatureSelection)pFLayer; ISelectionSet pSSet = pFSel.SelectionSet; if (pSSet.Count > 0) { IFeatureLayer pSelFL = pFLDef.CreateSelectionLayer(player.Name + "Selection", true, null, null); pMapControl.Map.AddLayer(pSelFL); } else { MessageBox.Show("没有选中的对象!"); } this.Close(); } catch (System.Exception ex) { MessageBox.Show(ex.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Close(); }
public void SelectByLine(int IndexOfLayer, RubberLineClass Line) { int ConstantNum = 255; IActiveView CurrentView = axMapControl1.ActiveView; IScreenDisplay CurScreenDisplay = CurrentView.ScreenDisplay; CurScreenDisplay.StartDrawing(CurScreenDisplay.hDC, (System.Int16)esriScreenCache.esriNoScreenCache); IRgbColor RGBCOLORS = new ESRI.ArcGIS.Display.RgbColorClass(); RGBCOLORS.Red = ConstantNum; IColor MyColor = RGBCOLORS; ISimpleFillSymbol MySimpleFillSymbol = new SimpleFillSymbolClass(); MySimpleFillSymbol.Color = MyColor; ISymbol MySymbol = MySimpleFillSymbol as ISymbol; IRubberBand MyIRubberBand = Line; IGeometry MyGeometry = MyIRubberBand.TrackNew(CurScreenDisplay, MySymbol); CurScreenDisplay.SetSymbol(MySymbol); CurScreenDisplay.DrawPolygon(MyGeometry); CurScreenDisplay.FinishDrawing(); ISpatialFilter MySpatialFilter = new SpatialFilterClass(); MySpatialFilter.Geometry = MyGeometry; MySpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureLayer SelectedLayer = axMapControl1.ActiveView.FocusMap.get_Layer(IndexOfLayer) as IFeatureLayer; IFeatureSelection SelectedFeatures = SelectedLayer as IFeatureSelection; SelectedFeatures.SelectFeatures(MySpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false); ISelectionSet FinalSelection = SelectedFeatures.SelectionSet; axMapControl1.ActiveView.Refresh(); }
public void Object_Field_Visibility_Is_Correctly_Inherited_2() { // arrange var variables = new Mock <IVariableValueCollection>(); variables.Setup(t => t.GetVariable <bool>(It.IsAny <NameString>())) .Returns((NameString name) => name.Equals("v")); ISchema schema = SchemaBuilder.New() .AddStarWarsTypes() .Create(); ObjectType droid = schema.GetType <ObjectType>("Droid"); DocumentNode document = Utf8GraphQLParser.Parse( @"query foo($v: Boolean, $q: Boolean) { hero(episode: EMPIRE) @include(if: $v) { name @include(if: $q) } ... on Query { hero(episode: EMPIRE) { id } } ... @include(if: $v) { hero(episode: EMPIRE) { height } } }"); OperationDefinitionNode operation = document.Definitions.OfType <OperationDefinitionNode>().Single(); var fragments = new FragmentCollection(schema, document); // act IReadOnlyDictionary <SelectionSetNode, SelectionVariants> selectionSets = OperationCompiler.Compile(schema, fragments, operation); // assert var op = new Operation( "abc", document, operation, schema.QueryType, selectionSets); ISelectionSet rootSelections = op.RootSelectionVariants.GetSelectionSet( op.RootSelectionVariants.GetPossibleTypes().First()); ISelectionSet droidSelections = op.GetSelectionSet(rootSelections.Selections[0].SelectionSet !, droid); Assert.Collection( droidSelections.Selections.Where(t => t.IsIncluded(variables.Object)), t => Assert.Equal("id", t.ResponseName), t => Assert.Equal("height", t.ResponseName)); op.Print().MatchSnapshot(); }
public SelectedObjects(IFeatureClass pFC) { IDataset pDS; pDS = (IDataset)pFC; iClassID = pFC.FeatureClassID; sClassName = pDS.Name; pSelSet = pFC.Select(null, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionEmpty, pDS.Workspace); }
/// <summary> /// ����¼� /// </summary> public override void OnClick() { DataEditCommon.InitEditEnvironment(); DataEditCommon.CheckEditState(); m_pCurrentLayer = DataEditCommon.g_pLayer; ///20140216 lyf m_featureLayer = m_pCurrentLayer as IFeatureLayer; m_featureSelection = m_featureLayer as IFeatureSelection; m_selectionSet = m_featureSelection.SelectionSet;//QI��ISelectionSet if (m_selectionSet.Count != 1) { MessageBox.Show(@"��ѡ��һ��ͼԪ�ٽ��о���", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information); DataEditCommon.g_pMyMapCtrl.CurrentTool = null; return; } }
/// <summary> /// Combine selections (Paolo, march 2007) /// </summary> /// <param name="otherSet">current selectionset</param> /// <param name="setOp">selection operation</param> /// <param name="resultSet">output selectionset</param> public void Combine(ISelectionSet otherSet, esriSetOperation setOp, out ISelectionSet resultSet) { resultSet = this as ISelectionSet; //esriSetUnion IEnumIDs eids = otherSet.IDs; for (int i = 0; i < otherSet.Count; i++) { int oid = eids.Next(); if (oids.Contains(oid)) //oid already in selectionset { if (setOp == esriSetOperation.esriSetDifference) { oids.Remove(oid); } if (setOp == esriSetOperation.esriSetSymDifference) { oids.Remove(oid); } } else //oid not in selectionset { if (setOp == esriSetOperation.esriSetUnion) { oids.Add(oid); } if (setOp == esriSetOperation.esriSetIntersection) { oids.Remove(oid); } if (setOp == esriSetOperation.esriSetSymDifference) { oids.Add(oid); } } } }
void IMapViewController.ZoomToSelectSelectionSet(int layerIndex, ISelectionSet selectionSet) { throw new NotImplementedException(); }
public void FindCurves(String Name, IFeatureClass pFabricLinesFC, ISelectionSet selSet, string whereClause, myProgessor progressor) { CurveByInferenceSettings.FieldPositions positions = new CurveByInferenceSettings.FieldPositions((ITable)pFabricLinesFC); if (!positions.ValidCheckFields) { messageBox.Show(string.Format("One or more of the following fields are missing ({0}, {1})", CurveByInferenceSettings.Instance.RadiusFieldName, CurveByInferenceSettings.Instance.CenterpointIDFieldName)); } IQueryFilter qFilter = new QueryFilter(); if (String.IsNullOrEmpty(whereClause)) { qFilter.WhereClause = "CenterPointID is null and Radius is null"; } else { qFilter.WhereClause = string.Concat(whereClause, " and CenterPointID is null and Radius is null"); } IFeatureCursor cursor = null; if (selSet != null) { ICursor c; ISelectionSet subset = selSet.Select(qFilter, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, null); progressor.setStepProgressorProperties(subset.Count, String.Format("Layer {0}: Evaluating Selected Features", Name)); subset.Search(null, true, out c); cursor = (IFeatureCursor)c; } else { progressor.setStepProgressorProperties(((ITable)pFabricLinesFC).RowCount(qFilter), String.Format("Layer {0}: Evaluating Features", Name)); cursor = pFabricLinesFC.Search(qFilter, true); } //ISelectionSet pSelSet = pFabricLinesFC.Select(qFilter, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, null); //progressor.setStepProgressorProperties(pSelSet.Count, String.Format("Layer {0}: Evaluating Features", Name)); //ICursor cursor = null; //pSelSet.Search(null, false, out cursor); IFeature pLineFeat = null; while ((pLineFeat = (IFeature)cursor.NextFeature() as IFeature) != null) { if (!progressor.Continue()) break; progressor.Step(); if (!Curves.Any(w => w.ObjectID == pLineFeat.OID)) { IGeometry pGeom = pLineFeat.ShapeCopy; ISegmentCollection pSegColl = pGeom as ISegmentCollection; ISegment pSeg = null; if (pSegColl != null && pSegColl.SegmentCount == 1) { pSeg = pSegColl.get_Segment(0); } else { if (pSegColl == null) messageBox.Show(String.Format("The shape for objectid {0} could not be converted to a segement collection.", pLineFeat.OID)); //todo: but for now, only deals with single segment short segments Marshal.ReleaseComObject(pLineFeat); continue; } //if the geometry is a circular arc and the attributes reflect that, move on to the next feature //obsolete, filter is pushed to database //if (pSeg is ICircularArc) //{ // object dVal1 = pLineFeat.get_Value(idxRADIUS); // object dVal2 = pLineFeat.get_Value(idxCENTERPTID); // if (!(dVal1 is DBNull) && !(dVal2 is DBNull)) // { // Marshal.ReleaseComObject(pLineFeat); // continue; // } //} //query near lines List<RelatedLine> tangentLines; List<RelatedCurve> sCurveInfoFromNeighbours = GetTangentCurveMatchFeatures(pFabricLinesFC, pLineFeat, (IPolycurve)pGeom, "", positions.RadiusFieldIdx, positions.CenterpointIDFieldIdx, pSeg.Length, out tangentLines); if(sCurveInfoFromNeighbours.Count > 0) //if (HasTangentCurveMatchFeatures(pFabricLinesFC, (IPolycurve)pGeom, "", pSeg.Length, out iFoundTangent, ref sCurveInfoFromNeighbours)) { InferredCurve curve = new InferredCurve(pLineFeat.OID, Name, sCurveInfoFromNeighbours); IPolyline polyLine = (IPolyline)pGeom; curve.FromPoint = polyLine.FromPoint; curve.ToPoint = polyLine.ToPoint; //evaluated the position of any tangent lines, and determines if there is a junction situation. If there is, it will: // Retrun true with curve.Accepted set // Return true without curve.Accepted set // Return false (this indicates that the junction has been used to verify that this segemnt should not have a curve) if (evaluateJunctions(curve, tangentLines)) { //junction couldn't eliminate the curve, so return it Curves.Add(curve); curve.PropertyChanged += new PropertyChangedEventHandler(curve_PropertyChanged); curve.Parcel = (int)pLineFeat.get_Value(positions.ParcelIDFieldIdx); if (!curve.HasValue) //if the junction logic didn't set the curve { //check to see if one of the tange curves overlap if (curve.TangentCurves[0].Orientation == RelativeOrientation.Same || curve.TangentCurves[0].Orientation == RelativeOrientation.Reverse) { curve.InferredRadius = curve.TangentCurves[0].Radius; curve.InferredCenterpointID = curve.TangentCurves[0].CenterpointID; } else { //check radial and tangent lines (both need a single centerpoint and radius tangent curve (check done in function) RefineToBestRadiusAndCenterPoint(curve, pFabricLinesFC, pLineFeat, (IPolycurve)pGeom, tangentLines); } } //if the curve has an accepted curve (ie, it's a candidate to be changed), record the parcel id //if (curve.Accepted != null) // affectedParcels.Add(); //cache the parcel so it can be looked up later } } } Marshal.ReleaseComObject(pLineFeat); } Marshal.ReleaseComObject(cursor); Total = Curves.Count; Inferred = Curves.Count(w => w.Action == UpdateAction.Update); }
void IMapViewController.ZoomToSelectSelectionSet(string layerName, ISelectionSet selectionSet) { _map.ZoomToSelectSelectionSet(layerName, selectionSet); }
/// <summary> /// Removes the feature from a selection set. /// </summary> /// <param name="feature">The feature to remove from the selection set.</param> /// <param name="selSet">The selection set from which to remove the feature.</param> public static void RemoveFeatureFromSelection(IFeature feature, ISelectionSet selSet) { int oid = feature.OID; selSet.RemoveList(1, ref oid); }
public ITable OpenRelationshipQuery(IRelationshipClass pRelClass, bool joinForward, IQueryFilter pSrcQueryFilter, ISelectionSet pSrcSelectionSet, string TargetColumns, bool DoNotPushJoinToDB) { // I don't think this needs to be implemented for now. throw new NotImplementedException(); }
void IGMap.ZoomToSelectSelectionSet(string layerName, ISelectionSet selectionSet) { throw new NotImplementedException(); }
private void PrintSelectionSet(ISelectionSet ss) { IEnumIDs enumIDs = ss.IDs as IEnumIDs; try { int oid = enumIDs.Next(); while (oid != -1) { System.Diagnostics.Debug.WriteLine("OID:" + oid); oid = enumIDs.Next(); } } catch { System.Diagnostics.Debug.WriteLine("End of enum!"); } }
private void assignMapUnit(ISelectionSet theSelection, IFeatureLayer mapUnitPolysLayer, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit dmuEntry) { // Pass the selected features into a cursor that we can iterate through ICursor theCursor; theSelection.Search(null, false, out theCursor); string mupIdField = mapUnitPolysLayer.DisplayField; int IdFld = theCursor.FindField(mupIdField); // Build the Where Clause to get these features by looping through the cursor string sqlWhereClause = mupIdField + " = '"; IRow theRow = theCursor.NextRow(); while (theRow != null) { sqlWhereClause += theRow.get_Value(IdFld) + "' OR " + mupIdField + " = '"; theRow = theCursor.NextRow(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(theCursor); // If we didn't add anything to the where clause, bail if (sqlWhereClause == mupIdField + " = '") { return; } // Cleanup the where clause sqlWhereClause = sqlWhereClause.Remove(sqlWhereClause.Length - (" OR " + mupIdField + " = '").Length); // Get the MapUnitPolys MapUnitPolysAccess polysAccess = new MapUnitPolysAccess(m_theWorkspace, mapUnitPolysLayer.Name); polysAccess.AddMapUnitPolys(sqlWhereClause); //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- // Data Access Issue: I actually have to pass the dictionary into another object. // If I don't, once the first record is updated, the dictionary is changed. // Then the foreach loop fails, because what it is looping through was adjusted. // Not very happy with this. //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- // Sort using Linq syntax var sortedPolys = ( from entry in polysAccess.MapUnitPolysDictionary select entry); MapUnitPolysAccess secondPolysAccess = new MapUnitPolysAccess(m_theWorkspace, mapUnitPolysLayer.Name); try { // Cycle through the MapUnitPolys and update the MapUnit and Label attributes foreach (KeyValuePair<string, MapUnitPolysAccess.MapUnitPoly> anEntry in sortedPolys) { // Get the MapUnitPoly object secondPolysAccess.AddMapUnitPolys(mupIdField + " = '" + anEntry.Value.MapUnitPolys_ID + "'"); MapUnitPolysAccess.MapUnitPoly aPoly = secondPolysAccess.MapUnitPolysDictionary[anEntry.Value.MapUnitPolys_ID]; // Change the appropriate values aPoly.MapUnit = dmuEntry.MapUnit; aPoly.Label = dmuEntry.Label; // Update the Poly secondPolysAccess.UpdateMapUnitPoly(aPoly); } } catch (Exception err) { MessageBox.Show(err.Message); } // Save updates secondPolysAccess.SaveMapUnitPolys(); // Update the active view ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, mapUnitPolysLayer, null); }
private void InitTreeView( ISelectionSet pSelectSet,ILayer pLayer ) { if( pSelectSet==null || pLayer==null ) return; IFeatureClass pFtCls = ((IFeatureLayer)pLayer).FeatureClass; if (pFtCls == null) return; IFields pFields = pFtCls.Fields; //这里如果数据没有bsm怎么办 int nIndex = pFields.FindField("BSM"); if (nIndex == -1) { return; } string strId; ICursor pCursor; pSelectSet.Search( null,false,out pCursor ); IRow pRow = pCursor.NextRow(); if (pRow == null) { return; } TreeListNode noderoot = this.FTtreeList.AppendNode(new object[] { pLayer.Name }, null); while( pRow != null ) { //strId = pRow.OID.ToString(); if (pRow.get_Value(nIndex) != null) { strId = pRow.get_Value(nIndex).ToString(); //NodeRoot.Nodes.Add(strId); TreeListNode node = this.FTtreeList.AppendNode(new object[] { strId }, noderoot); } pRow = pCursor.NextRow(); } }
void IGMap.ZoomToSelectSelectionSet(int layerIndex, ISelectionSet selectionSet) { throw new NotImplementedException(); }
/// <summary> /// Excecute is called by Data Reviewer engine and passed the appropriate parameters. /// </summary> /// <param name="ipSelectionToValidate">ISelectionSet of features/rows to validate</param> /// <param name="arguments">comma delimited string of arguments</param> /// <returns> /// Collection of validation results. /// </returns> public IPLTSErrorCollection Execute(ISelectionSet ipSelectionToValidate, string arguments) { if (null == ipSelectionToValidate) { throw new ArgumentNullException("ISelectionSet parameter is null"); } if (String.IsNullOrEmpty(arguments)) { throw new ArgumentNullException("string parameter is null or empty"); } //Exit if there is nothing to check if (0 == ipSelectionToValidate.Count) { return new PLTSErrorCollectionClass(); } //Arguments and default values string strTargetFeatureClassName = ""; string strTargetSubtypeNumber = ""; string strSourceWhereClause = ""; string strTargetWhereClause = ""; esriSpatialRelEnum eSpatialOperation = esriSpatialRelEnum.esriSpatialRelIntersects; string strSpatialRelDescription = ""; string strUserMessage = ""; //Split comma delimited string into array string[] arrayOfArguments = arguments.Split(new char[] { ',' }, StringSplitOptions.None); //Parse arguments for (int i = 0; i < arrayOfArguments.Length; i++) { if (0 == i) { strTargetFeatureClassName = arrayOfArguments[i]; } else if (1 == i) { strTargetSubtypeNumber = arrayOfArguments[i]; } else if (2 == i) { try { eSpatialOperation = (esriSpatialRelEnum)Convert.ToInt32(arrayOfArguments[i]); } catch (Exception ex) { throw new Exception(String.Format("Error converting spatial operation parameter to esriSpatialRelEnum. Parameter value {0}", arrayOfArguments[i]), ex); } } else if (3 == i) { strTargetWhereClause = arrayOfArguments[i]; } else if (4 == i) { strSourceWhereClause = arrayOfArguments[i]; } else if (5 == i) { strSpatialRelDescription = arrayOfArguments[i]; } else if (6 == i) { strUserMessage = arrayOfArguments[i]; } else { throw new Exception("Invalid number of arguments. Only seven arguments are allowed. Arguments: (" + arguments + ")"); } } //Get handle to workspace IDataset ipSourceDataset = ipSelectionToValidate.Target as IDataset; IFeatureWorkspace ipFeatureWorkspace = ipSourceDataset.Workspace as IFeatureWorkspace; //Open the target feature class. Feature class name passed in should be fully qualified. IFeatureClass ipTargetFeatureClass = ipFeatureWorkspace.OpenFeatureClass(strTargetFeatureClassName); if (null == ipTargetFeatureClass) { throw new Exception(String.Format("Unable to open feature class {0} from workspace {1}", strTargetFeatureClassName, (ipFeatureWorkspace as IWorkspace).PathName)); } string strTargetSubtypeFieldName = (ipTargetFeatureClass as ISubtypes).SubtypeFieldName; //Setup spatial filter to apply to target feature class ISpatialFilter ipTargetSF = new SpatialFilterClass(); ipTargetSF.SpatialRel = eSpatialOperation; if ("*" == strTargetSubtypeNumber || String.IsNullOrEmpty(strTargetSubtypeNumber)) { if (strTargetWhereClause.Length > 0) { ipTargetSF.WhereClause = strTargetWhereClause; } } else { if (strTargetWhereClause.Length > 0) { ipTargetSF.WhereClause = strTargetSubtypeFieldName + " = " + strTargetSubtypeNumber + " AND " + strTargetWhereClause; } else { ipTargetSF.WhereClause = strTargetSubtypeFieldName + " = " + strTargetSubtypeNumber; } } if (eSpatialOperation == esriSpatialRelEnum.esriSpatialRelRelation) { ipTargetSF.SpatialRelDescription = strSpatialRelDescription; } //Prepare source where clause IQueryFilter ipSourceQF = new QueryFilterClass(); if (strSourceWhereClause.Length > 0) { ipSourceQF.WhereClause = strSourceWhereClause; } IPLTSErrorCollection ipRevResultCollection = new PLTSErrorCollectionClass(); //Loop through source geometries and perform a spatial query againts the target Feature Class. //For each geometry that does not satisfy the spatial relationship add a Reviewer result. ICursor ipCursor = null; ipSelectionToValidate.Search(ipSourceQF, false, out ipCursor); IFeatureCursor ipFeatureCursor = ipCursor as IFeatureCursor; IFeature ipSourceFeature = ipFeatureCursor.NextFeature(); while (null != ipSourceFeature) { Application.DoEvents(); IGeometry ipSourceGeometry = ipSourceFeature.ShapeCopy; ipTargetSF.Geometry = ipSourceGeometry; //If spatial filter returns zero records create a Reviewer result. if (ipTargetFeatureClass.FeatureCount(ipTargetSF) == 0) { //Create a Reviewer result IPLTSError2 ipReviewerResult = new PLTSErrorClass() as IPLTSError2; ipReviewerResult.ErrorKind = pltsValErrorKind.pltsValErrorKindStandard; ipReviewerResult.OID = ipSourceFeature.OID; ipReviewerResult.LongDescription = strUserMessage; ipReviewerResult.QualifiedTableName = ipSourceDataset.Name; ipReviewerResult.ErrorGeometry = ipSourceGeometry; ipRevResultCollection.AddError(ipReviewerResult); } ipSourceFeature = ipFeatureCursor.NextFeature(); }//end while loop //Release cursor Marshal.ReleaseComObject(ipFeatureCursor); ipFeatureCursor = null; Marshal.ReleaseComObject(ipCursor); ipCursor = null; //Return the collection of results return ipRevResultCollection; }
/// <summary> /// ��㡢�յ����Ҫ�ӱ߶��� /// </summary> /// <param name="bIsFromOver"></param> /// <param name="bIsToOver"></param> /// <param name="ipToSpatialFilter"></param> /// <param name="ipFromSpatialFilter"></param> /// <param name="ipSourceRow"></param> /// <param name="ipSourceCursor"></param> /// <param name="ipTargetSelectionSet"></param> /// <param name="sMatchEdgeWhereClause"></param> /// <param name="lSourceRowOID"></param> /// <param name="sSourceRowOID"></param> /// <param name="sOIDs"></param> /// <param name="sCheckInfos"></param> /// <returns></returns> private bool JointFromToPoints(bool bIsFromOver, bool bIsToOver, ISpatialFilter ipToSpatialFilter, ISpatialFilter ipFromSpatialFilter, ref IRow ipSourceRow, ICursor ipSourceCursor, ISelectionSet ipTargetSelectionSet, string sMatchEdgeWhereClause, int lSourceRowOID, string sSourceRowOID, ref List<string> sOIDs, ref List<string> sCheckInfos) { try { int lFromSelectionCount, lToSelectionCount; ISelectionSet ipFromSelectionSet = null; ISelectionSet ipToSelectionSet = null; if (bIsFromOver == false) { try { ipFromSelectionSet = ipTargetSelectionSet.Select(ipFromSpatialFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, null); } catch (Exception ex) { SendMessage(enumMessageType.Exception, ex.ToString()); Marshal.ReleaseComObject(ipSourceRow); ipSourceRow = ipSourceCursor.NextRow(); return false; } lFromSelectionCount = ipFromSelectionSet.Count; } else { lFromSelectionCount = 0; } if (bIsToOver == false) { try { ipToSelectionSet = ipTargetSelectionSet.Select(ipToSpatialFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, null); } catch (Exception ex) { SendMessage(enumMessageType.Exception, ex.ToString()); Marshal.ReleaseComObject(ipSourceRow); ipSourceRow = ipSourceCursor.NextRow(); return false; } lToSelectionCount = ipToSelectionSet.Count; } else { lToSelectionCount = 0; } if (lFromSelectionCount > 0 && lToSelectionCount > 0) { //�������յ��ͼ��ͼ�νӱ� ipFromSpatialFilter.WhereClause = sMatchEdgeWhereClause; ipToSpatialFilter.WhereClause = sMatchEdgeWhereClause; ISelectionSet ipFromAttrSelectionSet, ipToAttrSelectionSet; ipFromAttrSelectionSet = ipFromSelectionSet.Select(ipFromSpatialFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, null); ipToAttrSelectionSet = ipToSelectionSet.Select(ipToSpatialFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, null); int lFromAttrSelectionCount, lToAttrSelectionCount; lFromAttrSelectionCount = ipFromAttrSelectionSet.Count; lToAttrSelectionCount = ipToAttrSelectionSet.Count; if (lFromAttrSelectionCount > 0 && lToAttrSelectionCount > 0) { //�����յ������Խӱ� //�ж������յ�Ľӱ߶����Ƿ����һ�� ICursor ipFromAttrCursor, ipToAttrCursor; ipFromAttrSelectionSet.Search(null, false, out ipFromAttrCursor); ipToAttrSelectionSet.Search(null, false, out ipToAttrCursor); //�ж���� IRow ipFromAttrRow = ipFromAttrCursor.NextRow(); int nFromAttr = 0; while (ipFromAttrRow != null) { int lFromAttrOID = ipFromAttrRow.OID; if (lFromAttrOID != lSourceRowOID) { nFromAttr++; } ipFromAttrRow = ipFromAttrCursor.NextRow(); } //�ж��յ� IRow ipToAttrRow = ipToAttrCursor.NextRow(); int nToAttr = 0; while (ipToAttrRow != null) { int lToAttrOID = ipToAttrRow.OID; if (lToAttrOID != lSourceRowOID) { nToAttr++; } ipToAttrRow = ipToAttrCursor.NextRow(); } Marshal.ReleaseComObject(ipFromAttrCursor); Marshal.ReleaseComObject(ipToAttrCursor); string sInfo = null; if (nFromAttr > 1 && nToAttr > 1) { sOIDs.Add(sSourceRowOID); sInfo = sSourceRowOID + "Ҫ����㴦��" + nFromAttr + "���ӱ߶���;�յ㴦��" + nToAttr + "���ӱ߶���"; sCheckInfos.Add(sInfo); } else if (nFromAttr > 1) { sOIDs.Add(sSourceRowOID); sInfo = sSourceRowOID + "Ҫ����㴦��" + nFromAttr + "���ӱ߶���"; sCheckInfos.Add(sInfo); } else if (nToAttr > 1) { sOIDs.Add(sSourceRowOID); sInfo = sSourceRowOID + "Ҫ���յ㴦��" + nToAttr + "���ӱ߶���"; sCheckInfos.Add(sInfo); } } else if (lFromAttrSelectionCount > 0) { //��������Խӱ߶���,�յ�û�����Խӱ߶��� ICursor ipFromAttrCursor = null; ipFromAttrSelectionSet.Search(null, false, out ipFromAttrCursor); //�ж���� IRow ipFromAttrRow = ipFromAttrCursor.NextRow(); int nFromAttr = 0; while (ipFromAttrRow != null) { int lFromAttrOID = ipFromAttrRow.OID; if (lFromAttrOID != lSourceRowOID) { nFromAttr++; } ipFromAttrRow = ipFromAttrCursor.NextRow(); } Marshal.ReleaseComObject(ipFromAttrCursor); if (nFromAttr > 1) { sOIDs.Add(sSourceRowOID); string sInfo = sSourceRowOID + "Ҫ����㴦��" + nFromAttr + "���ӱ߶���,�����յ㴦�ӱ߶�������Բ�ͬ"; sCheckInfos.Add(sInfo); } else { sOIDs.Add(sSourceRowOID); string sInfo = sSourceRowOID + "Ҫ���յ㴦�ӱ߶�������Բ�ͬ"; sCheckInfos.Add(sInfo); } } else if (lToAttrSelectionCount > 0) { //�յ������Խӱ߶���,���û�����Խӱ߶��� //�ж��յ� ICursor ipToAttrCursor = null; ipToAttrSelectionSet.Search(null, false, out ipToAttrCursor); IRow ipToAttrRow = ipToAttrCursor.NextRow(); int nToAttr = 0; while (ipToAttrRow != null) { int lToAttrOID = ipToAttrRow.OID; if (lToAttrOID != lSourceRowOID) { nToAttr++; } ipToAttrRow = ipToAttrCursor.NextRow(); } Marshal.ReleaseComObject(ipToAttrCursor); if (nToAttr > 1) { sOIDs.Add(sSourceRowOID); string sInfo = sSourceRowOID + "Ҫ���յ㴦��" + nToAttr + "���ӱ߶���,������㴦�ӱ߶�������Բ�ͬ"; sCheckInfos.Add(sInfo); } else { sOIDs.Add(sSourceRowOID); string sInfo = sSourceRowOID + "Ҫ����㴦�ӱ߶�������Բ�ͬ"; sCheckInfos.Add(sInfo); } } else { sOIDs.Add(sSourceRowOID); //�����յ㶼û�����Խӱ߶��� string sInfo = sSourceRowOID + "Ҫ�������յ㴦�нӱ߶���,�����Բ�ͬ"; sCheckInfos.Add(sInfo); } } else if (lFromSelectionCount > 0) { ipFromSpatialFilter.WhereClause = sMatchEdgeWhereClause; ISelectionSet ipFromAttrSelectionSet = ipFromSelectionSet.Select(ipFromSpatialFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, null); int lFromAttrSelectionCount = ipFromAttrSelectionSet.Count; if (lFromAttrSelectionCount > 0) { //��������Խӱ߶��� ICursor ipFromAttrCursor = null; ipFromAttrSelectionSet.Search(null, false, out ipFromAttrCursor); //�ж���� IRow ipFromAttrRow = ipFromAttrCursor.NextRow(); int nFromAttr = 0; while (ipFromAttrRow != null) { int lFromAttrOID = ipFromAttrRow.OID; if (lFromAttrOID != lSourceRowOID) { nFromAttr++; } ipFromAttrRow = ipFromAttrCursor.NextRow(); } Marshal.ReleaseComObject(ipFromAttrCursor); if (nFromAttr > 1) { sOIDs.Add(sSourceRowOID); string sInfo = sSourceRowOID + "Ҫ����㴦��" + nFromAttr + "���ӱ߶���,�����յ㴦ȱ�ٽӱ߶���"; sCheckInfos.Add(sInfo); } else { if (nFromAttr < 1) { sOIDs.Add(sSourceRowOID); string sInfo = sSourceRowOID + "Ҫ���յ㴦ȱ�ٽӱ߶���"; sCheckInfos.Add(sInfo); } } } else { sOIDs.Add(sSourceRowOID); string sInfo = sSourceRowOID + "Ҫ����㴦�нӱ߶���,�����Բ�ͬ;�����յ㴦ȱ�ٽӱ߶���"; sCheckInfos.Add(sInfo); } } else if (lToSelectionCount > 0) { ipToSpatialFilter.WhereClause = sMatchEdgeWhereClause; ISelectionSet ipToAttrSelectionSet = ipToSelectionSet.Select(ipToSpatialFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, null); int lToAttrSelectionCount = ipToAttrSelectionSet.Count; if (lToAttrSelectionCount > 0) { //�յ������Խӱ߶��� ICursor ipToAttrCursor = null; ipToAttrSelectionSet.Search(null, false, out ipToAttrCursor); //�ж��յ� IRow ipToAttrRow = ipToAttrCursor.NextRow(); int nToAttr = 0; while (ipToAttrRow != null) { int lToAttrOID = ipToAttrRow.OID; if (lToAttrOID != lSourceRowOID) { nToAttr++; } ipToAttrRow = ipToAttrCursor.NextRow(); } Marshal.ReleaseComObject(ipToAttrCursor); if (nToAttr > 1) { sOIDs.Add(sSourceRowOID); string sInfo = sSourceRowOID + "Ҫ���յ㴦��" + nToAttr + "���ӱ߶���,������㴦ȱ�ٽӱ߶���"; sCheckInfos.Add(sInfo); } else { if (nToAttr < 1) { sOIDs.Add(sSourceRowOID); string sInfo = sSourceRowOID + "%sҪ����㴦ȱ�ٽӱ߶���"; sCheckInfos.Add(sInfo); } } } else { sOIDs.Add(sSourceRowOID); string sInfo = sSourceRowOID + "%sҪ���յ㴦�нӱ߶���,�����Բ�ͬ;������㴦ȱ�ٽӱ߶���"; sCheckInfos.Add(sInfo); } } else { if (bIsFromOver == false && bIsToOver == false) { sOIDs.Add(sSourceRowOID); //û��ͼ�νӱ� string sInfo = sSourceRowOID + "Ҫ�������յ㴦��ȱ�ٶ�Ӧ�Ľӱ߶���"; sCheckInfos.Add(sInfo); } } if (ipFromSelectionSet != null) { Marshal.ReleaseComObject(ipFromSelectionSet); } if (ipToSelectionSet != null) { Marshal.ReleaseComObject(ipToSelectionSet); } return true; } catch (Exception ex) { SendMessage(enumMessageType.Exception, ex.ToString()); Marshal.ReleaseComObject(ipSourceRow); ipSourceRow = ipSourceCursor.NextRow(); return false; } }
/// <summary> /// Excecute is called by Data Reviewer engine and passed the appropriate parameters. /// </summary> /// <param name="ipSelectionToValidate">ISelectionSet of features/rows to validate</param> /// <param name="arguments">comma delimited string of arguments</param> /// <returns> /// Collection of validation results. /// </returns> public IPLTSErrorCollection Execute(ISelectionSet ipSelectionToValidate, string arguments) { if (null == ipSelectionToValidate) { throw new ArgumentNullException("ISelectionSet parameter is null"); } if (String.IsNullOrEmpty(arguments)) { throw new ArgumentNullException("string parameter is null or empty"); } //Get cursor of selected features/rows ICursor ipCursor = null; ipSelectionToValidate.Search(null, true, out ipCursor); IDataset ipSourceDataset = ipSelectionToValidate.Target as IDataset; IFeatureClass ipSourceFeatureClass = null; //Setup reference to feature class to be used when creating results if (ipSourceDataset.Type == esriDatasetType.esriDTFeatureClass) { ipSourceFeatureClass = ipSourceDataset as IFeatureClass; } //Get the index of the field we are checking int iIndexOfField = -1; iIndexOfField = ipCursor.FindField(arguments); //arguments is the name of the field we are checking if (-1 == iIndexOfField) { throw new Exception(String.Format("Field {0} was not found in Dataset {1}", arguments, ipSourceDataset.Name)); } //Collection of results passed back to Data Reviewer IPLTSErrorCollection ipRevResultCollection = new PLTSErrorCollectionClass(); //Loop through rows and check if field is numeric IRow ipRow = ipCursor.NextRow(); while (null != ipRow) { object oValue = ipRow.get_Value(iIndexOfField); bool bIsNumeric = false; if (null != oValue) { double dOutValue; bIsNumeric = double.TryParse(oValue.ToString().Trim(), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out dOutValue); } if (!bIsNumeric) { //Create Reviewer result and add to collection IPLTSError2 ipRevResult = new PLTSErrorClass() as IPLTSError2; ipRevResult.ErrorKind = pltsValErrorKind.pltsValErrorKindStandard; ipRevResult.OID = ipRow.OID; ipRevResult.QualifiedTableName = ipSourceDataset.Name; ipRevResult.ShortDescription = "Field does not contain a number"; ipRevResult.LongDescription = oValue.ToString() + " in " + arguments + " is not a number."; if (null != ipSourceFeatureClass) { IFeature ipFeature = ipSourceFeatureClass.GetFeature(ipRow.OID); if (null != ipFeature) { ipRevResult.ErrorGeometry = ipFeature.ShapeCopy; } } ipRevResultCollection.AddError(ipRevResult); } ipRow = ipCursor.NextRow(); }//end while //Release cursor Marshal.ReleaseComObject(ipCursor); ipCursor = null; //Return the collection of results return ipRevResultCollection; }