Ejemplo n.º 1
0
        /// <summary>
        /// Update header extents from the geometries in a IShapeSource
        /// </summary>
        /// <param name="src"></param>
        protected void UpdateExtents(IShapeSource src)
        {
            var    sr  = new ShapeReader(src);
            Extent env = null;

            foreach (var page in sr)
            {
                foreach (var shape in page)
                {
                    Extent shapeExtent = shape.Value.Range.Extent;
                    if (env == null)
                    {
                        env = (Extent)shapeExtent.Clone();
                    }
                    else
                    {
                        env.ExpandToInclude(shapeExtent);
                    }
                }
            }

            // Extents for an empty file are unspecified according to the specification, so do nothing
            if (null == env)
            {
                return;
            }

            var sh = new ShapefileHeader(Filename);

            sh.SetExtent(env);
            sh.Save();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Forces each of the parts to adopt an extent equal to a calculated extents.
        /// The extents for the shape will expand to include those.
        /// </summary>
        public Extent CalculateExtents()
        {
            Extent ext = new Extent();

            foreach (PartRange part in Parts)
            {
                ext.ExpandToInclude(part.CalculateExtent());
            }
            Extent = ext;
            return(ext);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This creates a new extent and cycles through the coordinates to calculate what it is.
        /// Since the vertices may change so easily, this is not cached.
        /// </summary>
        /// <returns></returns>
        public Extent CalculateExtent()
        {
            // Create an extent for faster checking in most cases
            Extent ext = new Extent();

            // Do this once, and then we can re-use it for each other part.
            foreach (Vertex point in this)
            {
                ext.ExpandToInclude(point.X, point.Y);
            }
            return(ext);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This calculates the extent for the category and caches it in the extents collection
        /// </summary>
        /// <param name="category">
        /// </param>
        protected virtual Extent CalculateCategoryExtent(IFeatureCategory category)
        {
            Extent ext = new Extent(new[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue });
            if (_editMode)
            {
                IDictionary<IFeature, IDrawnState> features = _drawingFilter.DrawnStates;

                foreach (IFeature f in DataSet.Features)
                {
                    if (category == features[f].SchemeCategory)
                    {
                        ext.ExpandToInclude(new Extent(f.Envelope));
                    }
                }

                if (_categoryExtents.Keys.Contains(category))
                {
                    _categoryExtents[category] = ext.Copy();
                }
                else
                {
                    _categoryExtents.Add(category, ext.Copy());
                }
            }
            else
            {
                FastDrawnState[] states = DrawnStates;
                List<ShapeRange> ranges = DataSet.ShapeIndices;
                for (int shp = 0; shp < DrawnStates.Length; shp++)
                {
                    if (states[shp].Category != null)
                    {
                        if (!_categoryExtents.ContainsKey(states[shp].Category))
                        {
                            _categoryExtents.Add(states[shp].Category, ranges[shp].Extent.Copy());
                        }
                        else
                        {
                            _categoryExtents[states[shp].Category].ExpandToInclude(ranges[shp].Extent);
                        }
                    }
                }
            }

            return ext;
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        public virtual List<IFeature> Select(Extent region, out Extent affectedRegion)
        {
            var result = new List<IFeature>();
            affectedRegion = new Extent();

            if (IndexMode)
            {
                var aoi = new ShapeRange(region);
                var shapes = ShapeIndices;
                for (var shp = 0; shp < shapes.Count; shp++)
                {
                    if (!shapes[shp].Intersects(aoi))
                    {
                        continue;
                    }

                    var feature = GetFeature(shp);
                    affectedRegion.ExpandToInclude(feature.Envelope.ToExtent());
                    result.Add(feature);
                }
            }
            else
            {
                foreach (var feature in Features)
                {
                    if (!region.Intersects(feature.Envelope) ||
                       !feature.Intersects(region.ToEnvelope()))
                    {
                        continue;
                    }
                  
                    result.Add(feature);
                    affectedRegion.ExpandToInclude(feature.Envelope.ToExtent());
                }
            }

            return result;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// After changing coordinates, this will force the re-calculation of envelopes on a feature
        /// level or test the shapes in index mode to rebuild an Extent.
        /// </summary>
        public void UpdateExtent()
        {
            Extent mx;
            if (Count == 0)
            {
                mx = new Extent(-180, -90, 180, 90);
            }
            else
            {
                mx = new Extent();
                for (var i = 0; i < Count; i++)
                {
                    var extent = GetFeatureExtent(i);
                    mx.ExpandToInclude(extent);
                }
            }

            MyExtent = mx;
        }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        public virtual List<IFeature> Select(Extent region, out Extent affectedRegion)
        {
            List<IFeature> result = new List<IFeature>();
            if (IndexMode)
            {
                ShapeRange aoi = new ShapeRange(region);
                Extent affected = new Extent();
                List<ShapeRange> shapes = ShapeIndices;
                if (shapes != null)
                {
                    //ProgressMeter = new ProgressMeter(ProgressHandler, "Selecting shapes", shapes.Count);
                    for (int shp = 0; shp < shapes.Count; shp++)
                    {
                        //ProgressMeter.Next();
                        if (!shapes[shp].Intersects(aoi))
                        {
                            continue;
                        }

                        IFeature f = GetFeature(shp);
                        affected.ExpandToInclude(shapes[shp].Extent);
                        result.Add(f);
                    }
                    //ProgressMeter.Reset();
                }

                affectedRegion = affected;
                return result;
            }

            affectedRegion = new Extent();

            bool useProgress = (Features.Count > 10000);
            //ProgressMeter = new ProgressMeter(ProgressHandler, "Selecting Features", Features.Count);
            foreach (IFeature feature in Features)
            {
                //if (useProgress)
                //    ProgressMeter.Next();
                if (!region.Intersects(feature.Envelope))
                {
                    continue;
                }
                if (!feature.Intersects(region.ToEnvelope()))
                {
                    continue;
                }
                result.Add(feature);
                affectedRegion.ExpandToInclude(feature.Envelope.ToExtent());
            }
            //if (useProgress)
            //    ProgressMeter.Reset();

            return result;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Forces each of the parts to adopt an extent equal to a calculated extents.
 /// The extents for the shape will expand to include those.
 /// </summary>
 public Extent CalculateExtents()
 {
     Extent ext = new Extent();
     foreach (PartRange part in Parts)
     {
         ext.ExpandToInclude(part.CalculateExtent());
     }
     Extent = ext;
     return ext;
 }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// This creates a new extent and cylces through the coordinates to calculate what it is.
        /// Since the vertices may change so easilly, this is not cached.
        /// </summary>
        /// <returns></returns>
        public Extent CalculateExtent()
        {
            // Create an extent for faster checking in most cases
            Extent ext = new Extent();

            // Do this once, and then we can re-use it for each other part.
            foreach (Vertex point in this)
            {
                ext.ExpandToInclude(point.X, point.Y);
            }
            return ext;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// After changing coordinates, this will force the re-calculation of envelopes on a feature
        /// level or test the shapes in index mode to rebuild an Extent.
        /// </summary>
        public void UpdateExtent()
        {
            MyExtent = new Extent();
            if (!IndexMode)
            {
                if (Features == null || Features.Count <= 0)
                {
                     // jany_ (2015-07-17) return the empty extent because any other extent would result in to big extent when zooming to full map extent
                    return; 
                }

                foreach (IFeature feature in Features)
                {
                    feature.UpdateEnvelope();
                    MyExtent.ExpandToInclude(new Extent(feature.Envelope));
                }
            }
            else
            {
                if (_shapeIndices == null || _shapeIndices.Count == 0)
                {
                    // jany_ (2015-07-17) return the empty extent because any other extent would result in to big extent when zooming to full map extent
                    return;
                }

                foreach (ShapeRange range in _shapeIndices)
                {
                    range.CalculateExtents();
                    MyExtent.ExpandToInclude(range.Extent);
                }
            }
        }
Ejemplo n.º 12
0
        /// <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;
        }