コード例 #1
0
        public IFeature GetNodeFeatureAttributes(int nodeId, string[] attributes)
        {
            try
            {
                QueryFilter filter = new QueryFilter();
                filter.WhereClause = _fdb.DbColName("FDB_OID") + "=" + nodeId;
                filter.AddField("fcid");
                filter.AddField("oid");

                IFeature feature;
                using (IFeatureCursor cursor = GetNodeFeatures(filter))
                    feature = cursor.NextFeature;
                if (feature == null)
                {
                    return(null);
                }

                string          fcName  = _fdb.GetFeatureClassName((int)feature["fcid"]);
                IDatasetElement element = _dataset[fcName];
                if (element == null)
                {
                    return(null);
                }
                IFeatureClass fc = element.Class as IFeatureClass;
                if (fc == null)
                {
                    return(null);
                }

                filter = new QueryFilter();
                if (fc is IDatabaseNames)
                {
                    filter.WhereClause = ((IDatabaseNames)fc).DbColName(fc.IDFieldName) + "=" + Convert.ToInt32(feature["oid"]);
                }
                else
                {
                    filter.WhereClause = _fdb.DbColName(fc.IDFieldName) + "=" + Convert.ToInt32(feature["oid"]);
                }

                if (attributes == null)
                {
                    filter.AddField("*");
                }
                else
                {
                    foreach (string attribute in attributes)
                    {
                        if (attribute == "*")
                        {
                            filter.AddField(attribute);
                        }
                        else if (fc.FindField(attribute) != null)
                        {
                            filter.AddField(attribute);
                        }
                    }
                }

                using (IFeatureCursor cursor = fc.GetFeatures(filter))
                    feature = cursor.NextFeature;

                if (feature != null)
                {
                    feature.Fields.Add(new FieldValue("_classname", fc.Name));
                }

                return(feature);
            }
            catch
            {
                return(null);
            }
        }