예제 #1
0
        private bool HaveOne(FacilityClass facc, IGeometry pGeo)
        {
            bool haveone = false;

            string[] fc2D = facc.Fc2D.Split(';');
            if (fc2D.Length == 0)
            {
                return(false);
            }
            string           facID  = fc2D[0];
            DF2DFeatureClass dffacc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(facID);
            //如果图层不显示,则不查询
            TreeNodeComLayer treeLayer = dffacc.GetTreeLayer();

            if (treeLayer == null || !treeLayer.Visible)
            {
                return(false);
            }

            IFeatureClass  fc     = dffacc.GetFeatureClass();
            ISpatialFilter filter = new SpatialFilter();

            filter            = new SpatialFilter();
            filter.Geometry   = pGeo;
            filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            IFeatureCursor cursor  = fc.Search(filter, false);
            IFeature       feature = cursor.NextFeature();

            if (feature != null)
            {
                haveone = true;
                DataTable dt = new DataTable();
                dt.TableName = facc.Name;
                DataColumn oidcol = new DataColumn();
                oidcol.ColumnName = "oid";
                oidcol.Caption    = "ID";
                dt.Columns.Add(oidcol);
                foreach (DFDataConfig.Class.FieldInfo fitemp in facc.FieldInfoCollection)
                {
                    if (!fitemp.CanQuery)
                    {
                        continue;
                    }
                    DataColumn col = new DataColumn();
                    col.ColumnName = fitemp.Name;
                    col.Caption    = fitemp.Alias;
                    dt.Columns.Add(col);
                }

                DataRow dtRow = dt.NewRow();
                dtRow["oid"] = feature.get_Value(feature.Fields.FindField("OBJECTID"));
                foreach (DataColumn col in dt.Columns)
                {
                    int index1 = feature.Fields.FindField(col.ColumnName);
                    if (index1 < 0)
                    {
                        continue;
                    }
                    object obj1 = GetFieldValueByIndex(feature, index1);
                    string str  = "";
                    if (obj1 != null)
                    {
                        IField field = feature.Fields.get_Field(index1);
                        switch (field.Type)
                        {
                        case esriFieldType.esriFieldTypeBlob:
                        case esriFieldType.esriFieldTypeGeometry:
                        case esriFieldType.esriFieldTypeRaster:
                            continue;

                        case esriFieldType.esriFieldTypeDouble:

                            double d;
                            if (double.TryParse(obj1.ToString(), out d))
                            {
                                str = d.ToString("0.00");
                            }
                            break;

                        default:
                            str = obj1.ToString();
                            break;
                        }
                    }
                    dtRow[col.ColumnName] = str;
                }
                dt.Rows.Add(dtRow);
                if (dt.Rows.Count > 0)
                {
                    this._dict[facc.Alias] = dt;
                }
            }
            return(haveone);
        }