示例#1
0
 private void GetResultSet(IFeatureClass fc, IQueryFilter filter, DataTable dt)
 {
     if (fc != null)
     {
         IFdeCursor cursor = null;
         try
         {
             if (filter != null)
             {
                 filter.PostfixClause = "order by oid asc";
             }
             // 查找所有记录
             cursor = fc.Search(filter, true);
             if (cursor != null)
             {
                 dt.BeginLoadData();
                 IRowBuffer fdeRow = null;
                 DataRow    dr     = null;
                 while ((fdeRow = cursor.NextRow()) != null)
                 {
                     dr = dt.NewRow();
                     for (int i = 0; i < dt.Columns.Count; ++i)
                     {
                         string strColName = dt.Columns[i].ColumnName;
                         int    nPos       = fdeRow.FieldIndex(strColName);
                         if (nPos == -1 || fdeRow.IsNull(nPos))
                         {
                             continue;
                         }
                         object v = fdeRow.GetValue(nPos);  // 从库中读取值
                         dr[i] = v;
                     }
                     dt.Rows.Add(dr);
                 }
                 dt.EndLoadData();
             }
         }
         catch (COMException ex)
         {
             System.Diagnostics.Trace.WriteLine(ex.Message);
         }
         finally
         {
             if (cursor != null)
             {
                 cursor.Dispose();
                 cursor = null;
             }
         }
     }
 }
示例#2
0
        private void GetResultSet(IFeatureClass fc, IQueryFilter filter, DataTable dt)
        {
            if (fc != null)
            {
                IFdeCursor cursor = null;
                try
                {
                    if (filter != null)
                    {
                        filter.PostfixClause = "order by oid asc";
                    }
                    // 查找所有记录
                    cursor = fc.Search(filter, true);
                    if (cursor != null)
                    {
                        dt.BeginLoadData();
                        IRowBuffer fdeRow = null;
                        DataRow    dr     = null;
                        while ((fdeRow = cursor.NextRow()) != null)
                        {
                            dr = dt.NewRow();
                            for (int i = 0; i < dt.Columns.Count; ++i)
                            {
                                string strColName = dt.Columns[i].ColumnName;
                                int    nPos       = fdeRow.FieldIndex(strColName);
                                if (nPos == -1 || fdeRow.IsNull(nPos))
                                {
                                    continue;
                                }
                                object v = fdeRow.GetValue(nPos);  // 从库中读取值
                                dr[i] = v;

                                if (i == 0)
                                {
                                    // 创建管子
                                    int       geoPos = fdeRow.FieldIndex("Geometry");
                                    IGeometry geo    = (IGeometry)fdeRow.GetValue(geoPos);
                                    if (geo.GeometryType == gviGeometryType.gviGeometryPolyline)
                                    {
                                        IPolyline       pl  = (IPolyline)fdeRow.GetValue(geoPos);
                                        IRenderPipeLine rpl = this.axRenderControl1.ObjectManager.CreateRenderPipeLine(pl, rootId);
                                        rpl.Radius = 10;
                                        rpl.Color  = System.Drawing.Color.Red;
                                        ArrayList rpls = new ArrayList();
                                        rpls.Add(rpl);
                                        pipeMap.Add(v, rpls);
                                    }
                                    else if (geo.GeometryType == gviGeometryType.gviGeometryMultiPolyline)
                                    {
                                        IMultiPolyline multiPolyline = geo as IMultiPolyline;
                                        ArrayList      rpls          = new ArrayList();
                                        for (int g = 0; g < multiPolyline.GeometryCount; g++)
                                        {
                                            IPolyline       plIndex = multiPolyline.GetGeometry(g) as IPolyline;
                                            IRenderPipeLine rpl     = this.axRenderControl1.ObjectManager.CreateRenderPipeLine(plIndex, rootId);
                                            rpl.Radius = 10;
                                            rpl.Color  = System.Drawing.Color.Red;
                                            rpls.Add(rpl);
                                        }
                                        pipeMap.Add(v, rpls);
                                    }
                                }
                            }
                            dt.Rows.Add(dr);
                        }
                        dt.EndLoadData();
                    }
                }
                catch (COMException ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.Message);
                }
                finally
                {
                    if (cursor != null)
                    {
                        cursor.Dispose();
                        cursor = null;
                    }
                }
            }
        }
