Example #1
0
        /// <summary>
        /// Selects all of the features whose centroids lie within a given polygon.
        /// </summary>
        /// <remarks>This method searches for all features whose centroids are within the given polygon and updates the
        /// default selection.</remarks>
        /// <param name="mapAlias">MapAlias of the map.</param>
        /// <param name="points">Array of points forming the polygon.</param>
        public virtual void PolygonSelection(string mapAlias, System.Drawing.Point[] points)
        {
            Map map = GetMapObj(mapAlias);

            // Convert them to map coordinates
            MapInfo.Geometry.DPoint [] dpnts = new MapInfo.Geometry.DPoint[points.Length];
            for (int indx = 0; indx < points.Length; indx++)
            {
                map.DisplayTransform.FromDisplay(points[indx], out dpnts[indx]);
            }

            // Create a polygon from these points
            CoordSys dispCSys = map.GetDisplayCoordSys();
            CoordSys geomCSys =
                Session.Current.CoordSysFactory.CreateCoordSys(dispCSys.Type, dispCSys.Datum, dispCSys.Units, dispCSys.OriginLongitude, dispCSys.OriginLatitude, dispCSys.StandardParallelOne, dispCSys.StandardParallelTwo, dispCSys.Azimuth, dispCSys.ScaleFactor, dispCSys.FalseEasting, dispCSys.FalseNorthing, dispCSys.Range, map.Layers.Bounds, dispCSys.AffineTransform);

            MapInfo.Geometry.MultiPolygon mp = new MapInfo.Geometry.MultiPolygon(geomCSys, MapInfo.Geometry.CurveSegmentType.Linear, dpnts);

            // Search and select
            SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWithinGeometry(mp, ContainsType.Centroid);

            Session.Current.Selections.DefaultSelection.Clear();
            IMapLayerFilter _selFilter = MapLayerFilterFactory.FilterForTools(
                map, MapLayerFilterFactory.FilterByLayerType(LayerType.Normal), MapLayerFilterFactory.FilterVisibleLayers(true),
                "MapInfo.Tools.MapToolsDefault.SelectLayers", null);

            ITableEnumerator table = map.Layers.GetTableEnumerator(_selFilter);

            if (table != null)                 // null will be returned is select enabled layer is not visible, thus non-selectable
            {
                Session.Current.Catalog.Search(table, si, Session.Current.Selections.DefaultSelection, ResultSetCombineMode.AddTo);
            }
        }
Example #2
0
        // this is similar to searchwithinscreenrect, but the rect constructed is a map rectangle
        // as opposed to a screen rectangle (try both and see the difference)
        private void menuItemSearchWithinRect_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                System.Drawing.Rectangle rect = mapControl1.Bounds;
                rect.X     += rect.Width / 3;
                rect.Width  = rect.Width / 3;
                rect.Y     += rect.Height / 3;
                rect.Height = rect.Height / 3;
                DRect mapRect = new DRect();

                // use csys and transform of feature layer, because that is the
                // layer we are doing the search on
                FeatureLayer layer = _map.Layers["uscty_1k"] as FeatureLayer;
                layer.DisplayTransform.FromDisplay(rect, out mapRect);
                SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWithinRect(mapRect, layer.CoordSys, ContainsType.Centroid);
                IResultSetFeatureCollection fc = _catalog.Search(layer.Table, si);

                // show search geometry on screen for visual confirmation
                DPoint [] pts = new DPoint[4];
                mapRect.GetCornersOfRect(pts);
                FeatureGeometry g = new MapInfo.Geometry.MultiPolygon(layer.CoordSys, CurveSegmentType.Linear, pts);
                ShowSearchGeometry(g);

                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Example #3
0
        // find cities nearest to center within 3 pixel radius
        private void menuItemMapSearchNearest_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                System.Drawing.Rectangle rect = mapControl1.Bounds;
                System.Drawing.Point     pt   = new System.Drawing.Point(rect.Left, rect.Top);
                pt.X += rect.Width / 2;
                pt.Y += rect.Height / 2;


                SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(_map, pt, 3);
                IResultSetFeatureCollection fc = _catalog.Search("uscty_1k", si);

                rect.X      = pt.X;
                rect.Y      = pt.Y;
                rect.Width  = 0;
                rect.Height = 0;
                rect.Inflate(3, 3);
                // show search geometry on screen for visual confirmation
                MapInfo.Geometry.MultiPolygon p = MapInfo.Mapping.SearchInfoFactory.CreateScreenRect(_map, rect);
                ShowSearchGeometry(p);

                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Example #4
0
        // find cities with 1/3 radius of center
        private void menuItemMapSearchWithinScreenRadius_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                System.Drawing.Rectangle rect = mapControl1.Bounds;
                System.Drawing.Point     pt   = new System.Drawing.Point(rect.Left, rect.Top);
                pt.X += rect.Width / 2;
                pt.Y += rect.Height / 2;
                SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchWithinScreenRadius(_map, pt, rect.Width / 6, 20, ContainsType.Centroid);
                IResultSetFeatureCollection fc = _catalog.Search("uscty_1k", si);

                // show search geometry on screen for visual confirmation
                MapInfo.Geometry.MultiPolygon p = MapInfo.Mapping.SearchInfoFactory.CreateScreenCircle(_map.Layers["temp"] as FeatureLayer, pt, rect.Width / 6, 20);
                ShowSearchGeometry(p);

                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Example #5
0
        // this is similar to searchwithinscreenrect, but the rect constructed is a map rectangle
        // as opposed to a screen rectangle (try both and see the difference)
        private void menuItemSearchWithinRect_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                System.Drawing.Rectangle rect=mapControl1.Bounds;
                rect.X += rect.Width/3;
                rect.Width = rect.Width/3;
                rect.Y += rect.Height/3;
                rect.Height = rect.Height/3;
                DRect mapRect=new DRect();

                // use csys and transform of feature layer, because that is the
                // layer we are doing the search on
                FeatureLayer layer = _map.Layers["uscty_1k"] as FeatureLayer;
                layer.DisplayTransform.FromDisplay(rect, out mapRect);
                SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWithinRect(mapRect, layer.CoordSys, ContainsType.Centroid);
                IResultSetFeatureCollection fc = _catalog.Search(layer.Table, si);

                // show search geometry on screen for visual confirmation
                DPoint []pts = new DPoint[4];
                mapRect.GetCornersOfRect(pts);
                FeatureGeometry g = new MapInfo.Geometry.MultiPolygon(layer.CoordSys, CurveSegmentType.Linear, pts);
                ShowSearchGeometry(g);

                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }