Пример #1
0
        // find and select cities with Georgia and Florida using geometry
        private void menuItemSearchWithinGeometry_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                // find and select cities with Georgia and Florida using geometry
                // also uses search for feature
                Feature                     fFlorida = _catalog.SearchForFeature("usa", MapInfo.Data.SearchInfoFactory.SearchWhere("State='FL'"));
                Feature                     fGeorgia = _catalog.SearchForFeature("usa", MapInfo.Data.SearchInfoFactory.SearchWhere("State='GA'"));
                FeatureGeometry             g        = fFlorida.Geometry.Combine(fGeorgia.Geometry);
                SearchInfo                  si       = MapInfo.Data.SearchInfoFactory.SearchWithinGeometry(g, ContainsType.Centroid);
                IResultSetFeatureCollection fc       = _catalog.Search("uscty_1k", si);
                // set map view to show search results
                _map.SetView(fc.Envelope);

                ShowSearchGeometry(g);

                // show results as selection
                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #2
0
        /// <summary>
        /// method to do the real server side process for info tool.
        /// </summary>
        public override void Process()
        {
            //get pixel tolerance from url of client side.
            int pixelTolerance = System.Convert.ToInt32(HttpContext.Current.Request[PixelToleranceKey]);

            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);

            //extract points from url of client side.
            System.Drawing.Point[] points = ExtractPoints(DataString);

            //do searching and get results back
            MultiResultSetFeatureCollection mrfc = RetrieveInfo(points, pixelTolerance);

            IEnumerator resultEnum = mrfc.GetEnumerator();

            //retrieve the selected feature from collection
            while (resultEnum.MoveNext())
            {
                IResultSetFeatureCollection irfc    = (IResultSetFeatureCollection)resultEnum.Current;
                IFeatureEnumerator          ftrEnum = irfc.GetFeatureEnumerator();

                while (ftrEnum.MoveNext())
                {
                    Feature ftr = (Feature)ftrEnum.Current;
                    //create a html table to display feature info and stream back to client side.
                    CreateInfoTable(ftr);
                    irfc.Close();
                    mrfc.Clear();
                    break;
                }
                break;
            }
        }
Пример #3
0
        // search through all tables to find objects that intersect
        // the states bordering KS
        private void menuItemSearchMultipleTables_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                // find states that intersect KS
                // then combine them and search all layers within
                // also uses search for feature
                Feature    fKS = _catalog.SearchForFeature("usa", MapInfo.Data.SearchInfoFactory.SearchWhere("State='KS'"));
                SearchInfo si  = MapInfo.Data.SearchInfoFactory.SearchIntersectsFeature(fKS, IntersectType.Geometry);
                IResultSetFeatureCollection fc = _catalog.Search("usa", si);

                MapInfo.FeatureProcessing.FeatureProcessor fp = new MapInfo.FeatureProcessing.FeatureProcessor();
                Feature f = fp.Combine(fc);

                si = MapInfo.Data.SearchInfoFactory.SearchWithinFeature(f, ContainsType.Centroid);
                MultiResultSetFeatureCollection mfc = _catalog.Search(_catalog.EnumerateTables(TableFilterFactory.FilterMappableTables()), si);

                // set map view to show search results
                _map.SetView(f);

                ShowSearchGeometry(f.Geometry);

                // show results as selection
                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #4
0
        // find nearest city to center of map
        private void menuItemSearchNearest_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                // to compare to SearchWithinScreenRadius, we are calculating
                // the search distance the same way it does
                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;

                DPoint dpt1 = new DPoint();
                // convert center point to map coords (could use map.Center)
                _map.DisplayTransform.FromDisplay(pt, out dpt1);
                Distance d = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance(_map, 3);

                SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchNearest(dpt1, _map.GetDisplayCoordSys(), d);
                IResultSetFeatureCollection fc = _catalog.Search("uscty_1k", si);

                MapInfo.Geometry.Point p      = new MapInfo.Geometry.Point(_map.GetDisplayCoordSys(), dpt1);
                FeatureGeometry        buffer = p.Buffer(d.Value, d.Unit, 20, DistanceType.Spherical);
                ShowSearchGeometry(buffer);

                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #5
