Example #1
0
        public void ExtentExpandToIncludeTwoValuesTest()
        {
            Extent e = new Extent();

            // make sure all x and y values are no longer NaN
            e.ExpandToInclude(5, 7);
            Assert.AreEqual(5, e.MinX, "6 != e.MinX");
            Assert.AreEqual(7, e.MinY, "7 != e.MinY");
            Assert.AreEqual(5, e.MaxX, "5 != e.MaxX");
            Assert.AreEqual(7, e.MaxY, "7 != e.MaxY");

            // make sure only MinX and MinY change
            e.ExpandToInclude(4, 6);
            Assert.AreEqual(4, e.MinX, "4 != e.MinX");
            Assert.AreEqual(6, e.MinY, "6 != e.MinY");
            Assert.AreEqual(5, e.MaxX, "5 != e.MaxX");
            Assert.AreEqual(7, e.MaxY, "7 != e.MaxY");

            // make sure only MaxX and MaxY change
            e.ExpandToInclude(13, 14);
            Assert.AreEqual(4, e.MinX, "4 != e.MinX");
            Assert.AreEqual(6, e.MinY, "6 != e.MinY");
            Assert.AreEqual(13, e.MaxX, "13 != e.MaxX");
            Assert.AreEqual(14, e.MaxY, "14 != e.MaxY");
        }
Example #2
0
        public void ExtentExpandToIncludeExtentTest()
        {
            Extent e = new Extent();

            e.ExpandToInclude(new Extent(4, 5, 6, 7));
            Assert.AreEqual(4, e.MinX, "4 != e.MinX");
            Assert.AreEqual(5, e.MinY, "5 != e.MinY");
            Assert.AreEqual(6, e.MaxX, "6 != e.MaxX");
            Assert.AreEqual(7, e.MaxY, "7 != e.MaxY");

            // make sure only MinX and MaxY change
            e.ExpandToInclude(new Extent(1, 6, 5, 8));
            Assert.AreEqual(1, e.MinX, "1 != e.MinX");
            Assert.AreEqual(5, e.MinY, "5 != e.MinY");
            Assert.AreEqual(6, e.MaxX, "6 != e.MaxX");
            Assert.AreEqual(8, e.MaxY, "8 != e.MaxY");

            // make sure only MinY and MaxX change
            e.ExpandToInclude(new Extent(2, 3, 7, 7));
            Assert.AreEqual(1, e.MinX, "1 != e.MinX");
            Assert.AreEqual(3, e.MinY, "3 != e.MinY");
            Assert.AreEqual(7, e.MaxX, "7 != e.MaxX");
            Assert.AreEqual(8, e.MaxY, "8 != e.MaxY");

            // make sure nothing changes
            e.ExpandToInclude(null);
            Assert.AreEqual(1, e.MinX, "1 != e.MinX");
            Assert.AreEqual(3, e.MinY, "3 != e.MinY");
            Assert.AreEqual(7, e.MaxX, "7 != e.MaxX");
            Assert.AreEqual(8, e.MaxY, "8 != e.MaxY");
        }
Example #3
0
        public Extent GetMaxExtent()
        {
            Extent extent = new Extent();
            Extent x      = new Extent();

            for (int i = 0; i < Servicies.Count(); i++)
            {
                if (Servicies.ElementAt(i).GetType() == typeof(WMSClient))
                {
                    WMSClient WmsClient = (WMSClient)Servicies.ElementAt(i);
                    x = WmsClient.GetMaxSize();
                }
                else
                {
                    WMTClient WmtClient = (WMTClient)Servicies.ElementAt(i);
                    x = WmtClient.Extent();
                }

                if (i == 0)
                {
                    extent = x;
                }
                else
                {
                    extent.ExpandToInclude(x);
                }
            }

            return(extent);
        }
        private void buttonZoomToPoints_Click(object sender, EventArgs e)
        {
            Extent ext = layer.Extent;

            ext.ExpandToInclude(env);
            map1.ViewExtents = ext;
        }
