예제 #1
0
        /// <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);
            }
        }
예제 #2
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);
            }
        }
 public OleDbSchemaReader(OleDbConnection connection,
                          ITableEnumerator tableEnumerator           = null,
                          ITableColumnExtractor tableColumnExtractor = null,
                          ITableIndexExtractor tableIndexExtractor   = null)
     : this(new OleDbConnectionWrapper(connection), tableEnumerator, tableColumnExtractor, tableIndexExtractor)
 {
 }
 internal OleDbSchemaReader(
     IOleDbConnectionWrapper connection,
     ITableEnumerator tableEnumerator,
     ITableColumnExtractor tableColumnExtractor,
     ITableIndexExtractor tableIndexExtractor)
 {
     _tableEnumerator      = tableEnumerator ?? new OleDbTableEnumerator(connection);
     _tableColumnExtractor = tableColumnExtractor ?? new OleDbTableColumnExtractor(connection);
     _tableIndexExtractor  = tableIndexExtractor ?? new OleDbTableIndexExtractor(connection);
 }
예제 #5
0
        private void BindOpenedTablesAliasToRepeater()
        {
            ArrayList        aliasList = new ArrayList();
            ITableEnumerator iEnum     = MapInfo.Engine.Session.Current.Catalog.EnumerateTables();

            while (iEnum.MoveNext())
            {
                aliasList.Add(iEnum.Current.Alias);
            }
            Repeater1.DataSource = aliasList;
            Repeater1.DataBind();
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            int n = 0;

            Table []         tables = null;
            ITableEnumerator tenum  = Session.Current.Catalog.EnumerateTables(TableFilterFactory.FilterMappableTables());

            while (tenum.MoveNext())
            {
                n++;
            }
            tables = new Table[n];
            n      = 0;
            foreach (Table t in tenum)
            {
                tables[n++] = t;
            }

            NewMapDlg dlg;

            if (n > 0)
            {
                dlg = new NewMapDlg(tables);
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    // build map using MapTableLoader
                    tables = dlg.SelectedTables;
                    n      = dlg.SelectionCount;
                }
                else
                {
                    return;
                }
            }
            // now build map from tables if any
            Map m;

            if (n == 0)
            {
                m = Session.Current.MapFactory.CreateEmptyMap(null, null, IntPtr.Zero, mapControl1.Size);
            }
            else
            {
                m = Session.Current.MapFactory.Create(IntPtr.Zero, mapControl1.Size, new MapTableLoader(tables));
            }
            SetMap(m);
            UpdateMapComboBox();
        }
예제 #8
0
        /// <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);
            }
        }
예제 #9
0
        /// <summary>
        /// Creates a new SelectTablesDlg object using a list of tables as input.
        /// </summary>
        /// <remarks>None.</remarks>
        /// <param name="tables">List of open tables.</param>
        public SelectTablesDlg(ITableEnumerator tables)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // Populate the table list
            // Add tables to the listbox
            foreach(Table tab in tables) {
                listBoxTables.Items.Add(tab);
            }
            // Set initial selection (first item in list)
            if (listBoxTables.Items.Count > 0)
            {
                listBoxTables.SelectedIndex = 0;
            }
        }
예제 #10
0
        /// <summary>
        /// Creates a new SelectTablesDlg object using a list of tables as input.
        /// </summary>
        /// <remarks>None.</remarks>
        /// <param name="tables">List of open tables.</param>
        public SelectTablesDlg(ITableEnumerator tables)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // Populate the table list
            // Add tables to the listbox
            foreach (Table tab in tables)
            {
                listBoxTables.Items.Add(tab);
            }
            // Set initial selection (first item in list)
            if (listBoxTables.Items.Count > 0)
            {
                listBoxTables.SelectedIndex = 0;
            }
        }
예제 #11
0
        private void mnuCloseTable_Click(object sender, System.EventArgs e)
        {
            Catalog          catalog    = Session.Current.Catalog;
            ITableEnumerator tables     = catalog.EnumerateTables();
            ArrayList        tablesList = new ArrayList();

            while (tables.MoveNext())
            {
                tablesList.Add(tables.Current);
            }
            CloseTableDlg closeTableDlg = new CloseTableDlg();

            closeTableDlg.Items.AddRange(tablesList);
            closeTableDlg.SelectedIndex = 0;
            if (closeTableDlg.ShowDialog() == DialogResult.OK)
            {
                ArrayList   selectedTables = closeTableDlg.SelectedItems;
                IEnumerator tableToClose   = selectedTables.GetEnumerator();
                while (tableToClose.MoveNext())
                {
                    catalog.CloseTable(((MapInfo.Data.Table)tableToClose.Current).Alias);
                }

                // if all the tables were closed, reset the menus
                if (tablesList.Count == selectedTables.Count)
                {
                    // remove the layers from the map so that theme layers get removed
                    RemoveAllMapLayers();

                    mnuCloseTable.Enabled  = false;
                    mnuCloseAll.Enabled    = false;
                    mnuTheme.Enabled       = false;
                    mnuAddTheme.Enabled    = false;
                    mnuRemoveTheme.Enabled = false;
                    mnuModifyTheme.Enabled = false;
                }
            }
        }
예제 #12
0
        /// <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);
            }
        }
예제 #13
0
        /// <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]);
                }
            }
        }