/// <summary>
        ///
        /// </summary>
        /// <param name="envelope"></param>
        /// <param name="rectangle"></param>
        /// <returns></returns>
        public static int DetermineZoomLevel(Envelope envelope, Rectangle rectangle)
        {
            double metersAcross = EarthRadiusKms * envelope.Width * Math.PI / 180; //find the arc length represented by the displayed map
            metersAcross *= Math.Cos(envelope.Center().Y * Math.PI / 180); //correct for the center latitude

            double metersAcrossPerPixel = metersAcross / rectangle.Width; //find the resolution in meters per pixel

            //find zoomlevel such that metersAcrossPerPix is close
            for (int i = 2; i < 19; i++)
            {
                double groundRes = GroundResolution(envelope.Center().Y, i);

                if (metersAcrossPerPixel > groundRes)
                {
                    //System.Diagnostics.Debug.WriteLine("metersPerPixel: " + metersAcrossPerPixel);
                    //System.Diagnostics.Debug.WriteLine("groundRes:      " + groundRes);
                    //double ratio = metersAcrossPerPixel / groundRes;
                    //System.Diagnostics.Debug.WriteLine("ratio: " + ratio);

                    //fix zoom level..
                    //changed to a slightly lower zoom level to increase readability
                    if (i > 2 && i < 18) return i - 1;

                    ////MessageBox.Show("MAPP: "+metersAcrossPerPixel+" , zoom: "+(i-1));
                    return i;
                }
            }

            return -1;
        }
Beispiel #2
0
 public Tile(int x, int y, int zoomLevel, Envelope envelope, Bitmap bitmap)
 {
     X = x;
     Y = y;
     ZoomLevel = zoomLevel;
     Envelope = envelope;
     Bitmap = bitmap;
 }
        /// <summary>
        /// Generates a new envelope based on the extents of this shapefile.
        /// </summary>
        /// <returns>An Envelope</returns>
        public static IEnvelope ToEnvelope(this ShapefileHeader header)
        {
            if (header == null) throw new ArgumentNullException("header");

            var env = new Envelope(header.Xmin, header.Xmax, header.Ymin, header.Ymax, header.Zmin, header.Zmax);
            env.Minimum.M = header.Mmin;
            env.Maximum.M = header.Mmax;
            return env;
        }
Beispiel #4
0
        private static void ExpandEnv(Envelope env, SqlGeometry geom)
        {
            for (int i = 0, c = geom.STNumPoints().Value; i < c; i++)
            {
                SqlGeometry geomPoint = geom.STPointN(i + 1);

                env.ExpandToInclude(geomPoint.STX.Value, geomPoint.STY.Value);
            }
        }