Example #5
0
        /// <summary>
        /// Expands the first envelope to include the second.
        /// </summary>
        /// <param name="input1">The first input raster to union the envelope for.</param>
        /// <param name="input2">The second input raster to union the envelope for.</param>
        /// <returns>The expanded envelope.</returns>
        private static Extent UnionEnvelope(IRaster input1, IRaster input2)
        {
            Extent e1 = input1.Bounds.Extent;
            Extent e2 = input2.Bounds.Extent;

            e1.ExpandToInclude(e2);
            return(e1);
        }
Example #6
0
 /// <summary>
 /// Notifies the layer that the next time an area that intersects with this region
 /// is specified, it must first re-draw content to the image buffer.
 /// </summary>
 /// <param name="region">The envelope where content has become invalidated.</param>
 public virtual void Invalidate(Extent region)
 {
     if (_invalidatedRegion != null)
     {
         // This is set to null when we do the redrawing, so we would rather expand
         // the redraw region than forget to update a modified area.
         _invalidatedRegion.ExpandToInclude(region);
     }
     else
     {
         _invalidatedRegion = region;
     }
 }
Example #7
0
        public override void Run()
        {
            ILegendItem selectedItem = (GIS.FrameWork.Application.App.Legend as GIS.Common.Dialogs.Legend).SelectedLegendMenuItem;

            if (selectedItem != null && selectedItem is MapFrame)
            {
                //get max extent from maplayercollection
                IMapLayerCollection _layers = GIS.FrameWork.Application.App.Map.Layers;
                Extent         ext          = null;
                IList <ILayer> layers       = _layers.Cast <ILayer>().ToList();
                if (layers != null)
                {
                    foreach (ILayer layer in layers)
                    {
                        if (layer.Extent != null && !layer.Extent.IsEmpty()) // changed by jany (2015-07-17) don't add extents of empty layers, because they cause a wrong overall extent
                        {
                            if (ext == null)
                            {
                                ext = (Extent)layer.Extent.Clone();
                            }
                            else
                            {
                                ext.ExpandToInclude(layer.Extent);
                            }
                        }
                    }
                }
                //calculate expands
                double eps    = 1e-7;
                var    maxExt = ext.Width < eps || ext.Height < eps
                    ? new Extent(ext.MinX - eps, ext.MinY - eps, ext.MaxX + eps, ext.MaxY + eps)
                    : ext;
                maxExt.ExpandBy(maxExt.Width / 10, maxExt.Height / 10);

                GIS.FrameWork.Application.App.Map.ViewExtents = maxExt;
            }
        }