示例#3
0
文件: MainForm.cs 项目: batuZ/Samples
        public void SelectFeaturesFromBaseLyr(IPolyline polyLine)
        {
            btn_analyse.Enabled              = false;
            btn_createLine.Enabled           = false;
            this.btnFlyToSourcePoint.Enabled = false;
            this.btnFlyToTargetPoint.Enabled = false;

            IFdeCursor cursor = null;

            try
            {
                this.dataGridView1.Rows.Clear();
                this.axRenderControl1.FeatureManager.UnhighlightAll();

                IRowBuffer        row   = null;
                int               index = 0;
                List <IRowBuffer> list  = new List <IRowBuffer>();
                foreach (IFeatureClass fc in fcMap.Keys)
                {
                    ISpatialFilter filter = new SpatialFilter();
                    filter.Geometry      = polyline;
                    filter.SpatialRel    = gviSpatialRel.gviSpatialRelEnvelope;
                    filter.GeometryField = "Geometry";
                    cursor = fc.Search(filter, false);
                    while ((row = cursor.NextRow()) != null)
                    {
                        list.Add(row);
                    }

                    foreach (IRowBuffer r in list)
                    {
                        index++;
                        int geometryIndex = -1;
                        geometryIndex = r.FieldIndex("Geometry");
                        if (geometryIndex != -1)
                        {
                            string    fid    = "";
                            IEnvelope env    = null;
                            int       fidPos = r.FieldIndex(fc.FidFieldName);
                            this.axRenderControl1.FeatureManager.HighlightFeature(fc, int.Parse(r.GetValue(fidPos).ToString()), System.Drawing.Color.Red);
                            for (int i = 0; i < r.FieldCount; i++)
                            {
                                string fieldName = r.Fields.Get(i).Name;
                                if (r.Fields.Get(i).Name == "oid")
                                {
                                    fid = r.GetValue(i).ToString();
                                }
                                else if (r.Fields.Get(i).Name == "Geometry")
                                {
                                    IGeometry geometry = r.GetValue(i) as IGeometry;
                                    if (geometry.GeometryType == gviGeometryType.gviGeometryPolyline)
                                    {
                                        geometry = geometry as IPolyline;
                                    }
                                    else if (geometry.GeometryType == gviGeometryType.gviGeometryMultiPolyline)
                                    {
                                        geometry = geometry as IMultiPolyline;
                                    }
                                    env = geometry.Envelope;
                                }
                            }
                            RowObject ro = new RowObject()
                            {
                                FID = fid, FeatureClass = fc, Envelop = env
                            };
                            if (!rowMap.ContainsKey(ro.FID))
                            {
                                rowMap.Add(ro.FID, ro);
                            }
                        }
                    } // end of foreach (IRowBuffer r in list)
                }     // end of foreach (IFeatureClass fc in fcMap.Keys)
                this.Text = "空间查询完成!";
                LoadGridView();
            }
            catch (Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
            finally
            {
                this.btn_analyse.Enabled         = true;
                this.btn_createLine.Enabled      = true;
                this.btnFlyToSourcePoint.Enabled = true;
                this.btnFlyToTargetPoint.Enabled = true;

                if (cursor != null)
                {
                    cursor.Dispose();
                    cursor = null;
                }
            }
        }
示例#4
0
文件: MainForm.cs 项目: batuZ/Samples
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            if (PickResult == null)
            {
                return;
            }

            this.dataGridView1.Rows.Clear();
            this.axRenderControl1.FeatureManager.UnhighlightAll();
            rowMap.Clear();

            IPickResult pr = PickResult;

            if (pr.Type != gviObjectType.gviObjectFeatureLayer)
            {
                return;
            }
            IFeatureLayerPickResult fpr   = pr as IFeatureLayerPickResult;
            IFeatureLayer           layer = fpr.FeatureLayer;
            IFeatureClassInfo       cinfo = layer.FeatureClassInfo;

            if (cinfo.DataSourceConnectionString.Contains("FireBird2x"))
            {
                return;
            }
            IDataSource     ds       = (new DataSourceFactory()).OpenDataSourceByString(cinfo.DataSourceConnectionString);
            IFeatureDataSet dset     = ds.OpenFeatureDataset(cinfo.DataSetName);
            IFeatureClass   shpfc    = dset.OpenFeatureClass(cinfo.FeatureClassName);
            IRowBuffer      shprow   = shpfc.GetRow(fpr.FeatureId);
            int             shpindex = shprow.FieldIndex("Geometry");
            IPolygon        polygon  = shprow.GetValue(shpindex) as IPolygon;

            if (polygon == null)
            {
                return;
            }

            IFdeCursor cursor = null;

            try
            {
                foreach (IFeatureClass fc in fcMap.Keys)
                {
                    IRowBuffer        row  = null;
                    List <IRowBuffer> list = new List <IRowBuffer>();

                    ISpatialFilter filter = new SpatialFilter();
                    filter.Geometry      = polygon;
                    filter.SpatialRel    = gviSpatialRel.gviSpatialRelEnvelope;
                    filter.GeometryField = "Geometry";
                    cursor = fc.Search(filter, false);
                    while ((row = cursor.NextRow()) != null)
                    {
                        list.Add(row);
                    }

                    foreach (IRowBuffer r in list)
                    {
                        int geometryIndex = -1;
                        geometryIndex = r.FieldIndex("Geometry");
                        if (geometryIndex != -1)
                        {
                            int oid = int.Parse(r.GetValue(0).ToString());
                            this.axRenderControl1.FeatureManager.HighlightFeature(fc, oid, System.Drawing.Color.Red);

                            string    fid = "";
                            IEnvelope env = null;
                            for (int i = 0; i < r.FieldCount; i++)
                            {
                                string fieldName = r.Fields.Get(i).Name;
                                if (r.Fields.Get(i).Name == "oid")
                                {
                                    fid = r.GetValue(i).ToString();
                                }
                                else if (r.Fields.Get(i).Name == "Geometry")
                                {
                                    IGeometry geometry = r.GetValue(i) as IModelPoint;
                                    env = geometry.Envelope;
                                }
                            }
                            RowObject ro = new RowObject()
                            {
                                FID = fid, FCGUID = fc.Guid.ToString(), FCName = fc.Name, FeatureClass = fc, Envelop = env
                            };
                            if (!rowMap.ContainsKey(ro.FID + "/" + ro.FCGUID))
                            {
                                rowMap.Add(ro.FID + "/" + ro.FCGUID, ro);
                            }
                        }
                    } // end of foreach (IRowBuffer r in list)
                }     // end of foreach (IFeatureClass fc in fcMap.Keys)
                this.Text = "分析完成!";
                LoadGridView();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (cursor != null)
                {
                    cursor.Dispose();
                    cursor = null;
                }
            }
        }