Beispiel #5
0
 private Bitmap GetTile(int x, int y, Envelope envelope, int zoom)
 {
     Bitmap bm;
     try
     {
         bm = _serviceProvider.GetBitmap(x, y, envelope, zoom) ?? Resources.nodata;
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         bm = Resources.nodata;
     }
     return bm;
 }
        public override Bitmap GetBitmap(int x, int y, Envelope envelope, int zoom)
        {
            try
            {
                var url = _url;
                if (url == null)
                {
                    return null;
                }

                if (url.Contains("{key}"))
                {
                    var quadKey = TileCalculator.TileXYToBingQuadKey(x, y, zoom);
                    url = url.Replace("{key}", quadKey);
                }
                else
                {
                    url = url.Replace("{zoom}", zoom.ToString(CultureInfo.InvariantCulture));
                    url = url.Replace("{x}", x.ToString(CultureInfo.InvariantCulture));
                    url = url.Replace("{y}", y.ToString(CultureInfo.InvariantCulture));
                }

                using (var client = new WebClient())
                {
                    var stream = client.OpenRead(url);
                    if (stream != null)
                    {
                        var bitmap = new Bitmap(stream);
                        stream.Flush();
                        stream.Close();
                        return bitmap;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is WebException ||
                    ex is TimeoutException)
                {
                    return ExceptionToBitmap(ex, 256, 256);
                }
                Debug.WriteLine(ex.Message);
            }

            return null;
        }
        public override Bitmap GetBitmap(int x, int y, Envelope envelope, int zoom)
        {
            var ts = TileSource;
            if (ts == null) return null;

            var zoomS = zoom.ToString(CultureInfo.InvariantCulture);
            try
            {
                var index = new TileIndex(x, y, zoom.ToString(CultureInfo.InvariantCulture));
                var tc = TileCache;
                var bytes = tc != null ? tc.Find(index) : null;
                if (bytes == null)
                {
                    var mapVertices = new[]
                    {
                        envelope.TopLeft().X, envelope.TopLeft().Y,
                        envelope.BottomRight().X, envelope.BottomRight().Y
                    };
                    double[] viewExtentZ = { 0.0, 0.0 };
                    Reproject.ReprojectPoints(mapVertices, viewExtentZ, Wgs84Proj, _data.CrsProjectionInfo, 0, mapVertices.Length / 2);
                    var geogEnv = new Envelope(mapVertices[0], mapVertices[2], mapVertices[1], mapVertices[3]);
                    bytes = ts.Provider.GetTile(new TileInfo {Extent = ToBrutileExtent(geogEnv), Index = index});
                    var bm = new Bitmap(new MemoryStream(bytes));
                    if (tc != null)
                    {
                        tc.Add(index, bytes);
                    }
                    return bm;
                }
                return new Bitmap(new MemoryStream(bytes));
            }
            catch (Exception ex)
            {
                if (ex is WebException ||
                    ex is TimeoutException)
                {
                    return ExceptionToBitmap(ex, TileSource.Schema.GetTileWidth(zoomS), TileSource.Schema.GetTileHeight(zoomS));
                }
                Debug.WriteLine(ex.Message);
            }
            return null;
        }
        public override Bitmap GetBitmap(int x, int y, Envelope envelope, int zoom)
        {
            var ts = TileSource;
            if (ts == null) return null;

            var zoomS = zoom.ToString(CultureInfo.InvariantCulture);
            try
            {
                var index = new TileIndex(x, y, zoomS);
                var tc = TileCache;
                var bytes = tc != null ? tc.Find(index) : null;
                if (bytes == null)
                {
                    var extent = ToBrutileExtent(envelope);
                    var tileInfo = ts.Schema.GetTilesInView(extent, zoomS).FirstOrDefault();
                    if (tileInfo == null)
                    {
                        return null;
                    }
                    tileInfo.Index = index;
                    bytes = ts.Provider.GetTile(tileInfo);
                    var bm = new Bitmap(new MemoryStream(bytes));
                    if (tc != null)
                    {
                        tc.Add(index, bytes);
                    }
                    return bm;
                }
                return new Bitmap(new MemoryStream(bytes));
            }
            catch (Exception ex)
            {
                if (ex is WebException ||
                    ex is TimeoutException)
                {
                    return ExceptionToBitmap(ex, TileSource.Schema.GetTileWidth(zoomS), TileSource.Schema.GetTileHeight(zoomS));
                }
                Debug.WriteLine(ex.Message);
            }
            return null;
        }
Beispiel #9
0
        public Tile[,] GetTiles(Envelope envelope, Rectangle bounds)
        {
            Coordinate mapTopLeft = envelope.TopLeft();
            Coordinate mapBottomRight = envelope.BottomRight();

            //Clip the coordinates so they are in the range of the web mercator projection
            mapTopLeft.Y = TileCalculator.Clip(mapTopLeft.Y, TileCalculator.MinLatitude, TileCalculator.MaxLatitude);
            mapTopLeft.X = TileCalculator.Clip(mapTopLeft.X, TileCalculator.MinLongitude, TileCalculator.MaxLongitude);

            mapBottomRight.Y = TileCalculator.Clip(mapBottomRight.Y, TileCalculator.MinLatitude, TileCalculator.MaxLatitude);
            mapBottomRight.X = TileCalculator.Clip(mapBottomRight.X, TileCalculator.MinLongitude, TileCalculator.MaxLongitude);

            int zoom = TileCalculator.DetermineZoomLevel(envelope, bounds);

            Point topLeftTileXY = TileCalculator.LatLongToTileXY(mapTopLeft, zoom);
            Point btmRightTileXY = TileCalculator.LatLongToTileXY(mapBottomRight, zoom);

            var tileMatrix = new Tile[(int)(btmRightTileXY.X - topLeftTileXY.X) + 1, (int)(btmRightTileXY.Y - topLeftTileXY.Y) + 1];

            Parallel.For((int) topLeftTileXY.Y, (int) btmRightTileXY.Y + 1,
                         y => Parallel.For((int) topLeftTileXY.X, (int) btmRightTileXY.X + 1,
                                           x =>
                                               {
                                                   var currTopLeftPixXY = TileCalculator.TileXYToTopLeftPixelXY(x, y);
                                                   var currTopLeftCoord =TileCalculator.PixelXYToLatLong((int) currTopLeftPixXY.X,
                                                                                       (int) currTopLeftPixXY.Y, zoom);

                                                   var currBtmRightPixXY = TileCalculator.TileXYToBottomRightPixelXY(x,
                                                                                                                     y);
                                                   var currBtmRightCoord =TileCalculator.PixelXYToLatLong((int) currBtmRightPixXY.X,
                                                                                       (int) currBtmRightPixXY.Y, zoom);

                                                   var currEnv = new Envelope(currTopLeftCoord, currBtmRightCoord);

                                                   var tile = GetTile(x, y, currEnv, zoom);
                                                   tileMatrix[x - (int) topLeftTileXY.X, y - (int) topLeftTileXY.Y] =tile;
                                               }
                                  ));

            return tileMatrix;
        }
        public ShapefileReader(string path, IGeometryFactory geometryFactory = null, GeometryTransform transform = null)
        {
            _gf = geometryFactory ?? new GeometryFactory();
            _reader = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read));
            ShapeHeader = ShapefileHeader.Read(_reader);
            ShapeEnvelope = new Envelope();

            switch (ShapeHeader.ShapeType)
            {
                case ShapefileGeometryType.Point:
                case ShapefileGeometryType.PointZ:
                    _shapeFunc = ReadPoint;
                    break;
                case ShapefileGeometryType.PolyLine:
                case ShapefileGeometryType.PolyLineZ:
                    _shapeFunc = ReadPolyLine;
                    break;
                case ShapefileGeometryType.Polygon:
                case ShapefileGeometryType.PolygonZ:
                    _shapeFunc = ReadPolygon;
                    break;
                case ShapefileGeometryType.MultiPoint:
                case ShapefileGeometryType.MultiPointZ:
                    _shapeFunc = ReadMultiPoint;
                    break;
                default:
                    throw new Exception("Shape type is not supported");
            }

            if (transform != null)
            {
                _transform = transform;

                Func<IGeometry> origFun = _shapeFunc;
                _shapeFunc = () =>
                {
                    return _transform.Apply(origFun());
                };
            }
        }
