Exemplo n.º 1
0
        public void UseShapefileFeaturesAdFeatureCoverageSource()
        {
            string path =
                Path.Combine(sharpMapGisShapeFilePath, "rivers.shp");
            ShapeFile shapeFile = new ShapeFile(path);

            // select only some features from shapefile
            IEnvelope coverageFeatureEnvelope = shapeFile.GetExtents();

            coverageFeatureEnvelope.ExpandBy(0.5, 0.5);

            var coverage = new FeatureCoverage();

            coverage.Components.Add(new Variable <double>("value"));
            coverage.Arguments.Add(new Variable <Feature>("feature"));
            coverage.Features = new EventedList <IFeature>(shapeFile.Features.Cast <IFeature>());
            coverage.FeatureVariable.AddValues(coverage.Features);

            double[] values = new double[coverage.FeatureVariable.Values.Count];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = i;
            }

            coverage.SetValues(values);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Zooms to the extents of all layers
        /// Adds an extra 10 % marge to each border
        /// </summary>
        public virtual void ZoomToExtents()
        {
            IEnvelope boundingBox = GetExtents();

            if (null == boundingBox)
            {
                return;
            }
            boundingBox = (IEnvelope)boundingBox.Clone();
            // beware of true 1d networks
            if ((boundingBox.Width < 1.0e-6) && (boundingBox.Height < 1.0e-6))
            {
                return;
            }
            double minX = 0.0;
            double minY = 0.0;

            if (boundingBox.Width < 1.0e-6)
            {
                minX = 1.0;
            }
            if (boundingBox.Height < 1.0e-6)
            {
                minY = 1.0;
            }
            boundingBox.ExpandBy(minX + boundingBox.Width / 10, minY + boundingBox.Height / 10);
            ZoomToBox(boundingBox);
        }
Exemplo n.º 3
0
        private void ZoomToLayer(IMapLayer layerToZoom)
        {
            const double eps           = 1e-7;
            IEnvelope    layerEnvelope = layerToZoom.Extent.ToEnvelope();

            if (layerEnvelope.Width > eps && layerEnvelope.Height > eps)
            {
                layerEnvelope.ExpandBy(layerEnvelope.Width / 10, layerEnvelope.Height / 10); // work item #84
            }
            else
            {
                double zoomInFactor    = 0.05; //fixed zoom-in by 10% - 5% on each side
                double newExtentWidth  = App.Map.ViewExtents.Width * zoomInFactor;
                double newExtentHeight = App.Map.ViewExtents.Height * zoomInFactor;
                layerEnvelope.ExpandBy(newExtentWidth, newExtentHeight);
            }

            App.Map.ViewExtents = layerEnvelope.ToExtent();
        }
