Esempio n. 1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            IEnvelope extent;

            if (this.rdoCurrentMapExtend.Checked)
            {
                extent            = (this.Map as IActiveView).Extent;
                this.ClipGeometry = extent;
            }
            else if (this.rdoCustomExtend.Checked)
            {
                double num;
                double num2;
                double num3;
                double num4;
                if (!double.TryParse(this.txtBottom.Text, out num))
                {
                    MessageBox.Show("底部值输入错误!");
                    return;
                }
                if (!double.TryParse(this.txtLeft.Text, out num2))
                {
                    MessageBox.Show("左边值输入错误!");
                    return;
                }
                if (!double.TryParse(this.txtTop.Text, out num3))
                {
                    MessageBox.Show("顶部值输入错误!");
                    return;
                }
                if (!double.TryParse(this.txtRight.Text, out num4))
                {
                    MessageBox.Show("右边值输入错误!");
                    return;
                }
                extent = new EnvelopeClass
                {
                    XMin = num2,
                    XMax = num4,
                    YMax = num3,
                    YMin = num
                };
                this.ClipGeometry = extent;
            }
            else if (this.rdoLayerExtend.Checked)
            {
                IEnumGeometry        geometry;
                ITopologicalOperator @operator;
                if (this.cboLayers.SelectedIndex == -1)
                {
                    MessageBox.Show("请选择图层!");
                    return;
                }
                extent = null;
                ILayer layer = (this.cboLayers.SelectedItem as LayerObject).Layer;
                if (this.cboFeatures.SelectedIndex == 0)
                {
                    geometry = new EnumFeatureGeometryClass();
                    (geometry as IEnumGeometryBind).BindGeometrySource(null, (layer as IGeoFeatureLayer).FeatureClass);
                    @operator = new PolygonClass();
                    @operator.ConstructUnion(geometry);
                    this.ClipGeometry = @operator as IGeometry;
                }
                else if (this.cboFeatures.SelectedIndex == 1)
                {
                    IQueryFilter outputFilter = new SpatialFilterClass();
                    (outputFilter as ISpatialFilter).Geometry   = this.Extend;
                    (outputFilter as ISpatialFilter).SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    geometry = new EnumFeatureGeometryClass();
                    (geometry as IEnumGeometryBind).BindGeometrySource(outputFilter,
                                                                       (layer as IGeoFeatureLayer).FeatureClass);
                    IGeometryFactory3 factory   = new GeometryEnvironmentClass();
                    IGeometry         geometry2 = factory.CreateGeometryFromEnumerator(geometry);
                    int geometryCount           = (geometry2 as IGeometryCollection).GeometryCount;
                    @operator = new PolygonClass();
                    @operator.ConstructUnion(geometry2 as IEnumGeometry);
                    this.ClipGeometry = @operator as IGeometry;
                }
                else
                {
                    geometry = new EnumFeatureGeometryClass();
                    (geometry as IEnumGeometryBind).BindGeometrySource(null, (layer as IFeatureSelection).SelectionSet);
                    @operator = new PolygonClass();
                    @operator.ConstructUnion(geometry);
                    this.ClipGeometry = @operator as IGeometry;
                }
            }
            else
            {
                this.ClipGeometry = this.method_3(this.Map as IGraphicsContainerSelect);
            }
            base.DialogResult = DialogResult.OK;
        }
Esempio n. 2
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 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);
        }
 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);
 }
Esempio n. 6
0
        private void btnOKNextScale_Click(object sender, EventArgs e)
        {
            if (!CheckRequirements())
            {
                return;
            }

            IFeatureLayer buildingslayer = _utilitiesArcMap.FeatureLayer(this.cboBuildingLayer.Text);

            try
            {
                if (buildingslayer != null)
                {
                    int indexField           = _utilitiesArcMap.FindField(buildingslayer, "rsi_index");
                    int inspectionfieldindex = _utilitiesArcMap.FindField(buildingslayer, "rsi");

                    IFeatureClass     buildingsfeatureclass     = buildingslayer.FeatureClass;
                    IFeatureSelection buildingsfeatureselection = buildingslayer as IFeatureSelection;
                    if (buildingsfeatureselection.SelectionSet.Count > 0)
                    {
                        Update(1, buildingslayer);
                    }

                    IFeatureCursor featurecursor = null;
                    IQueryFilter   queryfilter   = new QueryFilterClass();
                    queryfilter.WhereClause = "\"rsi\" IS NULL";


                    if (indexField > -1)
                    {
                        queryfilter.SubFields = "rsi_index";
                        IQueryFilterDefinition queryFilterDef = (IQueryFilterDefinition)queryfilter;
                        queryFilterDef.PostfixClause = "ORDER BY rsi_index";
                    }

                    featurecursor = buildingsfeatureclass.Search(queryfilter, false);

                    IFeature feature = null;

                    while ((feature = featurecursor.NextFeature()) != null)
                    {
                        IPolygon  polygon  = feature.Shape as IPolygon;
                        IPolyline polyline = feature.Shape as IPolyline;

                        if ((polygon != null) || (polyline != null))
                        {
                            buildingsfeatureselection.Clear();
                            buildingsfeatureselection.Add(feature);
                            buildingsfeatureselection.SelectionChanged();
                            IEnumGeometry     enumgeometry     = new EnumFeatureGeometryClass();
                            IEnumGeometryBind enumgeometrybind = enumgeometry as IEnumGeometryBind;
                            enumgeometrybind.BindGeometrySource(null, buildingsfeatureselection.SelectionSet);
                            IGeometryFactory geometryfactory = new GeometryEnvironmentClass();
                            IGeometry        geometry        = geometryfactory.CreateGeometryFromEnumerator(enumgeometry);

                            double    scale    = _map.MapScale;
                            IEnvelope envelope = geometry.Envelope;
                            _activeView.Extent = envelope;
                            _map.MapScale      = scale;
                            _activeView.Refresh();

                            GetStatus();

                            return;
                        }

                        IPoint point = feature.Shape as IPoint;
                        if (point != null)
                        {
                            buildingsfeatureselection.Clear();
                            buildingsfeatureselection.Add(feature);
                            buildingsfeatureselection.SelectionChanged();
                            double    scale    = _map.MapScale;
                            IEnvelope envelope = _activeView.Extent;
                            envelope.CenterAt(point);
                            _activeView.Extent = envelope;
                            _map.MapScale      = scale;
                            _activeView.Refresh();

                            GetStatus();

                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Building Inspector", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                //_restartreport = false;
            }
        }
Esempio n. 7
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();
        }