private static object GetValueForField(string attributeName, IFields fields, IRasterIdentifyObj2 row)
        {
            var    fieldCount = fields.FieldCount;
            string value      = null;
            var    i          = 0;

            try
            {
                while (i <= fieldCount)
                {
                    string property;
                    row.GetPropAndValues(i, out property, out value);

                    if (string.Equals(property, attributeName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(value);
                    }
                    if (attributeName == "VALUE" && property.ToUpperInvariant() == "PIXEL VALUE")
                    {
                        return(value);
                    }

                    i = i + 1;
                }
            }
            catch (COMException)
            {
                // NoData pixel found
                value = null;
            }

            return(value);
        }
Ejemplo n.º 2
0
        private static ValueList GetPixelData(IMap map, IEnvelope extent, HashSet <string> includeFields)
        {
            ValueList result = new ValueList();

            for (int i = 0; i < map.LayerCount; i += 1)
            {
                ILayer layer = map.get_Layer(i);
                if (!layer.Visible)
                {
                    continue;
                }
                IIdentify id = layer as IIdentify;
                if (id == null)
                {
                    continue;
                }
                IArray data = id.Identify(extent);
                if (data != null)
                {
                    for (int j = 0; j < data.Count; j += 1)
                    {
                        object foundObj            = data.get_Element(j);
                        IRasterIdentifyObj2 raster = foundObj as IRasterIdentifyObj2;
                        IRowIdentifyObject  row    = foundObj as IRowIdentifyObject;
                        if (raster != null)
                        {
                            int    propertyIndex = 0;
                            string property;
                            string value;
                            while (true)
                            {
                                try {
                                    raster.GetPropAndValues(propertyIndex, out property, out value);
                                    if ((!"NoData".Equals(value)) &&
                                        ((includeFields == null) || includeFields.Contains(property)))
                                    {
                                        result.Add(property, value);
                                    }
                                    propertyIndex += 1;
                                } catch {
                                    break;
                                }
                            }
                            continue;
                        }
                        else if (row != null)
                        {
                            IFields fields = row.Row.Fields;
                            for (int k = 0; k < fields.FieldCount; k += 1)
                            {
                                string fieldName = fields.get_Field(k).Name;
                                if ((includeFields == null) ? (!result.ContainsKey(fieldName)) : includeFields.Contains(fieldName))
                                {
                                    result.Add(fieldName, row.Row.get_Value(k));
                                }
                            }
                        }
                    }
                    break;
                }
            }
            return(result);
        }