Beispiel #11
0
        public Tiles GetTiles(Envelope envelope, Rectangle bounds, BackgroundWorker bw)
        {
            var mapTopLeft = envelope.TopLeft();
            var mapBottomRight = envelope.BottomRight();

            //Clip the coordinates so they are in the range of the web mercator projection
            mapTopLeft.Y = TileCalculator.Clip(mapTopLeft.Y, TileCalculator.MinLatitude, TileCalculator.MaxLatitude);
            mapTopLeft.X = TileCalculator.Clip(mapTopLeft.X, TileCalculator.MinLongitude, TileCalculator.MaxLongitude);

            mapBottomRight.Y = TileCalculator.Clip(mapBottomRight.Y, TileCalculator.MinLatitude, TileCalculator.MaxLatitude);
            mapBottomRight.X = TileCalculator.Clip(mapBottomRight.X, TileCalculator.MinLongitude, TileCalculator.MaxLongitude);

            var zoom = TileCalculator.DetermineZoomLevel(envelope, bounds);

            var topLeftTileXY = TileCalculator.LatLongToTileXY(mapTopLeft, zoom);
            var btmRightTileXY = TileCalculator.LatLongToTileXY(mapBottomRight, zoom);

            var tileMatrix = new Bitmap[(int)(btmRightTileXY.X - topLeftTileXY.X) + 1, (int)(btmRightTileXY.Y - topLeftTileXY.Y) + 1];
            var po = new ParallelOptions { MaxDegreeOfParallelism = -1 };
            Parallel.For((int)topLeftTileXY.Y, (int)btmRightTileXY.Y + 1, po,
                         (y, loopState) => Parallel.For((int)topLeftTileXY.X, (int)btmRightTileXY.X + 1, po,
                                           (x, loopState2) =>
                                           {
                                               if (bw.CancellationPending)
                                               {
                                                   loopState.Stop();
                                                   loopState2.Stop();
                                                   return;
                                               }
                                               var currEnv = GetTileEnvelope(x, y, zoom);
                                               tileMatrix[x - (int)topLeftTileXY.X, y - (int)topLeftTileXY.Y] = GetTile(x, y, currEnv, zoom);
                                           }
                                  ));

            return new Tiles(tileMatrix,
                GetTileEnvelope((int)topLeftTileXY.X, (int)topLeftTileXY.Y, zoom),  // top left tile = tileMatrix[0,0]
                GetTileEnvelope((int)btmRightTileXY.X, (int)btmRightTileXY.Y, zoom) // bottom right tile = tileMatrix[last, last]
                );
        }
