/// <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);
            }
        }
        /// <summary>
        /// Select all features in all visible and selectable layers near a given point using a given pixel tolerance.
        /// </summary>
        /// <remarks>This method searches all features near a given point in all visible and selectable layers and then updates the
        /// default selection.
        /// </remarks>
        /// <param name="mapAlias">MapAlias of the map.</param>
        /// <param name="point">Point in pixels.</param>
        /// <param name="pixelTolerance">Pixel tolerance.</param>
        public void PointSelection(string mapAlias, System.Drawing.Point point, int pixelTolerance)
        {
            Map map = GetMapObj(mapAlias);

            // Do the search and show selections
            SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, point, pixelTolerance);

            (si.SearchResultProcessor as ClosestSearchResultProcessor).Options = ClosestSearchOptions.StopAtFirstMatch;

            MapInfo.Geometry.Distance d = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance(map, pixelTolerance);
            (si.SearchResultProcessor as ClosestSearchResultProcessor).DistanceUnit = d.Unit;
            (si.SearchResultProcessor as ClosestSearchResultProcessor).MaxDistance  = d.Value;

            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);
            }
        }
Beispiel #3
0
        private void DeletePieTheme()
        {
            // Remove previous themes:
            MapLayerEnumerator e = mapControl1.Map.Layers.GetMapLayerEnumerator(MapLayerFilterFactory.FilterByType(typeof(ObjectThemeLayer)));

            while (e.MoveNext())
            {
                mapControl1.Map.Layers.Remove(e.Current);
                e = mapControl1.Map.Layers.GetMapLayerEnumerator(MapLayerFilterFactory.FilterByType(typeof(ObjectThemeLayer)));
            }
        }
        /// <summary>
        /// Get a MultiFeatureCollection containing features in all layers falling into the tolerance of the point.
        /// </summary>
        /// <param name="points">points array</param>
        /// <param name="pixelTolerance">pixel tolerance used when searching</param>
        /// <returns>Returns a MultiResultSetFeatureCollection object</returns>
        protected MultiResultSetFeatureCollection RetrieveInfo(Point[] points, int pixelTolerance)
        {
            if (points.Length != 1)
            {
                return(null);
            }

            MapControlModel model = MapControlModel.GetModelFromSession();

            //get map object from map model
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);

            if (map == null)
            {
                return(null);
            }

            //creat a layer filter to include normal visible layers for searching
            IMapLayerFilter layerFilter = MapLayerFilterFactory.FilterForTools(
                map, MapLayerFilterFactory.FilterByLayerType(LayerType.Normal), MapLayerFilterFactory.FilterVisibleLayers(true),
                "MapInfo.Tools.MapToolsDefault.SelectLayers", null);

            ITableEnumerator tableEnum = map.Layers.GetTableEnumerator(layerFilter);

            //return if there is no valid layer to search
            if (tableEnum == null)
            {
                return(null);
            }

            System.Drawing.Point center = points[0];

            //create a SearchInfo with a point and tolerance
            SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, center, pixelTolerance);

            (si.SearchResultProcessor as ClosestSearchResultProcessor).Options = ClosestSearchOptions.StopAtFirstMatch;
            //retrieve all columns
            si.QueryDefinition.Columns = null;

            MapInfo.Geometry.Distance d = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance(map, pixelTolerance);
            (si.SearchResultProcessor as ClosestSearchResultProcessor).DistanceUnit = d.Unit;
            (si.SearchResultProcessor as ClosestSearchResultProcessor).MaxDistance  = d.Value;


            //do search
            MultiResultSetFeatureCollection mrfc = MapInfo.Engine.Session.Current.Catalog.Search(tableEnum, si);

            return(mrfc);
        }
        /// <summary>
        /// Selects all feature within a given radius.
        /// </summary>
        /// <remarks>This method searches for all features whose centroids are within the given radius and updates the
        /// default selection.</remarks>
        /// <param name="mapAlias">MapAlias of the map.</param>
        /// <param name="center">Center of the circle.</param>
        /// <param name="radius">Radius of the circle.</param>
        public virtual void RadiusSelection(string mapAlias, System.Drawing.Point center, int radius)
        {
            Map map = GetMapObj(mapAlias);

            SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchWithinScreenRadius(map, center, radius, 20, 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);
            }
        }
        /// <summary>
        /// Selects all features within a given rectangle.
        /// </summary>
        /// <remarks>This method searches for all features whose centroids are within the given rectangle and updates the
        /// default selection.</remarks>
        /// <param name="mapAlias">MapAlias of the map.</param>
        /// <param name="point1">First corner of the rectangle.</param>
        /// <param name="point2">Second corner of the rectangle.</param>
        public virtual void RectangleSelection(string mapAlias, System.Drawing.Point point1, System.Drawing.Point point2)
        {
            Map map = GetMapObj(mapAlias);

            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(point1.X, point1.Y, 0, 0);
            rect.Width  = Math.Abs(point2.X - point1.X);
            rect.Height = Math.Abs(point2.Y - point1.Y);

            // Do the search and show selections
            SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchWithinScreenRect(map, rect, 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);
            }
        }
        /// <summary>
        /// Select all feature with given radius but ones selected by the center point.
        /// </summary>
        /// <remarks>This method searches for all features whose centroids are within the given radius but ones selected by the center point and updates the
        /// default selection. This method will clear DefaultSelection if radius is 0 or only one click happened in client side.</remarks>
        /// <param name="mapAlias">MapAlias of the map</param>
        /// <param name="myMap">Map object</param>
        private void RadiusSelection(Map myMap, System.Drawing.Point[] points)
        {
            Session.Current.Selections.DefaultSelection.Clear();

            // just return if it is one point only or first and second points are same.
            if (points.Length == 1 || points[0] == points[1])
            {
                return;
            }

            IMapLayerFilter _selFilter = MapLayerFilterFactory.FilterForTools(
                myMap, MapLayerFilterFactory.FilterByLayerType(LayerType.Normal), MapLayerFilterFactory.FilterVisibleLayers(true),
                "MapInfo.Tools.MapToolsDefault.SelectLayers", null);

            // alias for temp selection object.
            string           tempAlias  = "tempSelection";
            ITableEnumerator iTableEnum = myMap.Layers.GetTableEnumerator(_selFilter);

            if (iTableEnum != null)
            {
                try
                {
                    // Get center and radius
                    System.Drawing.Point center = points[0];
                    int radius = points[1].X;

                    // search within screen radius.
                    SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchWithinScreenRadius(myMap, center, radius, 20, ContainsType.Centroid);
                    Session.Current.Catalog.Search(iTableEnum, si, Session.Current.Selections.DefaultSelection, ResultSetCombineMode.AddTo);

                    // Create the temp selection object.
                    Session.Current.Selections.CreateSelection(tempAlias);

                    // Search nearest the center point.
                    si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(myMap, center, 6);
                    Session.Current.Catalog.Search(iTableEnum, si, Session.Current.Selections[tempAlias], ResultSetCombineMode.AddTo);

                    // Subtract radius selected features from point selected features.
                    IEnumerator iEnum = Session.Current.Selections[tempAlias].GetEnumerator();
                    while (iEnum.MoveNext())
                    {
                        IResultSetFeatureCollection pntCollection = iEnum.Current as IResultSetFeatureCollection;

                        IResultSetFeatureCollection radiusCollection = null;
                        for (int index = 0; index < Session.Current.Selections.DefaultSelection.Count; index++)
                        {
                            // Need to find out the IResultSetFeatureCollection based on the same BaseTable.
                            if (Session.Current.Selections.DefaultSelection[index].BaseTable.Alias == pntCollection.BaseTable.Alias)
                            {
                                radiusCollection = Session.Current.Selections.DefaultSelection[index];
                                break;
                            }
                        }
                        if (radiusCollection != null)
                        {
                            // Remove features in pntCollection from radiusCollection.
                            radiusCollection.Remove(pntCollection);
                        }
                    }
                }
                catch (Exception)
                {
                    Session.Current.Selections.DefaultSelection.Clear();
                }
                finally
                {
                    Session.Current.Selections.Remove(Session.Current.Selections[tempAlias]);
                }
            }
        }