예제 #1
0
        /// <summary>
        /// Builds from the given provider.
        /// </summary>
        /// <param name="provider">
        /// The base <see cref="SharpMap.Data.Providers.IProvider"/> 
		/// from witch initialize the <see cref="NtsProvider"/> instance.
        /// </param>
        private void BuildFromProvider(SharpMap.Data.Providers.IProvider provider)
        {            
            // Features list initialization
            features = new List<GisSharpBlog.NetTopologySuite.Features.Feature>(provider.GetFeatureCount());

            try
            {
                // Load all features from the given provider
                provider.Open();                
                Collection<uint> ids = provider.GetObjectIDsInView(provider.GetExtents());             
                foreach (uint id in ids)
                {
                    SharpMap.Data.FeatureDataRow dataRow = provider.GetFeature(id);
                    GisSharpBlog.NetTopologySuite.Geometries.Geometry geometry = GeometryConverter.ToNTSGeometry(dataRow.Geometry, geometryFactory);
                    GisSharpBlog.NetTopologySuite.Features.AttributesTable attributes = new GisSharpBlog.NetTopologySuite.Features.AttributesTable();
                    foreach (DataColumn column in dataRow.Table.Columns)
                    {                        
                        if (dataRow[column] == null || dataRow[column].GetType() == typeof(System.DBNull))
                            throw new ApplicationException("Null values not supported");
                        attributes.AddAttribute(column.ColumnName, dataRow[column]);
                    }
                    features.Add(new GisSharpBlog.NetTopologySuite.Features.Feature(geometry, attributes));
                }
            }
            finally
            {
                if (provider.IsOpen)
                    provider.Close();
            }
        }