0
        private void menuItemSetColumns_Click(object sender, System.EventArgs e)
        {
            try
            {
                // build up a search info by hand (not using the factory)
                QueryFilter     filter = new SqlExpressionFilter("POP_90 < 1000000");
                QueryDefinition qd     = new QueryDefinition(filter, "MI_Key");

                // to Add Columns
                qd.AppendColumns("State", "MI_Geometry");

                // to set all new set of columns
                // not using MI_Geometry here
                string[] cols = new string[] { "MI_Key", "MI_Style", "State_Name", "POP_90", "Households_90" };
                qd.Columns = cols;

                // Note: if you are doing a multi table search, the columns must apply to each table
                // alternatively, you can derive a new class from QueryDefinition and
                // override the GetColumns() method to return different columns for each table being searched

                SearchInfo si = new SearchInfo(null, qd);

                IResultSetFeatureCollection fc = _catalog.Search("mexico", si);
                // set map view to show search results
                _map.SetView(_map.Layers["mexico"] as FeatureLayer);

                // show results as selection
                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #6
0
        // uses intersect filter to get states that intersect florida
        private void menuItemIntersectFeature_Click(object sender, System.EventArgs e)
        {
            try
            {
                Feature fFlorida = _catalog.SearchForFeature("usa", MapInfo.Data.SearchInfoFactory.SearchWhere("State='FL'"));

                // build up a search info by hand (not using the factory)
                QueryFilter     filter = new  IntersectFilter(fFlorida.Geometry, IntersectType.Bounds);
                QueryDefinition qd     = new QueryDefinition(filter, "*");
                SearchInfo      si     = new SearchInfo(null, qd);

                IResultSetFeatureCollection fc = _catalog.Search("usa", si);
                // set map view to show search results
                _map.SetView(fc.Envelope);

                ShowSearchGeometry(fFlorida.Geometry);

                // show results as selection
                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #7
0
        // uses custom filter to select objects within a distance range from
        // chicago
        private void menuItemCustomQueryFilter_Click(object sender, System.EventArgs e)
        {
            try
            {
                Feature fChicago = _catalog.SearchForFeature("uscty_1k", MapInfo.Data.SearchInfoFactory.SearchWhere("City='Chicago'"));

                // build up a search info by hand (not using the factory)
                Distance        d1     = new Distance(35, DistanceUnit.Mile);
                Distance        d2     = new Distance(125, DistanceUnit.Mile);
                QueryFilter     filter = new  MyCustomFilter(fChicago.Geometry, d1, d2);
                QueryDefinition qd     = new QueryDefinition(filter, "*");
                SearchInfo      si     = new SearchInfo(null, qd);

                IResultSetFeatureCollection fc = _catalog.Search("uscty_1k", si);
                // set map view to show search results
                _map.SetView(fc.Envelope);

                // make a search geometry to show what we are doing
                FeatureGeometry buffer1 = fChicago.Geometry.Buffer(d1.Value, d1.Unit, 20, DistanceType.Spherical);
                FeatureGeometry buffer2 = fChicago.Geometry.Buffer(d2.Value, d2.Unit, 20, DistanceType.Spherical);
                ShowSearchGeometry(buffer1);
                ShowSearchGeometry(buffer2, false);

                // show results as selection
                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #8
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;
            }
        }
Пример #9
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;
            }
        }
Пример #10
0
        // select features in feature collection
        private void SelectFeatureCollection(IResultSetFeatureCollection fc)
        {
            // force map to update
            mapControl1.Update();

            _selection.Clear();
            _selection.Add(fc);
        }
Пример #11
0
 void Tools_FeatureSelected(object sender, FeatureSelectedEventArgs e)
 {
     try
     {
         IResultSetFeatureCollection fSelectCollection = e.Selection[0];
         SelectedFeature = fSelectCollection[0];
     }
     catch
     {
         SelectedFeature = null;
     }
 }
Пример #12
0
 public override bool ProcessRow(MIDataReader reader, IResultSetFeatureCollection features)
 {
     if (_maxRows == 0 || _rowCount < _maxRows)
     {
         features.Add(reader.Current);
     }
     _rowCount++;
     if (_maxRows > 0 && _rowCount >= _maxRows)
     {
         return(false);                                                       // stop processing of this table
     }
     return(true);
 }
Пример #13
0
        //高亮指定地点
        private void SelectPlace(String tName, String sName)
        {
            SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("Name = '" + sName + "'");
            IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(tName, si);

            if (ifs.Count == 1)
            {
                mapControl.Map.SetView(ifs.Envelope);
                mapControl.Map.Scale = mapControl.Map.Scale * 2;
                //缩放到选择图元范围
                //高亮显示
                MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();
                MapInfo.Engine.Session.Current.Selections.DefaultSelection.Add(ifs);
            }
            ifs.Close();
        }
Пример #14
0
        /// <summary>
        /// 搜索附近信息
        /// </summary>
        /// <param name="x">经度</param>
        /// <param name="y">纬度</param>
        /// <param name="layerIndex">图层顺序号</param>
        /// <param name="colname">列名</param>
        /// <param name="distance">默认最大距离</param>
        /// <returns></returns>
        public String SearchNearInfo(double x, double y, int layerIndex, string colname, double distance = 100)
        {
            Point      pSearchPoint = new Point(cs, x, y);
            String     RoadName     = string.Empty;
            SearchInfo si           = MapInfo.Data.SearchInfoFactory.SearchNearest(pSearchPoint, new Distance(distance, DistanceUnit.Meter));

            si.QueryDefinition.Columns = null;
            Table tmpTable = (map.Layers[layerIndex] as FeatureLayer).Table;
            IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(tmpTable, si);

            if (ifs.Count > 0)
            {
                RoadName = ifs[0][colname].ToString();
            }
            return(RoadName);
        }
Пример #15
0
        //查询矩形区域内的地物
        private List <String> GetPlacesInRect(DPoint dpt1, DPoint dpt2, String lName)
        {
            List <String> list = new List <string>();

            try
            {
                MapInfo.Data.SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWithinRect(new DRect(dpt1, dpt2), mapControl.Map.GetDisplayCoordSys(), ContainsType.Centroid);
                si.QueryDefinition.Columns = new string[] { "*" };
                IResultSetFeatureCollection fc = MapInfo.Engine.Session.Current.Catalog.Search(Session.Current.Catalog.GetTable(lName), si);
                foreach (Feature ftr in fc)
                {
                    list.Add(ftr["Name"].ToString());
                }
            }
            catch { }
            return(list);
        }
Пример #16
0
        // find states whre pop 1990 < 4 million
        private void menuItemSearchWhere_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                // find and select all states with pop > 2 million
                SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("POP_90 > 2000000");
                IResultSetFeatureCollection fc = _catalog.Search("mexico", si);
                // set map view to show search results
                _map.SetView(fc.Envelope);

                // show results as selection
                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #17
0
        /// <summary>
        /// Delete a feature in the temporary layer.
        /// </summary>
        /// <param name="mapAlias">MapAlias of the map</param>
        /// <param name="point">Point in pixels</param>
        private void PointDeletion(Map map, System.Drawing.Point point)
        {
            // Do the search and show selections
            SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, point, 10);

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

            Table table = MapInfo.Engine.Session.Current.Catalog[SampleConstants.TempTableAlias];

            if (table != null)
            {
                IResultSetFeatureCollection ifc = Session.Current.Catalog.Search(table, si);
                foreach (Feature f in ifc)
                {
                    table.DeleteFeature(f);
                }
                ifc.Close();
            }
        }
Пример #18
0
        private void Search(string SearchWords)
        {
            //按照关键字查找图元
            Session.Current.Selections.DefaultSelection.Clear();
            bool bFind = false;

            //遍历图层
            foreach (IMapLayer layer in this.mapControl1.Map.Layers)
            {
                if (layer is FeatureLayer)
                {
                    Table tLayer = (layer as FeatureLayer).Table;
                    if (tLayer != null)
                    {
                        //生成查询条件 表中所有字段匹配即可
                        string Where = "0=1";
                        foreach (Column c in (layer as FeatureLayer).Table.TableInfo.Columns)
                        {
                            if ("Obj".Equals(c.Alias) || "MI_Style".Equals(c.Alias))
                            {
                                continue;
                            }
                            Where += " or " + c.Alias + " like '%" + SearchWords + "%'";
                        }
                        //查找
                        SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere(Where);
                        IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(tLayer, si);
                        if (ifs.Count > 0)
                        {
                            //查询结果选中并定位到地图中兴
                            Session.Current.Selections.DefaultSelection.Add(ifs);
                            this.mapControl1.Map.Center = ifs[0].Geometry.Centroid;
                            bFind = true;
                        }
                    }
                }
            }
            if (!bFind)
            {
                MessageBox.Show("未找到查找的内容!");
            }
        }
Пример #19
0
        private void menuItemSqlExpressionFilter_Click(object sender, System.EventArgs e)
        {
            try
            {
                // build up a search info by hand (not using the factory)
                QueryFilter     filter = new SqlExpressionFilter("Buses_91 * 3 < Trucks_91");
                QueryDefinition qd     = new QueryDefinition(filter, "*");
                SearchInfo      si     = new SearchInfo(null, qd);

                IResultSetFeatureCollection fc = _catalog.Search("mexico", si);
                // set map view to show search results
                _map.SetView(fc.Envelope);

                // show results as selection
                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #20
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;
            }
        }
Пример #21
0
        // find states that intersect KS
        private void menuItemSearchIntersectsFeature_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                // find states that intersect KS
                // also uses search for feature
                Feature    fKS = _catalog.SearchForFeature("usa", MapInfo.Data.SearchInfoFactory.SearchWhere("State='KS'"));
                SearchInfo si  = MapInfo.Data.SearchInfoFactory.SearchIntersectsFeature(fKS, IntersectType.Geometry);
                IResultSetFeatureCollection fc = _catalog.Search("usa", si);
                // set map view to show search results
                _map.SetView(fc.Envelope);

                ShowSearchGeometry(fKS.Geometry);

                // show results as selection
                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #22
0
        void Tools_FeatureAdded(object sender, FeatureAddedEventArgs e)
        {
            //MessageBox.Show(e.ClientCoordinate.X.ToString() + "/" + e.ClientCoordinate.Y.ToString());
            //IGeometryEdit iEditG= e.Feature.GetGeometryEditor();
            SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchIntersectsGeometry(e.Feature, IntersectType.Geometry);

            si.QueryDefinition.Columns = new string[] { "*" };// new string[] { "NDH" }; //null
            IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search("JKINFO", si);
            Feature fEdit = ifs[0];

            fEdit.Geometry = new MapInfo.Geometry.Point(mapControl1.Map.GetDisplayCoordSys(), ConvertTOJWDu(e.ClientCoordinate));
            fEdit.Table.UpdateFeature(fEdit);
            //FeatureLayer flayer = (FeatureLayer)mapControl1.Map.Layers["JKINFO"];
            //flayer.Table.Refresh();
            //FeatureLayer lyrTemp = (FeatureLayer)mapControl1.Map.Layers["JKINFO"];
            //if (lyrTemp != null)
            //{
            //    IFeatureEnumerator fen = (lyrTemp.Table as IFeatureCollection).GetFeatureEnumerator();

            //    int n = 0;
            //    while (fen.MoveNext()) n++;
            //}
            //MessageBox.Show(e.Feature.Centroid.x.ToString());
        }
Пример #23
0
        // return the first 10 rows from cities sorted by state in reverse
        private void menuItemCustomProcessor_Click(object sender, System.EventArgs e)
        {
            try
            {
                QueryFilter     filter  = new SqlExpressionFilter(null);            // all rows
                QueryDefinition qd      = new QueryDefinition(filter, "*");
                string []       orderby = new string[1];
                orderby[0] = "State Desc";
                qd.OrderBy = orderby;
                SearchResultProcessor srp = new MySearchResultProcessor(10);                 // stop after 10 rows
                SearchInfo            si  = new SearchInfo(srp, qd);

                IResultSetFeatureCollection fc = _catalog.Search("usa", si);
                // set map view to show search results
                _map.SetView(fc.Envelope);

                // show results as selection
                SelectFeatureCollection(fc);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Пример #24
0
        // select features in feature collection
        private void SelectFeatureCollection(IResultSetFeatureCollection fc)
        {
            // force map to update
            mapControl1.Update();

            _selection.Clear();
            _selection.Add(fc);
        }
Пример #25
0
 private void listView1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count == 1)
     {
         string PointCode = listView1.FocusedItem.Text;
         MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(strTempMapPointTable);
         SearchInfo searchInfo = MapInfo.Data.SearchInfoFactory.SearchWhere(string.Format("ID= '{0}'", PointCode.ToString().Replace("'", "''")));
         MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();
         MapInfo.Engine.Session.Current.Selections.DefaultSelection.Add(MapInfo.Engine.Session.Current.Catalog.Search(table, searchInfo));
         selectionFeature = MapInfo.Engine.Session.Current.Catalog.Search(table, searchInfo);
         if (selectionFeature != null && selectionFeature.Count != 0)
         {
             //mapControl1.Map.Center = selectionFeature[0].Geometry.Centroid;
             DPoint p = selectionFeature[0].Geometry.Centroid;
             mapControl1.Map.SetView(new DPoint(p.x, p.y),
            Session.Current.CoordSysFactory.CreateLongLat(DatumID.WGS84),
            108851.80);
         }
     }
 }
Пример #26
0
 public override bool ProcessRow(MIDataReader reader, IResultSetFeatureCollection features)
 {
     if (_maxRows == 0 || _rowCount < _maxRows) {
         features.Add(reader.Current);
     }
     _rowCount++;
     if (_maxRows > 0 && _rowCount >= _maxRows) return false; // stop processing of this table
     return true;
 }
Пример #27
0
        void t_Tick(object sender, EventArgs e)
        {
            JKINFOBLL bllJKINFO   = new JKINFOBLL();
            String    MDBFileName = (SysInfo.HTDBInfo[cbMaps.Text] as DBInfo).MDBPath;

            dtAllRow = bllJKINFO.GetList(MDBFileName, "").Tables[0].Copy();

            if (dtAllRow.Rows.Count <= 0)
            {
                return;
            }

            SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("1=1");

            si.QueryDefinition.Columns = new string[] { "*" };// new string[] { "NDH" }; //null
            IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search("JKINFO", si);

            foreach (MapInfo.Data.Feature f in ifs)
            {
                try
                {
                    Int32 iNDH = -1;
                    if (f["NDH"] != null)
                    {
                        try
                        {
                            iNDH = Convert.ToInt32(f["NDH"]);
                            foreach (DataRow dr in dtAllRow.Rows)
                            {
                                try
                                {
                                    if (iNDH == Convert.ToInt32(dr["NDH"]))
                                    {
                                        f["SJ"] = dr["SJ"];
                                        f["DW"] = dr["DW"];
                                        f.Table.UpdateFeature(f);
                                        break;
                                    }
                                }
                                catch
                                { }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                catch //(Exception ex)
                {
                    //MessageBox.Show("更新中发生错误:" + ex.Message);
                }
            }

            //SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("1=1");
            //si.QueryDefinition.Columns = new string[] { "*" } ;// new string[] { "NDH" }; //null
            //IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search("JKINFO", si);
            //if (ifs.Count <= 0)
            //{
            //    return;
            //}
            //else
            //{
            //    //FeatureLayer lyrTemp = (FeatureLayer)mapControl1.Map.Layers["JKINFO"];
            //    //if (lyrTemp != null)
            //    //{
            //    //    IFeatureEnumerator fen = (lyrTemp.Table as IFeatureCollection).GetFeatureEnumerator();
            //    //    while (fen.MoveNext())
            //    //    {
            //    //        Feature ftemp = fen.Current;
            //    //        try
            //    //        {
            //    //            Int32 iNDH = -1;
            //    //            if (ftemp["NDH"] == null)
            //    //                continue;
            //    //            try
            //    //            {
            //    //                iNDH = Convert.ToInt32(ftemp["NDH"]);
            //    //                foreach (DataRow dr in dtAllRow.Rows)
            //    //                {
            //    //                    try
            //    //                    {
            //    //                        if (iNDH == Convert.ToInt32(dr["NDH"]))
            //    //                        {
            //    //                            ftemp["SJ"] = dr["SJ"];
            //    //                            ftemp["DW"] = dr["DW"];
            //    //                            ftemp.Table.UpdateFeature(ftemp);
            //    //                            break;
            //    //                        }
            //    //                    }
            //    //                    catch
            //    //                    { }
            //    //                }
            //    //            }
            //    //            catch
            //    //            {
            //    //            }
            //    //        }
            //    //        catch (Exception ex)
            //    //        {
            //    //            MessageBox.Show("更新中发生错误:" + ex.Message);
            //    //        }
            //    //    }
            //    //}

            //    for (int i = 0; i < ifs.Count; i++)
            //    {
            //        try
            //        {
            //            Int32 iNDH = -1;
            //            if (ifs[i]["NDH"] != null)
            //            {
            //                try
            //                {
            //                    iNDH = Convert.ToInt32(ifs[i]["NDH"]);
            //                    foreach (DataRow dr in dtAllRow.Rows)
            //                    {
            //                        try
            //                        {
            //                            if (iNDH == Convert.ToInt32(dr["NDH"]))
            //                            {
            //                                ifs[i]["SJ"] = dr["SJ"];
            //                                ifs[i]["DW"] = dr["DW"];
            //                                ifs[i].Table.UpdateFeature(ifs[i]);
            //                                break;
            //                            }
            //                        }
            //                        catch
            //                        { }
            //                    }
            //                }
            //                catch
            //                {
            //                }
            //            }
            //        }
            //        catch //(Exception ex)
            //        {
            //            //MessageBox.Show("更新中发生错误:" + ex.Message);
            //        }

            //    }
            //}
        }
Пример #28
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]);
                }
            }
        }
