Beispiel #1
0
        public int QueryValues(IRowBuffer row)
        {
            try
            {
                if (m_currentOGRFeature == null)
                {
                    return(-1);
                }

                // loop and only set values in the rowbuffer
                // that were requested from the fieldMap

                int count = m_esriQueryFieldMap.GetLength(0);

                for (int i = 0; i < count; i++)
                {
                    int esriFieldIndex = (int)m_esriQueryFieldMap.GetValue(i);

                    // have to skip 1) objectid and 2) geometry field or we will get an ESRI
                    // exception. Also have to skip anything that the query map is asking to ignore

                    if (esriFieldIndex == -1 ||
                        esriFieldIndex == m_pDataset.get_OIDFieldIndex(0) ||
                        esriFieldIndex == m_pDataset.get_ShapeFieldIndex(0))
                    {
                        continue;
                    }

                    try
                    {
                        IField valField = m_pDataset.get_Fields(0).get_Field(i);

                        object val = m_pDataset.get_mapped_value(m_currentOGRFeature, i);

                        row.set_Value(i, val);
                    }
                    catch (Exception ex)
                    {
                        // skip values that fail to be set but continue doing it anyway
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                }

                return(m_currentOGRFeature.GetFID());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(-1);
            }
        }
Beispiel #2
0
        public int QueryValues(IRowBuffer row)
        {
            try
            {
                if (m_currentOGRFeature == null)
                {
                    return(-1);
                }

                // Loop and only set values in the rowbuffer
                // that were requested by ArcGIS.
                //
                // Ignore the ArcObjects documentation because it says I should use the field map
                // and that is straight out incorrect. Only copy values if the fieldmap has any value
                // besides -1. Othewise, ignore whatever map it is asking to copy to and simply copy
                // to the right field.


                IFields pFields    = m_pDataset.get_Fields(0);
                int     fieldCount = pFields.FieldCount;

                for (int i = 0; i < fieldCount; i++)
                {
                    int esriFieldIndex = (int)m_esriQueryFieldMap.GetValue(i);

                    if (esriFieldIndex == -1 ||
                        i == m_pDataset.get_OIDFieldIndex(0) ||
                        i == m_pDataset.get_ShapeFieldIndex(0))
                    {
                        continue;
                    }

                    IField pField = pFields.get_Field(i);
                    object val    = null;

                    // DANGER - POTENTIAL BUG - Workaround. For some reason, in ArcGIS 10.1SP1 I am
                    // getting fields that should not be editable passed in to map into!!!?!? I am
                    // skipping those here. In theory, since we are the DataSource provider, we should be able to
                    // use a lower level set value that skips polymorphic behavior and hence allows
                    // the write to happen even in non-editable fields. Something analogous to
                    // ITableWrite::WriteRow, but for Rows. We don't have that, so I skip those values for those
                    // rows.
                    if (!pFields.get_Field(i).Editable)
                    {
                        continue;
                    }

                    try
                    {
                        val = m_pDataset.get_mapped_value(m_currentOGRFeature, i);

                        row.set_Value(i, val);
                    }
                    catch (Exception ex)
                    {
                        // skip values that fail to be set but continue doing it anyway
                        string msg = String.Format("OGRFID:[{0}] esriFieldName:[{1}] esriFieldIndex:[{2}] esriValue:[{3}] Exception:[{4}]",
                                                   m_currentOGRFeature.GetFID(),
                                                   pField.Name,
                                                   esriFieldIndex,
                                                   val != null ? val.ToString() : "<not set>",
                                                   ex.Message);
                        System.Diagnostics.Debug.WriteLine(msg);
                    }
                }

                return(m_currentOGRFeature.GetFID());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(-1);
            }
        }