Esempio n. 1
0
        //空间信息查询确定按钮
        private void Btn_QueryOk_Click(object sender, EventArgs e)
        {
            //获得图层ID
            int iLyrID = -1;

            for (int i = 0; i < axMapControl_1.LayerCount; i++)
            {
                if (axMapControl_1.get_Layer(i).Name == Cbx_LyrName.Text)
                {
                    iLyrID = i;
                    break;
                }
            }

            //获取图层信息及要素集
            pFeaLyr = axMapControl_1.get_Layer(iLyrID) as IFeatureLayer;
            IFeatureClass pFC = pFeaLyr.FeatureClass;
            //获得字段的ID
            int iClmID = -1;

            for (int i = 0; i < pFC.Fields.FieldCount; i++)
            {
                if (pFC.Fields.get_Field(i).Name == "Name" || pFC.Fields.get_Field(i).Name == "name")
                {
                    iClmID = i;
                    break;
                }
            }
            //开始查询
            if (iClmID != -1)
            {
                //初始化一个条件过滤器
                IQueryFilter qfilter   = new QueryFilter();
                string       ColumName = pFC.Fields.get_Field(iClmID).Name;
                qfilter.WhereClause = ColumName + " like'%" + Txt_Query.Text + "%'";
                IFeatureCursor fCursor = pFC.Search(qfilter, false);
                //初始化数据表
                DataTable DT = new DataTable();
                //数据表字段填充
                for (int i = 0; i < fCursor.Fields.FieldCount; i++)
                {
                    DT.Columns.Add(fCursor.Fields.get_Field(i).Name, typeof(string));
                }

                //清除地图选择集
                axMapControl_1.Map.ClearSelection();
                //清除Gridview中的字段,解除gridcontrol数据源
                GridView_Info.Columns.Clear();
                GridControl_Info.DataSource = null;
                //数据填充
                for (int i = 0; i < pFC.FeatureCount(qfilter); i++)
                {
                    IFeature feature = fCursor.NextFeature();
                    axMapControl_1.Map.SelectFeature(axMapControl_1.get_Layer(iLyrID), feature);
                    DataRow dr = DT.NewRow();
                    for (int j = 0; j < feature.Fields.FieldCount; j++)
                    {
                        dr[j] = feature.get_Value(j).ToString();
                    }
                    DT.Rows.Add(dr);
                }
                //绑定结果是
                GridControl_Info.DataSource = DT;
                for (int i = 0; i < GridView_Info.Columns.Count; i++)
                {
                    if (GridView_Info.Columns[i].Name == "colshape" || GridView_Info.Columns[i].Name == "colShape")
                    {
                        GridView_Info.Columns[i].Visible = false;
                    }
                }


                //地图窗口缩放到选择位置
                IFeatureSelection featureSelection = pFeaLyr as IFeatureSelection;
                if (featureSelection.SelectionSet.Count == 0)
                {
                    return;
                }
                IEnumGeometryBind tEnumGeometryBind = new EnumFeatureGeometryClass();
                tEnumGeometryBind.BindGeometrySource(null, featureSelection.SelectionSet);
                IEnumGeometry    tEnumGeometry    = (IEnumGeometry)tEnumGeometryBind;
                IGeometryFactory tGeometryFactory = new GeometryEnvironmentClass();
                IGeometry        tGeometry        = tGeometryFactory.CreateGeometryFromEnumerator(tEnumGeometry);
                //缓冲处理,使处于边界的元素在视图中能够完全显示
                ITopologicalOperator mTopologicalOperator = (ITopologicalOperator)tGeometry;
                IGeometry            mPolygonBuffer       = mTopologicalOperator.Buffer(0.001) as IGeometry;
                axMapControl_1.Extent = mPolygonBuffer.Envelope;

                axMapControl_1.ActiveView.Refresh();
            }


            else
            {
                MessageBox.Show("该图层没有名称字段!!!");
            }
        }
        private void FlashFeature(IQueryFilter queryFilter)
        {
            if (_pipeData == null)
                _pipeData = new List<string>();
            else
                _pipeData.Clear();

            try
            {
                //---------------------------------------------------------------------
                // CHANGED: CR23 (Merged features)
                // Flash all the features relating to the selected incid at once.
                // This method may be triggered more than once if there are too
                // many to pass via the Named Pipes in one go.
                //
                IEnumGeometryBind enumGeometryBind = new EnumFeatureGeometryClass();
                enumGeometryBind.BindGeometrySource(null, _hluFeatureSelection.SelectionSet.Select(queryFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, null));
                IGeometryFactory geometryFactory = new GeometryEnvironmentClass();
                IGeometry geom = geometryFactory.CreateGeometryFromEnumerator((IEnumGeometry)enumGeometryBind);

                IMxDocument mxDoc = (IMxDocument)_application.Document;
                IActiveView activeView = mxDoc.FocusMap as IActiveView;
                IScreenDisplay screenDisplay = activeView.ScreenDisplay;
                //---------------------------------------------------------------------
                //---------------------------------------------------------------------
                // FIX: 018 Bring ArcGIS and MapInfo into line by flashing all features twice
                FlashGeometry(geom, screenDisplay, 300, 2);
                //---------------------------------------------------------------------
            }
            catch { }
        }
 private void ZoomSelectedCursor(IQueryFilter queryFilter)
 {
     if ((queryFilter == null) || (_hluFeatureClass == null) || (_hluView == null)) return;
     IEnumGeometryBind enumGeometryBind = new EnumFeatureGeometryClass();
     enumGeometryBind.BindGeometrySource(queryFilter, _hluFeatureClass);
     IGeometryFactory geometryFactory = new GeometryEnvironmentClass();
     IGeometry geom = geometryFactory.CreateGeometryFromEnumerator((IEnumGeometry)enumGeometryBind);
     _hluView.Extent = geom.Envelope;
     _hluView.PartialRefresh(esriViewDrawPhase.esriViewGeography, _hluLayer, _hluView.Extent);
 }
        private void ZoomSelected()
        {
            if ((_hluFeatureClass == null) || (_hluView == null)) return;

            if (_hluFeatureSelection == null)
                _hluFeatureSelection = (IFeatureSelection)_hluFeatureClass;

            if (_hluFeatureSelection.SelectionSet.Count == 0) return;

            IEnumGeometryBind enumGeometryBind = new EnumFeatureGeometryClass();
            enumGeometryBind.BindGeometrySource(null, _hluFeatureSelection.SelectionSet);
            IGeometryFactory geometryFactory = new GeometryEnvironmentClass();
            IGeometry geom = geometryFactory.CreateGeometryFromEnumerator((IEnumGeometry)enumGeometryBind);
            _hluView.Extent = geom.Envelope;
            _hluView.PartialRefresh(esriViewDrawPhase.esriViewGeography, _hluLayer, _hluView.Extent);
        }
