/// <summary> /// Get Envelope in external coordinates. /// </summary> /// <param name="precisionModel"></param> /// <param name="envelope"></param> /// <returns></returns> public static IEnvelope GetEnvelopeExternal(PrecisionModel precisionModel, IEnvelope envelope) { // get envelose in external coordinates Coordinate min = new Coordinate(envelope.Minimum.X, envelope.Minimum.Y); Coordinate max = new Coordinate(envelope.Maximum.X, envelope.Maximum.Y); // min = precisionModel.ToExternal(min); // max = precisionModel.ToExternal(max); Envelope bounds = new Envelope(min.X, max.X, min.Y, max.Y); return bounds; }
/// <summary> /// /// </summary> /// <param name="querySeg"></param> /// <returns></returns> public virtual IList Query(LineSegment querySeg) { Envelope env = new Envelope(querySeg.P0, querySeg.P1); LineSegmentVisitor visitor = new LineSegmentVisitor(querySeg); index.Query(env, visitor); IList itemsFound = visitor.Items; return itemsFound; }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <param name="addEnv"></param> /// <returns></returns> public static Node CreateExpanded(Node node, IEnvelope addEnv) { Envelope expandEnv = new Envelope(addEnv); if (node != null) expandEnv.ExpandToInclude(node.env); Node largerNode = CreateNode(expandEnv); if (node != null) largerNode.InsertNode(node); return largerNode; }
/// <summary> /// Overrides the OnMouseUp event to handle the situation where we are tyring to /// identify the vector features in the specified area. /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { Coordinate c1 = e.Map.PixelToProj(new System.Drawing.Point(e.X - 8, e.Y - 8)); Coordinate c2 = e.Map.PixelToProj(new System.Drawing.Point(e.X + 8, e.Y + 8)); Coordinate s1 = e.Map.PixelToProj(new System.Drawing.Point(e.X - 1, e.Y - 1)); Coordinate s2 = e.Map.PixelToProj(new System.Drawing.Point(e.X + 1, e.Y + 1)); Coordinate center = e.Map.PixelToProj(new System.Drawing.Point(e.X, e.Y)); IEnvelope tolerant = new Envelope(c1, c2); IEnvelope strict = new Envelope(s1, s2); if (frmFeatureIdentifier == null) { frmFeatureIdentifier = new FeatureIdentifier(); } frmFeatureIdentifier.SuspendLayout(); frmFeatureIdentifier.Clear(); Identify(e.Map.MapFrame.GetLayers(), strict, tolerant); frmFeatureIdentifier.ReSelect(); frmFeatureIdentifier.ResumeLayout(); frmFeatureIdentifier.Show(); base.OnMouseUp(e); }
/// <summary> /// returns only the features that have envelopes that /// intersect with the specified envelope. If in indexMode, this uses the ShapeIndices to create /// features on demand, rather than loading all the features. It is much faster to use selectIndices /// when in index mode. /// </summary> /// <param name="region">The specified region to test for intersect with</param> /// <param name="affectedRegion">This returns the geographic extents that contains the modified contents.</param> /// <returns>A List of the IFeature elements that are contained in this region</returns> public virtual List<IFeature> Select(IEnvelope region, out IEnvelope affectedRegion) { List<IFeature> result = new List<IFeature>(); if(IndexMode) { ShapeRange aoi = new ShapeRange(new Extent(region)); IEnvelope env = region.Copy(); Extent affected = new Extent(); List<ShapeRange> shapes = ShapeIndices; if(shapes != null) { for(int shp = 0; shp < shapes.Count; shp++) { if (!shapes[shp].Intersects(aoi)) continue; IFeature f = GetFeature(shp); affected.ExpandToInclude(shapes[shp].Extent); result.Add(f); } } affectedRegion = affected.ToEnvelope(); return result; } affectedRegion = new Envelope(); foreach (IFeature feature in Features) { if (!feature.Envelope.Intersects(region)) continue; result.Add(feature); affectedRegion.ExpandToInclude(feature.Envelope); } return result; }
/// <summary> /// Handles the Mouse Up situation /// </summary> /// <param name="e"></param> protected override void OnMouseUp(GeoMouseArgs e) { Stopwatch sw = new Stopwatch(); sw.Start(); if (_isDragging == false) return; _currentPoint = e.Location; _isDragging = false; //Map.Invalidate(); // Get rid of the selection box //Application.DoEvents(); IEnvelope env = new Envelope(_geoStartPoint.X, e.GeographicLocation.X, _geoStartPoint.Y, e.GeographicLocation.Y); IEnvelope tolerant = env; if(_startPoint.X == e.X && _startPoint.Y == e.Y) { // click selection doesn't work quite right without some tiny tolerance. double tol = Map.MapFrame.Extents.Width/10000; env.ExpandBy(tol); } if (Math.Abs(_startPoint.X - e.X) < 8 && Math.Abs(_startPoint.Y - e.Y) < 8) { Coordinate c1 = e.Map.PixelToProj(new System.Drawing.Point(e.X - 4, e.Y - 4)); Coordinate c2 = e.Map.PixelToProj(new System.Drawing.Point(e.X + 4, e.Y + 4)); tolerant = new Envelope(c1, c2); } Map.MapFrame.SuspendEvents(); HandleSelection(tolerant, env); Map.MapFrame.ResumeEvents(); // Force an invalidate to clear the dotted lines, even if we haven't changed anything. e.Map.Invalidate(); //e.Map.MapFrame.Initialize(); sw.Stop(); Debug.WriteLine("Initialize: " + sw.ElapsedMilliseconds); base.OnMouseUp(e); }
/// <summary> /// Test whether a point lies in the envelopes of both input segments. /// A correctly computed intersection point should return <c>true</c> /// for this test. /// Since this test is for debugging purposes only, no attempt is /// made to optimize the envelope test. /// </summary> /// <param name="intPt"></param> /// <returns><c>true</c> if the input point lies within both input segment envelopes.</returns> private bool IsInSegmentEnvelopes(Coordinate intPt) { Envelope env0 = new Envelope(InputLines[0, 0], InputLines[0, 1]); Envelope env1 = new Envelope(InputLines[1, 0], InputLines[1, 1]); return env0.Contains(intPt) && env1.Contains(intPt); }
/// <summary> /// This uses extent checking (rather than full polygon intersection checking). It will add /// any members that are either contained by or intersect with the specified region /// depending on the SelectionMode property. The order of operation is the region /// acting on the feature, so Contains, for instance, would work with points. /// </summary> /// <param name="region"></param> /// <param name="affectedArea">The affected area of this addition</param> /// <returns>True if any item was actually added to the collection</returns> public bool AddRegion(IEnvelope region, out IEnvelope affectedArea) { bool added = false; SuspendChanges(); affectedArea = new Envelope(); Stopwatch sw = new Stopwatch(); Stopwatch total = new Stopwatch(); total.Start(); foreach (IFeature f in FeatureList) { bool doAdd = false; if (_selectionMode == SelectionModes.IntersectsExtent) { if (region.Intersects(f.Envelope)) { Add(f); affectedArea.ExpandToInclude(f.Envelope); added = true; } } else if (_selectionMode == SelectionModes.ContainsExtent) { if (region.Contains(f.Envelope)) { Add(f); affectedArea.ExpandToInclude(f.Envelope); added = true; } } IGeometry reg; if(region.Width == 0 && region.Height == 0) { reg = new Point(region.X, region.Y); } else if (region.Height == 0 || region.Width == 0) { Coordinate[] coords = new Coordinate[2]; coords[0] = new Coordinate(region.X, region.Y); coords[1] = new Coordinate(region.Bottom(), region.Right()); reg = new LineString(coords); } else { reg = region.ToPolygon(); } IGeometry geom = Geometry.FromBasicGeometry(f.BasicGeometry); switch (_selectionMode) { case SelectionModes.Contains: if(region.Contains(f.Envelope)) { doAdd = true; } else if (region.Intersects(f.Envelope)) { if (reg.Contains(geom)) doAdd = true; } break; case SelectionModes.CoveredBy: if (reg.CoveredBy(geom)) doAdd = true; break; case SelectionModes.Covers: if (reg.Covers(geom)) doAdd = true; break; case SelectionModes.Disjoint: if (reg.Disjoint(geom)) doAdd = true; break; case SelectionModes.Intersects: if (region.Contains(f.Envelope)) { doAdd = true; } else if (region.Intersects(f.Envelope)) { if (reg.Intersects(geom)) doAdd = true; } break; case SelectionModes.Overlaps: if (reg.Overlaps(geom)) doAdd = true; break; case SelectionModes.Touches: if (reg.Touches(geom)) doAdd = true; break; case SelectionModes.Within: if (reg.Within(geom)) doAdd = true; break; } if (doAdd) { Add(f); affectedArea.ExpandToInclude(f.Envelope); added = true; } } sw.Start(); ResumeChanges(); sw.Stop(); total.Stop(); Debug.WriteLine("Geometry Intersection Time: " + sw.ElapsedMilliseconds); Debug.WriteLine("Total Intersection Time: " + total.ElapsedMilliseconds); return added; }
private IEnvelope GetEnvelope() { IEnvelope env = new Envelope(); foreach (IFeature f in this) { env.ExpandToInclude(f.Envelope); } return env; }
/// <summary> /// Un-highlights or returns the features from the specified region. The specified selectionMode /// will be used to determine how to choose features. /// </summary> /// <param name="tolerant">The geographic envelope in cases like cliking near points where tolerance is allowed</param> /// <param name="strict">The geographic region when working with absolutes, without a tolerance</param> /// <param name="affectedArea">The geographic envelope that will be visibly impacted by the change</param> /// <param name="selectionMode">The selection mode that controls how to choose members relative to the region </param> /// <returns>Boolean, true if members were removed from the selection.</returns> public override bool UnSelect(IEnvelope tolerant, IEnvelope strict, SelectionModes selectionMode, out IEnvelope affectedArea) { if (!_drawnStatesNeeded && !_editMode) AssignFastDrawnStates(); IEnvelope region = tolerant; if (DataSet.FeatureType == FeatureTypes.Polygon) region = strict; affectedArea = new Envelope(); bool changed = false; if (IsWithinLegendSelection() || _scheme.IsWithinLegendSelection()) { if (_editMode) { _selection.SelectionMode = selectionMode; changed = _selection.RemoveRegion(region, out affectedArea); } else { _selection.SelectionMode = selectionMode; changed = _selection.RemoveRegion(region, out affectedArea); } } else { SuspendChangeEvent(); _selection.SuspendChanges(); List<IFeatureCategory> categories = _scheme.GetCategories().ToList(); foreach (IFeatureCategory category in categories) { if (!category.IsSelected) continue; _selection.RegionCategory = category; _selection.RemoveRegion(region, out affectedArea); _selection.RegionCategory = null; } _selection.ResumeChanges(); ResumeChangeEvent(); } return changed; }
/// <summary> /// Performs an intersection of this line segment with the specified envelope /// </summary> /// <param name="inEnvelope">The envelope to compare against</param> /// <returns>An ILineSegment, or null if there is no intersection.</returns> public ILineSegment Intersection(Envelope inEnvelope) { return inEnvelope.Intersection(this); }
/// <summary> /// Executes the Erase Opaeration tool programaticaly /// </summary> /// <param name="input1">The input raster</param> /// <param name="input2">The input raster</param> /// <param name="output">The output raster</param> /// <param name="cancelProgressHandler">The progress handler</param> /// <returns></returns> public bool Execute(IRaster input1, IRaster input2, IRaster output, MapWindow.Tools.ICancelProgressHandler cancelProgressHandler) { //Validates the input and output data if (input1 == null || input2 == null || output == null) { return false; } IEnvelope envelope = new Envelope() as IEnvelope; envelope = UnionEnvelope(input1, input2); int noOfCol; int noOfRow; //Figures out which raster has smaller cells IRaster smallestCellRaster; if (input1.CellWidth < input2.CellWidth) smallestCellRaster = input1; else smallestCellRaster = input2; //Given the envelope of the two rasters we calculate the number of columns / rows noOfCol = Convert.ToInt32(Math.Abs(envelope.Width / smallestCellRaster.CellWidth)); noOfRow = Convert.ToInt32(Math.Abs(envelope.Height / smallestCellRaster.CellHeight)); //Create the new raster with the appropriate dimensions Raster Temp = new Raster(); //Temp.CreateNew(output.Filename, noOfRow, noOfCol, input1.DataType); Temp.CreateNew(output.Filename, "", noOfCol, noOfRow, 1, input1.DataType, new string[] { "" }); Temp.CellWidth = smallestCellRaster.CellWidth; Temp.CellHeight = smallestCellRaster.CellHeight; Temp.Xllcenter = envelope.Minimum.X + (Temp.CellWidth / 2); Temp.Yllcenter = envelope.Minimum.Y + (Temp.CellHeight / 2); MapWindow.Geometries.ICoordinate I1 = new MapWindow.Geometries.Coordinate() as MapWindow.Geometries.ICoordinate; RcIndex v1 = new RcIndex(); RcIndex v2 = new RcIndex(); double val1; double val2; int previous=0; int current=0; int max = (Temp.Bounds.NumRows + 1); for (int i = 0; i < Temp.Bounds.NumRows; i++) { for (int j = 0; j < Temp.Bounds.NumColumns; j++) { I1 = Temp.CellToProj(i, j); v1 = input1.ProjToCell(I1); if (v1.Row <= input1.EndRow && v1.Column <= input1.EndColumn && v1.Row > -1 && v1.Column > -1) val1 = input1.Value[v1.Row, v1.Column]; else val1 = input1.NoDataValue; v2 = input2.ProjToCell(I1); if (v2.Row <= input2.EndRow && v2.Column <= input2.EndColumn && v2.Row > -1 && v2.Column > -1) val2 = input2.Value[v2.Row, v2.Column]; else val2 = input2.NoDataValue; if (val1 == input1.NoDataValue && val2 == input2.NoDataValue) { Temp.Value[i, j] = Temp.NoDataValue; } else if (val1 != input1.NoDataValue && val2 == input2.NoDataValue) { Temp.Value[i, j] = val1; } else if (val1 == input1.NoDataValue && val2 != input2.NoDataValue) { Temp.Value[i, j] = val2; } else { Temp.Value[i, j] = val1; } if (cancelProgressHandler.Cancel == true) return false; } current = Convert.ToInt32(Math.Round(i * 100D / max)); //only update when increment in persentage if(current>previous) cancelProgressHandler.Progress("", current, current.ToString() + "% progress completed"); previous = current; } output = Temp; output.Save(); return true; }
/// <summary> /// This method inverts the selection for the specified region. Members already a part of the selection /// will be removed from the selection, while members that are not a part of the selection will be added /// to the selection. /// </summary> /// <param name="tolerant">The region specifying where featuers should be added or removed from the selection</param> /// <param name="strict">With polygon selection it is better not to allow any tolerance since the polygons already contain it</param> /// <param name="affectedArea">The geographic region that will be impacted by the changes</param> /// <param name="selectionMode">The SelectionModes enumeration that clarifies how the features should interact with the region</param> public override bool InvertSelection(IEnvelope tolerant, IEnvelope strict, SelectionModes selectionMode, out IEnvelope affectedArea) { if (!_drawnStatesNeeded && !_editMode) AssignFastDrawnStates(); IEnvelope region = tolerant; bool changed = false; affectedArea = new Envelope(); if (DataSet.FeatureType == FeatureTypes.Polygon) { region = strict; } _selection.SelectionMode = selectionMode; if (IsWithinLegendSelection() || _scheme.IsWithinLegendSelection()) { changed = _selection.InvertSelection(region, out affectedArea); } else { List<IFeatureCategory> categories = _scheme.GetCategories().ToList(); foreach (IFeatureCategory category in categories) { if (!category.IsWithinLegendSelection()) continue; _selection.RegionCategory = category; if (_selection.AddRegion(region, out affectedArea)) changed = true; _selection.RegionCategory = null; } } return changed; }
/// <summary> /// Execute the union region for output envelope /// </summary> /// <param name="input1">input raster</param> /// <param name="input2">input raster</param> /// <returns>Envelope</returns> private IEnvelope UnionEnvelope(IRaster input1, IRaster input2) { IEnvelope e1 = new Envelope() as IEnvelope; IEnvelope e2 = new Envelope() as IEnvelope; e1 = input1.Bounds.Envelope; e2 = input2.Bounds.Envelope; e1.ExpandToInclude(e2); return (e1); }
/// <summary> /// /// </summary> /// <returns></returns> protected override IEnvelope ComputeEnvelopeInternal() { Envelope envelope = new Envelope(); for (int i = 0; i < _geometries.Length; i++) envelope.ExpandToInclude(_geometries[i].EnvelopeInternal); return envelope; }
/// <summary> /// /// </summary> /// <returns></returns> protected override object ComputeBounds() { Envelope bounds = null; for (IEnumerator i = ChildBoundables.GetEnumerator(); i.MoveNext(); ) { IBoundable childBoundable = (IBoundable) i.Current; if (bounds == null) bounds = new Envelope((Envelope)childBoundable.Bounds); else bounds.ExpandToInclude((Envelope)childBoundable.Bounds); } return bounds; }
/// <summary> /// Executes the Erase Opaeration tool programaticaly. /// </summary> /// <param name="input1">The input raster.</param> /// <param name="input2">The input raster.</param> /// <param name="output">The output raster.</param> /// <param name="cancelProgressHandler">The progress handler.</param> /// <returns></returns> public bool Execute(IRaster input1, IFeatureSet input2, IRaster output, MapWindow.Tools.ICancelProgressHandler cancelProgressHandler) { //Validates the input and output data if (input1 == null || input2 == null || output == null) { return false; } int noOfCol = input1.NumColumns; int noOfRow = input1.NumRows; //Calculate the Intersect Envelope IEnvelope envelope1 = new Envelope() as IEnvelope; IEnvelope envelope2 = new Envelope() as IEnvelope; envelope1 = input1.Bounds.Envelope; envelope2 = input2.Envelope; envelope1 = envelope1.Intersection(envelope2); //Create the new raster with the appropriate dimensions IRaster Temp = Raster.Create(output.Filename, "", noOfCol, noOfRow, 1, input1.DataType, new string[] { }); //Temp.CreateNew(output.Filename, noOfRow, noOfCol, input1.DataType); Temp.CellWidth = input1.CellWidth; Temp.CellHeight = input1.CellHeight; Temp.Xllcenter = envelope1.Minimum.X + (Temp.CellWidth / 2); Temp.Yllcenter = envelope1.Minimum.Y + (Temp.CellHeight / 2); MapWindow.Geometries.ICoordinate I1 = new MapWindow.Geometries.Coordinate() as MapWindow.Geometries.ICoordinate; RcIndex v1 = new RcIndex(); // MapWindow.Analysis.Topology.Algorithm.PointLocator pointLocator1 = new MapWindow.Analysis.Topology.Algorithm.PointLocator(); double val1; int previous = 0; int current = 0; int max = (Temp.Bounds.NumRows + 1); for (int i = 0; i < Temp.Bounds.NumRows; i++) { for (int j = 0; j < Temp.Bounds.NumColumns; j++) { I1 = Temp.CellToProj(i, j); v1 = input1.ProjToCell(I1); if (v1.Row <= input1.EndRow && v1.Column <= input1.EndColumn && v1.Row > -1 && v1.Column > -1) val1 = input1.Value[v1.Row, v1.Column]; else val1 = Temp.NoDataValue; //test if the coordinate is inside of the polygon bool isInside = false; IFeature pointFeat = new Feature(new Point(I1)) as IFeature; foreach (IFeature f in input2.Features) { if (f.Contains(pointFeat)) { Temp.Value[i, j] = val1; isInside = true; break; } } if (isInside == false) { Temp.Value[i, j] = Temp.NoDataValue; } if (cancelProgressHandler.Cancel == true) return false; } current = Convert.ToInt32(Math.Round(i * 100D / max)); //only update when increment in percentage if (current > previous) cancelProgressHandler.Progress("", current, current.ToString() + "% progress completed"); previous = current; } output = Temp; output.Save(); return true; }
/// <summary> /// Determines if any portion of this segment intersects the specified extent. /// </summary> /// <param name="inEnvelope">The</param> /// <returns>Boolean, true if this line segment intersects the specified envelope</returns> public bool Intersects(Envelope inEnvelope) { return inEnvelope.Intersects(this); }
/// <summary> /// /// </summary> /// <param name="env"></param> /// <param name="action"></param> public QueryVisitor(Envelope env, HotPixelSnapAction action) { this.env = env; this.action = action; }
/// <summary> /// Removes any members from existing in the selected state /// </summary> /// <param name="affectedAreas">The region of the selection that was cleared</param> /// <returns>Boolean, true if any sub-members of the group were changed by the clear method</returns> public override bool ClearSelection(out IEnvelope affectedAreas) { affectedAreas = new Envelope(); bool changed = false; if (!_selectionEnabled) return false; MapFrame.SuspendEvents(); foreach (ILayer layer in GetLayers()) { IEnvelope layerArea; if(layer.ClearSelection(out layerArea)) changed = true; affectedAreas.ExpandToInclude(layerArea); } MapFrame.ResumeEvents(); OnSelectionChanged(); // fires only AFTER the individual layers have fired their events. return changed; }
/// <summary> /// Tests each member currently in the selected features based on /// the SelectionMode. If it passes, it will remove the feature from /// the selection. /// </summary> /// <param name="region">The geographic region to remove</param> /// <param name="affectedArea">A geographic area that was affected by this change.</param> /// <returns>Boolean, true if the collection was changed</returns> public bool RemoveRegion(IEnvelope region, out IEnvelope affectedArea) { SuspendChanges(); bool removed = false; affectedArea = new Envelope(); var query = from pair in _filter.DrawnStates where pair.Value.IsSelected select pair.Key; List<IFeature> selectedFeatures = query.ToList(); foreach (IFeature f in selectedFeatures) { bool doRemove = false; if (_selectionMode == SelectionModes.IntersectsExtent) { if (region.Intersects(f.Envelope)) { if (Remove(f)) { removed = true; affectedArea.ExpandToInclude(f.Envelope); } } } else if (_selectionMode == SelectionModes.ContainsExtent) { if (region.Contains(f.Envelope)) { if (Remove(f)) { removed = true; affectedArea.ExpandToInclude(f.Envelope); } } } IPolygon reg = region.ToPolygon(); IGeometry geom = Geometry.FromBasicGeometry(f.BasicGeometry); switch (_selectionMode) { case SelectionModes.Contains: if (region.Intersects(f.Envelope)) { if (reg.Contains(geom)) doRemove = true; } break; case SelectionModes.CoveredBy: if (reg.CoveredBy(geom)) doRemove = true; break; case SelectionModes.Covers: if (reg.Covers(geom)) doRemove = true; break; case SelectionModes.Disjoint: if (reg.Disjoint(geom)) doRemove = true; break; case SelectionModes.Intersects: if(region.Intersects(f.Envelope)) { if (reg.Intersects(geom)) doRemove = true; } break; case SelectionModes.Overlaps: if (reg.Overlaps(geom)) doRemove = true; break; case SelectionModes.Touches: if (reg.Touches(geom)) doRemove = true; break; case SelectionModes.Within: if (reg.Within(geom)) doRemove = true; break; } if (doRemove) { if (Remove(f)) { affectedArea.ExpandToInclude(f.Envelope); removed = true; } } } ResumeChanges(); return removed; }
/// <summary> /// Adds any members found in the specified region to the selected state as long as SelectionEnabled is set to true. /// </summary> /// <param name="tolerant">The geographic region where selection occurs in cases like clicking near points where tolerance is allowed</param> /// <param name="strict">The geographic region in cases like selecting polygons where no tolerance is allowed</param> /// <param name="mode">The selection mode</param> /// <param name="affectedArea">The envelope affected area</param> /// <returns>Boolean, true if any members were added to the selection</returns> public override bool UnSelect(IEnvelope tolerant, IEnvelope strict, SelectionModes mode, out IEnvelope affectedArea) { affectedArea = new Envelope(); if (!_selectionEnabled) return false; bool somethingChanged = false; SuspendEvents(); foreach (ILayer s in GetLayers()) { IEnvelope layerArea; if (s.UnSelect(tolerant, strict, mode, out layerArea)) somethingChanged = true; affectedArea.ExpandToInclude(layerArea); } ResumeEvents(); OnSelectionChanged(); // fires only AFTER the individual layers have fired their events. return somethingChanged; }
/// <summary> /// Inverts the selection based on the current SelectionMode /// </summary> /// <param name="region">The geographic region to reverse the selected state</param> /// <param name="affectedArea">The affected area to invert</param> public bool InvertSelection(IEnvelope region, out IEnvelope affectedArea) { SuspendChanges(); bool flipped = false; affectedArea = new Envelope(); IDictionary<IFeature, IDrawnState> states = Filter.DrawnStates; foreach (KeyValuePair<IFeature, IDrawnState> kvp in states) { bool doFlip = false; IFeature f = kvp.Key; if (SelectionMode == SelectionModes.IntersectsExtent) { if (region.Intersects(f.Envelope)) { kvp.Value.IsSelected = !kvp.Value.IsSelected; affectedArea.ExpandToInclude(f.Envelope); } } else if (SelectionMode == SelectionModes.ContainsExtent) { if (region.Contains(f.Envelope)) { kvp.Value.IsSelected = !kvp.Value.IsSelected; affectedArea.ExpandToInclude(f.Envelope); } } IPolygon reg = region.ToPolygon(); IGeometry geom = Geometry.FromBasicGeometry(f.BasicGeometry); switch (SelectionMode) { case SelectionModes.Contains: if (region.Intersects(f.Envelope)) { if (reg.Contains(geom)) doFlip = true; } break; case SelectionModes.CoveredBy: if (reg.CoveredBy(geom)) doFlip = true; break; case SelectionModes.Covers: if (reg.Covers(geom)) doFlip = true; break; case SelectionModes.Disjoint: if (reg.Disjoint(geom)) doFlip = true; break; case SelectionModes.Intersects: if (region.Intersects(f.Envelope)) { if (reg.Intersects(geom)) doFlip = true; } break; case SelectionModes.Overlaps: if (reg.Overlaps(geom)) doFlip = true; break; case SelectionModes.Touches: if (reg.Touches(geom)) doFlip = true; break; case SelectionModes.Within: if (reg.Within(geom)) doFlip = true; break; } if (doFlip) { flipped = true; kvp.Value.IsSelected = !kvp.Value.IsSelected; affectedArea.ExpandToInclude(f.Envelope); } } ResumeChanges(); return flipped; }
/// <summary> /// This will draw any features that intersect this region. To specify the features /// directly, use OnDrawFeatures. This will not clear existing buffer content. /// For that call Initialize instead. /// </summary> /// <param name="args">A GeoArgs clarifying the transformation from geographic to image space</param> /// <param name="regions">The geographic regions to draw</param> public void DrawRegions(MapArgs args, List<IEnvelope> regions) { if (FeatureSet == null) return; if(FeatureSet.IndexMode) { // First determine the number of features we are talking about based on region. List<int> drawIndices = new List<int>(); foreach (IEnvelope region in regions) { if (region != null) { // We need to consider labels that go off the screen. figure a region // that is larger. IEnvelope sur = new Envelope(region.Copy()); sur.ExpandBy(region.Width, region.Height); Extent r = new Extent(sur); // Use union to prevent duplicates. No sense in drawing more than we have to. drawIndices = drawIndices.Union(FeatureSet.SelectIndices(r)).ToList(); } } List<Rectangle> clips = args.ProjToPixel(regions); DrawFeatures(args, drawIndices, clips, true); } else { // First determine the number of features we are talking about based on region. List<IFeature> drawList = new List<IFeature>(); foreach (IEnvelope region in regions) { if (region != null) { // We need to consider labels that go off the screen. figure a region // that is larger. IEnvelope r = region.Copy(); r.ExpandBy(region.Width, region.Height); // Use union to prevent duplicates. No sense in drawing more than we have to. drawList = drawList.Union(FeatureSet.Select(r)).ToList(); } } List<Rectangle> clipRects = args.ProjToPixel(regions); DrawFeatures(args, drawList, clipRects, true); } }
public override bool Select(IEnvelope tolerant, IEnvelope strict, SelectionModes mode, out IEnvelope affectedArea) { affectedArea = new Envelope(); if (!_selectionEnabled) return false; bool somethingChanged = false; MapFrame.SuspendEvents(); foreach (ILayer s in GetLayers()) { if (s.SelectionEnabled == false) continue; IEnvelope layerArea; if(s.Select(tolerant, strict, mode, out layerArea)) somethingChanged = true; affectedArea.ExpandToInclude(layerArea); } Stopwatch sw = new Stopwatch(); sw.Start(); MapFrame.ResumeEvents(); sw.Stop(); Debug.WriteLine("ResumeEvents: " + sw.ElapsedMilliseconds); OnSelectionChanged(); // fires only AFTER the individual layers have fired their events. return somethingChanged; }
/// <summary> /// Opens a *.mwprj file. /// </summary> /// <param name="filename">The string filename of the mwprj file to parse.</param> public virtual void Open(string filename) { _doc.Open(filename); Directory.SetCurrentDirectory(Path.GetDirectoryName(filename)); // Main document Properties _name = _doc.ReadText("name"); _type = _doc.ReadText("type"); _version = _doc.ReadText("version"); _configPath = _doc.ReadText("ConfigurationPath"); _projection = _doc.ReadText("ProjectProjection"); _mapUnits = _doc.ReadText("MapUnits"); _backColor = _doc.ReadColor("ViewBackColor"); _useDefaultBackColor = _doc.ReadBool("ViewBackColor_UseDefault"); _scaleBar = new ScaleBarInfo(); _scaleBar.Visible = _doc.ReadBool("ShowFloatingScaleBar"); _scaleBar.Position = (ScaleBarPositions)Enum.Parse(typeof(ScaleBarPositions), _doc.ReadText("FloatingScaleBarPosition")); _scaleBar.Unit = _doc.ReadText("FloatingScaleBarUnit"); _scaleBar.ForeColor = _doc.ReadColor("FloatingScaleBarForecolor"); _scaleBar.BackColor = _doc.ReadColor("FloatingScaleBarBackcolor"); _resizeBehavior = (ResizeBehaviors)_doc.ReadInteger("MapResizeBehavior"); _statusBar.GetFromProjection = _doc.ReadBool("ShowStatusBarCoords_Projected"); _statusBar.Alternate = _doc.ReadText("ShowStatusBarCoords_Alternate"); if (_doc.NavigateToChild("Plugins")) { foreach (XmlElement plugin in _doc.CurrentElement.ChildNodes) { PluginInfo pi = new PluginInfo(plugin.GetAttribute("SettingsString"), plugin.GetAttribute("Key")); _plugins.Add(pi); } _doc.NavigateToParent(); } if (_doc.NavigateToChild("ApplicationPlugins")) { foreach (XmlElement plugin in _doc.CurrentElement.ChildNodes) { PluginInfo pi = new PluginInfo(plugin.GetAttribute("SettingsString"), plugin.GetAttribute("Key")); _plugins.Add(pi); } _doc.NavigateToParent(); } if (_doc.NavigateToChild("Extents")) { double xMin = _doc.ReadDouble("xMin"); double xMax = _doc.ReadDouble("xMax"); double yMin = _doc.ReadDouble("yMin"); double yMax = _doc.ReadDouble("yMax"); _extents = new Envelope(xMin, xMax, yMin, yMax); } }
/// <summary> /// /// </summary> /// <param name="index"></param> /// <returns></returns> private Node CreateSubnode(int index) { // create a new subquad in the appropriate quadrant double minx = 0.0; double maxx = 0.0; double miny = 0.0; double maxy = 0.0; switch (index) { case 0: minx = env.Minimum.X; maxx = centre.X; miny = env.Minimum.Y; maxy = centre.Y; break; case 1: minx = centre.X; maxx = env.Maximum.X; miny = env.Minimum.Y; maxy = centre.Y; break; case 2: minx = env.Minimum.X; maxx = centre.X; miny = centre.Y; maxy = env.Maximum.Y; break; case 3: minx = centre.X; maxx = env.Maximum.X; miny = centre.Y; maxy = env.Maximum.Y; break; default: break; } Envelope sqEnv = new Envelope(minx, maxx, miny, maxy); Node node = new Node(sqEnv, level - 1); return node; }
/// <summary> /// Removes any members from existing in the selected state /// </summary> public bool ClearSelection(out IEnvelope affectedArea) { affectedArea = new Envelope(); if (MapFrame == null) return false; return MapFrame.ClearSelection(out affectedArea); }
/// <summary> /// /// </summary> /// <param name="testExtents"></param> /// <returns></returns> public IEnvelope PixelToProj(RectangleF testExtents) { Coordinate UL = PixelToProj(new PointF(testExtents.Left, testExtents.Top)); Coordinate LR = PixelToProj(new PointF(testExtents.Right, testExtents.Bottom)); IEnvelope result = new Envelope(UL.X, UL.Y, (LR.X - UL.X), (LR.Y - UL.Y)); return result; }
/// <summary> /// Adds any members found in the specified region to the selected state as long as SelectionEnabled is set to true. /// </summary> /// <param name="strict">The tight envelope to use for polygons</param> /// <param name="tolerant">The geographic region where selection occurs that is tolerant for point or linestrings</param> /// <param name="mode">The selection mode</param> /// <param name="affectedArea">The envelope affected area</param> /// <returns>Boolean, true if any members were added to the selection</returns> public bool UnSelect(IEnvelope tolerant, IEnvelope strict, SelectionModes mode, out IEnvelope affectedArea) { affectedArea = new Envelope(); if (MapFrame == null) return false; return MapFrame.UnSelect(tolerant, strict, mode, out affectedArea); }