Example #8
0
        /// <summary>
        /// Add REgion
        /// </summary>
        /// <param name="region"></param>
        /// <param name="affectedArea"></param>
        /// <returns></returns>
        public bool AddRegion(Envelope region, out Envelope affectedArea)
        {
            bool added = false;

            SuspendChanges();
            Extent   affected = new Extent();
            IPolygon reg      = region.ToPolygon();

            //ProgressMeter pm = new ProgressMeter(ProgressHandler, "Selecting shapes", _layer.DrawnStates.Length);
            for (int shp = 0; shp < _layer.DrawnStates.Length; shp++)
            {
                //pm.Next();
                if (_regionCategory != null && _layer.DrawnStates[shp].Category != _regionCategory)
                {
                    continue;
                }
                bool       doAdd = false;
                ShapeRange shape = _shapes[shp];

                if (_selectionMode == SelectionMode.Intersects)
                {
                    // Prevent geometry creation (which is slow) and use ShapeRange instead
                    ShapeRange env = new ShapeRange(region);
                    if (env.Intersects(shape))
                    {
                        _layer.DrawnStates[shp].Selected = _selectionState;
                        affected.ExpandToInclude(shape.Extent);
                        added = true;
                        OnChanged();
                    }
                }
                else if (_selectionMode == SelectionMode.IntersectsExtent)
                {
                    if (shape.Extent.Intersects(region))
                    {
                        _layer.DrawnStates[shp].Selected = _selectionState;
                        affected.ExpandToInclude(shape.Extent);
                        added = true;
                        OnChanged();
                    }
                }
                else if (_selectionMode == SelectionMode.ContainsExtent)
                {
                    if (shape.Extent.Within(region))
                    {
                        _layer.DrawnStates[shp].Selected = _selectionState;
                        affected.ExpandToInclude(shape.Extent);
                        added = true;
                        OnChanged();
                    }
                }
                else if (_selectionMode == SelectionMode.Disjoint)
                {
                    if (shape.Extent.Intersects(region))
                    {
                        IGeometry g = _layer.DataSet.Features[shp].Geometry;
                        if (reg.Disjoint(g))
                        {
                            doAdd = true;
                        }
                    }
                    else
                    {
                        doAdd = true;
                    }
                }
                else
                {
                    if (!shape.Extent.Intersects(region))
                    {
                        continue;
                    }
                    IGeometry geom = _layer.DataSet.GetFeature(shp).Geometry;
                    switch (_selectionMode)
                    {
                    case SelectionMode.Contains:
                        if (shape.Extent.Within(region))
                        {
                            doAdd = true;
                        }
                        else if (shape.Extent.Intersects(region))
                        {
                            if (reg.Contains(geom))
                            {
                                doAdd = true;
                            }
                        }
                        break;

                    case SelectionMode.CoveredBy:
                        if (reg.CoveredBy(geom))
                        {
                            doAdd = true;
                        }
                        break;

                    case SelectionMode.Covers:
                        if (reg.Covers(geom))
                        {
                            doAdd = true;
                        }
                        break;

                    case SelectionMode.Intersects:
                        if (shape.Extent.Within(region))
                        {
                            doAdd = true;
                        }
                        else if (shape.Extent.Intersects(region))
                        {
                            if (reg.Intersects(geom))
                            {
                                doAdd = true;
                            }
                        }
                        break;

                    case SelectionMode.Overlaps:
                        if (reg.Overlaps(geom))
                        {
                            doAdd = true;
                        }
                        break;

                    case SelectionMode.Touches:
                        if (reg.Touches(geom))
                        {
                            doAdd = true;
                        }
                        break;

                    case SelectionMode.Within:
                        if (reg.Within(geom))
                        {
                            doAdd = true;
                        }
                        break;
                    }
                }
                if (!doAdd)
                {
                    continue;
                }
                OnChanged();
                _layer.DrawnStates[shp].Selected = _selectionState;
                affected.ExpandToInclude(shape.Extent);
                added = true;
            }
            //pm.Reset();
            ResumeChanges();
            affectedArea = affected.ToEnvelope();
            return(added);
        }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="region"></param>
        /// <param name="affectedArea"></param>
        /// <returns></returns>
        public bool RemoveRegion(Envelope region, out Envelope affectedArea)
        {
            bool removed = false;

            SuspendChanges();

            Extent   affected = new Extent();
            IPolygon reg      = region.ToPolygon();

            FastDrawnState[] drawnStates = _layer.DrawnStates;
            for (int shp = 0; shp < drawnStates.Length; shp++)
            {
                if (_regionCategory != null && drawnStates[shp].Category != _regionCategory)
                {
                    continue;
                }
                bool       doRemove = false;
                ShapeRange shape    = _shapes[shp];
                if (_selectionMode == SelectionMode.IntersectsExtent)
                {
                    if (shape.Extent.Intersects(region))
                    {
                        drawnStates[shp].Selected = !_selectionState;
                        affected.ExpandToInclude(shape.Extent);
                        removed = true;
                    }
                }
                else if (_selectionMode == SelectionMode.ContainsExtent)
                {
                    if (shape.Extent.Within(region))
                    {
                        drawnStates[shp].Selected = !_selectionState;
                        affected.ExpandToInclude(shape.Extent);
                        removed = true;
                    }
                }
                if (_selectionMode == SelectionMode.Disjoint)
                {
                    if (shape.Extent.Intersects(region))
                    {
                        IGeometry g = _layer.DataSet.Features[shp].Geometry;
                        if (reg.Disjoint(g))
                        {
                            doRemove = true;
                        }
                    }
                    else
                    {
                        doRemove = true;
                    }
                }
                else
                {
                    if (!shape.Extent.Intersects(region))
                    {
                        continue;
                    }
                    IGeometry geom = _layer.DataSet.Features[shp].Geometry;
                    switch (_selectionMode)
                    {
                    case SelectionMode.Contains:
                        if (shape.Extent.Within(region))
                        {
                            doRemove = true;
                        }
                        else if (shape.Extent.Intersects(region))
                        {
                            if (reg.Contains(geom))
                            {
                                doRemove = true;
                            }
                        }
                        break;

                    case SelectionMode.CoveredBy:
                        if (reg.CoveredBy(geom))
                        {
                            doRemove = true;
                        }
                        break;

                    case SelectionMode.Covers:
                        if (reg.Covers(geom))
                        {
                            doRemove = true;
                        }
                        break;

                    case SelectionMode.Intersects:
                        if (shape.Extent.Within(region))
                        {
                            doRemove = true;
                        }
                        else if (shape.Extent.Intersects(region))
                        {
                            if (reg.Intersects(geom))
                            {
                                doRemove = true;
                            }
                        }
                        break;

                    case SelectionMode.Overlaps:
                        if (reg.Overlaps(geom))
                        {
                            doRemove = true;
                        }
                        break;

                    case SelectionMode.Touches:
                        if (reg.Touches(geom))
                        {
                            doRemove = true;
                        }
                        break;

                    case SelectionMode.Within:
                        if (reg.Within(geom))
                        {
                            doRemove = true;
                        }
                        break;
                    }
                }
                if (!doRemove)
                {
                    continue;
                }
                drawnStates[shp].Selected = !_selectionState;
                affected.ExpandToInclude(shape.Extent);
                removed = true;
            }
            affectedArea = affected.ToEnvelope();
            ResumeChanges();
            return(removed);
        }