Beispiel #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="envelope"></param>
        /// <param name="rectangle"></param>
        /// <returns></returns>
        public static int DetermineZoomLevel(Envelope envelope, Rectangle rectangle)
        {
            double metersAcross = EarthRadiusKms * envelope.Width * Math.PI / 180; //find the arc length represented by the displayed map
            metersAcross *= Math.Cos(envelope.Center().Y * Math.PI / 180); //correct for the center latitude

            double metersAcrossPerPixel = metersAcross / rectangle.Width; //find the resolution in meters per pixel

            //find zoomlevel such that metersAcrossPerPix is close
            for (int i = 2; i < 19; i++)
            {
                double groundRes = GroundResolution(envelope.Center().Y, i);

                if (metersAcrossPerPixel > groundRes)
                {
                    //fix zoom level..
                    //changed to a slightly lower zoom level to increase readability
                    if (i > 2 && i < 18) return i - 1;
                    return i;
                }
            }

            return -1;
        }
Beispiel #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="envelope"></param>
        /// <param name="zoom"></param>
        /// <returns></returns>
        public Tile GetTile(int x, int y, Envelope envelope, int zoom)
        {
            Bitmap bitmap = _tileCache.Get(zoom, x, y);
            if (null == bitmap)
            {
                bitmap = GetViaBrutile(x, y, zoom, envelope);
            }
            if (null != bitmap)
            {
                var tile = new Tile(x, y, zoom, envelope, bitmap);
                return tile;
            }
            try
            {
                string url = _tileServerUrl;

                if (url.Contains("{key}"))
                {
                    string quadKey = TileCalculator.TileXYToBingQuadKey(x, y, zoom);
                    url = url.Replace("{key}", quadKey);
                }
                else
                {
                    url = url.Replace("{zoom}", zoom.ToString());
                    url = url.Replace("{x}", x.ToString());
                    url = url.Replace("{y}", y.ToString());
                }

                var client = new WebClient();
                var stream = client.OpenRead(url);

                if (stream != null)
                    bitmap = new Bitmap(stream);

                var tile = new Tile(x, y, zoom, envelope, bitmap);

                if (stream != null)
                {
                    stream.Flush();
                    stream.Close();
                }

                //Put the tile in the cache
                _tileCache.Put(tile);

                return tile;
            }
            catch (Exception ex)
            {
                // We may see a 400 (Bad Request) when the user is zoomed in too far.
                Debug.WriteLine(ex.Message);

                //Return a No Data Available tile
                var noDataTile = new Tile(x, y, zoom, envelope, resources.NoDataTile);

                return noDataTile;
            }
        }