Exemplo n.º 4
0
        private void ZoomSelected_Click(object sender, EventArgs e)
        {
            const double distanceX = 2;
            const double distanceY = 2;
            const double EPS       = 1e-7;

            IEnvelope envelope = null;

            foreach (var layer in ((Map)App.Map).GetAllLayers())
            {
                var featureLayer = layer as IFeatureLayer;
                if (featureLayer == null || !featureLayer.Checked || featureLayer.Selection.Count == 0)
                {
                    continue;
                }

                var env = featureLayer.Selection.Envelope;
                envelope = envelope == null ? env : envelope.Union(env);
            }
            if (envelope == null)
            {
                return;
            }

            if (Math.Abs(envelope.Width - 0) < EPS || Math.Abs(envelope.Height - 0) < EPS)
            {
                envelope.ExpandBy(distanceX, distanceY);
            }

            if (envelope.Width > EPS && envelope.Height > EPS)
            {
                envelope.ExpandBy(envelope.Width / 10, envelope.Height / 10); // work item #84
            }
            else
            {
                const double zoomInFactor    = 0.05; //fixed zoom-in by 10% - 5% on each side
                var          newExtentWidth  = App.Map.ViewExtents.Width * zoomInFactor;
                var          newExtentHeight = App.Map.ViewExtents.Height * zoomInFactor;
                envelope.ExpandBy(newExtentWidth, newExtentHeight);
            }

            App.Map.ViewExtents = envelope.ToExtent();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Expands the given boundingBox by percentage.
        /// </summary>
        /// <param name="boundingBox">Boundingbox to expand</param>
        /// <param name="percentage">Percentage by which boundingBox is expanded</param>
        private static void AddMargin(IEnvelope boundingBox, double percentage)
        {
            double minX = 0.0;
            double minY = 0.0;

            if (boundingBox.Width < 1.0e-6)
            {
                minX = 1.0;
            }
            if (boundingBox.Height < 1.0e-6)
            {
                minY = 1.0;
            }

            var factor = percentage / 200;//factor is used left and right so divide by 200 (iso 100)

            boundingBox.ExpandBy(minX + boundingBox.Width * factor, minY + boundingBox.Height * factor);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Expands the given boundingBox by percentage.
        /// </summary>
        /// <param name="boundingBox">Boundingbox to expand</param>
        /// <param name="percentage">Percentage by which boundingBox is expanded</param>
        private static void AddMargin(IEnvelope boundingBox, double percentage)
        {
            double minX = 0.0;
            double minY = 0.0;

            if (boundingBox.Width < 1.0e-6)
            {
                minX = 1.0;
            }
            if (boundingBox.Height < 1.0e-6)
            {
                minY = 1.0;
            }

            var factor = percentage / 100;

            boundingBox.ExpandBy(minX + boundingBox.Width * factor, minY + boundingBox.Height * factor);
        }
Exemplo n.º 7
0
        private void MapImage_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (_Map != null)
            {
                if (MouseUp != null)
                {
                    MouseUp(this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)), e);
                }

                if (e.Button == MouseButtons.Left)
                {
                    if (this.ActiveTool == Tools.ZoomOut)
                    {
                        double scale = 0.5;
                        if (!mousedragging)
                        {
                            _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_Map.Center);
                            }
                        }
                        else
                        {
                            if (e.Y - mousedrag.Y < 0)                             //Zoom out
                            {
                                scale = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5);
                            }
                            else                             //Zoom in
                            {
                                scale = 1 + (e.Y - mousedrag.Y) * 0.1;
                            }
                        }
                        _Map.Zoom *= 1 / scale;
                        if (MapZoomChanged != null)
                        {
                            MapZoomChanged(_Map.Zoom);
                        }
                        Refresh();
                    }
                    else if (this.ActiveTool == Tools.ZoomIn)
                    {
                        double scale = 2;
                        if (!mousedragging)
                        {
                            _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_Map.Center);
                            }
                        }
                        else
                        {
                            if (e.Y - mousedrag.Y < 0)                             //Zoom out
                            {
                                scale = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5);
                            }
                            else                             //Zoom in
                            {
                                scale = 1 + (e.Y - mousedrag.Y) * 0.1;
                            }
                        }
                        _Map.Zoom *= 1 / scale;
                        if (MapZoomChanged != null)
                        {
                            MapZoomChanged(_Map.Zoom);
                        }
                        Refresh();
                    }
                    else if (this.ActiveTool == Tools.Pan)
                    {
                        if (mousedragging)
                        {
                            System.Drawing.Point pnt = new System.Drawing.Point(this.Width / 2 + (mousedrag.X - e.Location.X), this.Height / 2 + (mousedrag.Y - e.Location.Y));
                            _Map.Center = this._Map.ImageToWorld(pnt);
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_Map.Center);
                            }
                        }
                        else
                        {
                            _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_Map.Center);
                            }
                        }
                        Refresh();
                    }
                    else if (this.ActiveTool == Tools.Query)
                    {
                        if (_Map.Layers.Count > _queryLayerIndex && _queryLayerIndex > -1)
                        {
                            if (_Map.Layers[_queryLayerIndex].GetType() == typeof(SharpMap.Layers.VectorLayer))
                            {
                                SharpMap.Layers.VectorLayer layer = _Map.Layers[_queryLayerIndex] as SharpMap.Layers.VectorLayer;
                                IEnvelope bbox = GeometryFactory.CreatePoint(this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y))).EnvelopeInternal;
                                bbox.ExpandBy(_Map.PixelSize * 5);
                                SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
                                layer.DataSource.Open();
                                layer.DataSource.ExecuteIntersectionQuery(bbox, ds);
                                layer.DataSource.Close();
                                if (ds.Tables.Count > 0)
                                {
                                    if (MapQueried != null)
                                    {
                                        MapQueried(ds.Tables[0]);
                                    }
                                    else
                                    if (MapQueried != null)
                                    {
                                        MapQueried(new SharpMap.Data.FeatureDataTable());
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("No active layer to query");
                        }
                    }
                }
                if (mousedragImg != null)
                {
                    mousedragImg.Dispose();
                    mousedragImg = null;
                }
                mousedragging = false;
            }
        }
Exemplo n.º 8
0
        private void ZoomToLayerEnvelope(IEnvelope layerEnvelope)
        {
            if (_extendBuffer)
            {
                layerEnvelope.ExpandBy(layerEnvelope.Width, layerEnvelope.Height);
            }

            const double eps = 1e-7;
            if (layerEnvelope.Width > eps && layerEnvelope.Height > eps)
            {
                layerEnvelope.ExpandBy(layerEnvelope.Width / 10, layerEnvelope.Height / 10); // work item #84
            }
            else
            {
                double zoomInFactor = 0.05; //fixed zoom-in by 10% - 5% on each side
                double newExtentWidth = ViewExtents.Width * zoomInFactor;
                double newExtentHeight = ViewExtents.Height * zoomInFactor;
                layerEnvelope.ExpandBy(newExtentWidth, newExtentHeight);
            }

            ViewExtents = layerEnvelope.ToExtent();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Expands the given boundingBox by percentage.
        /// </summary>
        /// <param name="boundingBox">Boundingbox to expand</param>
        /// <param name="percentage">Percentage by which boundingBox is expanded</param>
        private static void AddMargin(IEnvelope boundingBox,double percentage)
        {
            double minX = 0.0;
            double minY = 0.0;
            if (boundingBox.Width < 1.0e-6)
            {
                minX = 1.0;
            }
            if (boundingBox.Height < 1.0e-6)
            {
                minY = 1.0;
            }

            var factor = percentage/100;
            boundingBox.ExpandBy(minX + boundingBox.Width * factor, minY + boundingBox.Height * factor);
        }