Example #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="region"></param>
        /// <param name="affectedArea"></param>
        /// <returns></returns>
        public bool InvertSelection(Envelope region, out Envelope affectedArea)
        {
            SuspendChanges();
            bool     flipped  = false;
            Extent   affected = new Extent();
            IPolygon reg      = region.ToPolygon();

            for (int shp = 0; shp < _layer.DrawnStates.Length; shp++)
            {
                if (_regionCategory != null && _layer.DrawnStates[shp].Category != _regionCategory)
                {
                    continue;
                }
                bool       doFlip = false;
                ShapeRange shape  = _shapes[shp];
                if (_selectionMode == SelectionMode.Intersects)
                {
                    // Prevent geometry creation (which is slow) and use ShapeRange instead
                    ShapeRange env = new ShapeRange(region);
                    if (env.Intersects(shape))
                    {
                        _layer.DrawnStates[shp].Selected = !_layer.DrawnStates[shp].Selected;
                        affected.ExpandToInclude(shape.Extent);
                        flipped = true;
                        OnChanged();
                    }
                }
                else if (_selectionMode == SelectionMode.IntersectsExtent)
                {
                    if (shape.Extent.Intersects(region))
                    {
                        _layer.DrawnStates[shp].Selected = !_layer.DrawnStates[shp].Selected;
                        affected.ExpandToInclude(shape.Extent);
                        flipped = true;
                        OnChanged();
                    }
                }
                else if (_selectionMode == SelectionMode.ContainsExtent)
                {
                    if (shape.Extent.Within(region))
                    {
                        _layer.DrawnStates[shp].Selected = !_layer.DrawnStates[shp].Selected;
                        affected.ExpandToInclude(shape.Extent);
                        flipped = true;
                        OnChanged();
                    }
                }
                else if (_selectionMode == SelectionMode.Disjoint)
                {
                    if (shape.Extent.Intersects(region))
                    {
                        IGeometry g = _layer.DataSet.Features[shp].Geometry;
                        if (reg.Disjoint(g))
                        {
                            doFlip = true;
                        }
                    }
                    else
                    {
                        doFlip = true;
                    }
                }
                else
                {
                    if (!shape.Extent.Intersects(region))
                    {
                        continue;
                    }
                    IFeature  f    = _layer.DataSet.Features[shp]; // only get this if envelopes intersect
                    IGeometry geom = f.Geometry;
                    switch (SelectionMode)
                    {
                    case SelectionMode.Contains:
                        if (region.Intersects(f.Geometry.EnvelopeInternal))
                        {
                            if (reg.Contains(geom))
                            {
                                doFlip = true;
                            }
                        }
                        break;

                    case SelectionMode.CoveredBy:
                        if (reg.CoveredBy(geom))
                        {
                            doFlip = true;
                        }
                        break;

                    case SelectionMode.Covers:
                        if (reg.Covers(geom))
                        {
                            doFlip = true;
                        }
                        break;

                    case SelectionMode.Intersects:
                        if (region.Intersects(f.Geometry.EnvelopeInternal))
                        {
                            if (reg.Intersects(geom))
                            {
                                doFlip = true;
                            }
                        }
                        break;

                    case SelectionMode.Overlaps:
                        if (reg.Overlaps(geom))
                        {
                            doFlip = true;
                        }
                        break;

                    case SelectionMode.Touches:
                        if (reg.Touches(geom))
                        {
                            doFlip = true;
                        }
                        break;

                    case SelectionMode.Within:
                        if (reg.Within(geom))
                        {
                            doFlip = true;
                        }
                        break;
                    }
                }
                if (!doFlip)
                {
                    continue;
                }
                flipped = true;
                _layer.DrawnStates[shp].Selected = !_layer.DrawnStates[shp].Selected;
                affected.ExpandToInclude(shape.Extent);
            }
            affectedArea = affected.ToEnvelope();
            ResumeChanges();
            return(flipped);
        }