Beispiel #14
0
 /// <summary>
 /// Deselect all features in all layers
 /// </summary>
 private void DeselectAll_Click(object sender, EventArgs e)
 {
     IEnvelope env = new Envelope();
     App.Map.MapFrame.ClearSelection(out env);
     
     //foreach (IMapLayer layer in App.Map.MapFrame.GetAllLayers())
     //{
     //    IMapFeatureLayer mapFeatureLayer = layer as IMapFeatureLayer;
     //    {
     //        mapFeatureLayer.UnSelectAll();
     //    }
     //}
 }
        /// <summary>
        /// Handles the Mouse Up situation
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseUp(GeoMouseArgs e)
        {
            if (Map == null) Map = e.Map;
            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.ViewExtents.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 Point(e.X - 4, e.Y - 4));
                Coordinate c2 = e.Map.PixelToProj(new Point(e.X + 4, e.Y + 4));
                tolerant = new Envelope(c1, c2);
            }

            former = null;
            foreach (var l in Map.MapFrame.GetAllLayers())
            {
                if (l.IsSelected)
                {
                    former = l;
                    l.IsSelected = false;
                }
            }
            if (former == null && Map.MapFrame.IsSelected)
            {
                former = Map.MapFrame;
            }
            Map.MapFrame.IsSelected = true;
            Map.MapFrame.SuspendEvents();
            HandleSelection(tolerant, env);
            Map.MapFrame.IsSelected = false;
            if (former != null)
            {
                former.IsSelected = true;
            }
            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);
            Map.IsBusy = false;
        }
 private IEnvelope GetEnvelope()
 {
     IEnvelope env = new Envelope();
     foreach (IFeature f in this)
     {
         env.ExpandToInclude(f.Envelope);
     }
     return env;
 }
        /// <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 == SelectionMode.IntersectsExtent)
                {
                    if (region.Intersects(f.Envelope))
                    {
                        kvp.Value.IsSelected = !kvp.Value.IsSelected;
                        affectedArea.ExpandToInclude(f.Envelope);
                    }
                }
                else if (SelectionMode == SelectionMode.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 SelectionMode.Contains:
                        if (region.Intersects(f.Envelope))
                        {
                            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.Disjoint:
                        if (reg.Disjoint(geom)) doFlip = true;
                        break;
                    case SelectionMode.Intersects:
                        if (region.Intersects(f.Envelope))
                        {
                            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)
                {
                    flipped = true;
                    kvp.Value.IsSelected = !kvp.Value.IsSelected;
                    affectedArea.ExpandToInclude(f.Envelope);
                }
            }
            ResumeChanges();
            return flipped;
        }
Beispiel #18
0
 /// <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 that is tolerant for point or linestrings.</param>
 /// <param name="strict">The tight envelope to use for polygons.</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, SelectionMode mode, out IEnvelope affectedArea)
 {
     affectedArea = new Envelope();
     if (MapFrame == null) return false;
     return MapFrame.UnSelect(tolerant, strict, mode, out affectedArea);
 }
Beispiel #19
0
        /// <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 features 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="selectionMode">
        /// The SelectionModes enumeration that clarifies how the features should
        /// interact with the region.
        /// </param>
        /// <param name="affectedArea">
        /// The geographic region that will be impacted by the changes.
        /// </param>
        /// <returns>
        /// The invert selection.
        /// </returns>
        public override bool InvertSelection(IEnvelope tolerant, IEnvelope strict, SelectionMode selectionMode,
                                             out IEnvelope affectedArea)
        {
            if (!_drawnStatesNeeded && !_editMode)
            {
                AssignFastDrawnStates();
            }

            IEnvelope region = tolerant;
            if (DataSet.FeatureType == FeatureType.Polygon)
            {
                region = strict;
            }

            affectedArea = new Envelope();
            bool changed = false;

            _selection.SelectionMode = selectionMode;
            if (IsWithinLegendSelection() || _scheme.IsWithinLegendSelection())
            {
                changed = _selection.InvertSelection(region, out affectedArea);
            }
            else
            {
                if (!_drawnStatesNeeded)
                {
                    AssignFastDrawnStates();
                }

                SuspendChangeEvent();
                _selection.SuspendChanges();
                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;
                }

                _selection.ResumeChanges();
                ResumeChangeEvent();
            }

            return changed;
        }
Beispiel #20
0
 /// <summary>
 /// Test the point q to see whether it intersects the Envelope
 /// defined by p1-p2.
 /// </summary>
 /// <param name="p1">One extremal point of the envelope.</param>
 /// <param name="p2">Another extremal point of the envelope.</param>
 /// <param name="q">Point to test for intersection.</param>
 /// <returns><c>true</c> if q intersects the envelope p1-p2.</returns>
 public static bool Intersects(Coordinate p1, Coordinate p2, Coordinate q)
 {
     Envelope env = new Envelope(p1, p2);
     return env.Intersects(q);
 }
