예제 #1
0
        /// <summary>
        /// Adds shapefile feature attributes to a <see cref="MapFeature"/> as metadata.
        /// </summary>
        /// <param name="targetFeature">The <see cref="MapFeature"/> whose metadata will be updated.</param>
        /// <param name="sourceFeatureIndex">The index of the feature in the shapefile on which the <see cref="MapFeature"/> is based.</param>
        /// <remarks> Attributes with <see cref="DBNull"/> value are translated to a <c>null</c> value in the
        /// <see cref="MapFeature.MetaData"/>.</remarks>
        protected void CopyMetaDataIntoFeature(MapFeature targetFeature, int sourceFeatureIndex)
        {
            DataRow      dataRow = ShapeFile.GetAttributes(sourceFeatureIndex, 1).Rows[0];
            List <Field> columns = ShapeFile.DataTable.Columns.OfType <Field>().ToList();

            for (var i = 0; i < columns.Count; i++)
            {
                object dataRowValue = dataRow[i];

                object newValue = null;
                Field  column   = columns[i];

                if (!(dataRowValue is DBNull))
                {
                    if (column.TypeCharacter != 'C' && dataRowValue is string)
                    {
                        string nullValue = string.Join(string.Empty, Enumerable.Repeat('*', column.Length));
                        if (!Equals(dataRowValue, nullValue))
                        {
                            newValue = dataRowValue;
                        }
                    }
                    else
                    {
                        newValue = dataRowValue;
                    }
                }

                targetFeature.MetaData[column.ColumnName] = newValue;
            }
        }