Example #11
0
        /// <summary>
        /// Runs the given action for all the shapes that are affected by the current SelectionMode and the given region.
        /// </summary>
        /// <param name="action">Action that is run on the affected shapes.</param>
        /// <param name="region">Region that is used to determine the affected shapes.</param>
        /// <param name="affectedArea">Area that results from the affected shapes.</param>
        /// <returns>True, if at least one shape was affected.</returns>
        private bool DoAction(Action <FastDrawnState> action, Envelope region, out Envelope affectedArea)
        {
            bool somethingChanged = false;

            SuspendChanges();
            Extent     affected = new Extent();
            IPolygon   reg      = region.ToPolygon();
            ShapeRange env      = new ShapeRange(region);
            Shape      envShape = new Shape(env.FeatureType)
            {
                Range = env
            };
            IGeometry envGeometry = envShape.ToGeometry();

            for (int shp = 0; shp < _layer.DrawnStates.Length; shp++)
            {
                if (RegionCategory != null && _layer.DrawnStates[shp].Category != RegionCategory)
                {
                    continue;
                }

                bool       doAction = false;
                ShapeRange shape    = _shapes[shp];
                Shape      numShape = new Shape(shape.FeatureType)
                {
                    Range = shape
                };
                IGeometry numGeometry = numShape.ToGeometry();
                switch (SelectionMode)
                {
                case SelectionMode.Intersects:
                    // Prevent geometry creation (which is slow) and use ShapeRange instead
                    //doAction = env.Intersects(shape);
                    doAction = envGeometry.Intersects(numGeometry);
                    break;

                case SelectionMode.IntersectsExtent:
                    doAction = shape.Extent.Intersects(region);
                    break;

                case SelectionMode.ContainsExtent:
                    doAction = shape.Extent.Within(region);
                    break;

                case SelectionMode.Disjoint:
                    if (!shape.Extent.Intersects(region))
                    {
                        doAction = true;
                    }
                    else
                    {
                        IGeometry g = _layer.DataSet.GetFeature(shp).Geometry;
                        doAction = reg.Disjoint(g);
                    }

                    break;
                }

                if (shape.Extent.Intersects(region))
                {
                    IGeometry geom = _layer.DataSet.GetFeature(shp).Geometry;
                    switch (SelectionMode)
                    {
                    case SelectionMode.Contains:
                        doAction = shape.Extent.Within(region) || reg.Contains(geom);
                        break;

                    case SelectionMode.CoveredBy:
                        doAction = reg.CoveredBy(geom);
                        break;

                    case SelectionMode.Covers:
                        doAction = reg.Covers(geom);
                        break;

                    case SelectionMode.Overlaps:
                        doAction = reg.Overlaps(geom);
                        break;

                    case SelectionMode.Touches:
                        doAction = reg.Touches(geom);
                        break;

                    case SelectionMode.Within:
                        doAction = reg.Within(geom);
                        break;
                    }
                }

                if (doAction)
                {
                    action(_layer.DrawnStates[shp]);
                    affected.ExpandToInclude(shape.Extent);
                    somethingChanged = true;
                    OnChanged();
                }
            }

            ResumeChanges();
            affectedArea = affected.ToEnvelope();
            return(somethingChanged);
        }
        /// <summary>
        /// Create search layer
        /// </summary>
        public IEnumerable <IMapPointLayer> Create()
        {
            var ext = new Extent();

            Debug.WriteLine("Starting Create method");
            if (!_searchResult.ResultItems.Any())
            {
                Debug.WriteLine("Returning new point layer");
                return(new List <IMapPointLayer>());
            }

            Debug.WriteLine("Getting data sites layer...");
            var root = _map.GetDataSitesLayer(true);

            Debug.WriteLine("Done");

            var layersToSelect = new List <MapPointLayer>();
            var result         = new List <IMapPointLayer>();

            Debug.WriteLine("Starting loop, count: " + _searchResult.ResultItems.Count());
            foreach (var item in _searchResult.ResultItems)
            {
                try
                {
                    Debug.WriteLine("creating search result layer");
                    var subResultLayer = CreateSearchResultLayer(item, root);
                    Debug.WriteLine("Done; adding subResultLayer to list of result layers");
                    result.Add(subResultLayer);
                    Debug.WriteLine("Done; adding subResultLayer to root");
                    root.Add(subResultLayer);
                    Debug.WriteLine("Done; adding subResultLayer to layersToSelect");
                    layersToSelect.Add(subResultLayer);
                    Debug.WriteLine("Done with loop iteration");
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Exception: " + e.Message);
                    Debug.WriteLine(e.StackTrace);
                }
            }
            Debug.WriteLine("Loop Done, refreshing map");
            _map.Refresh();
            Debug.WriteLine("Done");

            Debug.WriteLine("Starting another loop");
            //assign the projection again
            foreach (var item in _searchResult.ResultItems)
            {
                item.FeatureSet.Reproject(_map.Projection);
                ext.ExpandToInclude(item.FeatureSet.Extent);
            }
            Debug.WriteLine("Loop done. Now looping through layers: " + root.Layers.Count);
            for (int i = 0; i < root.Layers.Count; i++)
            {
                var layer    = root[i];
                var state    = layersToSelect.Contains(layer);
                var rendItem = layer as IRenderableLegendItem;
                if (rendItem != null)
                {
                    rendItem.IsVisible = state; // force a re-draw in the case where we are talking about layers.
                }
                else
                {
                    layer.Checked = state;
                }
            }
            Debug.WriteLine("End loop");

            ext.ExpandBy(_map.ViewExtents.Width / 100);
            _map.ViewExtents = ext;
            _map.Refresh();

            Debug.WriteLine("Return result");
            return(result);
        }