Beispiel #21
0
 /// <summary>
 /// Test the envelope defined by p1-p2 for intersection
 /// with the envelope defined by q1-q2
 /// </summary>
 /// <param name="p1">One extremal point of the envelope Point.</param>
 /// <param name="p2">Another extremal point of the envelope Point.</param>
 /// <param name="q1">One extremal point of the envelope Q.</param>
 /// <param name="q2">Another extremal point of the envelope Q.</param>
 /// <returns><c>true</c> if Q intersects Point</returns>
 public static bool Intersects(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2)
 {
     Envelope a = new Envelope(p1, p2);
     Envelope b = new Envelope(q1, q2);
     return a.Intersects(b);
 }
Beispiel #22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="point"></param>
 /// <param name="envelope"></param>
 /// <param name="zoom"></param>
 /// <returns></returns>
 public Tile GetTile(Point point, Envelope envelope, int zoom)
 {
     return GetTile((int)point.X, (int)point.Y, envelope, zoom);
 }
Beispiel #23
0
 /// <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);
 }
Beispiel #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="coord"></param>
        /// <param name="zoom"></param>
        /// <returns></returns>
        public Tile GetTileFromLatLong(Coordinate coord, int zoom)
        {
            var tileXY = TileCalculator.LatLongToTileXY(coord, zoom);

            //Figure out the extent of the tile so that it can be made into MWImageData
            var tileTopLeftXY = TileCalculator.TileXYToTopLeftPixelXY((int)tileXY.X, (int)tileXY.Y);
            var tileBottomRightXY = TileCalculator.TileXYToTopLeftPixelXY((int)tileXY.X + 1, (int)tileXY.Y + 1);

            var tileTopLeft = TileCalculator.PixelXYToLatLong((int)tileTopLeftXY.X, (int)tileTopLeftXY.Y, zoom);
            var tileBottomRight = TileCalculator.PixelXYToLatLong((int)tileBottomRightXY.X, (int)tileBottomRightXY.Y, zoom);

            var envelope = new Envelope(tileTopLeft, tileBottomRight);

            return GetTile(tileXY, envelope, zoom);
        }
        /// <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 == SelectionMode.IntersectsExtent)
                {
                    if (region.Intersects(f.Envelope))
                    {
                        Add(f);
                        affectedArea.ExpandToInclude(f.Envelope);
                        added = true;
                    }
                }
                else if (_selectionMode == SelectionMode.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 SelectionMode.Contains:
                        if (region.Contains(f.Envelope))
                        {
                            doAdd = true;
                        }
                        else if (region.Intersects(f.Envelope))
                        {
                            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.Disjoint:
                        if (reg.Disjoint(geom)) doAdd = true;
                        break;
                    case SelectionMode.Intersects:

                        if (region.Contains(f.Envelope))
                        {
                            doAdd = true;
                        }
                        else if (region.Intersects(f.Envelope))
                        {
                            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)
                {
                    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;
        }
Beispiel #26
0
 public virtual Bitmap GetBitmap(int x, int y, Envelope envelope, int zoom)
 {
     return null;
 }
        /// <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 == SelectionMode.IntersectsExtent)
                {
                    if (region.Intersects(f.Envelope))
                    {
                        if (Remove(f))
                        {
                            removed = true;
                            affectedArea.ExpandToInclude(f.Envelope);
                        }
                    }
                }
                else if (_selectionMode == SelectionMode.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 SelectionMode.Contains:
                        if (region.Intersects(f.Envelope))
                        {
                            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.Disjoint:
                        if (reg.Disjoint(geom)) doRemove = true;
                        break;
                    case SelectionMode.Intersects:
                        if (region.Intersects(f.Envelope))
                        {
                            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)
                {
                    if (Remove(f))
                    {
                        affectedArea.ExpandToInclude(f.Envelope);
                        removed = true;
                    }
                }
            }
            ResumeChanges();
            return removed;
        }
Beispiel #28
0
 /// <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);
 }
Beispiel #29
0
 /// <summary>
 /// Generates a new envelope based on the extents of this shapefile.
 /// </summary>
 /// <returns>An Envelope</returns>
 public IEnvelope ToEnvelope()
 {
     IEnvelope env = new Envelope(_xMin, _xMax, _yMin, _yMax, Zmin, Zmax);
     env.Minimum.M = _mMin;
     env.Maximum.M = _mMax;
     return env;
 }
Beispiel #30
0
 /// <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);
 }