Example #1
0
        // If you select the ICustomTypeDescriptor implemented by RowStructure into a
        // property grid, the values are somehow missing, so copy them over to a class
        // that works.
        private AdhocPropertyList CreatePropertyList(ShapefileDataReader sfdr)
        {
            object[] vals = new object[sfdr.FieldCount - 1]; // ignore the geometry column
            sfdr.GetValues(vals);
            AdhocPropertyList result = new AdhocPropertyList(vals.Length);

            for (int i = 0; i < vals.Length; i++)
            {
                string name = sfdr.GetName(i + 1);                        // yes it's +1
                result.Add(new AdhocProperty(name, vals[i], true, true)); // but the value isn't!
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Display the attributes of a specific row on this property page
        /// </summary>
        /// <param name="row">The row of interest (not null)</param>
        /// <exception cref="ArgumentNullException">If the supplied row is null</exception>
        internal void SetRow(Row row)
        {
            if (row == null)
            {
                throw new ArgumentNullException();
            }

            m_Row = row;

            // Set the text on the tab
            this.Text = row.Table.TableName;

            // We'll display any expanded domain values if we can
            IColumnDomain[] cds = row.Table.ColumnDomains;

            // Hmm, there isn't a PropertyGrid.DataSource property, so do it the
            // hard way (is there a better way?)

            DataRow   data  = row.Data;
            DataTable table = data.Table;

            object[]          items = data.ItemArray;
            AdhocPropertyList props = new AdhocPropertyList(items.Length);

            for (int i = 0; i < items.Length; i++)
            {
                DataColumn    dc         = table.Columns[i];
                string        columnName = dc.ColumnName;
                AdhocProperty item       = new AdhocProperty(columnName, items[i]);
                item.ReadOnly = true;

                // If the column is associated with a domain, lookup the expanded value and
                // record as the item's description

                IColumnDomain cd = Array.Find <IColumnDomain>(cds, t => String.Compare(t.ColumnName, columnName, true) == 0);

                if (cd != null)
                {
                    string shortValue = items[i].ToString();
                    string longValue  = cd.Domain.Lookup(m_DataServer.ConnectionString, shortValue);
                    item.Description = longValue;
                }

                props.Add(item);
            }

            propertyGrid.SelectedObject = props;
        }
Example #3
0
        public ShapeFile(string fileName)
        {
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException();
            }

            m_MapName = fileName;
            IEditSpatialIndex index = new SpatialIndex();

            ShapefileDataReader sfdr = Shapefile.CreateDataReader(fileName, new GeometryFactory());
            ShapefileHeader     hdr  = sfdr.ShapeHeader;
            Envelope            ex   = hdr.Bounds;

            m_Extent = new Window(ex.MinX, ex.MinY, ex.MaxX, ex.MaxY);

            foreach (object o in sfdr)
            {
                // You get back an instance of GisSharpBlog.NetTopologySuite.IO.RowStructure, but
                // that's internal, so cast to the interface it implements (we'll attach this to
                // the geometry we wrap).
                //ICustomTypeDescriptor row = (ICustomTypeDescriptor)o;
                AdhocPropertyList row  = CreatePropertyList(sfdr);
                NTS.Geometry      geom = sfdr.Geometry;
                geom.UserData = row;

                List <NTS.Geometry> geoms = GetBasicGeometries(geom);
                foreach (NTS.Geometry g in geoms)
                {
                    g.UserData = row;
                    if (g is NTS.Point)
                    {
                        index.Add(new PointWrapper((NTS.Point)g));
                    }
                    else
                    {
                        index.Add(new GeometryWrapper(g));
                    }
                }
            }

            // Don't permit any further additions
            m_Index = index;
        }
Example #4
0
        /// <summary>
        /// Display the attributes of a specific row on this property page
        /// </summary>
        /// <param name="row">The row of interest (not null)</param>
        /// <exception cref="ArgumentNullException">If the supplied row is null</exception>
        internal void SetRow(Row row)
        {
            if (row == null)
                throw new ArgumentNullException();

            m_Row = row;

            // Set the text on the tab
            this.Text = row.Table.TableName;

            // We'll display any expanded domain values if we can
            IColumnDomain[] cds = row.Table.ColumnDomains;

            // Hmm, there isn't a PropertyGrid.DataSource property, so do it the
            // hard way (is there a better way?)

            DataRow data = row.Data;
            DataTable table = data.Table;
            object[] items = data.ItemArray;
            AdhocPropertyList props = new AdhocPropertyList(items.Length);

            for (int i=0; i<items.Length; i++)
            {
                DataColumn dc = table.Columns[i];
                string columnName = dc.ColumnName;
                AdhocProperty item = new AdhocProperty(columnName, items[i]);
                item.ReadOnly = true;

                // If the column is associated with a domain, lookup the expanded value and
                // record as the item's description

                IColumnDomain cd = Array.Find<IColumnDomain>(cds, t => String.Compare(t.ColumnName, columnName, true) == 0);

                if (cd != null)
                {
                    string shortValue = items[i].ToString();
                    string longValue = cd.Domain.Lookup(m_DataServer.ConnectionString, shortValue);
                    item.Description = longValue;
                }

                props.Add(item);
            }

            propertyGrid.SelectedObject = props;
        }
Example #5
0
        // If you select the ICustomTypeDescriptor implemented by RowStructure into a
        // property grid, the values are somehow missing, so copy them over to a class
        // that works.
        private AdhocPropertyList CreatePropertyList(ShapefileDataReader sfdr)
        {
            object[] vals = new object[sfdr.FieldCount-1]; // ignore the geometry column
            sfdr.GetValues(vals);
            AdhocPropertyList result = new AdhocPropertyList(vals.Length);

            for(int i=0; i<vals.Length; i++)
            {
                string name = sfdr.GetName(i+1); // yes it's +1
                result.Add(new AdhocProperty(name, vals[i], true, true)); // but the value isn't!
            }

            return result;
        }