Exemplo n.º 1
0
        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();
                axRenderControl1.FeatureManager.UnhighlightAll();

                IRowBuffer        row   = null;
                int               index = 0;
                List <IRowBuffer> list  = new List <IRowBuffer>();
                this.Text = "开始粗查询";
                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);
                    }
                    this.Text = "开始细查询";
                    foreach (IRowBuffer r in list)
                    {
                        index++;
                        int geometryIndex = -1;
                        geometryIndex = r.FieldIndex("Geometry");
                        if (geometryIndex != -1)
                        {
                            IModelPoint        modelPoint = r.GetValue(geometryIndex) as IModelPoint;
                            IModel             model      = (fc.FeatureDataSet as IResourceManager).GetModel(modelPoint.ModelName);
                            IGeometryConvertor gc         = new GeometryConvertor();
                            this.Text = "正在计算第" + index.ToString() + "个IMultiTriMesh是否与线相交";
                            IMultiTriMesh triMesh = gc.ModelPointToTriMesh(model, modelPoint, false);

                            if (triMesh != null)
                            {
                                ILine l = geoFactory.CreateGeometry(gviGeometryType.gviGeometryLine, gviVertexAttribute.gviVertexAttributeZ) as ILine;
                                l.StartPoint = polyline.StartPoint;
                                l.EndPoint   = polyline.EndPoint;
                                IVector3 v3 = triMesh.LineSegmentIntersect(l);
                                if (v3 != null)
                                {
                                    string    fid     = "";
                                    string    fName   = "";
                                    string    groupId = "";
                                    IEnvelope env     = null;
                                    int       fidPos  = r.FieldIndex(fc.FidFieldName);
                                    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 == "groupid")
                                        {
                                            groupId = r.GetValue(i).ToString();
                                        }
                                        else if (r.Fields.Get(i).Name == "Name")
                                        {
                                            fName = 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, GroupId = groupId, Name = fName, 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)
                {
                    //Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
            }
        }