Пример #29
0
        private void Search(string SearchWords)
        {
            //按照关键字查找图元
            Session.Current.Selections.DefaultSelection.Clear();
            bool bFind = false;

            //遍历图层
            double minx = double.MaxValue;
            double miny = double.MaxValue;
            double maxx = double.MinValue;
            double maxy = double.MinValue;

            foreach (IMapLayer layer in this.mapControl1.Map.Layers)
            {
                if (layer is FeatureLayer)
                {
                    Table tLayer = (layer as FeatureLayer).Table;
                    if (tLayer != null)
                    {
                        //生成查询条件 表中所有字段匹配即可
                        string Where = "0=1";
                        foreach (Column c in (layer as FeatureLayer).Table.TableInfo.Columns)
                        {
                            if ("Obj".Equals(c.Alias) || "MI_Style".Equals(c.Alias))
                            {
                                continue;
                            }
                            Where += " or " + c.Alias + " like '%" + SearchWords + "%'";
                        }
                        //查找
                        SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere(Where);
                        IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(tLayer, si);
                        if (ifs.Count > 0)
                        {
                            //查询结果选中并定位到地图中兴
                            Session.Current.Selections.DefaultSelection.Add(ifs);
                            //this.mapControl1.Map.Center = ifs[0].Geometry.Centroid;
                            bFind = true;
                        }

                        foreach (Feature f in ifs)
                        {
                            if (f.Geometry.Centroid.x > maxx)
                            {
                                maxx = f.Geometry.Centroid.x;
                            }

                            if (f.Geometry.Centroid.y > maxy)
                            {
                                maxy = f.Geometry.Centroid.y;
                            }

                            if (f.Geometry.Centroid.x < minx)
                            {
                                minx = f.Geometry.Centroid.x;
                            }

                            if (f.Geometry.Centroid.y < miny)
                            {
                                miny = f.Geometry.Centroid.y;
                            }
                        }
                    }
                }
            }
            if (!bFind)
            {
                MessageBox.Show("未找到查找的内容!");
            }
            else
            {
                if (minx == maxx && miny == maxy)
                {
                    this.mapControl1.Map.Center = new DPoint(minx, miny);;
                }
                else
                {
                    this.mapControl1.Map.Bounds = new DRect(minx, miny, maxx, maxy);
                }
            }
        }
Пример #30
0
 public override void BeginProcessingTable(IResultSetFeatureCollection features)
 {
     _rowCount = 0;
 }
Пример #31
0
 public override void BeginProcessingTable(IResultSetFeatureCollection features)
 {
     _rowCount=0;
 }