Esempio n. 5
0
        // zooms to features in the map that correspond to selected features in the list view
        private void btnZoomSelected_Click(object sender, System.EventArgs e)
        {
            try
            {
                IQueryFilter pQueryFilter = new QueryFilterClass();
                IFeatureClass pFeatureClass = m_pFeatureLayer.FeatureClass;

                // build array of selected OIDs
                string[] OID = new string[lvGPS.SelectedItems.Count];
                for(int x = 0; x < lvGPS.SelectedItems.Count; x++)
                {
                    OID[x] = lvGPS.SelectedItems[x].Text;
                }

                string OIDs = String.Join(",",OID);

                // build the whereclause
                string whereclause = pFeatureClass.OIDFieldName + " IN (" + OIDs + ")";

                Debug.WriteLine(whereclause);

                pQueryFilter.WhereClause = whereclause;

                // bind query filter resultant geometry into a geometry bag
                IEnumGeometryBind pEnumBind = new EnumFeatureGeometryClass();
                IGeometryFactory pGeomFactory = new GeometryEnvironmentClass();
                pEnumBind.BindGeometrySource(pQueryFilter,pFeatureClass);
                IGeometryBag pGeometryBag = (IGeometryBag)pGeomFactory.CreateGeometryFromEnumerator((IEnumGeometry)pEnumBind);
                IGeometryCollection pGeomCollection = (IGeometryCollection)pGeometryBag;

                // TODO:
                //IMxDocument pMxDoc = (IMxDocument)m_pApp.Document;
                IActiveView pActiveView = (IActiveView)m_pISDUTExt.FocusMap; //pMxDoc.FocusMap;
                //util.Utils.Release(pMxDoc);

                IEnvelope pEnv = pGeometryBag.Envelope;
                if(pGeomCollection.GeometryCount == 1)
                {
                    // if only one point the do a pan instead of a zoom

                    IPoint pPoint = new PointClass();
                    pPoint.PutCoords(pEnv.XMin,pEnv.YMin);

                    // get SR of featureclass
                    IGeoDataset pGeodataset = (IGeoDataset)m_pFeatureLayer.FeatureClass;

                    pPoint.SpatialReference = pGeodataset.SpatialReference;

                    // project point to match focus map SR

                    // TODO:
                    //pMxDoc = (IMxDocument)m_pApp.Document;
                    pPoint.Project(m_pISDUTExt.FocusMap.SpatialReference);// pMxDoc.FocusMap.SpatialReference);
                    //util.Utils.Release(pMxDoc);

                    IEnvelope pPanEnv = pActiveView.Extent;
                    pPanEnv.CenterAt(pPoint);
                    pActiveView.Extent = pPanEnv;
                }
                else
                {
                    pEnv.Expand(1.1,1.1,true);
                    pActiveView.Extent = pEnv;
                }

                pActiveView.Refresh();
            }
            catch(Exception ex)
            {
                util.Logger.Write(" Descrip  : Zooms to features on the map the correspond with items selected in the list view." +
                                "\n Message  : " + ex.Message +
                                "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug);

                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
                Debug.WriteLine(ex.Message + "\n" + ex.StackTrace);
            }

            //lvGPS.Focus();
        }